summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-06-28 03:09:38 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-06-28 03:09:38 +0000
commitf72c02a9a54483a73878ebd770eec931ac64c8c2 (patch)
treed8695e34de7bf3e4b8250ab29ce2e5ec95c172c9 /spec
parent9b07a0e87250887c6fc30911f84fd7e885f56245 (diff)
downloadgitlab-ce-f72c02a9a54483a73878ebd770eec931ac64c8c2.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/background_migration/populate_operation_visibility_permissions_from_operations_spec.rb80
-rw-r--r--spec/migrations/populate_operation_visibility_permissions_spec.rb32
-rw-r--r--spec/requests/api/project_attributes.yml5
-rw-r--r--spec/services/projects/update_service_spec.rb36
4 files changed, 153 insertions, 0 deletions
diff --git a/spec/lib/gitlab/background_migration/populate_operation_visibility_permissions_from_operations_spec.rb b/spec/lib/gitlab/background_migration/populate_operation_visibility_permissions_from_operations_spec.rb
new file mode 100644
index 00000000000..1ebdca136a3
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/populate_operation_visibility_permissions_from_operations_spec.rb
@@ -0,0 +1,80 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::BackgroundMigration::PopulateOperationVisibilityPermissionsFromOperations do
+ let(:namespaces) { table(:namespaces) }
+ let(:project_features) { table(:project_features) }
+ let(:projects) { table(:projects) }
+
+ let(:namespace) { namespaces.create!(name: 'user', path: 'user') }
+
+ let(:proj_namespace1) { namespaces.create!(name: 'proj1', path: 'proj1', type: 'Project', parent_id: namespace.id) }
+ let(:proj_namespace2) { namespaces.create!(name: 'proj2', path: 'proj2', type: 'Project', parent_id: namespace.id) }
+ let(:proj_namespace3) { namespaces.create!(name: 'proj3', path: 'proj3', type: 'Project', parent_id: namespace.id) }
+
+ let(:project1) { create_project('test1', proj_namespace1) }
+ let(:project2) { create_project('test2', proj_namespace2) }
+ let(:project3) { create_project('test3', proj_namespace3) }
+
+ let!(:record1) { create_project_feature(project1) }
+ let!(:record2) { create_project_feature(project2, 20) }
+ let!(:record3) { create_project_feature(project3) }
+
+ let(:sub_batch_size) { 2 }
+ let(:start_id) { record1.id }
+ let(:end_id) { record3.id }
+ let(:batch_table) { :project_features }
+ let(:batch_column) { :id }
+ let(:pause_ms) { 1 }
+ let(:connection) { ApplicationRecord.connection }
+
+ let(:job) do
+ described_class.new(
+ start_id: start_id,
+ end_id: end_id,
+ batch_table: batch_table,
+ batch_column: batch_column,
+ sub_batch_size: sub_batch_size,
+ pause_ms: pause_ms,
+ connection: connection
+ )
+ end
+
+ subject(:perform) { job.perform }
+
+ it 'updates all project settings records from their operations_access_level', :aggregate_failures do
+ perform
+
+ expect_project_features_match_operations_access_level(record1)
+ expect_project_features_match_operations_access_level(record2)
+ expect_project_features_match_operations_access_level(record3)
+ end
+
+ private
+
+ def expect_project_features_match_operations_access_level(record)
+ record.reload
+ expect(record.monitor_access_level).to eq(record.operations_access_level)
+ expect(record.infrastructure_access_level).to eq(record.operations_access_level)
+ expect(record.feature_flags_access_level).to eq(record.operations_access_level)
+ expect(record.environments_access_level).to eq(record.operations_access_level)
+ end
+
+ def create_project(proj_name, proj_namespace)
+ projects.create!(
+ namespace_id: namespace.id,
+ project_namespace_id: proj_namespace.id,
+ name: proj_name,
+ path: proj_name
+ )
+ end
+
+ def create_project_feature(project, operations_access_level = 10)
+ project_features.create!(
+ project_id: project.id,
+ pages_access_level: 10,
+ operations_access_level: operations_access_level
+ )
+ end
+end
diff --git a/spec/migrations/populate_operation_visibility_permissions_spec.rb b/spec/migrations/populate_operation_visibility_permissions_spec.rb
new file mode 100644
index 00000000000..6737a6f84c3
--- /dev/null
+++ b/spec/migrations/populate_operation_visibility_permissions_spec.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+require_migration!
+
+RSpec.describe PopulateOperationVisibilityPermissions, :migration do
+ let(:migration) { described_class::MIGRATION }
+
+ before do
+ stub_const("#{described_class.name}::SUB_BATCH_SIZE", 2)
+ end
+
+ it 'schedules background migrations', :aggregate_failures do
+ migrate!
+
+ expect(migration).to have_scheduled_batched_migration(
+ table_name: :project_features,
+ column_name: :id,
+ interval: described_class::INTERVAL
+ )
+ end
+
+ describe '#down' do
+ it 'deletes all batched migration records' do
+ migrate!
+ schema_migrate_down!
+
+ expect(migration).not_to have_scheduled_batched_migration
+ end
+ end
+end
diff --git a/spec/requests/api/project_attributes.yml b/spec/requests/api/project_attributes.yml
index fa193c05222..8d3622ca17d 100644
--- a/spec/requests/api/project_attributes.yml
+++ b/spec/requests/api/project_attributes.yml
@@ -124,6 +124,11 @@ project_feature:
- created_at
- metrics_dashboard_access_level
- package_registry_access_level
+ - monitor_access_level
+ - infrastructure_access_level
+ - feature_flags_access_level
+ - environments_access_level
+ - releases_access_level
- project_id
- updated_at
computed_attributes:
diff --git a/spec/services/projects/update_service_spec.rb b/spec/services/projects/update_service_spec.rb
index 7b5bf1db030..a5e77104735 100644
--- a/spec/services/projects/update_service_spec.rb
+++ b/spec/services/projects/update_service_spec.rb
@@ -289,6 +289,42 @@ RSpec.describe Projects::UpdateService do
end
end
+ context 'when changing operations feature visibility' do
+ let(:feature_params) { { operations_access_level: ProjectFeature::DISABLED } }
+
+ it 'does not sync the changes to the related fields' do
+ result = update_project(project, user, project_feature_attributes: feature_params)
+
+ expect(result).to eq({ status: :success })
+ feature = project.project_feature
+
+ expect(feature.operations_access_level).to eq(ProjectFeature::DISABLED)
+ expect(feature.monitor_access_level).not_to eq(ProjectFeature::DISABLED)
+ expect(feature.infrastructure_access_level).not_to eq(ProjectFeature::DISABLED)
+ expect(feature.feature_flags_access_level).not_to eq(ProjectFeature::DISABLED)
+ expect(feature.environments_access_level).not_to eq(ProjectFeature::DISABLED)
+ end
+
+ context 'when split_operations_visibility_permissions feature is disabled' do
+ before do
+ stub_feature_flags(split_operations_visibility_permissions: false)
+ end
+
+ it 'syncs the changes to the related fields' do
+ result = update_project(project, user, project_feature_attributes: feature_params)
+
+ expect(result).to eq({ status: :success })
+ feature = project.project_feature
+
+ expect(feature.operations_access_level).to eq(ProjectFeature::DISABLED)
+ expect(feature.monitor_access_level).to eq(ProjectFeature::DISABLED)
+ expect(feature.infrastructure_access_level).to eq(ProjectFeature::DISABLED)
+ expect(feature.feature_flags_access_level).to eq(ProjectFeature::DISABLED)
+ expect(feature.environments_access_level).to eq(ProjectFeature::DISABLED)
+ end
+ end
+ end
+
context 'when updating a project that contains container images' do
before do
stub_container_registry_config(enabled: true)