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