diff --git a/app/models/project_setting.rb b/app/models/project_setting.rb index 4e37174e60482c7c0a0149b6dbf6d1fdf19405d6..00de0a8061f27cb27989dabca3b2e7819035cd9b 100644 --- a/app/models/project_setting.rb +++ b/app/models/project_setting.rb @@ -15,6 +15,10 @@ class ProjectSetting < ApplicationRecord validates :merge_commit_template, length: { maximum: 500 } validates :squash_commit_template, length: { maximum: 500 } + default_value_for(:legacy_open_source_license_available) do + Feature.enabled?(:legacy_open_source_license_available, default_enabled: :yaml, type: :ops) + end + def squash_enabled_by_default? %w[always default_on].include?(squash_option) end diff --git a/config/feature_flags/ops/legacy_open_source_license_available.yml b/config/feature_flags/ops/legacy_open_source_license_available.yml new file mode 100644 index 0000000000000000000000000000000000000000..2408e31633a0abfeb869039536828fdb38019cfb --- /dev/null +++ b/config/feature_flags/ops/legacy_open_source_license_available.yml @@ -0,0 +1,8 @@ +--- +name: legacy_open_source_license_available +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/79855 +rollout_issue_url: +milestone: '14.8' +type: ops +group: 'group::authentication and authorization' +default_enabled: true diff --git a/db/migrate/20220203133652_add_legacy_open_source_license_available_to_project_settings.rb b/db/migrate/20220203133652_add_legacy_open_source_license_available_to_project_settings.rb new file mode 100644 index 0000000000000000000000000000000000000000..47f92fae496f7f303b4889e98b79aa78975fb035 --- /dev/null +++ b/db/migrate/20220203133652_add_legacy_open_source_license_available_to_project_settings.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddLegacyOpenSourceLicenseAvailableToProjectSettings < Gitlab::Database::Migration[1.0] + enable_lock_retries! + + def change + add_column :project_settings, :legacy_open_source_license_available, :boolean, default: true, null: false + end +end diff --git a/db/schema_migrations/20220203133652 b/db/schema_migrations/20220203133652 new file mode 100644 index 0000000000000000000000000000000000000000..7deda2292b41c8c9b4180cddf8c037fb441e387c --- /dev/null +++ b/db/schema_migrations/20220203133652 @@ -0,0 +1 @@ +5642cf604a1aaf8bef6098a9918b582e0e336d79ca3b2a005cf90bb8eab0ca13 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 80dec806173b53bd8201adf5eebb38e7a831fe60..fd53183e8902cdd3093ee94fc58e7f759d71d8be 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -18701,6 +18701,7 @@ CREATE TABLE project_settings ( has_shimo boolean DEFAULT false NOT NULL, squash_commit_template text, show_diff_preview_in_email boolean DEFAULT true NOT NULL, + legacy_open_source_license_available boolean DEFAULT true NOT NULL, CONSTRAINT check_3a03e7557a CHECK ((char_length(previous_default_branch) <= 4096)), CONSTRAINT check_b09644994b CHECK ((char_length(squash_commit_template) <= 500)), CONSTRAINT check_bde223416c CHECK ((show_default_award_emojis IS NOT NULL)), diff --git a/ee/app/models/ee/project.rb b/ee/app/models/ee/project.rb index d12942e394283c7d5a6c06ca232272c708df6c15..e6cc1bedadbabcb5aa9a5fc0160e015d50eacefc 100644 --- a/ee/app/models/ee/project.rb +++ b/ee/app/models/ee/project.rb @@ -927,12 +927,18 @@ def load_licensed_feature_available(feature) if ::Gitlab::CurrentSettings.should_check_namespace_plan? && namespace globally_available && - (public? && namespace.public? || namespace.feature_available_in_plan?(feature)) + (open_source_license_granted? || namespace.feature_available_in_plan?(feature)) else globally_available end end + def open_source_license_granted? + public? && + namespace.public? && + project_setting.legacy_open_source_license_available? + end + def user_defined_rules strong_memoize(:user_defined_rules) do # Loading the relation in order to memoize it loaded diff --git a/ee/spec/models/project_spec.rb b/ee/spec/models/project_spec.rb index e7d1c31e0f9eb0e91d2de30760f3165905dd16d9..42e98cc094331868ee3ce2b4ed33dc25d938f139 100644 --- a/ee/spec/models/project_spec.rb +++ b/ee/spec/models/project_spec.rb @@ -1256,6 +1256,35 @@ subject end end + + context 'legacy open-source license' do + let(:feature) { :sast } + + before do + stub_application_setting(check_namespace_plan: true) + stub_licensed_features(feature => true) + end + + context 'public projects' do + let(:project) { build(:project, :public, namespace: namespace) } + + context 'when legacy_open_source_license_available feature flag is enabled' do + it 'allows ultimate features' do + is_expected.to eq(true) + end + end + + context 'when legacy_open_source_license_available feature flag is disabled' do + before do + stub_feature_flags(legacy_open_source_license_available: false) + end + + it 'prevent ultimate features' do + is_expected.to eq(false) + end + end + end + end end describe '#fetch_mirror' do diff --git a/spec/requests/api/project_attributes.yml b/spec/requests/api/project_attributes.yml index ef47263ad78ec80da6f0d669c2a1bea2cf20987a..93ae4e8b695f22cffdd4378d12398aacd9cd3a11 100644 --- a/spec/requests/api/project_attributes.yml +++ b/spec/requests/api/project_attributes.yml @@ -139,6 +139,7 @@ project_setting: - has_confluence - has_shimo - has_vulnerabilities + - legacy_open_source_license_available - prevent_merge_without_jira_issue - warn_about_potentially_unwanted_characters - previous_default_branch