diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2017-04-17 17:44:30 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2017-04-17 17:44:30 +0300 |
commit | 395fca1493f6a4f8a40941faf43f47f5bf45f5a5 (patch) | |
tree | 3662e0523545a4315c3c701fb7cfb0c68ce03dde /app/controllers/concerns | |
parent | 7de75920f768b62322a3706fa1ad01d0282a7396 (diff) | |
download | gitlab-ce-395fca1493f6a4f8a40941faf43f47f5bf45f5a5.tar.gz |
Refactor members controller destroy action
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/controllers/concerns')
-rw-r--r-- | app/controllers/concerns/membership_actions.rb | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/app/controllers/concerns/membership_actions.rb b/app/controllers/concerns/membership_actions.rb index 41438f0afe6..b1bacc8ffe5 100644 --- a/app/controllers/concerns/membership_actions.rb +++ b/app/controllers/concerns/membership_actions.rb @@ -4,7 +4,7 @@ module MembershipActions def create status = Members::CreateService.new(membershipable, current_user, params).execute - redirect_url = polymorphic_url([membershipable, :members]) + redirect_url = members_page_url if status redirect_to redirect_url, notice: 'Users were successfully added.' @@ -13,6 +13,20 @@ module MembershipActions end end + def destroy + Members::DestroyService.new(membershipable, current_user, params). + execute(:all) + + respond_to do |format| + format.html do + message = "User was successfully removed from #{source_type}." + redirect_to members_page_url, notice: message + end + + format.js { head :ok } + end + end + def request_access membershipable.request_access(current_user) @@ -23,20 +37,20 @@ module MembershipActions def approve_access_request Members::ApproveAccessRequestService.new(membershipable, current_user, params).execute - redirect_to polymorphic_url([membershipable, :members]) + redirect_to members_page_url end def leave member = Members::DestroyService.new(membershipable, current_user, user_id: current_user.id). execute(:all) - source_type = membershipable.class.to_s.humanize(capitalize: false) notice = if member.request? "Your access request to the #{source_type} has been withdrawn." else "You left the \"#{membershipable.human_name}\" #{source_type}." end + redirect_path = member.request? ? member.source : [:dashboard, membershipable.class.to_s.tableize] redirect_to redirect_path, notice: notice @@ -47,4 +61,16 @@ module MembershipActions def membershipable raise NotImplementedError end + + def members_page_url + if membershipable.is_a?(Project) + project_settings_members_path(membershipable) + else + polymorphic_url([membershipable, :members]) + end + end + + def source_type + @source_type ||= membershipable.class.to_s.humanize(capitalize: false) + end end |