Skip to content

Allow passing global project ID to compliance center

Illya Klymov requested to merge xanf-global-project-id-in-compliance-report into master

What does this MR do and why?

As a part of preparation for Add compliance center to project level (#441350) we need an ability to pass specific project id to compliance center and "lock it"

Under locking we understand disabling ability to filter by other project ids so reports are focused around current project

Screenshots or screen recordings


How to set up and validate locally

  • Apply this diff
diff --git a/ee/app/assets/javascripts/compliance_dashboard/compliance_dashboard_bundle.js b/ee/app/assets/javascripts/compliance_dashboard/compliance_dashboard_bundle.js
index c1f086a9b40c..80b0422e1f66 100644
--- a/ee/app/assets/javascripts/compliance_dashboard/compliance_dashboard_bundle.js
+++ b/ee/app/assets/javascripts/compliance_dashboard/compliance_dashboard_bundle.js
@@ -36,7 +36,10 @@ export default () => {
     defaultClient: createDefaultClient(),

-  const globalProjectId = parseInt(projectId, 10);
+  const globalProjectId = parseInt(
+    projectId || new URLSearchParams('test_project_id'),
+    10,
+  );

   const router = createRouter(basePath, {

This will allow you to set "projectId" from test_project_id browser param, because backend changes to support project compliance center are yet to be landed

Also, you might want to seed violations for your group. You can use following snippet, ran from rails console: (do not forget to replace 29 with group you're testing)

group = Group.find_by_id(29)

type = [:approved_by_insufficient_users, :approved_by_committer, :approved_by_merge_request_author]
levels = [:high, :low, :medium, :critical]

violations = {
  project = group.projects.sample
  merge_request = FactoryBot.create(:merge_request, source_project: project, target_project: project, state: :merged)
  merge_request.metrics.update!(merged_at: rand(1..30).days.ago)
  FactoryBot.create(:compliance_violation, type.sample, severity_level: levels.sample, merge_request: merge_request, violating_user: project.members.sample.user)

Open compliance center for specific group. Find id of one of the projects on this group (let's assume 50) and append &test_project_id=50 to the page Observe "locked" behavior

Edited by Illya Klymov

Merge request reports