Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
9668f3dc
Commit
9668f3dc
authored
Sep 08, 2020
by
ap4y
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add deletePolicy action to the networkPolicy store
This commit adds a new action for removing network policies.
parent
8e4df1a6
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
203 additions
and
0 deletions
+203
-0
ee/app/assets/javascripts/threat_monitoring/store/modules/network_policies/actions.js
...reat_monitoring/store/modules/network_policies/actions.js
+24
-0
ee/app/assets/javascripts/threat_monitoring/store/modules/network_policies/mutation_types.js
...nitoring/store/modules/network_policies/mutation_types.js
+4
-0
ee/app/assets/javascripts/threat_monitoring/store/modules/network_policies/mutations.js
...at_monitoring/store/modules/network_policies/mutations.js
+13
-0
ee/app/assets/javascripts/threat_monitoring/store/modules/network_policies/state.js
...threat_monitoring/store/modules/network_policies/state.js
+2
-0
ee/spec/frontend/threat_monitoring/components/policy_editor/__snapshots__/policy_editor_spec.js.snap
...ts/policy_editor/__snapshots__/policy_editor_spec.js.snap
+16
-0
ee/spec/frontend/threat_monitoring/store/modules/network_policies/actions_spec.js
...monitoring/store/modules/network_policies/actions_spec.js
+102
-0
ee/spec/frontend/threat_monitoring/store/modules/network_policies/mutations_spec.js
...nitoring/store/modules/network_policies/mutations_spec.js
+42
-0
No files found.
ee/app/assets/javascripts/threat_monitoring/store/modules/network_policies/actions.js
View file @
9668f3dc
...
...
@@ -88,3 +88,27 @@ export const updatePolicy = ({ state, commit }, { environmentId, policy }) => {
commitPolicyError
(
commit
,
types
.
RECEIVE_UPDATE_POLICY_ERROR
,
error
?.
response
?.
data
),
);
};
export
const
deletePolicy
=
({
state
,
commit
},
{
environmentId
,
policy
})
=>
{
if
(
!
state
.
policiesEndpoint
||
!
environmentId
||
!
policy
)
{
return
commitPolicyError
(
commit
,
types
.
RECEIVE_DELETE_POLICY_ERROR
);
}
commit
(
types
.
REQUEST_DELETE_POLICY
);
return
axios
.
delete
(
joinPaths
(
state
.
policiesEndpoint
,
policy
.
name
),
{
params
:
{
environment_id
:
environmentId
,
manifest
:
policy
.
manifest
,
},
})
.
then
(()
=>
{
commit
(
types
.
RECEIVE_DELETE_POLICY_SUCCESS
,
{
policy
,
});
})
.
catch
(
error
=>
commitPolicyError
(
commit
,
types
.
RECEIVE_DELETE_POLICY_ERROR
,
error
?.
response
?.
data
),
);
};
ee/app/assets/javascripts/threat_monitoring/store/modules/network_policies/mutation_types.js
View file @
9668f3dc
...
...
@@ -11,3 +11,7 @@ export const RECEIVE_CREATE_POLICY_ERROR = 'RECEIVE_CREATE_POLICY_ERROR';
export
const
REQUEST_UPDATE_POLICY
=
'
REQUEST_UPDATE_POLICY
'
;
export
const
RECEIVE_UPDATE_POLICY_SUCCESS
=
'
RECEIVE_UPDATE_POLICY_SUCCESS
'
;
export
const
RECEIVE_UPDATE_POLICY_ERROR
=
'
RECEIVE_UPDATE_POLICY_ERROR
'
;
export
const
REQUEST_DELETE_POLICY
=
'
REQUEST_DELETE_POLICY
'
;
export
const
RECEIVE_DELETE_POLICY_SUCCESS
=
'
RECEIVE_DELETE_POLICY_SUCCESS
'
;
export
const
RECEIVE_DELETE_POLICY_ERROR
=
'
RECEIVE_DELETE_POLICY_ERROR
'
;
ee/app/assets/javascripts/threat_monitoring/store/modules/network_policies/mutations.js
View file @
9668f3dc
...
...
@@ -46,4 +46,17 @@ export default {
state
.
isUpdatingPolicy
=
false
;
state
.
errorUpdatingPolicy
=
true
;
},
[
types
.
REQUEST_DELETE_POLICY
](
state
)
{
state
.
isRemovingPolicy
=
true
;
state
.
errorRemovingPolicy
=
false
;
},
[
types
.
RECEIVE_DELETE_POLICY_SUCCESS
](
state
,
{
policy
})
{
state
.
policies
=
state
.
policies
.
filter
(({
name
})
=>
name
!==
policy
.
name
);
state
.
isRemovingPolicy
=
false
;
state
.
errorRemovingPolicy
=
false
;
},
[
types
.
RECEIVE_DELETE_POLICY_ERROR
](
state
)
{
state
.
isRemovingPolicy
=
false
;
state
.
errorRemovingPolicy
=
true
;
},
};
ee/app/assets/javascripts/threat_monitoring/store/modules/network_policies/state.js
View file @
9668f3dc
...
...
@@ -5,4 +5,6 @@ export default () => ({
errorLoadingPolicies
:
false
,
isUpdatingPolicy
:
false
,
errorUpdatingPolicy
:
false
,
isRemovingPolicy
:
false
,
errorRemovingPolicy
:
false
,
});
ee/spec/frontend/threat_monitoring/components/policy_editor/__snapshots__/policy_editor_spec.js.snap
View file @
9668f3dc
...
...
@@ -226,6 +226,8 @@ spec:
Create policy
</gl-button-stub>
<!---->
<gl-button-stub
category="secondary"
href="/threat-monitoring"
...
...
@@ -237,5 +239,19 @@ spec:
</gl-button-stub>
</div>
</div>
<gl-modal-stub
actioncancel="[object Object]"
actionsecondary="[object Object]"
modalclass=""
modalid="delete-modal"
size="md"
title="Delete policy: "
titletag="h4"
>
Are you sure you want to delete this policy? This action cannot be undone.
</gl-modal-stub>
</section>
`;
ee/spec/frontend/threat_monitoring/store/modules/network_policies/actions_spec.js
View file @
9668f3dc
...
...
@@ -340,4 +340,106 @@ describe('Network Policy actions', () => {
}));
});
});
describe
(
'
deletePolicy
'
,
()
=>
{
describe
(
'
on success
'
,
()
=>
{
beforeEach
(()
=>
{
mock
.
onDelete
(
joinPaths
(
networkPoliciesEndpoint
,
policy
.
name
),
{
params
:
{
environment_id
:
environmentId
,
manifest
:
policy
.
manifest
,
},
})
.
replyOnce
(
httpStatus
.
OK
);
});
it
(
'
should dispatch the request and success actions
'
,
()
=>
testAction
(
actions
.
deletePolicy
,
{
environmentId
,
policy
},
state
,
[
{
type
:
types
.
REQUEST_DELETE_POLICY
},
{
type
:
types
.
RECEIVE_DELETE_POLICY_SUCCESS
,
payload
:
{
policy
},
},
],
[],
));
});
describe
(
'
on error
'
,
()
=>
{
const
error
=
{
error
:
'
foo
'
};
beforeEach
(()
=>
{
mock
.
onDelete
(
joinPaths
(
networkPoliciesEndpoint
,
policy
.
name
),
{
params
:
{
environment_id
:
environmentId
,
manifest
:
policy
.
manifest
,
},
})
.
replyOnce
(
500
,
error
);
});
it
(
'
should dispatch the request and error actions
'
,
()
=>
testAction
(
actions
.
deletePolicy
,
{
environmentId
,
policy
},
state
,
[
{
type
:
types
.
REQUEST_DELETE_POLICY
},
{
type
:
types
.
RECEIVE_DELETE_POLICY_ERROR
,
payload
:
'
foo
'
},
],
[],
).
then
(()
=>
{
expect
(
createFlash
).
toHaveBeenCalled
();
}));
});
describe
(
'
with an empty endpoint
'
,
()
=>
{
beforeEach
(()
=>
{
state
.
policiesEndpoint
=
''
;
});
it
(
'
should dispatch RECEIVE_DELETE_POLICY_ERROR
'
,
()
=>
testAction
(
actions
.
deletePolicy
,
{
environmentId
,
policy
},
state
,
[
{
type
:
types
.
RECEIVE_DELETE_POLICY_ERROR
,
payload
:
s__
(
'
NetworkPolicies|Something went wrong, failed to update policy
'
),
},
],
[],
).
then
(()
=>
{
expect
(
createFlash
).
toHaveBeenCalled
();
}));
});
describe
(
'
without environment id
'
,
()
=>
{
it
(
'
should dispatch RECEIVE_DELETE_POLICY_ERROR
'
,
()
=>
testAction
(
actions
.
deletePolicy
,
{
environmentId
:
undefined
,
policy
,
},
state
,
[
{
type
:
types
.
RECEIVE_DELETE_POLICY_ERROR
,
payload
:
s__
(
'
NetworkPolicies|Something went wrong, failed to update policy
'
),
},
],
[],
).
then
(()
=>
{
expect
(
createFlash
).
toHaveBeenCalled
();
}));
});
});
});
ee/spec/frontend/threat_monitoring/store/modules/network_policies/mutations_spec.js
View file @
9668f3dc
...
...
@@ -138,4 +138,46 @@ describe('Network Policies mutations', () => {
expect
(
state
.
errorUpdatingPolicy
).
toBe
(
true
);
});
});
describe
(
types
.
REQUEST_DELETE_POLICY
,
()
=>
{
beforeEach
(()
=>
{
mutations
[
types
.
REQUEST_DELETE_POLICY
](
state
);
});
it
(
'
sets isRemovingPolicy to true and sets errorRemovingPolicy to false
'
,
()
=>
{
expect
(
state
.
isRemovingPolicy
).
toBe
(
true
);
expect
(
state
.
errorRemovingPolicy
).
toBe
(
false
);
});
});
describe
(
types
.
RECEIVE_DELETE_POLICY_SUCCESS
,
()
=>
{
const
policy
=
{
id
:
1
,
name
:
'
production
'
,
manifest
:
'
foo
'
};
beforeEach
(()
=>
{
state
.
policies
.
push
(
policy
);
mutations
[
types
.
RECEIVE_DELETE_POLICY_SUCCESS
](
state
,
{
policy
,
});
});
it
(
'
removes the policy
'
,
()
=>
{
expect
(
state
.
policies
).
not
.
toEqual
(
expect
.
objectContaining
(
policy
));
});
it
(
'
sets isRemovingPolicy to false and sets errorRemovingPolicy to false
'
,
()
=>
{
expect
(
state
.
isRemovingPolicy
).
toBe
(
false
);
expect
(
state
.
errorRemovingPolicy
).
toBe
(
false
);
});
});
describe
(
types
.
RECEIVE_DELETE_POLICY_ERROR
,
()
=>
{
beforeEach
(()
=>
{
mutations
[
types
.
RECEIVE_DELETE_POLICY_ERROR
](
state
);
});
it
(
'
sets isRemovingPolicy to false and sets errorRemovingPolicy to true
'
,
()
=>
{
expect
(
state
.
isRemovingPolicy
).
toBe
(
false
);
expect
(
state
.
errorRemovingPolicy
).
toBe
(
true
);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment