summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-06-01 18:17:03 +0200
committerRémy Coutable <remy@rymai.me>2016-06-14 13:07:26 +0200
commitd75edf1a9854b2ab609c7d3acf5eee1ca89e8db9 (patch)
treef727b323c1ce9fd4419aea65c8c4aac4f07570b0
parentd71fbe0dbdb3b7aba6f71e6d3d50daaa890769e9 (diff)
downloadgitlab-ce-d75edf1a9854b2ab609c7d3acf5eee1ca89e8db9.tar.gz
Factorize access request routes into a new :access_requestable route concern
Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r--app/controllers/concerns/access_request_actions.rb2
-rw-r--r--app/helpers/members_helper.rb4
-rw-r--r--config/routes.rb19
-rw-r--r--spec/helpers/members_helper_spec.rb4
4 files changed, 10 insertions, 19 deletions
diff --git a/app/controllers/concerns/access_request_actions.rb b/app/controllers/concerns/access_request_actions.rb
index 1b0a1fe3081..c4d22749d6a 100644
--- a/app/controllers/concerns/access_request_actions.rb
+++ b/app/controllers/concerns/access_request_actions.rb
@@ -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)
diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb
index 6599c59d1c9..bd84b8b239f 100644
--- a/app/helpers/members_helper.rb
+++ b/app/helpers/members_helper.rb
@@ -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
diff --git a/config/routes.rb b/config/routes.rb
index 2eccb19deff..f5574fb99a5 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/spec/helpers/members_helper_spec.rb b/spec/helpers/members_helper_spec.rb
index f1782146241..c2f10e1db75 100644
--- a/spec/helpers/members_helper_spec.rb
+++ b/spec/helpers/members_helper_spec.rb
@@ -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