Commit 6574f767 authored by Sean Arnold's avatar Sean Arnold Committed by Peter Leitzen

Make status page setting object exist always

- refactor specs
parent 7b5ad03d
...@@ -8,7 +8,7 @@ module EE ...@@ -8,7 +8,7 @@ module EE
extend ActiveSupport::Concern extend ActiveSupport::Concern
prepended do prepended do
helper_method :tracing_setting helper_method :tracing_setting, :status_page_setting
private private
...@@ -16,6 +16,10 @@ module EE ...@@ -16,6 +16,10 @@ module EE
@tracing_setting ||= project.tracing_setting || project.build_tracing_setting @tracing_setting ||= project.tracing_setting || project.build_tracing_setting
end end
def status_page_setting
@status_page_setting ||= project.status_page_setting || project.build_status_page_setting
end
def has_tracing_license? def has_tracing_license?
project.feature_available?(:tracing, current_user) project.feature_available?(:tracing, current_user)
end end
......
...@@ -20,14 +20,14 @@ module OperationsHelper ...@@ -20,14 +20,14 @@ module OperationsHelper
} }
end end
def status_page_settings_data(status_page_setting) def status_page_settings_data
{ {
'user-can-enable-status-page' => can?(current_user, :admin_operations, @project).to_s, 'operations-settings-endpoint' => project_settings_operations_path(@project),
'setting-enabled' => status_page_setting&.enabled?&.to_s, 'enabled' => status_page_setting.enabled?.to_s,
'setting-aws-access-key' => status_page_setting&.aws_access_key, 'bucket-name' => status_page_setting.aws_s3_bucket_name,
'setting-masked-aws-secret-key' => status_page_setting&.masked_aws_secret_key, 'region' => status_page_setting.aws_region,
'setting-aws-region' => status_page_setting&.aws_region, 'aws-access-key' => status_page_setting.aws_access_key,
'setting-aws-s3-bucket-name' => status_page_setting&.aws_s3_bucket_name 'aws-secret-key' => status_page_setting.masked_aws_secret_key
} }
end end
end end
...@@ -32,6 +32,8 @@ class StatusPageSetting < ApplicationRecord ...@@ -32,6 +32,8 @@ class StatusPageSetting < ApplicationRecord
scope :enabled, -> { where(enabled: true) } scope :enabled, -> { where(enabled: true) }
def masked_aws_secret_key def masked_aws_secret_key
return if aws_secret_key.blank?
'*' * 40 '*' * 40
end end
......
- return unless @project.feature_available?(:status_page, current_user) && @project.beta_feature_available?(:status_page) - return unless @project.feature_available?(:status_page, current_user) && @project.beta_feature_available?(:status_page)
- setting = status_page_settings_data(@project.status_page_setting) .js-status-page-settings{ data: status_page_settings_data }
.js-status-page-settings{ data: { operations_settings_endpoint: project_settings_operations_path(@project),
enabled: setting['setting-enabled'],
bucket_name: setting['setting-aws-s3-bucket-name'],
region: setting['setting-aws-region'],
aws_access_key: setting['setting-aws-access-key'],
aws_secret_key: setting['setting-masked-aws-secret-key'] } }
...@@ -6,39 +6,27 @@ describe OperationsHelper do ...@@ -6,39 +6,27 @@ describe OperationsHelper do
describe '#status_page_settings_data' do describe '#status_page_settings_data' do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :private) } let_it_be(:project) { create(:project, :private) }
let_it_be(:status_page_setting) { project.build_status_page_setting }
subject { helper.status_page_settings_data(status_page_setting) } subject { helper.status_page_settings_data }
before do before do
helper.instance_variable_set(:@project, project) helper.instance_variable_set(:@project, project)
allow(helper).to receive(:status_page_setting) { status_page_setting }
allow(helper).to receive(:current_user) { user } allow(helper).to receive(:current_user) { user }
allow(helper) allow(helper)
.to receive(:can?).with(user, :admin_operations, project) { true } .to receive(:can?).with(user, :admin_operations, project) { true }
end end
context 'setting does not exist' do 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',
'setting-aws-region',
'setting-aws-s3-bucket-name'
)
end
it 'returns the correct values' do it 'returns the correct values' do
expect(subject).to eq( expect(subject).to eq(
'user-can-enable-status-page' => 'true', 'operations-settings-endpoint' => project_settings_operations_path(project),
'setting-enabled' => nil, 'enabled' => 'false',
'setting-aws-access-key' => nil, 'aws-access-key' => nil,
'setting-masked-aws-secret-key' => nil, 'aws-secret-key' => nil,
'setting-aws-region' => nil, 'region' => nil,
'setting-aws-s3-bucket-name' => nil 'bucket-name' => nil
) )
end end
...@@ -50,12 +38,12 @@ describe OperationsHelper do ...@@ -50,12 +38,12 @@ describe OperationsHelper do
it 'returns the correct values' do it 'returns the correct values' do
expect(subject).to eq( expect(subject).to eq(
'user-can-enable-status-page' => 'false', 'operations-settings-endpoint' => project_settings_operations_path(project),
'setting-enabled' => nil, 'enabled' => 'false',
'setting-aws-access-key' => nil, 'aws-access-key' => nil,
'setting-masked-aws-secret-key' => nil, 'aws-secret-key' => nil,
'setting-aws-region' => nil, 'region' => nil,
'setting-aws-s3-bucket-name' => nil 'bucket-name' => nil
) )
end end
end end
...@@ -65,14 +53,14 @@ describe OperationsHelper do ...@@ -65,14 +53,14 @@ describe OperationsHelper do
let(:status_page_setting) { create(:status_page_setting) } let(:status_page_setting) { create(:status_page_setting) }
it 'returns the correct values' do it 'returns the correct values' do
aggregate_failures do expect(subject).to eq(
expect(subject['user-can-enable-status-page']).to eq('true') 'operations-settings-endpoint' => project_settings_operations_path(project),
expect(subject['setting-enabled']).to eq(status_page_setting.enabled.to_s) 'enabled' => status_page_setting.enabled.to_s,
expect(subject['setting-aws-access-key']).to eq(status_page_setting.aws_access_key) 'aws-access-key' => status_page_setting.aws_access_key,
expect(subject['setting-masked-aws-secret-key']).to eq(status_page_setting.masked_aws_secret_key) 'aws-secret-key' => status_page_setting.masked_aws_secret_key,
expect(subject['setting-aws-region']).to eq(status_page_setting.aws_region) 'region' => status_page_setting.aws_region,
expect(subject['setting-aws-s3-bucket-name']).to eq(status_page_setting.aws_s3_bucket_name) 'bucket-name' => status_page_setting.aws_s3_bucket_name
end )
end end
end end
end end
......
...@@ -74,6 +74,20 @@ describe StatusPageSetting do ...@@ -74,6 +74,20 @@ describe StatusPageSetting do
end end
end end
describe '#masked_aws_secret_key' do
let(:status_page_setting) { build(:status_page_setting) }
subject { status_page_setting.masked_aws_secret_key }
it { is_expected.to eq('*' * 40) }
context 'when no secret saved' do
let(:status_page_setting) { build(:status_page_setting, aws_secret_key: nil) }
it { is_expected.to eq(nil) }
end
end
describe '#enabled?' do describe '#enabled?' do
let(:status_page_setting) { build(:status_page_setting, :enabled) } let(:status_page_setting) { build(:status_page_setting, :enabled) }
......
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