Commit d3f779ba authored by Jannik Lehmann's avatar Jannik Lehmann Committed by Markus Koller

Add conditional Link to CE Security Config

This adresses: https://gitlab.com/gitlab-org/gitlab/-/issues/320906
It adds a conditional Link functionality to the Static
Security Configuration Page for non Ultimate User.
parent 66e31810
......@@ -7,6 +7,12 @@ export default {
GlLink,
GlSprintf,
},
inject: {
upgradePath: {
from: 'upgradePath',
default: '#',
},
},
i18n: {
UPGRADE_CTA,
},
......@@ -17,7 +23,7 @@ export default {
<span>
<gl-sprintf :message="$options.i18n.UPGRADE_CTA">
<template #link="{ content }">
<gl-link target="_blank" href="https://about.gitlab.com/pricing/">
<gl-link target="_blank" :href="upgradePath">
{{ content }}
</gl-link>
</template>
......
......@@ -14,13 +14,14 @@ export const initStaticSecurityConfiguration = (el) => {
defaultClient: createDefaultClient(),
});
const { projectPath } = el.dataset;
const { projectPath, upgradePath } = el.dataset;
return new Vue({
el,
apolloProvider,
provide: {
projectPath,
upgradePath,
},
render(createElement) {
return createElement(SecurityConfigurationApp);
......
# frozen_string_literal: true
module Projects
module Security
module ConfigurationHelper
def security_upgrade_path
'https://about.gitlab.com/pricing/'
end
end
end
end
::Projects::Security::ConfigurationHelper.prepend_if_ee('::EE::Projects::Security::ConfigurationHelper')
- breadcrumb_title _("Security Configuration")
- page_title _("Security Configuration")
#js-security-configuration-static{ data: {project_path: @project.full_path} }
#js-security-configuration-static{ data: { project_path: @project.full_path, upgrade_path: security_upgrade_path } }
# frozen_string_literal: true
module EE
module Projects
module Security
module ConfigurationHelper
extend ::Gitlab::Utils::Override
override :security_upgrade_path
def security_upgrade_path
return super unless show_discover_project_security?(@project)
project_security_discover_path(@project)
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe EE::Projects::Security::ConfigurationHelper do
include ActionView::Helpers::UrlHelper
let_it_be(:project) { create(:project) }
let(:current_user) { create(:user) }
subject { helper.security_upgrade_path }
before do
helper.instance_variable_set(:@project, project)
allow(helper).to receive(:show_discover_project_security?).and_return(can_access_discover_security)
end
context 'when user can access discover security' do
let(:can_access_discover_security) { true }
it { is_expected.to eq(project_security_discover_path(project)) }
end
context 'when user can not access discover security' do
let(:can_access_discover_security) { false }
it { is_expected.to eq('https://about.gitlab.com/pricing/') }
end
end
......@@ -2,27 +2,28 @@ import { mount } from '@vue/test-utils';
import { UPGRADE_CTA } from '~/security_configuration/components/features_constants';
import Upgrade from '~/security_configuration/components/upgrade.vue';
const TEST_URL = 'http://www.example.test';
let wrapper;
const createComponent = () => {
wrapper = mount(Upgrade, {});
const createComponent = (componentData = {}) => {
wrapper = mount(Upgrade, componentData);
};
beforeEach(() => {
createComponent();
});
afterEach(() => {
wrapper.destroy();
});
describe('Upgrade component', () => {
beforeEach(() => {
createComponent({ provide: { upgradePath: TEST_URL } });
});
it('renders correct text in link', () => {
expect(wrapper.text()).toMatchInterpolatedText(UPGRADE_CTA);
});
it('renders link with correct attributes', () => {
it('renders link with correct default attributes', () => {
expect(wrapper.find('a').attributes()).toMatchObject({
href: 'https://about.gitlab.com/pricing/',
href: TEST_URL,
target: '_blank',
});
});
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::Security::ConfigurationHelper do
let(:current_user) { create(:user) }
describe 'security_upgrade_path' do
subject { security_upgrade_path }
it { is_expected.to eq('https://about.gitlab.com/pricing/') }
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