Commit 33bbcd4e authored by David Fernandez's avatar David Fernandez

Merge branch 'tancnle/tweak-code-styles-and-doc-on-external-approval-rules' into 'master'

Tweak code styles & doc on external approval rules API

See merge request gitlab-org/gitlab!57363
parents 4281600b c9bd3922
......@@ -645,7 +645,7 @@ DELETE /projects/:id/external_approval_rules/:rule_id
You can update an existing external approval rule for a project using the following endpoint:
```plaintext
PATCH /projects/:id/external_approval_rules/:rule_id
PUT /projects/:id/external_approval_rules/:rule_id
```
| Attribute | Type | Required | Description |
......
......@@ -6,32 +6,38 @@ module API
feature_category :source_code_management
before { authenticate! }
before { user_project }
before { check_feature_enabled!(@project) }
before do
authenticate!
check_feature_enabled!
end
helpers do
def check_feature_enabled!(project)
unauthorized! unless project.feature_available?(:compliance_approval_gates) &&
Feature.enabled?(:ff_compliance_approval_gates, project)
def check_feature_enabled!
unauthorized! unless user_project.feature_available?(:compliance_approval_gates) &&
Feature.enabled?(:ff_compliance_approval_gates, user_project)
end
end
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
segment ':id/external_approval_rules' do
params do
requires :name, type: String, desc: 'The name of the rule'
requires :external_url, type: String, desc: 'The URL to notify when MR receives new commits'
optional :protected_branch_ids, type: Array[Integer], coerce_with: ::API::Validations::Types::CommaSeparatedToIntegerArray.coerce, desc: 'The protected branch ids for this rule'
end
desc 'Create a new external approval rule' do
success ::API::Entities::ExternalApprovalRule
detail 'This feature is gated by the :ff_compliance_approval_gates feature flag.'
end
params do
requires :name, type: String, desc: 'The name of the external approval rule'
requires :external_url, type: String, desc: 'The URL to notify when MR receives new commits'
optional :protected_branch_ids,
type: Array[Integer],
coerce_with: ::API::Validations::Types::CommaSeparatedToIntegerArray.coerce,
desc: 'The protected branch ids for this rule'
end
post do
service = ::ExternalApprovalRules::CreateService.new(container: @project,
current_user: current_user,
params: declared(params, include_missing: false)).execute
service = ::ExternalApprovalRules::CreateService.new(
container: user_project,
current_user: current_user,
params: declared_params(include_missing: false)
).execute
if service.success?
present service.payload[:rule], with: ::API::Entities::ExternalApprovalRule
......@@ -47,42 +53,48 @@ module API
use :pagination
end
get do
unauthorized! unless current_user.can?(:admin_project, @project)
unauthorized! unless current_user.can?(:admin_project, user_project)
present paginate(@project.external_approval_rules), with: ::API::Entities::ExternalApprovalRule
present paginate(user_project.external_approval_rules), with: ::API::Entities::ExternalApprovalRule
end
segment ':rule_id' do
desc 'Delete an external approval rule' do
detail 'This feature is gated by the :ff_compliance_approval_gates feature flag.'
end
params do
requires :rule_id, type: Integer, desc: 'The approval rule ID'
requires :rule_id, type: Integer, desc: 'The ID of the external approval rule'
end
delete do
external_approval_rule = user_project.external_approval_rules.find(params[:rule_id])
destroy_conditionally!(external_approval_rule) do |external_approval_rule|
::ExternalApprovalRules::DestroyService.new(
container: @project,
container: user_project,
current_user: current_user
).execute(external_approval_rule)
end
end
desc 'Update new external approval rule' do
desc 'Update an external approval rule' do
success ::API::Entities::ExternalApprovalRule
detail 'This feature is gated by the :ff_compliance_approval_gates feature flag.'
end
params do
requires :rule_id, type: Integer, desc: 'The approval rule ID'
optional :name, type: String, desc: 'The approval rule\'s name'
requires :rule_id, type: Integer, desc: 'The ID of the external approval rule'
optional :name, type: String, desc: 'The name of the approval rule'
optional :external_url, type: String, desc: 'The URL to notify when MR receives new commits'
optional :protected_branch_ids, type: Array[Integer], coerce_with: ::API::Validations::Types::CommaSeparatedToIntegerArray.coerce, desc: 'The protected branch ids for this rule'
optional :protected_branch_ids,
type: Array[Integer],
coerce_with: ::API::Validations::Types::CommaSeparatedToIntegerArray.coerce,
desc: 'The protected branch ids for this rule'
end
put do
service = ::ExternalApprovalRules::UpdateService.new(container: @project,
current_user: current_user,
params: declared(params, include_missing: false)).execute
service = ::ExternalApprovalRules::UpdateService.new(
container: user_project,
current_user: current_user,
params: declared_params(include_missing: false)
).execute
if service.success?
present service.payload[:rule], with: ::API::Entities::ExternalApprovalRule
......
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