Commit 83e3527b authored by Jarka Košanová's avatar Jarka Košanová

Merge branch '208900-check-license-for-status-page-operations-settings' into 'master'

Resolve "Check license for Status Page operations settings"

Closes #208900

See merge request gitlab-org/gitlab!26451
parents 64fdcbca 85296e80
......@@ -41,6 +41,10 @@ module EE
project.feature_available?(:tracing, current_user)
end
def has_status_page_license?
project.feature_available?(:status_page, current_user)
end
def track_tracing_external_url
external_url_previous_change = project&.tracing_setting&.external_url_previous_change
return unless external_url_previous_change
......@@ -58,7 +62,9 @@ module EE
permitted_params[:tracing_setting_attributes] = [:external_url]
end
permitted_params.merge!(status_page_setting_params)
if has_status_page_license?
permitted_params.merge!(status_page_setting_params)
end
permitted_params
end
......
......@@ -22,7 +22,8 @@ module OperationsHelper
def status_page_settings_data(status_page_setting)
{
'setting-enabled' => status_page_setting&.enabled?,
'user-can-enable-status-page' => can?(current_user, :admin_operations, @project).to_s,
'setting-enabled' => status_page_setting&.enabled?&.to_s,
'setting-aws-access-key' => status_page_setting&.aws_access_key,
'setting-masked-aws-secret-key' => status_page_setting&.masked_aws_secret_key,
'setting-aws-region' => status_page_setting&.aws_region,
......
......@@ -117,6 +117,15 @@ describe Projects::Settings::OperationsController do
expect(project.tracing_setting).to be_nil
end
it 'does not create status_page_setting' do
update_project(
project,
status_page_params: attributes_for(:status_page_setting)
)
expect(project.status_page_setting).to be_nil
end
end
context 'format html' do
......@@ -158,7 +167,7 @@ describe Projects::Settings::OperationsController do
context 'with a license' do
before do
stub_licensed_features(tracing: true, incident_management: true)
stub_licensed_features(tracing: true, incident_management: true, status_page: true)
end
shared_examples 'user with write access' do |project_visibility|
......@@ -324,7 +333,7 @@ describe Projects::Settings::OperationsController do
context 'without a license' do
before do
stub_licensed_features(tracing: false, incident_management: false)
stub_licensed_features(tracing: false, incident_management: false, status_page: false)
end
it_behaves_like 'user without write access', :public, :maintainer
......
......@@ -4,14 +4,25 @@ require 'spec_helper'
describe OperationsHelper do
describe '#status_page_settings_data' do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :private) }
subject { helper.status_page_settings_data(status_page_setting) }
before do
helper.instance_variable_set(:@project, project)
allow(helper).to receive(:current_user) { user }
allow(helper)
.to receive(:can?).with(user, :admin_operations, project) { true }
end
context 'setting does not exist' do
let(:status_page_setting) { nil }
it 'returns the correct values' do
expect(subject.keys)
.to contain_exactly(
'user-can-enable-status-page',
'setting-enabled',
'setting-aws-access-key',
'setting-masked-aws-secret-key',
......@@ -20,8 +31,33 @@ describe OperationsHelper do
)
end
it 'returns nil for the values' do
expect(subject.values.uniq).to contain_exactly(nil)
it 'returns the correct values' do
expect(subject).to eq(
'user-can-enable-status-page' => 'true',
'setting-enabled' => nil,
'setting-aws-access-key' => nil,
'setting-masked-aws-secret-key' => nil,
'setting-aws-region' => nil,
'setting-aws-s3-bucket-name' => nil
)
end
context 'user does not have permission' do
before do
allow(helper)
.to receive(:can?).with(user, :admin_operations, project) { false }
end
it 'returns the correct values' do
expect(subject).to eq(
'user-can-enable-status-page' => 'false',
'setting-enabled' => nil,
'setting-aws-access-key' => nil,
'setting-masked-aws-secret-key' => nil,
'setting-aws-region' => nil,
'setting-aws-s3-bucket-name' => nil
)
end
end
end
......@@ -30,7 +66,8 @@ describe OperationsHelper do
it 'returns the correct values' do
aggregate_failures do
expect(subject['setting-enabled']).to eq(status_page_setting.enabled)
expect(subject['user-can-enable-status-page']).to eq('true')
expect(subject['setting-enabled']).to eq(status_page_setting.enabled.to_s)
expect(subject['setting-aws-access-key']).to eq(status_page_setting.aws_access_key)
expect(subject['setting-masked-aws-secret-key']).to eq(status_page_setting.masked_aws_secret_key)
expect(subject['setting-aws-region']).to eq(status_page_setting.aws_region)
......
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