rosa-build/app/controllers/groups/members_controller.rb

39 lines
1.2 KiB
Ruby
Raw Normal View History

class Groups::MembersController < Groups::BaseController
2015-03-19 23:31:41 +00:00
before_action -> { authorize @group, :manage_members? }
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
2015-03-12 22:43:13 +00:00
raise Pundit::NotAuthorizedError if @group.owner_id.to_s == params[:member_id]
2014-11-11 23:50:15 +00:00
relation = @group.actors.where(actor_id: params[:member_id], actor_type: 'User').first
relation ||= @group.actors.build(actor_id: params[:member_id], actor_type: 'User')
relation.role = params[:role]
relation.save!
flash[:notice] = t("flash.members.successfully_changed")
2014-03-04 10:46:10 +00:00
redirect_to group_members_path(@group)
2011-12-05 12:32:18 +00:00
end
def remove
2014-11-11 23:50:15 +00:00
User.where(id: params[:members]).each do |user|
2014-03-04 10:46:10 +00:00
@group.remove_member(user)
end
2014-03-04 10:46:10 +00:00
redirect_to group_members_path(@group)
2011-12-05 12:32:18 +00:00
end
def add
2015-03-19 23:31:41 +00:00
@user = User.find_by(id: params[:member_id])
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])
flash[:notice] = t("flash.members.successfully_added")
else
flash[:error] = t("flash.members.error_in_adding")
end
2014-03-04 10:46:10 +00:00
redirect_to group_members_path(@group)
end
2011-12-05 12:32:18 +00:00
end