Commit 2ee5dcf2 authored by Aishwarya Subramanian's avatar Aishwarya Subramanian

API to delete group push rule

Adds ability for group owners and admins
to delete push rules for a group.
parent ce721bd7
......@@ -1170,10 +1170,14 @@ DELETE /groups/:id/share/:group_id
## Push Rules **(STARTER)**
> Introduced in [GitLab Starter](https://about.gitlab.com/pricing/) 13.4.
### Get group push rules **(STARTER)**
Get the [push rules](../user/group/index.md#group-push-rules-starter) of a group.
Only available to group owners and administrators.
```plaintext
GET /groups/:id/push_rule
```
......@@ -1215,6 +1219,8 @@ the `commit_committer_check` and `reject_unsigned_commits` parameters:
Adds [push rules](../user/group/index.md#group-push-rules-starter) to the specified group.
Only available to group owners and administrators.
```plaintext
POST /groups/:id/push_rule
```
......@@ -1260,6 +1266,8 @@ Response:
Edit push rules for a specified group.
Only available to group owners and administrators.
```plaintext
PUT /groups/:id/push_rule
```
......@@ -1300,3 +1308,17 @@ Response:
"max_file_size": 100
}
```
### Delete group push rule **(STARTER)**
Deletes the [push rules](../user/group/index.md#group-push-rules-starter) of a group.
Only available to group owners and administrators.
```plaintext
DELETE /groups/:id/push_rule
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the group](README.md#namespaced-path-encoding) |
---
title: API to delete group push rule
merge_request: 40293
author:
type: added
......@@ -3,8 +3,7 @@
module API
class GroupPushRule < Grape::API::Instance
before { authenticate! }
before { authorize_admin_group }
before { check_feature_availability! }
before { check_group_push_rule_access! }
before { authorize_change_param(user_group, :commit_committer_check, :reject_unsigned_commits) }
params do
......@@ -13,8 +12,8 @@ module API
resource :groups do
helpers do
def check_feature_availability!
not_found! unless user_group.feature_available?(:push_rules)
def check_group_push_rule_access!
not_found! unless can?(current_user, :change_push_rules, user_group)
end
params :push_rule_params do
......@@ -82,6 +81,16 @@ module API
render_validation_error!(push_rule)
end
end
desc 'Deletes group push rule' do
detail 'This feature was introduced in GitLab 13.4.'
end
delete ":id/push_rule" do
push_rule = user_group.push_rule
not_found! unless push_rule
destroy_conditionally!(push_rule)
end
end
end
end
......@@ -77,19 +77,19 @@ RSpec.describe API::GroupPushRule, 'GroupPushRule', api: true do
expect(json_response).to eq(
{
"author_email_regex" => attributes[:author_email_regex],
"branch_name_regex" => nil,
"commit_committer_check" => true,
"commit_message_negative_regex" => attributes[:commit_message_negative_regex],
"commit_message_regex" => attributes[:commit_message_regex],
"created_at" => group.reload.push_rule.created_at.iso8601(3),
"deny_delete_tag" => false,
"file_name_regex" => nil,
"id" => group.push_rule.id,
"max_file_size" => 100,
"member_check" => false,
"prevent_secrets" => true,
"reject_unsigned_commits" => true
"author_email_regex" => attributes[:author_email_regex],
"branch_name_regex" => nil,
"commit_committer_check" => true,
"commit_message_negative_regex" => attributes[:commit_message_negative_regex],
"commit_message_regex" => attributes[:commit_message_regex],
"created_at" => group.reload.push_rule.created_at.iso8601(3),
"deny_delete_tag" => false,
"file_name_regex" => nil,
"id" => group.push_rule.id,
"max_file_size" => 100,
"member_check" => false,
"prevent_secrets" => true,
"reject_unsigned_commits" => true
}
)
end
......@@ -292,8 +292,8 @@ RSpec.describe API::GroupPushRule, 'GroupPushRule', api: true do
it 'updates attributes as expected' do
expect { subject }.to change { group.reload.push_rule.author_email_regex }
.from(attributes[:author_email_regex])
.to(attributes_for_update[:author_email_regex])
.from(attributes[:author_email_regex])
.to(attributes_for_update[:author_email_regex])
end
context 'when push rule does not exist for group' do
......@@ -366,4 +366,46 @@ RSpec.describe API::GroupPushRule, 'GroupPushRule', api: true do
end
end
end
describe 'DELETE /groups/:id/push_rule' do
let_it_be(:push_rule) { create(:push_rule, **attributes) }
let_it_be(:group) { create(:group, push_rule: push_rule) }
context 'authorized user' do
context 'when licensed' do
include_context 'licensed features available'
context 'with group push rule' do
it do
delete api("/groups/#{group.id}/push_rule", admin)
expect(response).to have_gitlab_http_status(:no_content)
expect(group.reload.push_rule).to be nil
end
end
context 'when push rule does not exist' do
it 'returns not found' do
no_push_rule_group = create(:group)
delete api("/groups/#{no_push_rule_group.id}/push_rule", admin)
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
context 'when unlicensed' do
subject { delete api("/groups/#{group.id}/push_rule", admin) }
it_behaves_like 'not found when feature is unavailable'
end
end
context 'permissions' do
subject { delete api("/groups/#{group.id}/push_rule", user) }
it_behaves_like 'allow access to api based on role'
end
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