Commit 80ec92bb authored by Mathieu Parent's avatar Mathieu Parent

Add pages_access_level to projects API

Fixes: #30972
parent bf0f387e
...@@ -62,6 +62,10 @@ module ProjectFeaturesCompatibility ...@@ -62,6 +62,10 @@ module ProjectFeaturesCompatibility
write_feature_attribute_string(:snippets_access_level, value) write_feature_attribute_string(:snippets_access_level, value)
end end
def pages_access_level=(value)
write_feature_attribute_string(:pages_access_level, value)
end
private private
def write_feature_attribute_boolean(field, value) def write_feature_attribute_boolean(field, value)
......
...@@ -322,7 +322,7 @@ class Project < ApplicationRecord ...@@ -322,7 +322,7 @@ class Project < ApplicationRecord
:pages_enabled?, :public_pages?, :private_pages?, :pages_enabled?, :public_pages?, :private_pages?,
:merge_requests_access_level, :forking_access_level, :issues_access_level, :merge_requests_access_level, :forking_access_level, :issues_access_level,
:wiki_access_level, :snippets_access_level, :builds_access_level, :wiki_access_level, :snippets_access_level, :builds_access_level,
:repository_access_level, :repository_access_level, :pages_access_level,
to: :project_feature, allow_nil: true to: :project_feature, allow_nil: true
delegate :scheduled?, :started?, :in_progress?, :failed?, :finished?, delegate :scheduled?, :started?, :in_progress?, :failed?, :finished?,
prefix: :import, to: :import_state, allow_nil: true prefix: :import, to: :import_state, allow_nil: true
......
---
title: Add pages_access_level to projects API
merge_request: 23176
author: Mathieu Parent
type: added
...@@ -1008,6 +1008,7 @@ POST /projects ...@@ -1008,6 +1008,7 @@ POST /projects
| `builds_access_level` | string | no | One of `disabled`, `private` or `enabled` | | `builds_access_level` | string | no | One of `disabled`, `private` or `enabled` |
| `wiki_access_level` | string | no | One of `disabled`, `private` or `enabled` | | `wiki_access_level` | string | no | One of `disabled`, `private` or `enabled` |
| `snippets_access_level` | string | no | One of `disabled`, `private` or `enabled` | | `snippets_access_level` | string | no | One of `disabled`, `private` or `enabled` |
| `pages_access_level` | string | no | One of `disabled`, `private`, `enabled` or `public` |
| `resolve_outdated_diff_discussions` | boolean | no | Automatically resolve merge request diffs discussions on lines changed with a push | | `resolve_outdated_diff_discussions` | boolean | no | Automatically resolve merge request diffs discussions on lines changed with a push |
| `container_registry_enabled` | boolean | no | Enable container registry for this project | | `container_registry_enabled` | boolean | no | Enable container registry for this project |
| `container_expiration_policy_attributes` | hash | no | Update the container expiration policy for this project. Accepts: `cadence` (string), `keep_n` (string), `older_than` (string), `name_regex` (string), `enabled` (boolean) | | `container_expiration_policy_attributes` | hash | no | Update the container expiration policy for this project. Accepts: `cadence` (string), `keep_n` (string), `older_than` (string), `name_regex` (string), `enabled` (boolean) |
...@@ -1074,6 +1075,7 @@ POST /projects/user/:user_id ...@@ -1074,6 +1075,7 @@ POST /projects/user/:user_id
| `builds_access_level` | string | no | One of `disabled`, `private` or `enabled` | | `builds_access_level` | string | no | One of `disabled`, `private` or `enabled` |
| `wiki_access_level` | string | no | One of `disabled`, `private` or `enabled` | | `wiki_access_level` | string | no | One of `disabled`, `private` or `enabled` |
| `snippets_access_level` | string | no | One of `disabled`, `private` or `enabled` | | `snippets_access_level` | string | no | One of `disabled`, `private` or `enabled` |
| `pages_access_level` | string | no | One of `disabled`, `private`, `enabled` or `public` |
| `resolve_outdated_diff_discussions` | boolean | no | Automatically resolve merge request diffs discussions on lines changed with a push | | `resolve_outdated_diff_discussions` | boolean | no | Automatically resolve merge request diffs discussions on lines changed with a push |
| `container_registry_enabled` | boolean | no | Enable container registry for this project | | `container_registry_enabled` | boolean | no | Enable container registry for this project |
| `shared_runners_enabled` | boolean | no | Enable shared runners for this project | | `shared_runners_enabled` | boolean | no | Enable shared runners for this project |
...@@ -1139,6 +1141,7 @@ PUT /projects/:id ...@@ -1139,6 +1141,7 @@ PUT /projects/:id
| `builds_access_level` | string | no | One of `disabled`, `private` or `enabled` | | `builds_access_level` | string | no | One of `disabled`, `private` or `enabled` |
| `wiki_access_level` | string | no | One of `disabled`, `private` or `enabled` | | `wiki_access_level` | string | no | One of `disabled`, `private` or `enabled` |
| `snippets_access_level` | string | no | One of `disabled`, `private` or `enabled` | | `snippets_access_level` | string | no | One of `disabled`, `private` or `enabled` |
| `pages_access_level` | string | no | One of `disabled`, `private`, `enabled` or `public` |
| `resolve_outdated_diff_discussions` | boolean | no | Automatically resolve merge request diffs discussions on lines changed with a push | | `resolve_outdated_diff_discussions` | boolean | no | Automatically resolve merge request diffs discussions on lines changed with a push |
| `container_registry_enabled` | boolean | no | Enable container registry for this project | | `container_registry_enabled` | boolean | no | Enable container registry for this project |
| `container_expiration_policy_attributes` | hash | no | Update the container expiration policy for this project. Accepts: `cadence` (string), `keep_n` (string), `older_than` (string), `name_regex` (string), `enabled` (boolean) | | `container_expiration_policy_attributes` | hash | no | Update the container expiration policy for this project. Accepts: `cadence` (string), `keep_n` (string), `older_than` (string), `name_regex` (string), `enabled` (boolean) |
......
...@@ -311,6 +311,7 @@ module API ...@@ -311,6 +311,7 @@ module API
expose(:wiki_access_level) { |project, options| project.project_feature.string_access_level(:wiki) } expose(:wiki_access_level) { |project, options| project.project_feature.string_access_level(:wiki) }
expose(:builds_access_level) { |project, options| project.project_feature.string_access_level(:builds) } expose(:builds_access_level) { |project, options| project.project_feature.string_access_level(:builds) }
expose(:snippets_access_level) { |project, options| project.project_feature.string_access_level(:snippets) } expose(:snippets_access_level) { |project, options| project.project_feature.string_access_level(:snippets) }
expose(:pages_access_level) { |project, options| project.project_feature.string_access_level(:pages) }
expose :shared_runners_enabled expose :shared_runners_enabled
expose :lfs_enabled?, as: :lfs_enabled expose :lfs_enabled?, as: :lfs_enabled
......
...@@ -27,6 +27,7 @@ module API ...@@ -27,6 +27,7 @@ module API
optional :wiki_access_level, type: String, values: %w(disabled private enabled), desc: 'Wiki access level. One of `disabled`, `private` or `enabled`' optional :wiki_access_level, type: String, values: %w(disabled private enabled), desc: 'Wiki access level. One of `disabled`, `private` or `enabled`'
optional :builds_access_level, type: String, values: %w(disabled private enabled), desc: 'Builds access level. One of `disabled`, `private` or `enabled`' optional :builds_access_level, type: String, values: %w(disabled private enabled), desc: 'Builds access level. One of `disabled`, `private` or `enabled`'
optional :snippets_access_level, type: String, values: %w(disabled private enabled), desc: 'Snippets access level. One of `disabled`, `private` or `enabled`' optional :snippets_access_level, type: String, values: %w(disabled private enabled), desc: 'Snippets access level. One of `disabled`, `private` or `enabled`'
optional :pages_access_level, type: String, values: %w(disabled private enabled public), desc: 'Pages access level. One of `disabled`, `private`, `enabled` or `public`'
optional :shared_runners_enabled, type: Boolean, desc: 'Flag indication if shared runners are enabled for that project' optional :shared_runners_enabled, type: Boolean, desc: 'Flag indication if shared runners are enabled for that project'
optional :resolve_outdated_diff_discussions, type: Boolean, desc: 'Automatically resolve merge request diffs discussions on lines changed with a push' optional :resolve_outdated_diff_discussions, type: Boolean, desc: 'Automatically resolve merge request diffs discussions on lines changed with a push'
...@@ -107,6 +108,7 @@ module API ...@@ -107,6 +108,7 @@ module API
:name, :name,
:only_allow_merge_if_all_discussions_are_resolved, :only_allow_merge_if_all_discussions_are_resolved,
:only_allow_merge_if_pipeline_succeeds, :only_allow_merge_if_pipeline_succeeds,
:pages_access_level,
:path, :path,
:printing_merge_request_link_enabled, :printing_merge_request_link_enabled,
:public_builds, :public_builds,
......
...@@ -4,8 +4,8 @@ require 'spec_helper' ...@@ -4,8 +4,8 @@ require 'spec_helper'
describe ProjectFeaturesCompatibility do describe ProjectFeaturesCompatibility do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:features_except_repository) { %w(issues wiki builds merge_requests snippets) } let(:features_enabled) { %w(issues wiki builds merge_requests snippets) }
let(:features) { features_except_repository + ['repository'] } let(:features) { features_enabled + %w(repository pages) }
# We had issues_enabled, snippets_enabled, builds_enabled, merge_requests_enabled and issues_enabled fields on projects table # We had issues_enabled, snippets_enabled, builds_enabled, merge_requests_enabled and issues_enabled fields on projects table
# All those fields got moved to a new table called project_feature and are now integers instead of booleans # All those fields got moved to a new table called project_feature and are now integers instead of booleans
...@@ -13,37 +13,53 @@ describe ProjectFeaturesCompatibility do ...@@ -13,37 +13,53 @@ describe ProjectFeaturesCompatibility do
# So we can keep it compatible # So we can keep it compatible
it "converts fields from 'true' to ProjectFeature::ENABLED" do it "converts fields from 'true' to ProjectFeature::ENABLED" do
features_except_repository.each do |feature| features_enabled.each do |feature|
project.update_attribute("#{feature}_enabled".to_sym, "true") project.update_attribute("#{feature}_enabled".to_sym, "true")
expect(project.project_feature.public_send("#{feature}_access_level")).to eq(ProjectFeature::ENABLED) expect(project.project_feature.public_send("#{feature}_access_level")).to eq(ProjectFeature::ENABLED)
end end
end end
it "converts fields from 'false' to ProjectFeature::DISABLED" do it "converts fields from 'false' to ProjectFeature::DISABLED" do
features_except_repository.each do |feature| features_enabled.each do |feature|
project.update_attribute("#{feature}_enabled".to_sym, "false") project.update_attribute("#{feature}_enabled".to_sym, "false")
expect(project.project_feature.public_send("#{feature}_access_level")).to eq(ProjectFeature::DISABLED) expect(project.project_feature.public_send("#{feature}_access_level")).to eq(ProjectFeature::DISABLED)
end end
end end
it "converts fields from true to ProjectFeature::ENABLED" do it "converts fields from true to ProjectFeature::ENABLED" do
features_except_repository.each do |feature| features_enabled.each do |feature|
project.update_attribute("#{feature}_enabled".to_sym, true) project.update_attribute("#{feature}_enabled".to_sym, true)
expect(project.project_feature.public_send("#{feature}_access_level")).to eq(ProjectFeature::ENABLED) expect(project.project_feature.public_send("#{feature}_access_level")).to eq(ProjectFeature::ENABLED)
end end
end end
it "converts fields from false to ProjectFeature::DISABLED" do it "converts fields from false to ProjectFeature::DISABLED" do
features_except_repository.each do |feature| features_enabled.each do |feature|
project.update_attribute("#{feature}_enabled".to_sym, false) project.update_attribute("#{feature}_enabled".to_sym, false)
expect(project.project_feature.public_send("#{feature}_access_level")).to eq(ProjectFeature::DISABLED) expect(project.project_feature.public_send("#{feature}_access_level")).to eq(ProjectFeature::DISABLED)
end end
end end
it "accepts private as ProjectFeature::PRIVATE" do describe "access levels" do
using RSpec::Parameterized::TableSyntax
where(:access_level, :expected_result) do
'disabled' | ProjectFeature::DISABLED
'private' | ProjectFeature::PRIVATE
'enabled' | ProjectFeature::ENABLED
'public' | ProjectFeature::PUBLIC
end
with_them do
it "accepts access level" do
features.each do |feature| features.each do |feature|
project.update!("#{feature}_access_level".to_sym => 'private') # Only pages as public access level
expect(project.project_feature.public_send("#{feature}_access_level")).to eq(ProjectFeature::PRIVATE) next if feature != 'pages' && access_level == 'public'
project.update!("#{feature}_access_level".to_sym => access_level)
expect(project.project_feature.public_send("#{feature}_access_level")).to eq(expected_result)
end
end
end end
end end
end end
...@@ -1394,6 +1394,7 @@ describe API::Projects do ...@@ -1394,6 +1394,7 @@ describe API::Projects do
expect(json_response['jobs_enabled']).to be_present expect(json_response['jobs_enabled']).to be_present
expect(json_response['snippets_enabled']).to be_present expect(json_response['snippets_enabled']).to be_present
expect(json_response['snippets_access_level']).to be_present expect(json_response['snippets_access_level']).to be_present
expect(json_response['pages_access_level']).to be_present
expect(json_response['repository_access_level']).to be_present expect(json_response['repository_access_level']).to be_present
expect(json_response['issues_access_level']).to be_present expect(json_response['issues_access_level']).to be_present
expect(json_response['merge_requests_access_level']).to be_present expect(json_response['merge_requests_access_level']).to be_present
...@@ -2230,6 +2231,16 @@ describe API::Projects do ...@@ -2230,6 +2231,16 @@ describe API::Projects do
expect(json_response['builds_access_level']).to eq('private') expect(json_response['builds_access_level']).to eq('private')
end end
it 'updates pages_access_level' do
project_param = { pages_access_level: 'private' }
put api("/projects/#{project3.id}", user), params: project_param
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['pages_access_level']).to eq('private')
end
it 'updates build_git_strategy' do it 'updates build_git_strategy' do
project_param = { build_git_strategy: 'clone' } project_param = { build_git_strategy: 'clone' }
......
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