Commit c749e95e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add packages_enabled attribute to Projects API

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent ae22cb3c
......@@ -780,6 +780,7 @@ PUT /projects/:id
| `mirror_trigger_builds` | boolean | no | Pull mirroring triggers builds |
| `only_mirror_protected_branches` | boolean | no | Only mirror protected branches |
| `mirror_overwrites_diverged_branches` | boolean | no | Pull mirror overwrites diverged branches |
| `packages_enabled` | boolean | no | Enable or disable packages repository feature |
>**Note**: If your HTTP repository is not publicly accessible,
add authentication information to the URL: `https://username:password@gitlab.company.com/group/project.git`
......
---
title: Add packages_enabled attribute to Projects API
merge_request: 8604
author:
type: changed
......@@ -25,6 +25,7 @@ module EE
expose :mirror_overwrites_diverged_branches, if: ->(project, _) { project.mirror? }
expose :external_authorization_classification_label,
if: ->(_, _) { License.feature_available?(:external_authorization_service) }
expose :packages_enabled, if: ->(project, _) { project.feature_available?(:packages) }
end
end
......
......@@ -19,6 +19,7 @@ module EE
optional :only_mirror_protected_branches, type: Grape::API::Boolean, desc: 'Only mirror protected branches'
optional :mirror_overwrites_diverged_branches, type: Grape::API::Boolean, desc: 'Pull mirror overwrites diverged branches'
optional :import_url, type: String, desc: 'URL from which the project is imported'
optional :packages_enabled, type: Grape::API::Boolean, desc: 'Enable project packages feature'
end
def apply_filters(projects)
......@@ -65,7 +66,8 @@ module EE
:approvals_before_merge,
:repository_storage,
:external_authorization_classification_label,
:import_url
:import_url,
:packages_enabled
]
end
end
......
......@@ -238,6 +238,40 @@ describe API::Projects do
expect(response).to have_gitlab_http_status(:forbidden)
end
end
describe 'updating packages_enabled attribute' do
it 'is enabled by default' do
expect(project.packages_enabled).to be true
end
context 'packages feature is allowed by license' do
before do
stub_licensed_features(packages: true)
end
it 'disables project packages feature' do
put(api("/projects/#{project.id}", user), packages_enabled: false)
expect(response).to have_gitlab_http_status(200)
expect(project.reload.packages_enabled).to be false
expect(json_response['packages_enabled']).to eq(false)
end
end
context 'packages feature is not allowed by license' do
before do
stub_licensed_features(packages: false)
end
it 'disables project packages feature but does not return packages_enabled attribute' do
put(api("/projects/#{project.id}", user), packages_enabled: false)
expect(response).to have_gitlab_http_status(200)
expect(project.reload.packages_enabled).to be false
expect(json_response['packages_enabled']).to be_nil
end
end
end
end
describe 'GET /projects' do
......@@ -317,6 +351,24 @@ describe API::Projects do
expect(json_response['external_authorization_classification_label']).to be_nil
end
end
describe 'packages_enabled attribute' do
it 'exposed when the feature is available' do
stub_licensed_features(packages: true)
get api("/projects/#{project.id}", user)
expect(json_response).to have_key 'packages_enabled'
end
it 'not exposed when the feature is available' do
stub_licensed_features(packages: false)
get api("/projects/#{project.id}", user)
expect(json_response).not_to have_key 'packages_enabled'
end
end
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