Commit 43ddc964 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'emilyring-approval-show' into 'master'

Add get api for a single project_approval_rule

See merge request gitlab-org/gitlab!47823
parents fde9a88e fe58526d
......@@ -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.
......
---
title: Add get api endpoint for a single project approval rule
merge_request: 47823
author:
type: added
......@@ -33,6 +33,17 @@ module API
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
......
......@@ -11,6 +11,35 @@ RSpec.describe API::ProjectApprovalRules do
let_it_be(:approver) { create(:user) }
let_it_be(:other_approver) { create(:user) }
describe 'GET /projects/:id/approval_rules/:approval_rule_id' do
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
it 'matches the response schema', :aggregate_failures do
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')
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
context 'when the user is not authorized' 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
let(:url) { "/projects/#{project.id}/approval_rules" }
......
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