"Empty" project level approval rule created when using `user_ids` or `group_ids` when using the API
Summary
"Empty" (and invalid?) project level approval rule created when using user_ids
or group_ids
when using the API.
Steps to reproduce
- Create a new project
- Use the API to create new approval rules
# Using `group_ids` - Doesn't work
$ curl --request POST --header "PRIVATE-TOKEN: <TOKEN>" --header 'Content-Type: application/json' --data '{"name": "test5", "approvals_required": 1, "rule_type": "regular", "group_ids": [68871993]}' https://gitlab.com/api/v4/projects/46873013/approval_rules
{"id":15789224,"name":"test5","rule_type":"regular","eligible_approvers":[],"approvals_required":1,"users":[],"groups":[],"contains_hidden_groups":false,"protected_branches":[],"applies_to_all_protected_branches":false}
# Using `groups` - Works
$ curl --request POST --header "PRIVATE-TOKEN: <TOKEN>" --header 'Content-Type: application/json' --data '{"name": "test4", "approvals_required": 1, "rule_type": "regular", "groups": [68871993]}' https://gitlab.com/api/v4/projects/46873013/approval_rules
{"id":15789123,"name":"test4","rule_type":"regular","eligible_approvers":[{"id":7685703,"username":"kenneth","name":"Kenneth Chu","state":"active"...<REDACTED for simplicity>...}
# Using `user_ids` - Doesn't work
$ curl --request POST --header "PRIVATE-TOKEN: TOKEN" --header 'Content-Type: application/json' --data '{"name": "userids_test", "approvals_required": 1, "rule_type": "regular", "user_ids": [9323986, 7685703]}' https://gitlab.com/api/v4/projects/46873013/approval_rules
{"id":15789763,"name":"userids_test","rule_type":"regular","eligible_approvers":[],"approvals_required":1,"users":[],"groups":[],"contains_hidden_groups":false,"protected_branches":[],"applies_to_all_protected_branches":false}
- In addition, there is a weird behaviour when the rule_type is
any_approver
, where the API returns that the rule was successfully created, but doesn't show up in the UI at all.
$ curl --request POST --header "PRIVATE-TOKEN: TOKEN" --header 'Content-Type: application/json' --data '{"name": "test7", "approvals_required": 1, "rule_type": "any_approver", "groups": [68871993, 16207900]}' https://gitlab.com/api/v4/projects/46873013/approval_rules
{"id":15789963,"name":"test7","rule_type":"any_approver","eligible_approvers":[{"id":7685703,"username":"kenneth","name":"Kenneth Chu","state":"active"...<REDACTED for simplicity>...}
Example Project
For GitLab team members, they can look at the project here: https://gitlab.com/gitlab-silver/kenneth-silver/zd418859-project/-/settings/merge_requests
What is the current bug behavior?
Project level approval rules created with user_ids
or group_ids
creates an "empty" rule.
What is the expected correct behavior?
Project level approval rules created with user_ids
or group_ids
creates a valid rule.
Relevant logs and/or screenshots
- API response: (
GET
on https://gitlab.com/api/v4/projects/46873013/approval_rules)
[
{
"id": 15789963,
"name": "test7",
"rule_type": "any_approver",
"eligible_approvers": [
{
"username": "kenneth",
"name": "Kenneth Chu",
...
...
},
{
"id": 9323986,
"username": "kenneth-auditor",
"name": "Kenneth Chu",
...
...
},
{
"id": 9671016,
"username": "dkua1",
"name": "Daphne Kua",
...
...
}
],
"approvals_required": 1,
"users": [],
"groups": [],
"contains_hidden_groups": false,
"protected_branches": [],
"applies_to_all_protected_branches": false
},
{
"id": 15789123,
"name": "test4",
"rule_type": "regular",
"eligible_approvers": [
{
"id": 7685703,
"username": "kenneth",
"name": "Kenneth Chu",
...
...
},
{
"id": 9323986,
"username": "kenneth-auditor",
"name": "Kenneth Chu",
...
...
}
],
"approvals_required": 1,
"users": [],
"groups": [
{
"id": 68871993,
"web_url": "https://gitlab.com/groups/gitlab-silver/kenneth-silver/zd418859-approvers",
"name": "ZD418859-approvers",
"path": "zd418859-approvers",
...
}
],
"contains_hidden_groups": false,
"protected_branches": [],
"applies_to_all_protected_branches": false
},
{
"id": 15789224,
"name": "test5",
"rule_type": "regular",
"eligible_approvers": [],
"approvals_required": 1,
"users": [],
"groups": [],
"contains_hidden_groups": false,
"protected_branches": [],
"applies_to_all_protected_branches": false
},
{
"id": 15789760,
"name": "test6",
"rule_type": "regular",
"eligible_approvers": [],
"approvals_required": 1,
"users": [],
"groups": [],
"contains_hidden_groups": false,
"protected_branches": [],
"applies_to_all_protected_branches": false
},
{
"id": 15789763,
"name": "userids_test",
"rule_type": "regular",
"eligible_approvers": [],
"approvals_required": 1,
"users": [],
"groups": [],
"contains_hidden_groups": false,
"protected_branches": [],
"applies_to_all_protected_branches": false
}
]
- Rules are created in the UI, but show up with no approvers. NOTE that the
test7
rule does not show up in the UI at all.
Output of checks
This bug happens on GitLab.com - GitLab Enterprise Edition 16.1.0-pre 1033acf5311
Possible fixes
I've tried to do a bit of digging as to what may have changed, here is what I've found so far.
- API code: https://gitlab.com/gitlab-org/gitlab/-/blob/b8d4ff88fe70c9f4b13e356cf6c3c7c771bb5e3d/ee/lib/api/project_approval_rules.rb#L39-41
- Which uses this helper: https://gitlab.com/gitlab-org/gitlab/-/blob/9177cc2445744b584ff24e81c62839c6500f3f04/ee/lib/api/helpers/project_approval_rules_helpers.rb#L13
- Which uses this validation: https://gitlab.com/gitlab-org/gitlab/-/blob/9177cc2445744b584ff24e81c62839c6500f3f04/lib/api/validations/types/comma_separated_to_integer_array.rb
- And going by the commit history (and mentioned in the helper file), the validation uses the functions from the
grape
gem.
I found this MR that updates the grape gem, and the update was deployed to gitlab.com on June 13th, which seems to fit the timeframe of when the customer I was helping mentioned this started.
Workaround
use groups
and users
rather than group_ids
and user_ids