Commit d75edf1a authored by Rémy Coutable's avatar Rémy Coutable

Factorize access request routes into a new :access_requestable route concern

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent d71fbe0d
......@@ -8,7 +8,7 @@ module AccessRequestActions
notice: 'Your request for access has been queued for review.'
end
def approve
def approve_access_request
@member = access_requestable_resource.public_send(member_entity_name.pluralize).request.find(params[:id])
return render_403 unless can?(current_user, :"update_#{member_entity_name}", @member)
......
......@@ -53,9 +53,9 @@ module MembersHelper
def approve_request_member_path(member)
case member.source
when Project
approve_namespace_project_project_member_path(member.source.namespace, member.source, member)
approve_access_request_namespace_project_project_member_path(member.source.namespace, member.source, member)
when Group
approve_group_group_member_path(member.source, member)
approve_access_request_group_group_member_path(member.source, member)
else
raise ArgumentError.new('Unknown object class')
end
......
......@@ -32,7 +32,7 @@ Rails.application.routes.draw do
concern :access_requestable do
post :request_access, on: :collection
post :approve_access_request_access_request, on: :member
post :approve_access_request, on: :member
end
namespace :ci do
......@@ -414,16 +414,9 @@ Rails.application.routes.draw do
end
scope module: :groups do
resources :group_members, only: [:index, :create, :update, :destroy] do
collection do
delete :leave
post :request_access
end
member do
post :resend_invite
post :approve
end
resources :group_members, only: [:index, :create, :update, :destroy], concerns: :access_requestable do
post :resend_invite, on: :member
delete :leave, on: :collection
end
resource :avatar, only: [:destroy]
......@@ -777,10 +770,9 @@ Rails.application.routes.draw do
end
end
resources :project_members, except: [:new, :edit], constraints: { id: /[a-zA-Z.\/0-9_\-#%+]+/ } do
resources :project_members, except: [:new, :edit], constraints: { id: /[a-zA-Z.\/0-9_\-#%+]+/ }, concerns: :access_requestable do
collection do
delete :leave
post :request_access
# Used for import team
# from another project
......@@ -790,7 +782,6 @@ Rails.application.routes.draw do
member do
post :resend_invite
post :approve
end
end
......
......@@ -72,8 +72,8 @@ describe MembersHelper do
let(:project_member) { create(:project_member) }
let(:group_member) { create(:group_member) }
it { expect(approve_request_member_path(project_member)).to eq approve_namespace_project_project_member_path(project_member.source.namespace, project_member.source, project_member) }
it { expect(approve_request_member_path(group_member)).to eq approve_group_group_member_path(group_member.source, group_member) }
it { expect(approve_request_member_path(project_member)).to eq approve_access_request_namespace_project_project_member_path(project_member.source.namespace, project_member.source, project_member) }
it { expect(approve_request_member_path(group_member)).to eq approve_access_request_group_group_member_path(group_member.source, group_member) }
it { expect { approve_request_member_path(double(:member, source: 'foo')) }.to raise_error ArgumentError, 'Unknown object class' }
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