Commit 4f88f110 authored by James Lopez's avatar James Lopez

Merge branch 'rc/add_metrics_access_level_to_db' into 'master'

Add metrics_access_level to project features

See merge request gitlab-org/gitlab!29371
parents 57f864fa 9bb4e539
......@@ -66,6 +66,10 @@ module ProjectFeaturesCompatibility
write_feature_attribute_string(:pages_access_level, value)
end
def metrics_dashboard_access_level=(value)
write_feature_attribute_string(:metrics_dashboard_access_level, value)
end
private
def write_feature_attribute_boolean(field, value)
......
......@@ -340,7 +340,7 @@ class Project < ApplicationRecord
:pages_enabled?, :public_pages?, :private_pages?,
:merge_requests_access_level, :forking_access_level, :issues_access_level,
:wiki_access_level, :snippets_access_level, :builds_access_level,
:repository_access_level, :pages_access_level,
:repository_access_level, :pages_access_level, :metrics_dashboard_access_level,
to: :project_feature, allow_nil: true
delegate :scheduled?, :started?, :in_progress?, :failed?, :finished?,
prefix: :import, to: :import_state, allow_nil: true
......
......@@ -22,7 +22,7 @@ class ProjectFeature < ApplicationRecord
ENABLED = 20
PUBLIC = 30
FEATURES = %i(issues forking merge_requests wiki snippets builds repository pages).freeze
FEATURES = %i(issues forking merge_requests wiki snippets builds repository pages metrics_dashboard).freeze
PRIVATE_FEATURES_MIN_ACCESS_LEVEL = { merge_requests: Gitlab::Access::REPORTER }.freeze
PRIVATE_FEATURES_MIN_ACCESS_LEVEL_FOR_PRIVATE_PROJECT = { repository: Gitlab::Access::REPORTER }.freeze
STRING_OPTIONS = HashWithIndifferentAccess.new({
......@@ -90,13 +90,14 @@ class ProjectFeature < ApplicationRecord
validate :repository_children_level
validate :allowed_access_levels
default_value_for :builds_access_level, value: ENABLED, allows_nil: false
default_value_for :issues_access_level, value: ENABLED, allows_nil: false
default_value_for :forking_access_level, value: ENABLED, allows_nil: false
default_value_for :merge_requests_access_level, value: ENABLED, allows_nil: false
default_value_for :snippets_access_level, value: ENABLED, allows_nil: false
default_value_for :wiki_access_level, value: ENABLED, allows_nil: false
default_value_for :repository_access_level, value: ENABLED, allows_nil: false
default_value_for :builds_access_level, value: ENABLED, allows_nil: false
default_value_for :issues_access_level, value: ENABLED, allows_nil: false
default_value_for :forking_access_level, value: ENABLED, allows_nil: false
default_value_for :merge_requests_access_level, value: ENABLED, allows_nil: false
default_value_for :snippets_access_level, value: ENABLED, allows_nil: false
default_value_for :wiki_access_level, value: ENABLED, allows_nil: false
default_value_for :repository_access_level, value: ENABLED, allows_nil: false
default_value_for :metrics_dashboard_access_level, value: PRIVATE, allows_nil: false
default_value_for(:pages_access_level, allows_nil: false) do |feature|
if ::Gitlab::Pages.access_control_is_forced?
......
---
title: Add metrics_dashboard_access_level to project features
merge_request: 29371
author:
type: added
# frozen_string_literal: true
class AddMetricsDashboardAccessLevelToProjectFeature < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
with_lock_retries do
add_column :project_features, :metrics_dashboard_access_level, :integer
end
end
def down
with_lock_retries do
remove_column :project_features, :metrics_dashboard_access_level, :integer
end
end
end
......@@ -4884,7 +4884,8 @@ CREATE TABLE public.project_features (
updated_at timestamp without time zone,
repository_access_level integer DEFAULT 20 NOT NULL,
pages_access_level integer NOT NULL,
forking_access_level integer
forking_access_level integer,
metrics_dashboard_access_level integer
);
CREATE SEQUENCE public.project_features_id_seq
......@@ -13176,6 +13177,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200408154624
20200408175424
20200409211607
20200410232012
20200415160722
20200415161021
20200415161206
......
......@@ -12,7 +12,8 @@ module EE
:snippets_access_level,
:builds_access_level,
:repository_access_level,
:pages_access_level].freeze
:pages_access_level,
:metrics_dashboard_access_level].freeze
def initialize(current_user, model, project)
@project = project
......
......@@ -17,12 +17,15 @@ describe EE::Audit::ProjectFeatureChangesAuditor do
columns = project.project_feature.attributes.keys.select { |attr| attr.end_with?('level') }
columns.each do |column|
features.update_attribute(column, 0)
previous_value = features.method(column).call
new_value = ProjectFeature::DISABLED
features.update_attribute(column, new_value)
expect { foo_instance.execute }.to change { SecurityEvent.count }.by(1)
event = SecurityEvent.last
expect(event.details[:from]).to eq 'Public'
expect(event.details[:to]).to eq 'Private'
expect(event.details[:from]).to eq ::Gitlab::VisibilityLevel.level_name(previous_value)
expect(event.details[:to]).to eq ::Gitlab::VisibilityLevel.level_name(new_value)
expect(event.details[:change]).to eq column
end
end
......
......@@ -79,7 +79,7 @@ describe Gitlab::BackgroundMigration::UserMentions::CreateResourceUserMention, s
context 'migrate commit mentions' do
let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '', 'group/project') }
let(:commit) { Commit.new(RepoHelpers.sample_commit, project.becomes(Project)) }
let(:commit) { Commit.new(RepoHelpers.sample_commit, project) }
let(:commit_user_mentions) { table(:commit_user_mentions) }
let!(:note1) { notes.create!(commit_id: commit.id, noteable_type: 'Commit', project_id: project.id, author_id: author.id, note: description_mentions) }
......
......@@ -595,6 +595,7 @@ ProjectFeature:
- builds_access_level
- repository_access_level
- pages_access_level
- metrics_dashboard_access_level
- created_at
- updated_at
ProtectedBranch::MergeAccessLevel:
......
......@@ -14,7 +14,7 @@ describe CleanupEmptyCommitUserMentions, :migration, :sidekiq do
let(:project) { projects.create!(name: 'gitlab1', path: 'gitlab1', namespace_id: group.id, visibility_level: 0) }
let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '', 'group/project') }
let(:commit) { Commit.new(RepoHelpers.sample_commit, project.becomes(Project)) }
let(:commit) { Commit.new(RepoHelpers.sample_commit, project) }
let(:commit_user_mentions) { table(:commit_user_mentions) }
let!(:resource1) { notes.create!(commit_id: commit.id, noteable_type: 'Commit', project_id: project.id, author_id: user.id, note: 'note1 for @root to check') }
......
......@@ -14,7 +14,7 @@ describe MigrateCommitNotesMentionsToDb, :migration, :sidekiq do
let(:project) { projects.create!(name: 'gitlab1', path: 'gitlab1', namespace_id: group.id, visibility_level: 0) }
let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '', 'group/project') }
let(:commit) { Commit.new(RepoHelpers.sample_commit, project.becomes(Project)) }
let(:commit) { Commit.new(RepoHelpers.sample_commit, project) }
let(:commit_user_mentions) { table(:commit_user_mentions) }
let!(:resource1) { notes.create!(commit_id: commit.id, noteable_type: 'Commit', project_id: project.id, author_id: user.id, note: 'note1 for @root to check') }
......
......@@ -27,7 +27,7 @@ describe ProjectFeature do
end
describe '#feature_available?' do
let(:features) { %w(issues wiki builds merge_requests snippets repository pages) }
let(:features) { %w(issues wiki builds merge_requests snippets repository pages metrics_dashboard) }
context 'when features are disabled' do
it "returns false" do
......@@ -123,7 +123,7 @@ describe ProjectFeature do
end
context 'public features' do
features = %w(issues wiki builds merge_requests snippets repository)
features = %w(issues wiki builds merge_requests snippets repository metrics_dashboard)
features.each do |feature|
it "does not allow public access level for #{feature}" do
......
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