From e430f312834b1023a242749d1fd262285512c915 Mon Sep 17 00:00:00 2001 From: Emily Ring Date: Mon, 16 Nov 2020 13:50:01 -0500 Subject: [PATCH 1/5] Add show route to project_approval_rules Updated api to include project_approval_rules show Updated associated tests --- ee/lib/api/project_approval_rules.rb | 11 ++++++++++ .../api/project_approval_rules_spec.rb | 22 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/ee/lib/api/project_approval_rules.rb b/ee/lib/api/project_approval_rules.rb index ef0688ce1ce98f..ff6f087cab55dc 100644 --- a/ee/lib/api/project_approval_rules.rb +++ b/ee/lib/api/project_approval_rules.rb @@ -33,6 +33,17 @@ class ProjectApprovalRules < ::API::Base end segment ':approval_rule_id' do + desc 'Get a single approval rule' do + success EE::API::Entities::ProjectApprovalRule + end + get do + authorize_create_merge_request_in_project + + approval_rule = user_project.approval_rules.find(params[:approval_rule_id]) + + present approval_rule, with: EE::API::Entities::ProjectApprovalRule, current_user: current_user + end + desc 'Update project approval rule' do success EE::API::Entities::ProjectApprovalRule end diff --git a/ee/spec/requests/api/project_approval_rules_spec.rb b/ee/spec/requests/api/project_approval_rules_spec.rb index 0733705bbc8cec..7f6e5536095159 100644 --- a/ee/spec/requests/api/project_approval_rules_spec.rb +++ b/ee/spec/requests/api/project_approval_rules_spec.rb @@ -11,6 +11,28 @@ let_it_be(:approver) { create(:user) } let_it_be(:other_approver) { create(:user) } + describe 'GET /projects/:id/approval_rules/:approval_rule_id' do + let!(:approval_rule) { create(:approval_project_rule, project: project) } + let(:url) { "/projects/#{project.id}/approval_rules/#{approval_rule.id}" } + + context 'when the request is correct' do + let(:developer) { project.creator } + + it 'matches the response schema', :aggregate_failures do + get api(url, developer) + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to match_response_schema('public_api/v4/project_approval_rule', dir: 'ee') + + rule = json_response + + expect(rule['approvals_required']).to eq(approval_rule.approvals_required) + expect(rule['id']).to eq(approval_rule.id) + expect(rule['name']).to eq(approval_rule.name) + end + end + end + describe 'GET /projects/:id/approval_rules' do let(:url) { "/projects/#{project.id}/approval_rules" } -- GitLab From 7374f70094173c5ea85c6c606adb342e33c79f2a Mon Sep 17 00:00:00 2001 From: Emily Ring Date: Tue, 17 Nov 2020 07:33:48 -0500 Subject: [PATCH 2/5] Added changelog and docs for approval rule update --- .../unreleased/emilyring-approval-show.yml | 5 + doc/api/merge_request_approvals.md | 98 +++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 changelogs/unreleased/emilyring-approval-show.yml diff --git a/changelogs/unreleased/emilyring-approval-show.yml b/changelogs/unreleased/emilyring-approval-show.yml new file mode 100644 index 00000000000000..a8300646a0f9c8 --- /dev/null +++ b/changelogs/unreleased/emilyring-approval-show.yml @@ -0,0 +1,5 @@ +--- +title: Add get api endpoint for a single project approval rule +merge_request: 47823 +author: +type: added diff --git a/doc/api/merge_request_approvals.md b/doc/api/merge_request_approvals.md index 89e4224c7357a5..b7862ff52a3e6c 100644 --- a/doc/api/merge_request_approvals.md +++ b/doc/api/merge_request_approvals.md @@ -173,6 +173,104 @@ GET /projects/:id/approval_rules ] ``` +### Get a single project-level rule + +> - Introduced 13.7. + +You can request information about a single project approval rules using the following endpoint: + +```plaintext +GET /projects/:id/approval_rules/:approval_rule_id +``` + +**Parameters:** + +| Attribute | Type | Required | Description | +|----------------------|---------|----------|-----------------------------------------------------------| +| `id` | integer | yes | The ID of a project | +| `approval_rule_id` | integer | yes | The ID of a approval rule | + +```json +{ + "id": 1, + "name": "security", + "rule_type": "regular", + "eligible_approvers": [ + { + "id": 5, + "name": "John Doe", + "username": "jdoe", + "state": "active", + "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon", + "web_url": "http://localhost/jdoe" + }, + { + "id": 50, + "name": "Group Member 1", + "username": "group_member_1", + "state": "active", + "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon", + "web_url": "http://localhost/group_member_1" + } + ], + "approvals_required": 3, + "users": [ + { + "id": 5, + "name": "John Doe", + "username": "jdoe", + "state": "active", + "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon", + "web_url": "http://localhost/jdoe" + } + ], + "groups": [ + { + "id": 5, + "name": "group1", + "path": "group1", + "description": "", + "visibility": "public", + "lfs_enabled": false, + "avatar_url": null, + "web_url": "http://localhost/groups/group1", + "request_access_enabled": false, + "full_name": "group1", + "full_path": "group1", + "parent_id": null, + "ldap_cn": null, + "ldap_access": null + } + ], + "protected_branches": [ + { + "id": 1, + "name": "master", + "push_access_levels": [ + { + "access_level": 30, + "access_level_description": "Developers + Maintainers" + } + ], + "merge_access_levels": [ + { + "access_level": 30, + "access_level_description": "Developers + Maintainers" + } + ], + "unprotect_access_levels": [ + { + "access_level": 40, + "access_level_description": "Maintainers" + } + ], + "code_owner_approval_required": "false" + } + ], + "contains_hidden_groups": false +} +``` + ### Create project-level rule > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/11877) in [GitLab Starter](https://about.gitlab.com/pricing/) 12.3. -- GitLab From 4e01d0ecfc9194e65e26388570e0e6491b8d99de Mon Sep 17 00:00:00 2001 From: Emily Ring Date: Tue, 17 Nov 2020 07:33:48 -0500 Subject: [PATCH 3/5] Move changelog to ee folder --- .../changelogs}/unreleased/emilyring-approval-show.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {changelogs => ee/changelogs}/unreleased/emilyring-approval-show.yml (100%) diff --git a/changelogs/unreleased/emilyring-approval-show.yml b/ee/changelogs/unreleased/emilyring-approval-show.yml similarity index 100% rename from changelogs/unreleased/emilyring-approval-show.yml rename to ee/changelogs/unreleased/emilyring-approval-show.yml -- GitLab From d46a2d559cbe685b81120159c2cbd92e08945b78 Mon Sep 17 00:00:00 2001 From: Emily Ring Date: Thu, 19 Nov 2020 11:57:37 -0500 Subject: [PATCH 4/5] Added extra tests to project_approval_rules --- .../requests/api/project_approval_rules_spec.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ee/spec/requests/api/project_approval_rules_spec.rb b/ee/spec/requests/api/project_approval_rules_spec.rb index 7f6e5536095159..58886f4bdcb309 100644 --- a/ee/spec/requests/api/project_approval_rules_spec.rb +++ b/ee/spec/requests/api/project_approval_rules_spec.rb @@ -12,14 +12,13 @@ let_it_be(:other_approver) { create(:user) } describe 'GET /projects/:id/approval_rules/:approval_rule_id' do - let!(:approval_rule) { create(:approval_project_rule, project: project) } - let(:url) { "/projects/#{project.id}/approval_rules/#{approval_rule.id}" } + let_it_be(:private_project) { create(:project, :private, creator: user, namespace: user.namespace) } + let!(:approval_rule) { create(:approval_project_rule, project: private_project) } + let(:url) { "/projects/#{private_project.id}/approval_rules/#{approval_rule.id}" } context 'when the request is correct' do - let(:developer) { project.creator } - it 'matches the response schema', :aggregate_failures do - get api(url, developer) + get api(url, user) expect(response).to have_gitlab_http_status(:ok) expect(response).to match_response_schema('public_api/v4/project_approval_rule', dir: 'ee') @@ -31,6 +30,14 @@ expect(rule['name']).to eq(approval_rule.name) end end + + context 'when authorization is missing' do + it 'does not display rule information' do + get api(url, user2) + + expect(response).to have_gitlab_http_status(:not_found) + end + end end describe 'GET /projects/:id/approval_rules' do -- GitLab From 907fb077ee726c945a40fa2599f7b4a567d79f8f Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Fri, 20 Nov 2020 11:38:37 +0000 Subject: [PATCH 5/5] Apply 1 suggestion(s) to 1 file(s) --- ee/spec/requests/api/project_approval_rules_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ee/spec/requests/api/project_approval_rules_spec.rb b/ee/spec/requests/api/project_approval_rules_spec.rb index 58886f4bdcb309..dccd2bef542359 100644 --- a/ee/spec/requests/api/project_approval_rules_spec.rb +++ b/ee/spec/requests/api/project_approval_rules_spec.rb @@ -31,7 +31,7 @@ end end - context 'when authorization is missing' do + context 'when the user is not authorized' do it 'does not display rule information' do get api(url, user2) -- GitLab