Commit d1c2f290 authored by Aishwarya Subramanian's avatar Aishwarya Subramanian

Added group policy for compliance frameworks

Updated FF checks at namespace level
parent daf53c85
...@@ -4,7 +4,7 @@ module ComplianceManagement ...@@ -4,7 +4,7 @@ module ComplianceManagement
module ComplianceFramework module ComplianceFramework
module GroupSettingsHelper module GroupSettingsHelper
def show_compliance_frameworks? def show_compliance_frameworks?
License.feature_available?(:custom_compliance_frameworks) && Feature.enabled?(:ff_custom_compliance_frameworks) current_user.can?(:admin_compliance_framework, @group)
end end
def compliance_frameworks_list_data def compliance_frameworks_list_data
......
...@@ -119,6 +119,11 @@ module EE ...@@ -119,6 +119,11 @@ module EE
condition(:eligible_for_trial, scope: :subject) { @subject.eligible_for_trial? } condition(:eligible_for_trial, scope: :subject) { @subject.eligible_for_trial? }
condition(:compliance_framework_available) do
@subject.feature_available?(:custom_compliance_frameworks) &&
::Feature.enabled?(:ff_custom_compliance_frameworks, @subject)
end
rule { public_group | logged_in_viewable }.policy do rule { public_group | logged_in_viewable }.policy do
enable :read_wiki enable :read_wiki
enable :download_wiki_code enable :download_wiki_code
...@@ -335,6 +340,8 @@ module EE ...@@ -335,6 +340,8 @@ module EE
prevent :create_deploy_token prevent :create_deploy_token
prevent :create_subgroup prevent :create_subgroup
end end
rule { can?(:owner_access) & compliance_framework_available }.enable :admin_compliance_framework
end end
override :lookup_access_level! override :lookup_access_level!
......
...@@ -81,7 +81,7 @@ module EE ...@@ -81,7 +81,7 @@ module EE
framework_identifier = settings.delete(:framework) framework_identifier = settings.delete(:framework)
if framework_identifier.blank? if framework_identifier.blank?
settings.merge!(_destroy: true) settings.merge!(_destroy: true)
elsif ::Feature.enabled?(:ff_custom_compliance_frameworks) elsif ::Feature.enabled?(:ff_custom_compliance_frameworks, project.namespace)
settings[:compliance_management_framework] = project.namespace.root_ancestor.compliance_management_frameworks.find(framework_identifier) settings[:compliance_management_framework] = project.namespace.root_ancestor.compliance_management_frameworks.find(framework_identifier)
else else
settings[:compliance_management_framework] = ComplianceManagement::Framework.find_or_create_legacy_default_framework(project, framework_identifier) settings[:compliance_management_framework] = ComplianceManagement::Framework.find_or_create_legacy_default_framework(project, framework_identifier)
......
- user_has_edit_permissions = current_user.can?(:admin_compliance_framework, @project) - user_has_edit_permissions = current_user.can?(:admin_compliance_framework, @project)
.row .row
.form-group.col-md-9.gl-mb-6 .form-group.col-md-9.gl-mb-6
- if Feature.enabled?(:ff_custom_compliance_frameworks) - if Feature.enabled?(:ff_custom_compliance_frameworks, @project.namespace)
- frameworks = @project.namespace.root_ancestor.compliance_management_frameworks - frameworks = @project.namespace.root_ancestor.compliance_management_frameworks
- if user_has_edit_permissions - if user_has_edit_permissions
= f.fields_for :compliance_framework_setting, ComplianceManagement::ComplianceFramework::ProjectSettings.new do |cf| = f.fields_for :compliance_framework_setting, ComplianceManagement::ComplianceFramework::ProjectSettings.new do |cf|
......
...@@ -3,19 +3,21 @@ ...@@ -3,19 +3,21 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe ComplianceManagement::ComplianceFramework::GroupSettingsHelper do RSpec.describe ComplianceManagement::ComplianceFramework::GroupSettingsHelper do
let_it_be(:group) { build(:group) } let_it_be_with_refind(:group) { create(:group) }
let_it_be(:current_user) { build(:admin) }
before do before do
assign(:group, group) assign(:group, group)
allow(helper).to receive(:current_user) { current_user }
end end
describe '#show_compliance_frameworks?' do describe '#show_compliance_frameworks?' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
where(:feature_flag_enabled, :license_feature_enabled, :result) do where(:feature_flag_enabled, :license_feature_enabled, :result) do
true | true | true true | true | true
false | true | false false | true | false
true | false | false true | false | false
false | false | false false | false | false
end end
......
...@@ -1427,5 +1427,34 @@ RSpec.describe GroupPolicy do ...@@ -1427,5 +1427,34 @@ RSpec.describe GroupPolicy do
it { is_expected.to(allowed ? be_allowed(policy) : be_disallowed(policy)) } it { is_expected.to(allowed ? be_allowed(policy) : be_disallowed(policy)) }
end end
end end
describe ':admin_compliance_framework' do
using RSpec::Parameterized::TableSyntax
let(:policy) { :admin_compliance_framework }
where(:role, :licensed, :feature_flag, :allowed) do
:owner | true | true | true
:owner | true | false | false
:owner | false | true | false
:owner | false | false | false
:admin | true | true | true
:maintainer | true | true | false
:developer | true | true | false
:reporter | true | true | false
:guest | true | true | false
end
with_them do
let(:current_user) { public_send(role) }
before do
stub_licensed_features(custom_compliance_frameworks: licensed)
stub_feature_flags(ff_custom_compliance_frameworks: feature_flag)
end
it { is_expected.to(allowed ? be_allowed(policy) : be_disallowed(policy)) }
end
end
end end
end end
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