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
015f6fd5
Commit
015f6fd5
authored
Mar 09, 2022
by
Jose Ivan Vargas
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'removes_empty_approvers' into 'master'
Remove empty approvers See merge request gitlab-org/gitlab!82338
parents
1aeea01f
7b9b2ddc
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
20 deletions
+43
-20
ee/app/assets/javascripts/threat_monitoring/components/policy_editor/scan_result_policy/lib/actions.js
...omponents/policy_editor/scan_result_policy/lib/actions.js
+11
-8
ee/spec/frontend/threat_monitoring/components/policy_editor/scan_result_policy/lib/actions_spec.js
...ents/policy_editor/scan_result_policy/lib/actions_spec.js
+32
-10
ee/spec/frontend/threat_monitoring/components/policy_editor/scan_result_policy/policy_action_builder_spec.js
...y_editor/scan_result_policy/policy_action_builder_spec.js
+0
-2
No files found.
ee/app/assets/javascripts/threat_monitoring/components/policy_editor/scan_result_policy/lib/actions.js
View file @
015f6fd5
import
{
omitBy
,
isEmpty
}
from
'
lodash
'
;
export
const
USER_TYPE
=
'
user
'
;
const
GROUP_TYPE
=
'
group
'
;
...
...
@@ -41,12 +43,13 @@ export function groupApprovers(existingApprovers) {
Convert approvers into yaml fields (user_approvers, users_approvers_ids) in relation to action.
*/
export
function
decomposeApprovers
(
action
,
approvers
)
{
const
newAction
=
{
...
action
};
delete
newAction
.
group_approvers
;
delete
newAction
.
user_approvers
;
return
{
...
newAction
,
const
newAction
=
{
type
:
action
.
type
,
approvals_required
:
action
.
approvals_required
};
const
approversInfo
=
omitBy
(
{
user_approvers_ids
:
userIds
(
approvers
),
group_approvers_ids
:
groupIds
(
approvers
),
};
},
isEmpty
,
);
return
{
...
newAction
,
...
approversInfo
};
}
ee/spec/frontend/threat_monitoring/components/policy_editor/scan_result_policy/lib/actions_spec.js
View file @
015f6fd5
...
...
@@ -25,12 +25,19 @@ const groupApprover = {
web_url
:
null
,
};
const
actionDataWithoutApprovers
=
{
approvals_required
:
1
,
type
:
'
require_approval
'
,
};
const
unknownApprover
=
{
id
:
3
,
name
:
null
};
const
allApprovers
=
[
userApprover
,
groupApprover
];
const
groupedApprovers
=
groupApprovers
(
allApprovers
);
const
userOnlyGroupedApprovers
=
groupApprovers
([
userApprover
]);
describe
(
'
groupApprovers
'
,
()
=>
{
describe
(
'
with mixed approvers
'
,
()
=>
{
it
(
'
returns a copy of the input values with their proper type attribute
'
,
()
=>
{
...
...
@@ -104,7 +111,8 @@ describe('groupApprovers', () => {
describe
(
'
decomposeApprovers
'
,
()
=>
{
it
(
'
returns a copy of approvers adding id fields for both group and users
'
,
()
=>
{
expect
(
decomposeApprovers
({},
groupedApprovers
)).
toStrictEqual
({
expect
(
decomposeApprovers
(
actionDataWithoutApprovers
,
groupedApprovers
)).
toStrictEqual
({
...
actionDataWithoutApprovers
,
group_approvers_ids
:
[
groupApprover
.
id
],
user_approvers_ids
:
[
userApprover
.
id
],
});
...
...
@@ -112,27 +120,41 @@ describe('decomposeApprovers', () => {
it
(
'
removes group_approvers and user_approvers keys only keeping the id fields
'
,
()
=>
{
expect
(
decomposeApprovers
({
user_approvers
:
null
,
group_approvers
:
null
},
groupedApprovers
),
decomposeApprovers
(
{
...
actionDataWithoutApprovers
,
user_approvers
:
null
,
group_approvers
:
null
},
groupedApprovers
,
),
).
toStrictEqual
({
...
actionDataWithoutApprovers
,
group_approvers_ids
:
[
groupApprover
.
id
],
user_approvers_ids
:
[
userApprover
.
id
],
});
});
it
(
'
preserves any other keys in addition to the id fields
'
,
()
=>
{
expect
(
decomposeApprovers
({
existingKey
:
null
},
groupedApprovers
)).
toStrictEqual
({
group_approvers_ids
:
[
groupApprover
.
id
],
it
(
'
returns only user info when group info is empty
'
,
()
=>
{
expect
(
decomposeApprovers
({
...
actionDataWithoutApprovers
},
userOnlyGroupedApprovers
),
).
toStrictEqual
({
...
actionDataWithoutApprovers
,
user_approvers_ids
:
[
userApprover
.
id
],
existingKey
:
null
,
});
});
it
(
'
returns empty id fields if there is only unknown types
'
,
()
=>
{
expect
(
decomposeApprovers
({},
[
unknownApprover
])).
toStrictEqual
({
group_approvers_ids
:
[],
user_approvers_ids
:
[],
it
(
'
removes unrelated keys
'
,
()
=>
{
expect
(
decomposeApprovers
({
...
actionDataWithoutApprovers
,
existingKey
:
null
},
groupedApprovers
),
).
toStrictEqual
({
...
actionDataWithoutApprovers
,
group_approvers_ids
:
[
groupApprover
.
id
],
user_approvers_ids
:
[
userApprover
.
id
],
});
});
it
(
'
does not returns any approvers for unknown types
'
,
()
=>
{
expect
(
decomposeApprovers
(
actionDataWithoutApprovers
,
[
unknownApprover
])).
toStrictEqual
(
actionDataWithoutApprovers
,
);
});
});
describe
(
'
userIds
'
,
()
=>
{
...
...
ee/spec/frontend/threat_monitoring/components/policy_editor/scan_result_policy/policy_action_builder_spec.js
View file @
015f6fd5
...
...
@@ -117,7 +117,6 @@ describe('PolicyActionBuilder', () => {
{
approvals_required
:
ACTION
.
approvals_required
,
user_approvers_ids
:
[
APPROVER_2
.
id
],
group_approvers_ids
:
[],
},
],
]);
...
...
@@ -140,7 +139,6 @@ describe('PolicyActionBuilder', () => {
{
approvals_required
:
ACTION
.
approvals_required
,
user_approvers_ids
:
[
APPROVER_1
.
id
,
APPROVER_2
.
id
,
NEW_APPROVER
.
id
],
group_approvers_ids
:
[],
},
],
]);
...
...
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