diff options
author | George Koltsov <koltsov.george@gmail.com> | 2019-07-19 03:00:23 +0000 |
---|---|---|
committer | Evan Read <eread@gitlab.com> | 2019-07-19 03:00:23 +0000 |
commit | 9ef196b7a7d51043c09c848699f7d393edf7af03 (patch) | |
tree | ffecebd027d122e197e46f626ff40d118491f06f | |
parent | 0da7c9250880b508c49baa94cfa18398771f3add (diff) | |
download | gitlab-ce-9ef196b7a7d51043c09c848699f7d393edf7af03.tar.gz |
Set Private visibility for restricted Internal imported projects
With https://gitlab.com/gitlab-org/gitlab-ee/issues/12388 change going
live there is potential risk of breaking imports of 'Internal' projects.
This change makes sure if 'Internal' visibility level is restricted
all 'Internal' projects will be marked as 'Private'
See: https://gitlab.com/gitlab-org/gitlab-ce/issues/64311
4 files changed, 31 insertions, 0 deletions
diff --git a/changelogs/unreleased/georgekoltsov-64311-set-visibility-private-if-internal-restricted.yml b/changelogs/unreleased/georgekoltsov-64311-set-visibility-private-if-internal-restricted.yml new file mode 100644 index 00000000000..18af16e5216 --- /dev/null +++ b/changelogs/unreleased/georgekoltsov-64311-set-visibility-private-if-internal-restricted.yml @@ -0,0 +1,5 @@ +--- +title: Set visibility level 'Private' for restricted 'Internal' imported projects when 'Internal' visibility setting is restricted in admin settings +merge_request: 30522 +author: +type: other diff --git a/doc/user/project/settings/import_export.md b/doc/user/project/settings/import_export.md index 7241df613eb..35d5320c0b1 100644 --- a/doc/user/project/settings/import_export.md +++ b/doc/user/project/settings/import_export.md @@ -116,3 +116,8 @@ For more details on the specific data persisted in a project export, see the 1. Click on **Import project** to begin importing. Your newly imported project page will appear soon. + +NOTE: **Note:** +If use of the `Internal` visibility level +[is restricted](../../../public_access/public_access.md#restricting-the-use-of-public-or-internal-projects), +all imported projects are given the visibility of `Private`. diff --git a/lib/gitlab/import_export/project_tree_restorer.rb b/lib/gitlab/import_export/project_tree_restorer.rb index dec99c23a2d..91fe4e5d074 100644 --- a/lib/gitlab/import_export/project_tree_restorer.rb +++ b/lib/gitlab/import_export/project_tree_restorer.rb @@ -130,6 +130,7 @@ module Gitlab def visibility_level level = override_params['visibility_level'] || json_params['visibility_level'] || @project.visibility_level level = @project.group.visibility_level if @project.group && level.to_i > @project.group.visibility_level + level = Gitlab::VisibilityLevel::PRIVATE if level == Gitlab::VisibilityLevel::INTERNAL && Gitlab::CurrentSettings.restricted_visibility_levels.include?(level) { 'visibility_level' => level } end diff --git a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb index e6ce3f1bcea..3b7de185cf1 100644 --- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb @@ -496,6 +496,18 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do end end + context 'with restricted internal visibility' do + describe 'internal project' do + let(:visibility) { Gitlab::VisibilityLevel::INTERNAL } + + it 'uses private visibility' do + stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::INTERNAL]) + + expect(restorer.restored_project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE) + end + end + end + context 'with group visibility' do before do group = create(:group, visibility_level: group_visibility) @@ -528,6 +540,14 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do it 'uses the group visibility' do expect(restorer.restored_project.visibility_level).to eq(group_visibility) end + + context 'with restricted internal visibility' do + it 'sets private visibility' do + stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::INTERNAL]) + + expect(restorer.restored_project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE) + end + end end end end |