Skip to content

Add API to query Group MR approval settings

Tan Le requested to merge 273544-group-mr-approval-settings-api into master

🧩 What does this MR do?

This MR adds database table and backend fabrication to allow managing Group level MR approval settings.

Initially, this will be used to store Group-level MR approval settings. Later, we plan to expand this setup to Project-level ones. By having these settings stored in the same table, the aim is to improve hierarchical lookup of these settings across projects and their groups.

This feature is behind a feature flag :group_merge_request_approval_settings_feature_flag

Implementation

  • Endpoints: GET /groups/:id/merge_request_approval_settings
  • Permissions: Admin or Owner role
  • EE License: :group_merge_requess_approval_settings (GitLab Premium)

Example response payload:

{
  "namespace_id": 22,
  "allow_author_approval": true
}

🐘 Database

Query

The below query is used by the GET endpoint to retrieve the merge_request_approval_settings for a given namespace_id. This is a new table and there is currently no facility to insert/update records yet.

EXPLAIN ANALYZE SELECT "merge_request_approval_settings".* FROM "merge_request_approval_settings" WHERE "merge_request_approval_settings"."namespace_id" = 22 LIMIT 1;
                                                                                          QUERY PLAN                                                                                          
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=0.15..1.17 rows=1 width=33) (actual time=0.088..0.089 rows=1 loops=1)
   ->  Index Scan using index_merge_request_approval_settings_on_namespace_id on merge_request_approval_settings  (cost=0.15..7.28 rows=7 width=33) (actual time=0.088..0.088 rows=1 loops=1)
         Index Cond: (namespace_id = 22)
 Planning Time: 2.719 ms
 Execution Time: 0.129 ms

Revert

rake db:migrate:down VERSION=20201207042112
== 20201207042112 AddMergeRequestApprovalSettings: reverting ==================
-- drop_table(:merge_request_approval_settings)
   -> 0.0020s
== 20201207042112 AddMergeRequestApprovalSettings: reverted (0.0109s) =========

Migrate

rake db:migrate:up VERSION=20201207042112
== 20201207042112 AddMergeRequestApprovalSettings: migrating ==================
-- table_exists?(:merge_request_approval_settings)
   -> 0.0008s
-- create_table(:merge_request_approval_settings)
   -> 0.0079s
== 20201207042112 AddMergeRequestApprovalSettings: migrated (0.0172s) =========

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team

Related to #273544 (closed)

Edited by Tan Le

Merge request reports