Groups base functional.
This commit is contained in:
parent
81e290a9b3
commit
9cc820080b
|
@ -29,8 +29,11 @@ class CollaboratorsController < ApplicationController
|
|||
|
||||
def update
|
||||
all_user_ids = []
|
||||
all_groups_ids = []
|
||||
puts params.inspect
|
||||
Relation::ROLES.each { |r|
|
||||
all_user_ids = all_user_ids | params[r.to_sym].keys if params[r.to_sym]
|
||||
all_user_ids = all_user_ids | params['user'][r.to_sym].keys if params['user'][r.to_sym]
|
||||
all_groups_ids = all_groups_ids | params['group'][r.to_sym].keys if params['group'][r.to_sym]
|
||||
}
|
||||
|
||||
# Remove relations
|
||||
|
@ -40,11 +43,17 @@ class CollaboratorsController < ApplicationController
|
|||
users_for_removing.each do |u|
|
||||
Relation.by_object(u).by_target(@project).each {|r| r.destroy}
|
||||
end
|
||||
groups_for_removing = @project.groups.select do |u|
|
||||
!all_groups_ids.map{|k| k.to_i}.include? u.id and @project.owner != u
|
||||
end
|
||||
groups_for_removing.each do |u|
|
||||
Relation.by_object(u).by_target(@project).each {|r| r.destroy}
|
||||
end
|
||||
|
||||
# Create relations
|
||||
Relation::ROLES.each { |r|
|
||||
#users_for_creating = users_for_creating params[:user].keys.map{|p| p.to_i} - @project.collaborators.map(&:id)
|
||||
params[r.to_sym].keys.each { |u|
|
||||
params['user'][r.to_sym].keys.each { |u|
|
||||
if relation = @project.relations.find_by_object_id_and_object_type(u, 'User')
|
||||
relation.update_attribute(:role, r)
|
||||
else
|
||||
|
@ -53,7 +62,17 @@ class CollaboratorsController < ApplicationController
|
|||
puts r
|
||||
relation.save!
|
||||
end
|
||||
} if params[r.to_sym]
|
||||
} if params['user'][r.to_sym]
|
||||
params['group'][r.to_sym].keys.each { |u|
|
||||
if relation = @project.relations.find_by_object_id_and_object_type(u, 'Group')
|
||||
relation.update_attribute(:role, r)
|
||||
else
|
||||
relation = @project.relations.build(:object_id => u, :object_type => 'Group', :role => r)
|
||||
puts relation.inspect
|
||||
puts r
|
||||
relation.save!
|
||||
end
|
||||
} if params['group'][r.to_sym]
|
||||
}
|
||||
|
||||
if @project.save
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
class MembersController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
is_related_controller!
|
||||
|
||||
belongs_to :group, :optional => true
|
||||
|
||||
# before_filter :find_target
|
||||
before_filter :find_users
|
||||
|
||||
def index
|
||||
redirect_to edit_group_members_path(parent)
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def edit
|
||||
if params[:id]
|
||||
@user = User.find params[:id]
|
||||
render :edit_rights and return
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
end
|
||||
|
||||
def update
|
||||
all_user_ids = []
|
||||
Relation::ROLES.each { |r|
|
||||
all_user_ids = all_user_ids | params[r.to_sym].keys if params[r.to_sym]
|
||||
}
|
||||
|
||||
# Remove relations
|
||||
users_for_removing = parent.members.select do |u|
|
||||
!all_user_ids.map{|k| k.to_i}.include? u.id and parent.owner != u
|
||||
end
|
||||
users_for_removing.each do |u|
|
||||
Relation.by_object(u).by_target(parent).each {|r| r.destroy}
|
||||
end
|
||||
|
||||
# Create relations
|
||||
Relation::ROLES.each { |r|
|
||||
#users_for_creating = users_for_creating params[:user].keys.map{|p| p.to_i} - @project.collaborators.map(&:id)
|
||||
params[r.to_sym].keys.each { |u|
|
||||
if relation = parent.objects.find_by_object_id_and_object_type(u, 'User')
|
||||
relation.update_attribute(:role, r)
|
||||
else
|
||||
relation = parent.objects.build(:object_id => u, :object_type => 'User', :role => r)
|
||||
puts relation.inspect
|
||||
puts r
|
||||
relation.save!
|
||||
end
|
||||
} if params[r.to_sym]
|
||||
}
|
||||
|
||||
if parent.save
|
||||
flash[:notice] = t("flash.members.successfully_changed")
|
||||
else
|
||||
flash[:error] = t("flash.members.error_in_changing")
|
||||
end
|
||||
redirect_to parent_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def find_users
|
||||
@users = User.all
|
||||
end
|
||||
|
||||
end
|
|
@ -29,12 +29,19 @@ class Ability
|
|||
can [:index, :destroy], AutoBuildList, :project_id => user.own_project_ids
|
||||
# If rules goes one by one CanCan joins them by 'OR' sql operator
|
||||
can :read, Project, :visibility => 'open'
|
||||
can :read, Group
|
||||
can :read, User
|
||||
can :manage_collaborators, Project do |project|
|
||||
project.relations.exists? :object_id => user.id, :object_type => 'User', :role => 'admin'
|
||||
end
|
||||
|
||||
can :manage_members, Group do |group|
|
||||
group.objects.exists? :object_id => user.id, :object_type => 'User', :role => 'admin'
|
||||
end
|
||||
|
||||
# Put here model names which objects can user create
|
||||
can :create, Project
|
||||
can :create, Group
|
||||
can :publish, BuildList do |build_list|
|
||||
build_list.can_published? && build_list.project.relations.exists?(:object_type => 'User', :object_id => user.id)
|
||||
end
|
||||
|
@ -51,6 +58,10 @@ class Ability
|
|||
can [:read, :update, :process_build, :build], Project, projects_in_relations_with(:role => ['writer', 'admin'], :object_type => 'User', :object_id => user.id) do |project|
|
||||
project.relations.exists?(:role => ['writer', 'admin'], :object_type => 'User', :object_id => user.id)
|
||||
end
|
||||
|
||||
can [:read, :update], Group, groups_in_relations_with(:role => ['writer', 'admin'], :object_type => 'User', :object_id => user.id) do |group|
|
||||
group.objects.exists?(:role => ['writer', 'admin'], :object_type => 'User', :object_id => user.id)
|
||||
end
|
||||
|
||||
can :manage, Platform, :owner_type => 'User', :owner_id => user.id
|
||||
#can :read, Platform, :members => {:id => user.id}
|
||||
|
@ -110,7 +121,7 @@ class Ability
|
|||
|
||||
# Sub query for platforms, projects relations
|
||||
# TODO: Replace table names list by method_missing way
|
||||
%w[platforms projects repositories].each do |table_name|
|
||||
%w[platforms projects repositories groups].each do |table_name|
|
||||
define_method table_name + "_in_relations_with" do |opts|
|
||||
query = "#{ table_name }.id IN (SELECT target_id FROM relations WHERE relations.target_type = '#{ table_name.singularize.camelize }'"
|
||||
opts.each do |key, value|
|
||||
|
@ -126,4 +137,4 @@ class Ability
|
|||
#def projects_in_relations_with(opts={})
|
||||
# ["projects.id IN (SELECT target_id FROM relations WHERE relations.object_id #{ opts[:object_id].class == Array ? 'IN (?)' : '= ?' } AND relations.object_type = '#{ opts[:object_type] }' AND relations.target_type = 'Platform') AND relations.role", opts[:object_id]]
|
||||
#end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,28 +22,29 @@
|
|||
= link_to user.name, user_path(user)
|
||||
%td
|
||||
- Relation::ROLES.each do |role|
|
||||
= check_box_tag "#{ role }[#{user.id}]", '1', ((@project.relations.exists? :object_id => user.id, :object_type => 'User', :role => role) ? :checked : nil), {:class => "user_role_chbx"}
|
||||
= label_tag "#{ role }[#{user.id}]", t("layout.collaborators.roles.#{ role }")
|
||||
= check_box_tag "user[#{ role }][#{user.id}]", '1', ((@project.relations.exists? :object_id => user.id, :object_type => 'User', :role => role) ? :checked : nil), {:class => "user_role_chbx"}
|
||||
= label_tag "user[#{ role }][#{user.id}]", t("layout.collaborators.roles.#{ role }")
|
||||
%td
|
||||
= user.uname
|
||||
/%h2.title= t("layout.groups.list_header")
|
||||
/%table.table
|
||||
/ %tr
|
||||
/ %th.first ID
|
||||
/ %th= t("activerecord.attributes.group.name")
|
||||
/ %th= t("activerecord.attributes.group.uname")
|
||||
/ %th.last= t("layout.collaborators.add")
|
||||
/ - @groups.each do |group|
|
||||
/ %tr{:class => cycle("odd", "even")}
|
||||
/ %td
|
||||
/ = group.id
|
||||
/ %td
|
||||
/ = link_to group.name, group_path(group)
|
||||
/ %td
|
||||
/ = group.uname
|
||||
/ %td.last
|
||||
/ = check_box_tag "group[#{group.id}]", '1', (@project.groups.include? group) ? :checked : nil
|
||||
/ = label_tag "group[#{group.id}]", t("layout.collaborators.add")
|
||||
%h2.title= t("layout.groups.list_header")
|
||||
%table.table
|
||||
%tr
|
||||
%th.first ID
|
||||
%th= t("activerecord.attributes.group.name")
|
||||
%th= t("activerecord.attributes.group.uname")
|
||||
%th.last= t("layout.collaborators.add")
|
||||
- @groups.each do |group|
|
||||
%tr{:class => cycle("odd", "even")}
|
||||
%td
|
||||
= group.id
|
||||
%td
|
||||
= link_to group.name, group_path(group)
|
||||
%td
|
||||
- Relation::ROLES.each do |role|
|
||||
= check_box_tag "group[#{role}][#{group.id}]", '1', ((@project.relations.exists? :object_id => group.id, :object_type => 'Group', :role => role) ? :checked : nil), {:class => "user_role_chbx"}
|
||||
= label_tag "group[#{role}][#{group.id}]", t("layout.collaborators.roles.#{role}")
|
||||
%td
|
||||
= group.uname
|
||||
.group.navform.wat-cf
|
||||
%button.button{:type => "submit"}
|
||||
= image_tag("web-app-theme/icons/tick.png", :alt => t("layout.save"))
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
.block.notice
|
||||
%h3= t("layout.groups.members")
|
||||
.content
|
||||
- @group.members.each do |member|
|
||||
%p= link_to member.name, member
|
||||
%p
|
||||
%ul
|
||||
- @group.members.each do |user|
|
||||
%li
|
||||
- if can? :read, user
|
||||
= link_to user.name, user_path(user)
|
||||
- else
|
||||
= user.name
|
||||
- if (@group.owner == user)
|
||||
= '(' + t("layout.owner") + ')'
|
||||
%br
|
||||
= link_to t("layout.groups.edit_members"), edit_group_members_path(@group) if can? :manage_members, @group
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
-if can? :index, Project
|
||||
%li{:class => controller.controller_path == 'projects' ? 'active' : '' }
|
||||
%a{:href => projects_path}= t("layout.menu.projects")
|
||||
-if can? :index, Group
|
||||
%li{:class => controller.controller_path == 'groups' ? 'active' : '' }
|
||||
%a{:href => groups_path}= t("layout.menu.groups")
|
||||
-if can? :index, Download
|
||||
%li{:class => controller.controller_path == 'downloads' ? 'active' : '' }
|
||||
%a{:href => downloads_path}= t("layout.menu.downloads")
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
.block
|
||||
.secondary-navigation
|
||||
%ul.wat-cf
|
||||
%li.first= link_to t("layout.members.back_to_group"), parent_path
|
||||
%li.active= link_to t("layout.members.edit"), edit_group_members_path(@group)
|
||||
.content
|
||||
.inner
|
||||
= form_tag group_members_path(parent) do
|
||||
%h2.title= t("layout.users.list_header")
|
||||
%table.table
|
||||
%tr
|
||||
%th.first ID
|
||||
%th= t("activerecord.attributes.user.name")
|
||||
%th= t("activerecord.attributes.user.roles")
|
||||
%th= t("activerecord.attributes.user.uname")
|
||||
- #TODO: Replace this Chelyabinsk add/remove collaborators method by more human method
|
||||
- @users.each do |user|
|
||||
%tr{:class => cycle("odd", "even")}
|
||||
%td
|
||||
= user.id
|
||||
%td
|
||||
= link_to user.name, user_path(user)
|
||||
%td
|
||||
- Relation::ROLES.each do |role|
|
||||
= check_box_tag "#{ role }[#{user.id}]", '1', ((parent.relations.exists? :object_id => user.id, :object_type => 'User', :role => role) ? :checked : nil), {:class => "user_role_chbx"}
|
||||
= label_tag "#{ role }[#{user.id}]", t("layout.members.roles.#{ role }")
|
||||
%td
|
||||
= user.uname
|
||||
.group.navform.wat-cf
|
||||
%button.button{:type => "submit"}
|
||||
= image_tag("web-app-theme/icons/tick.png", :alt => t("layout.save"))
|
||||
= t("layout.save")
|
||||
%span.text_button_padding= t("layout.or")
|
||||
= link_to t("layout.cancel"), group_path(parent), :class => "text_button_padding link_button"
|
||||
|
|
@ -13,8 +13,18 @@
|
|||
= user.name
|
||||
- if (@project.owner == user)
|
||||
= '(' + t("layout.owner") + ')'
|
||||
%br
|
||||
/%br
|
||||
-# if can? :update, @project
|
||||
%p
|
||||
%b
|
||||
= "#{t("layout.projects.groups")}:"
|
||||
%ul
|
||||
- @project.groups.each do |group|
|
||||
%li
|
||||
= link_to group.name, group_path(group)
|
||||
- if (@project.owner == group)
|
||||
= '(' + t("layout.owner") + ')'
|
||||
%br
|
||||
= link_to t("layout.projects.edit_collaborators"), edit_project_collaborators_path(@project) if can? :manage_collaborators, @project
|
||||
|
||||
/ %p
|
||||
|
|
|
@ -221,6 +221,10 @@ ru:
|
|||
roles_header: Роли для
|
||||
add_role: Добавить/Удалить роль
|
||||
|
||||
members:
|
||||
back_to_group: Вернуться к группе
|
||||
edit: Редактировать список
|
||||
roles: Роли
|
||||
|
||||
groups:
|
||||
list: Список
|
||||
|
@ -233,6 +237,7 @@ ru:
|
|||
show: Группа
|
||||
back_to_the_list: ⇐ К списку групп
|
||||
confirm_delete: Вы уверены, что хотите удалить эту группу?
|
||||
edit_members: Изменить список участников
|
||||
|
||||
users:
|
||||
list: Список
|
||||
|
@ -319,6 +324,10 @@ ru:
|
|||
successfully_changed: Список коллабораторов успешно изменен
|
||||
error_in_changing: Ошибка изменения списка коллабораторов
|
||||
|
||||
members:
|
||||
successfully_changed: Список участников успешно изменен
|
||||
error_in_changing: Ошибка изменения списка участников
|
||||
|
||||
auto_build_list:
|
||||
success: Сборка проекта автоматизорована!
|
||||
failed: Не удалось автоматизировать сборку!
|
||||
|
|
|
@ -105,6 +105,18 @@ Rosa::Application.routes.draw do
|
|||
end
|
||||
end
|
||||
|
||||
resources :groups do
|
||||
resources :members, :only => [:index, :edit, :update] do
|
||||
collection do
|
||||
get :edit
|
||||
post :update
|
||||
end
|
||||
member do
|
||||
post :update
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
resources :users, :groups do
|
||||
resources :platforms, :only => [:new, :create]
|
||||
|
||||
|
|
Loading…
Reference in New Issue