Commit 395fca14 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor members controller destroy action

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 7de75920
......@@ -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
......@@ -29,15 +29,6 @@ class Groups::GroupMembersController < Groups::ApplicationController
@group_member.update_attributes(member_params)
end
def destroy
Members::DestroyService.new(@group, current_user, id: params[:id]).execute(:all)
respond_to do |format|
format.html { redirect_to group_group_members_path(@group), notice: 'User was successfully removed from group.' }
format.js { head :ok }
end
end
def resend_invite
redirect_path = group_group_members_path(@group)
......
......@@ -18,18 +18,6 @@ class Projects::ProjectMembersController < Projects::ApplicationController
@project_member.update_attributes(member_params)
end
def destroy
Members::DestroyService.new(@project, current_user, params).
execute(:all)
respond_to do |format|
format.html do
redirect_to namespace_project_settings_members_path(@project.namespace, @project)
end
format.js { head :ok }
end
end
def resend_invite
redirect_path = namespace_project_settings_members_path(@project.namespace, @project)
......
......@@ -225,7 +225,7 @@ describe Projects::ProjectMembersController do
id: member
expect(response).to redirect_to(
namespace_project_project_members_path(project.namespace, project)
namespace_project_settings_members_path(project.namespace, project)
)
expect(project.members).to include member
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment