diff options
author | Rémy Coutable <remy@rymai.me> | 2018-02-16 15:10:22 +0100 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-02-27 16:02:22 +0100 |
commit | 1c88d92b3fe174a56080575a14d6b473f17f7d8f (patch) | |
tree | 7150c48b368e82d70f6bfc228c3d836c7be7c3ac /app/controllers | |
parent | e82f629be4b9c91e2611095cd4296e487ed137ef (diff) | |
download | gitlab-ce-1c88d92b3fe174a56080575a14d6b473f17f7d8f.tar.gz |
Improve Member servicesrc/reduce-delta-with-ce-in-controllers-ce
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/admin/groups_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/concerns/membership_actions.rb | 53 | ||||
-rw-r--r-- | app/controllers/groups/group_members_controller.rb | 20 | ||||
-rw-r--r-- | app/controllers/projects/project_members_controller.rb | 20 |
4 files changed, 39 insertions, 56 deletions
diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index a94726887d9..cc38608eda5 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -48,7 +48,7 @@ class Admin::GroupsController < Admin::ApplicationController def members_update member_params = params.permit(:user_ids, :access_level, :expires_at) - result = Members::CreateService.new(@group, current_user, member_params.merge(limit: -1)).execute + result = Members::CreateService.new(current_user, member_params.merge(limit: -1)).execute(@group) if result[:status] == :success redirect_to [:admin, @group], notice: 'Users were successfully added.' diff --git a/app/controllers/concerns/membership_actions.rb b/app/controllers/concerns/membership_actions.rb index 82fdb797d2a..7a6a00b8e13 100644 --- a/app/controllers/concerns/membership_actions.rb +++ b/app/controllers/concerns/membership_actions.rb @@ -3,33 +3,31 @@ module MembershipActions def create create_params = params.permit(:user_ids, :access_level, :expires_at) - result = Members::CreateService.new(membershipable, current_user, create_params).execute - - redirect_url = members_page_url + result = Members::CreateService.new(current_user, create_params).execute(membershipable) if result[:status] == :success - redirect_to redirect_url, notice: 'Users were successfully added.' + redirect_to members_page_url, notice: 'Users were successfully added.' else - redirect_to redirect_url, alert: result[:message] + redirect_to members_page_url, alert: result[:message] end end def update + update_params = params.require(root_params_key).permit(:access_level, :expires_at) member = membershipable.members_and_requesters.find(params[:id]) - @member = Members::UpdateService - .new(membershipable, current_user, member_params) + member = Members::UpdateService + .new(current_user, update_params) .execute(member) .present(current_user: current_user) respond_to do |format| - format.js { render 'shared/members/update' } + format.js { render 'shared/members/update', locals: { member: member } } end end def destroy member = membershipable.members_and_requesters.find(params[:id]) - Members::DestroyService.new(membershipable, current_user, params) - .execute(member) + Members::DestroyService.new(current_user).execute(member) respond_to do |format| format.html do @@ -51,7 +49,7 @@ module MembershipActions def approve_access_request access_requester = membershipable.requesters.find(params[:id]) Members::ApproveAccessRequestService - .new(membershipable, current_user, params) + .new(current_user, params) .execute(access_requester) redirect_to members_page_url @@ -59,8 +57,7 @@ module MembershipActions def leave member = membershipable.members_and_requesters.find_by!(user_id: current_user.id) - Members::DestroyService.new(membershipable, current_user) - .execute(member) + Members::DestroyService.new(current_user).execute(member) notice = if member.request? @@ -79,17 +76,43 @@ module MembershipActions end end + def resend_invite + member = membershipable.members.find(params[:id]) + + if member.invite? + member.resend_invite + + redirect_to members_page_url, notice: 'The invitation was successfully resent.' + else + redirect_to members_page_url, alert: 'The invitation has already been accepted.' + end + end + protected def membershipable raise NotImplementedError end + def root_params_key + case membershipable + when Namespace + :group_member + when Project + :project_member + else + raise "Unknown membershipable type: #{membershipable}!" + end + end + def members_page_url - if membershipable.is_a?(Project) + case membershipable + when Namespace + polymorphic_url([membershipable, :members]) + when Project project_project_members_path(membershipable) else - polymorphic_url([membershipable, :members]) + raise "Unknown membershipable type: #{membershipable}!" end end diff --git a/app/controllers/groups/group_members_controller.rb b/app/controllers/groups/group_members_controller.rb index 23ade14edfd..f210434b2d7 100644 --- a/app/controllers/groups/group_members_controller.rb +++ b/app/controllers/groups/group_members_controller.rb @@ -27,26 +27,6 @@ class Groups::GroupMembersController < Groups::ApplicationController @group_member = @group.group_members.new end - def resend_invite - redirect_path = group_group_members_path(@group) - - @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, :expires_at) - end - # MembershipActions concern alias_method :membershipable, :group end diff --git a/app/controllers/projects/project_members_controller.rb b/app/controllers/projects/project_members_controller.rb index 006d5df767c..e9b4679f94c 100644 --- a/app/controllers/projects/project_members_controller.rb +++ b/app/controllers/projects/project_members_controller.rb @@ -26,20 +26,6 @@ class Projects::ProjectMembersController < Projects::ApplicationController @project_member = @project.project_members.new end - def resend_invite - redirect_path = project_project_members_path(@project) - - @project_member = @project.project_members.find(params[:id]) - - if @project_member.invite? - @project_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 - def import @projects = current_user.authorized_projects.order_id_desc end @@ -58,12 +44,6 @@ class Projects::ProjectMembersController < Projects::ApplicationController notice: notice) end - protected - - def member_params - params.require(:project_member).permit(:user_id, :access_level, :expires_at) - end - # MembershipActions concern alias_method :membershipable, :project end |