2012-05-02 10:18:07 +01:00
|
|
|
class Groups::MembersController < Groups::BaseController
|
2014-03-11 07:39:25 +00:00
|
|
|
before_filter -> { authorize! :manage_members, @group }
|
2011-12-05 12:32:18 +00:00
|
|
|
|
|
|
|
def index
|
2014-03-24 18:28:03 +00:00
|
|
|
@members = @group.members.order(:uname) - [@group.owner]
|
2011-12-05 12:32:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2012-05-03 15:08:02 +01:00
|
|
|
params['user'].keys.each do |user_id|
|
2012-03-01 15:41:40 +00:00
|
|
|
role = params['user'][user_id]
|
2014-03-18 13:58:51 +00:00
|
|
|
if relation = @group.actors.where(actor_id: user_id, actor_type: 'User')
|
2014-03-04 10:46:10 +00:00
|
|
|
relation.update_all(role: role) if @group.owner.id.to_s != user_id
|
2012-03-01 15:41:40 +00:00
|
|
|
else
|
2014-03-04 10:46:10 +00:00
|
|
|
relation = @group.actors.build(actor_id: user_id, actor_type: 'User', role: role)
|
2012-03-01 15:41:40 +00:00
|
|
|
relation.save!
|
|
|
|
end
|
2012-05-03 15:08:02 +01:00
|
|
|
end if params['user']
|
2014-03-04 10:46:10 +00:00
|
|
|
if @group.save
|
2011-12-05 12:32:18 +00:00
|
|
|
flash[:notice] = t("flash.members.successfully_changed")
|
|
|
|
else
|
|
|
|
flash[:error] = t("flash.members.error_in_changing")
|
|
|
|
end
|
2014-03-04 10:46:10 +00:00
|
|
|
redirect_to group_members_path(@group)
|
2011-12-05 12:32:18 +00:00
|
|
|
end
|
|
|
|
|
2012-03-01 14:23:26 +00:00
|
|
|
def remove
|
2012-05-02 10:18:07 +01:00
|
|
|
all_user_ids = []
|
2012-05-03 15:43:23 +01:00
|
|
|
params['user_remove'].each do |user_id, remove|
|
2012-10-16 14:42:52 +01:00
|
|
|
all_user_ids << user_id if remove == ["1"]
|
2012-05-03 15:08:02 +01:00
|
|
|
end if params['user_remove']
|
2014-01-21 04:51:49 +00:00
|
|
|
User.where(id: all_user_ids).each do |user|
|
2014-03-04 10:46:10 +00:00
|
|
|
@group.remove_member(user)
|
2012-03-01 15:41:40 +00:00
|
|
|
end
|
2014-03-04 10:46:10 +00:00
|
|
|
redirect_to group_members_path(@group)
|
2011-12-05 12:32:18 +00:00
|
|
|
end
|
|
|
|
|
2011-12-09 23:40:13 +00:00
|
|
|
def add
|
2014-03-18 13:58:51 +00:00
|
|
|
@user = User.find_by uname: params[:user_uname]
|
2012-11-13 14:29:45 +00:00
|
|
|
if !@user
|
2014-01-21 04:51:49 +00:00
|
|
|
flash[:error] = t("flash.collaborators.wrong_user", uname: params[:user_uname])
|
2014-03-04 10:46:10 +00:00
|
|
|
elsif @group.add_member(@user, params[:role])
|
2012-11-13 14:29:45 +00:00
|
|
|
flash[:notice] = t("flash.members.successfully_added")
|
|
|
|
else
|
|
|
|
flash[:error] = t("flash.members.error_in_adding")
|
2011-12-09 23:40:13 +00:00
|
|
|
end
|
2014-03-04 10:46:10 +00:00
|
|
|
redirect_to group_members_path(@group)
|
2011-12-09 23:40:13 +00:00
|
|
|
end
|
2011-12-05 12:32:18 +00:00
|
|
|
end
|