Add prevent approval by author check for GitLab standards adherence
What does this MR do and why?
- Add prevent approval by author check to Gitlab standard. This check is executed whenever 'prevent approval by author' merge request approval setting is updated. It creates a row inside the
projects_compliance_standards_adherence
table storing the current compliance status for the project. - Create a reusable finder class
AdherenceFinder
to fetch rows from the above table. - Inherit the base class from
BaseContainerService
to resolve this follow-up comment.
Database
Query 1
SELECT
"project_compliance_standards_adherence".*
FROM
"project_compliance_standards_adherence"
WHERE
"project_compliance_standards_adherence"."namespace_id" = 6670
AND "project_compliance_standards_adherence"."project_id" = 278964
AND "project_compliance_standards_adherence"."check_name" = 0
AND "project_compliance_standards_adherence"."standard" = 0
ORDER BY
"project_compliance_standards_adherence"."id" ASC
LIMIT 1
Link to DB lab - https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/19752/commands/64664
We don't have any rows inside projects_compliance_standards_adherence
table.
Query 2
SELECT
"projects"."id"
FROM
"projects"
WHERE
"projects"."namespace_id" IN (
SELECT
namespaces.traversal_ids[array_length(namespaces.traversal_ids, 1)] AS id
FROM
"namespaces"
WHERE
"namespaces"."type" = 'Group'
AND (traversal_ids @> ('{9970}')))
Link to DB bab - https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/19752/commands/64645
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
Test the project level settings
- Ensure that you have a GitLab Ultimate license.
- Run
Projects::ComplianceStandards::Adherence.count
inside rails console and ensure that the count is zero. - Navigate to a project's Settings > Merge requests and then enable 'Prevent approval by author' setting.
- Run
Projects::ComplianceStandards::Adherence.last
inside rails console and ensure that a row with correct attributes for status, check_name, standard is created. - Navigate to a project's Settings > Merge requests and then disable 'Prevent approval by author' setting.
- Run
Projects::ComplianceStandards::Adherence.last
inside rails console and ensure that thestatus
column has been updated tofail
fromsuccess
.
Test the group level settings
- Navigate to a group's Settings > General. Expand the 'Merge request approvals' section and then enable 'Prevent approval by author' setting.
- Run
Projects::ComplianceStandards::Adherence.for_group(<group_id>)
inside rails console and ensure that records for all the projects inside that group is is created (including projects inside a sub-groups). - Also ensure that the fields for these rows are correct, the
status
should be 'success' for all the rows,standard
should be 'gitlab' andcheck_name
should be 'prevent_approval_by_merge_request_author'. - Navigate to a group's Settings > General. Expand the 'Merge request approvals' section and then disable 'Prevent approval by author' setting.
- Run
Projects::ComplianceStandards::Adherence.for_group(<group_id>)
inside rails console and verify that the the rows are now compliance as per their project settings.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Closes #413233 (closed)
Edited by Huzaifa Iftikhar