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
7b9b2ddc
Commit
7b9b2ddc
authored
Mar 07, 2022
by
Zamir Martins Filho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove empty approvers in regards to
user_approvers_ids and group_approvers_ids. Changelog: fixed EE: true
parent
b1088a03
Changes
3
Hide 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 @
7b9b2ddc
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
,
user_approvers_ids
:
userIds
(
approvers
),
group_approvers_ids
:
groupIds
(
approvers
),
};
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 @
7b9b2ddc
...
...
@@ -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 @
7b9b2ddc
...
...
@@ -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