2015-04-26 12:48:37 +05:30
|
|
|
class Groups::GroupMembersController < Groups::ApplicationController
|
2016-06-16 23:09:34 +05:30
|
|
|
include MembershipActions
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
# Authorize
|
2016-06-16 23:09:34 +05:30
|
|
|
before_action :authorize_admin_group_member!, except: [:index, :leave, :request_access]
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
def index
|
|
|
|
@project = @group.projects.find(params[:project_id]) if params[:project_id]
|
|
|
|
@members = @group.group_members
|
2016-06-16 23:09:34 +05:30
|
|
|
@members = @members.non_pending unless can?(current_user, :admin_group, @group)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
if params[:search].present?
|
|
|
|
users = @group.users.search(params[:search]).to_a
|
|
|
|
@members = @members.where(user_id: users)
|
|
|
|
end
|
|
|
|
|
|
|
|
@members = @members.order('access_level DESC').page(params[:page]).per(50)
|
2015-11-26 14:37:03 +05:30
|
|
|
|
|
|
|
@group_member = @group.group_members.new
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@group.add_users(params[:user_ids].split(','), params[:access_level], current_user)
|
|
|
|
|
|
|
|
redirect_to group_group_members_path(@group), notice: 'Users were successfully added.'
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2015-11-26 14:37:03 +05:30
|
|
|
@group_member = @group.group_members.find(params[:id])
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
return render_403 unless can?(current_user, :update_group_member, @group_member)
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
@group_member.update_attributes(member_params)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@group_member = @group.group_members.find(params[:id])
|
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
return render_403 unless can?(current_user, :destroy_group_member, @group_member)
|
|
|
|
|
|
|
|
@group_member.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to group_group_members_path(@group), notice: 'User was successfully removed from group.' }
|
2016-06-02 11:05:42 +05:30
|
|
|
format.js { head :ok }
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def resend_invite
|
|
|
|
redirect_path = group_group_members_path(@group)
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
@group_member = @group.group_members.find(params[:id])
|
|
|
|
|
|
|
|
if @group_member.invite?
|
|
|
|
@group_member.resend_invite
|
|
|
|
|
|
|
|
redirect_to redirect_path, notice: 'The invitation was successfully resent.'
|
|
|
|
else
|
|
|
|
redirect_to redirect_path, alert: 'The invitation has already been accepted.'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def member_params
|
|
|
|
params.require(:group_member).permit(:access_level, :user_id)
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
|
|
|
|
# MembershipActions concern
|
|
|
|
alias_method :membershipable, :group
|
|
|
|
|
|
|
|
def cannot_leave?
|
|
|
|
@group.last_owner?(current_user)
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|