Commit b6ab1abf authored by Enrique Alcántara's avatar Enrique Alcántara

Merge branch '333978-limit-changing-security-policy-project' into 'master'

Add ability to change security policy project

See merge request gitlab-org/gitlab!68017
parents 5774f6f5 6b999c86
...@@ -10,14 +10,19 @@ export default { ...@@ -10,14 +10,19 @@ export default {
GlAlert, GlAlert,
ScanNewPolicyModal, ScanNewPolicyModal,
}, },
inject: ['documentationPath', 'assignedPolicyProject', 'newPolicyPath'], inject: [
'assignedPolicyProject',
'disableSecurityPolicyProject',
'documentationPath',
'newPolicyPath',
],
i18n: { i18n: {
title: s__('NetworkPolicies|Policies'), title: s__('SecurityOrchestration|Policies'),
subtitle: s__( subtitle: s__(
'NetworkPolicies|Enforce security for this project. %{linkStart}More information.%{linkEnd}', 'SecurityOrchestration|Enforce security for this project. %{linkStart}More information.%{linkEnd}',
), ),
newPolicyButtonText: s__('NetworkPolicies|New policy'), newPolicyButtonText: s__('SecurityOrchestration|New policy'),
editPolicyButtonText: s__('NetworkPolicies|Edit policy project'), editPolicyProjectButtonText: s__('SecurityOrchestration|Edit policy project'),
}, },
data() { data() {
return { return {
...@@ -86,12 +91,13 @@ export default { ...@@ -86,12 +91,13 @@ export default {
</p> </p>
</div> </div>
<gl-button <gl-button
v-if="!disableSecurityPolicyProject"
data-testid="edit-project-policy-button" data-testid="edit-project-policy-button"
class="gl-mr-4" class="gl-mr-4"
:loading="projectIsBeingLinked" :loading="projectIsBeingLinked"
@click="showNewPolicyModal" @click="showNewPolicyModal"
> >
{{ $options.i18n.editPolicyButtonText }} {{ $options.i18n.editPolicyProjectButtonText }}
</gl-button> </gl-button>
<gl-button data-testid="new-policy-button" variant="confirm" :href="newPolicyPath"> <gl-button data-testid="new-policy-button" variant="confirm" :href="newPolicyPath">
{{ $options.i18n.newPolicyButtonText }} {{ $options.i18n.newPolicyButtonText }}
......
...@@ -8,6 +8,7 @@ describe('Policies Header Component', () => { ...@@ -8,6 +8,7 @@ describe('Policies Header Component', () => {
const documentationPath = '/path/to/docs'; const documentationPath = '/path/to/docs';
const newPolicyPath = '/path/to/new/policy/page'; const newPolicyPath = '/path/to/new/policy/page';
const projectLinkSuccessText = 'Project was linked successfully.';
const findAlert = () => wrapper.findComponent(GlAlert); const findAlert = () => wrapper.findComponent(GlAlert);
const findScanNewPolicyModal = () => wrapper.findComponent(ScanNewPolicyModal); const findScanNewPolicyModal = () => wrapper.findComponent(ScanNewPolicyModal);
...@@ -17,12 +18,21 @@ describe('Policies Header Component', () => { ...@@ -17,12 +18,21 @@ describe('Policies Header Component', () => {
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');
const linkSecurityPoliciesProject = async () => {
findScanNewPolicyModal().vm.$emit('project-updated', {
text: projectLinkSuccessText,
variant: 'success',
});
await wrapper.vm.$nextTick();
};
const createWrapper = ({ provide } = {}) => { const createWrapper = ({ provide } = {}) => {
wrapper = shallowMountExtended(PoliciesHeader, { wrapper = shallowMountExtended(PoliciesHeader, {
provide: { provide: {
documentationPath, documentationPath,
newPolicyPath, newPolicyPath,
assignedPolicyProject: null, assignedPolicyProject: null,
disableSecurityPolicyProject: false,
...provide, ...provide,
}, },
stubs: { stubs: {
...@@ -36,6 +46,7 @@ describe('Policies Header Component', () => { ...@@ -36,6 +46,7 @@ describe('Policies Header Component', () => {
wrapper.destroy(); wrapper.destroy();
}); });
describe('project owner', () => {
beforeEach(() => { beforeEach(() => {
createWrapper(); createWrapper();
}); });
...@@ -53,25 +64,6 @@ describe('Policies Header Component', () => { ...@@ -53,25 +64,6 @@ describe('Policies Header Component', () => {
expect(findAlert().exists()).toBe(false); expect(findAlert().exists()).toBe(false);
}); });
it('displays the alert component when scan new modal policy emits events', async () => {
const text = 'Project was linked successfully.';
findScanNewPolicyModal().vm.$emit('project-updated', {
text,
variant: 'success',
});
// When the project is updated it displays the output message.
await wrapper.vm.$nextTick();
expect(findAlert().text()).toBe(text);
// When the project is being updated once again, it removes the alert so that
// the new one will be displayed.
findScanNewPolicyModal().vm.$emit('updating-project');
await wrapper.vm.$nextTick();
expect(findAlert().exists()).toBe(false);
});
it('mounts the scan new policy modal', () => { it('mounts the scan new policy modal', () => {
expect(findScanNewPolicyModal().exists()).toBe(true); expect(findScanNewPolicyModal().exists()).toBe(true);
}); });
...@@ -87,7 +79,36 @@ describe('Policies Header Component', () => { ...@@ -87,7 +79,36 @@ describe('Policies Header Component', () => {
}); });
it('displays the subheader', () => { it('displays the subheader', () => {
expect(findSubheader().text()).toContain('Enforce security for this project.'); expect(findSubheader().text()).toMatchInterpolatedText(
'Enforce security for this project. More information.',
);
expect(findMoreInformationLink().attributes('href')).toBe(documentationPath); expect(findMoreInformationLink().attributes('href')).toBe(documentationPath);
}); });
describe('linking security policies project', () => {
beforeEach(async () => {
await linkSecurityPoliciesProject();
});
it('displays the alert component when scan new modal policy emits event', async () => {
expect(findAlert().text()).toBe(projectLinkSuccessText);
});
it('hides the previous alert when scan new modal policy is processing a new link', async () => {
findScanNewPolicyModal().vm.$emit('updating-project');
await wrapper.vm.$nextTick();
expect(findAlert().exists()).toBe(false);
});
});
});
describe('project user', () => {
beforeEach(() => {
createWrapper({ provide: { disableSecurityPolicyProject: true } });
});
it('does not display the Edit policy project button', () => {
expect(findEditPolicyProjectButton().exists()).toBe(false);
});
});
}); });
...@@ -22076,12 +22076,6 @@ msgstr "" ...@@ -22076,12 +22076,6 @@ msgstr ""
msgid "NetworkPolicies|Edit policy" msgid "NetworkPolicies|Edit policy"
msgstr "" msgstr ""
msgid "NetworkPolicies|Edit policy project"
msgstr ""
msgid "NetworkPolicies|Enforce security for this project. %{linkStart}More information.%{linkEnd}"
msgstr ""
msgid "NetworkPolicies|Enforcement status" msgid "NetworkPolicies|Enforcement status"
msgstr "" msgstr ""
...@@ -22124,9 +22118,6 @@ msgstr "" ...@@ -22124,9 +22118,6 @@ msgstr ""
msgid "NetworkPolicies|Please %{installLinkStart}install%{installLinkEnd} and %{configureLinkStart}configure a Kubernetes Agent for this project%{configureLinkEnd} to enable alerts." msgid "NetworkPolicies|Please %{installLinkStart}install%{installLinkEnd} and %{configureLinkStart}configure a Kubernetes Agent for this project%{configureLinkEnd} to enable alerts."
msgstr "" msgstr ""
msgid "NetworkPolicies|Policies"
msgstr ""
msgid "NetworkPolicies|Policies are a specification of how groups of pods are allowed to communicate with each other's network endpoints." msgid "NetworkPolicies|Policies are a specification of how groups of pods are allowed to communicate with each other's network endpoints."
msgstr "" msgstr ""
...@@ -29537,9 +29528,21 @@ msgstr "" ...@@ -29537,9 +29528,21 @@ msgstr ""
msgid "SecurityOrchestration|An error occurred assigning your security policy project" msgid "SecurityOrchestration|An error occurred assigning your security policy project"
msgstr "" msgstr ""
msgid "SecurityOrchestration|Edit policy project"
msgstr ""
msgid "SecurityOrchestration|Enforce security for this project. %{linkStart}More information.%{linkEnd}"
msgstr ""
msgid "SecurityOrchestration|New policy"
msgstr ""
msgid "SecurityOrchestration|Only owners can update Security Policy Project" msgid "SecurityOrchestration|Only owners can update Security Policy Project"
msgstr "" msgstr ""
msgid "SecurityOrchestration|Policies"
msgstr ""
msgid "SecurityOrchestration|Security policy project was linked successfully" msgid "SecurityOrchestration|Security policy project was linked successfully"
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