diff options
author | Rémy Coutable <remy@rymai.me> | 2016-09-09 18:06:36 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-09-22 15:50:48 +0200 |
commit | 5dcdf1d51bbd5bde4ea9417dd4402571608c90f0 (patch) | |
tree | ef7617be280bdf72718d4ef806cc45a3fddbeea7 | |
parent | b3f0a82f501ce26717a6f9e57d91cb2b1f1a967b (diff) | |
download | gitlab-ce-5dcdf1d51bbd5bde4ea9417dd4402571608c90f0.tar.gz |
Ensure Members::ApproveAccessRequestService can fin a requester by ID
Signed-off-by: Rémy Coutable <remy@rymai.me>
4 files changed, 13 insertions, 3 deletions
diff --git a/app/controllers/concerns/membership_actions.rb b/app/controllers/concerns/membership_actions.rb index ba7c02b0ba7..b8ed2c159a7 100644 --- a/app/controllers/concerns/membership_actions.rb +++ b/app/controllers/concerns/membership_actions.rb @@ -9,7 +9,7 @@ module MembershipActions end def approve_access_request - Members::ApproveAccessRequestService.new(membershipable, current_user, user_id: params[:id]).execute + Members::ApproveAccessRequestService.new(membershipable, current_user, params).execute redirect_to polymorphic_url([membershipable, :members]) end diff --git a/app/services/members/approve_access_request_service.rb b/app/services/members/approve_access_request_service.rb index 0324f0bb4bd..c05d061b6a0 100644 --- a/app/services/members/approve_access_request_service.rb +++ b/app/services/members/approve_access_request_service.rb @@ -11,7 +11,8 @@ module Members end def execute - access_requester = source.requesters.find_by!(user_id: params[:user_id]) + condition = params[:user_id] ? { user_id: params[:user_id] } : { id: params[:id] } + access_requester = source.requesters.find_by!(condition) raise Gitlab::Access::AccessDeniedError if cannot_update_access_requester?(access_requester) diff --git a/spec/controllers/groups/group_members_controller_spec.rb b/spec/controllers/groups/group_members_controller_spec.rb index c34475976c6..92b97bf3d0c 100644 --- a/spec/controllers/groups/group_members_controller_spec.rb +++ b/spec/controllers/groups/group_members_controller_spec.rb @@ -2,9 +2,10 @@ require 'spec_helper' describe Groups::GroupMembersController do let(:user) { create(:user) } - let(:group) { create(:group) } describe '#index' do + let(:group) { create(:group) } + before do group.add_owner(user) stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC]) diff --git a/spec/services/members/approve_access_request_service_spec.rb b/spec/services/members/approve_access_request_service_spec.rb index 6951adc5828..6fca80b5613 100644 --- a/spec/services/members/approve_access_request_service_spec.rb +++ b/spec/services/members/approve_access_request_service_spec.rb @@ -83,6 +83,14 @@ describe Members::ApproveAccessRequestService, services: true do it_behaves_like 'a service approving an access request' do let(:source) { group } end + + context 'when given a :id' do + let(:params) { { id: project.requesters.find_by!(user_id: access_requester.id).id } } + + it_behaves_like 'a service approving an access request' do + let(:source) { project } + end + end end end end |