Commit c251ad8c authored by Frédéric Caplette's avatar Frédéric Caplette

Merge branch '354140-non-owner-security-project-button' into 'master'

Add "view policy project" button for non-owners

See merge request gitlab-org/gitlab!82341
parents 1b0648b1 dbedd6a8
<script> <script>
import { GlAlert, GlSprintf, GlButton } from '@gitlab/ui'; import { GlAlert, GlButton, GlIcon, GlSprintf } from '@gitlab/ui';
import { joinPaths } from '~/lib/utils/url_utility';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { NEW_POLICY_BUTTON_TEXT } from '../constants'; import { NEW_POLICY_BUTTON_TEXT } from '../constants';
import ScanNewPolicyModal from './scan_new_policy_modal.vue'; import ScanNewPolicyModal from './scan_new_policy_modal.vue';
export default { export default {
components: { components: {
GlSprintf,
GlButton,
GlAlert, GlAlert,
GlButton,
GlIcon,
GlSprintf,
ScanNewPolicyModal, ScanNewPolicyModal,
}, },
inject: [ inject: [
...@@ -24,6 +26,7 @@ export default { ...@@ -24,6 +26,7 @@ export default {
), ),
newPolicyButtonText: NEW_POLICY_BUTTON_TEXT, newPolicyButtonText: NEW_POLICY_BUTTON_TEXT,
editPolicyProjectButtonText: s__('SecurityOrchestration|Edit policy project'), editPolicyProjectButtonText: s__('SecurityOrchestration|Edit policy project'),
viewPolicyProjectButtonText: s__('SecurityOrchestration|View policy project'),
}, },
data() { data() {
return { return {
...@@ -38,6 +41,9 @@ export default { ...@@ -38,6 +41,9 @@ export default {
hasAssignedPolicyProject() { hasAssignedPolicyProject() {
return Boolean(this.assignedPolicyProject?.id); return Boolean(this.assignedPolicyProject?.id);
}, },
securityPolicyProjectPath() {
return joinPaths('/', this.assignedPolicyProject?.full_path);
},
}, },
methods: { methods: {
updateAlertText({ text, variant }) { updateAlertText({ text, variant }) {
...@@ -101,6 +107,16 @@ export default { ...@@ -101,6 +107,16 @@ export default {
> >
{{ $options.i18n.editPolicyProjectButtonText }} {{ $options.i18n.editPolicyProjectButtonText }}
</gl-button> </gl-button>
<gl-button
v-else-if="hasAssignedPolicyProject"
data-testid="view-project-policy-button"
class="gl-mr-4"
target="_blank"
:href="securityPolicyProjectPath"
>
<gl-icon name="external-link" />
{{ $options.i18n.viewPolicyProjectButtonText }}
</gl-button>
<gl-button <gl-button
data-testid="new-policy-button" data-testid="new-policy-button"
data-qa-selector="new_policy_button" data-qa-selector="new_policy_button"
......
...@@ -17,6 +17,7 @@ describe('Policies Header Component', () => { ...@@ -17,6 +17,7 @@ describe('Policies Header Component', () => {
const findHeader = () => wrapper.findByRole('heading'); const findHeader = () => wrapper.findByRole('heading');
const findMoreInformationLink = () => wrapper.findComponent(GlButton); const findMoreInformationLink = () => wrapper.findComponent(GlButton);
const findEditPolicyProjectButton = () => wrapper.findByTestId('edit-project-policy-button'); const findEditPolicyProjectButton = () => wrapper.findByTestId('edit-project-policy-button');
const findViewPolicyProjectButton = () => wrapper.findByTestId('view-project-policy-button');
const findNewPolicyButton = () => wrapper.findByTestId('new-policy-button'); const findNewPolicyButton = () => wrapper.findByTestId('new-policy-button');
const findSubheader = () => wrapper.findByTestId('policies-subheader'); const findSubheader = () => wrapper.findByTestId('policies-subheader');
...@@ -58,12 +59,14 @@ describe('Policies Header Component', () => { ...@@ -58,12 +59,14 @@ describe('Policies Header Component', () => {
expect(findNewPolicyButton().attributes('href')).toBe(newPolicyPath); expect(findNewPolicyButton().attributes('href')).toBe(newPolicyPath);
}); });
it('displays the Edit policy project button', () => { it.each`
expect(findEditPolicyProjectButton().text()).toBe('Edit policy project'); status | component | findFn | exists
}); ${'does'} | ${'edit policy project button'} | ${findEditPolicyProjectButton} | ${true}
${'does not'} | ${'view policy project button'} | ${findViewPolicyProjectButton} | ${false}
it('does not display the alert component by default', () => { ${'does not'} | ${'alert component'} | ${findAlert} | ${false}
expect(findAlert().exists()).toBe(false); ${'does'} | ${'header'} | ${findHeader} | ${true}
`('$status display the $component', ({ findFn, exists }) => {
expect(findFn().exists()).toBe(exists);
}); });
it('mounts the scan new policy modal', () => { it('mounts the scan new policy modal', () => {
...@@ -76,10 +79,6 @@ describe('Policies Header Component', () => { ...@@ -76,10 +79,6 @@ describe('Policies Header Component', () => {
expect(findScanNewPolicyModal().props().visible).toBe(true); expect(findScanNewPolicyModal().props().visible).toBe(true);
}); });
it('displays the header', () => {
expect(findHeader().text()).toBe('Policies');
});
it('displays the subheader', () => { it('displays the subheader', () => {
expect(findSubheader().text()).toMatchInterpolatedText( expect(findSubheader().text()).toMatchInterpolatedText(
'Enforce security for this project. More information.', 'Enforce security for this project. More information.',
...@@ -106,12 +105,36 @@ describe('Policies Header Component', () => { ...@@ -106,12 +105,36 @@ describe('Policies Header Component', () => {
}); });
describe('project user', () => { describe('project user', () => {
beforeEach(() => { describe('with a security policy project', () => {
createWrapper({ provide: { disableSecurityPolicyProject: true } }); beforeEach(() => {
createWrapper({
provide: { assignedPolicyProject: { id: '1' }, disableSecurityPolicyProject: true },
});
});
it.each`
status | component | findFn | exists
${'does not'} | ${'edit policy project button'} | ${findEditPolicyProjectButton} | ${false}
${'does'} | ${'view policy project button'} | ${findViewPolicyProjectButton} | ${true}
`('$status display the $component', ({ findFn, exists }) => {
expect(findFn().exists()).toBe(exists);
});
}); });
it('does not display the Edit policy project button', () => { describe('without a security policy project', () => {
expect(findEditPolicyProjectButton().exists()).toBe(false); beforeEach(() => {
createWrapper({
provide: { disableSecurityPolicyProject: true },
});
});
it.each`
component | findFn
${'edit policy project button'} | ${findEditPolicyProjectButton}
${'view policy project button'} | ${findViewPolicyProjectButton}
`('does not display the $component', ({ findFn }) => {
expect(findFn().exists()).toBe(false);
});
}); });
}); });
}); });
...@@ -32758,6 +32758,9 @@ msgstr "" ...@@ -32758,6 +32758,9 @@ msgstr ""
msgid "SecurityOrchestration|Update scan policies" msgid "SecurityOrchestration|Update scan policies"
msgstr "" msgstr ""
msgid "SecurityOrchestration|View policy project"
msgstr ""
msgid "SecurityOrchestration|a" msgid "SecurityOrchestration|a"
msgstr "" msgstr ""
......
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