2015-03-12 11:08:48 -04:00
|
|
|
class Groups::GroupMembersController < Groups::ApplicationController
|
2013-06-17 09:51:43 -04:00
|
|
|
before_filter :group
|
|
|
|
|
|
|
|
# Authorize
|
|
|
|
before_filter :authorize_admin_group!
|
|
|
|
|
|
|
|
layout 'group'
|
|
|
|
|
|
|
|
def create
|
2014-09-14 12:32:51 -04:00
|
|
|
@group.add_users(params[:user_ids].split(','), params[:access_level])
|
2013-06-17 09:51:43 -04:00
|
|
|
|
2013-07-12 12:01:39 -04:00
|
|
|
redirect_to members_group_path(@group), notice: 'Users were successfully added.'
|
2013-06-17 09:51:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2014-09-14 12:32:51 -04:00
|
|
|
@member = @group.group_members.find(params[:id])
|
2014-06-26 08:00:09 -04:00
|
|
|
@member.update_attributes(member_params)
|
2013-06-17 09:51:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2015-03-13 11:16:51 -04:00
|
|
|
@group_member = @group.group_members.find(params[:id])
|
2014-10-20 06:18:07 -04:00
|
|
|
|
2015-03-13 11:16:51 -04:00
|
|
|
if can?(current_user, :destroy_group_member, @group_member) # May fail if last owner.
|
|
|
|
@group_member.destroy
|
2014-02-07 11:59:55 -05:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to members_group_path(@group), notice: 'User was successfully removed from group.' }
|
|
|
|
format.js { render nothing: true }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
return render_403
|
2013-06-17 09:51:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def group
|
2014-01-19 13:55:59 -05:00
|
|
|
@group ||= Group.find_by(path: params[:group_id])
|
2013-06-17 09:51:43 -04:00
|
|
|
end
|
|
|
|
|
2014-06-26 08:00:09 -04:00
|
|
|
def member_params
|
2014-09-14 14:52:54 -04:00
|
|
|
params.require(:group_member).permit(:access_level, :user_id)
|
2014-06-26 08:00:09 -04:00
|
|
|
end
|
2013-06-17 09:51:43 -04:00
|
|
|
end
|