Skip to content

Add assignee to alert management list view

Sarah Yasonik requested to merge alert-assignee-list-view into master

What does this MR do?

This MR adds support for assignees on alerts & the ability to view them from the alert management list view.

This includes the following items:

  • Adds table for alert_assignees table & model
  • Adds relationship to AlertManagement::Alert model
  • Exposes assignees via GraphQL API
  • FE pieces - Approved & merged into this MR !32842 (merged)

Context

This MR represents a vertical slice of functionality for assigning alerts to users. This is slice 2/4.

This work will occur in 4 slices:

  1. Create sidebar view for alert - !32642 (merged)
  2. Add assignee to list view
  3. Add assignee dropdown to sidebar of alert detail view - !33122 (merged)
  4. Add system notes for alert assignment - MR TBD

Database Review

-----Click here for supplemental database review materials------

Up migration output: All migrations

$ rake db:migrate
== 20200521225327 CreateAlertManagementAlertAssignees: migrating ==============
-- create_table(:alert_management_alert_assignees)
   -> 0.0104s
== 20200521225327 CreateAlertManagementAlertAssignees: migrated (0.0105s) =====

== 20200521225337 AddForeignKeyToUserIdOnAlertManagementAlertAssignees: migrating 
-- add_foreign_key(:alert_management_alert_assignees, :users, {:column=>:user_id, :on_delete=>:cascade})
   -> 0.0075s
== 20200521225337 AddForeignKeyToUserIdOnAlertManagementAlertAssignees: migrated (0.0143s) 

== 20200521225346 AddForeignKeyToAlertIdOnAlertMangagementAlertAssignees: migrating 
-- add_foreign_key(:alert_management_alert_assignees, :alert_management_alerts, {:column=>:alert_id, :on_delete=>:cascade})
   -> 0.0057s
== 20200521225346 AddForeignKeyToAlertIdOnAlertMangagementAlertAssignees: migrated (0.0071s) 

$ bin/rails dbconsole
psql (11.7)
Type "help" for help.

gitlabhq_development=# \d alert_management_alert_assignees
                             Table "public.alert_management_alert_assignees"
  Column  |  Type  | Collation | Nullable |                           Default                            
----------+--------+-----------+----------+--------------------------------------------------------------
 id       | bigint |           | not null | nextval('alert_management_alert_assignees_id_seq'::regclass)
 user_id  | bigint |           | not null | 
 alert_id | bigint |           | not null | 
Indexes:
    "alert_management_alert_assignees_pkey" PRIMARY KEY, btree (id)
    "index_alert_assignees_on_user_id_and_alert_id" UNIQUE, btree (user_id, alert_id)
    "index_alert_assignees_on_alert_id" btree (alert_id)
Foreign-key constraints:
    "fk_rails_93c0f6703b" FOREIGN KEY (alert_id) REFERENCES alert_management_alerts(id) ON DELETE CASCADE
    "fk_rails_d47570ac62" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE

Rollback alert_id foreign key constraint

$ rake db:migrate:down VERSION=20200521225346
== 20200521225346 AddForeignKeyToAlertIdOnAlertMangagementAlertAssignees: reverting 
-- remove_foreign_key(:alert_management_alert_assignees, {:column=>:alert_id})
   -> 0.0048s
== 20200521225346 AddForeignKeyToAlertIdOnAlertMangagementAlertAssignees: reverted (0.0107s) 

$ bin/rails dbconsole
psql (11.7)
Type "help" for help.

gitlabhq_development=# \d alert_management_alert_assignees
                             Table "public.alert_management_alert_assignees"
  Column  |  Type  | Collation | Nullable |                           Default                            
----------+--------+-----------+----------+--------------------------------------------------------------
 id       | bigint |           | not null | nextval('alert_management_alert_assignees_id_seq'::regclass)
 user_id  | bigint |           | not null | 
 alert_id | bigint |           | not null | 
Indexes:
    "alert_management_alert_assignees_pkey" PRIMARY KEY, btree (id)
    "index_alert_assignees_on_user_id_and_alert_id" UNIQUE, btree (user_id, alert_id)
    "index_alert_assignees_on_alert_id" btree (alert_id)
Foreign-key constraints:
    "fk_rails_d47570ac62" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE

Rollback user_id foreign key constraint

$ rake db:migrate:down VERSION=20200521225337
== 20200521225337 AddForeignKeyToUserIdOnAlertManagementAlertAssignees: reverting 
-- remove_foreign_key(:alert_management_alert_assignees, {:column=>:user_id})
   -> 0.0051s
== 20200521225337 AddForeignKeyToUserIdOnAlertManagementAlertAssignees: reverted (0.0086s) 

$ bin/rails dbconsole
psql (11.7)
Type "help" for help.

gitlabhq_development=# \d alert_management_alert_assignees
                             Table "public.alert_management_alert_assignees"
  Column  |  Type  | Collation | Nullable |                           Default                            
----------+--------+-----------+----------+--------------------------------------------------------------
 id       | bigint |           | not null | nextval('alert_management_alert_assignees_id_seq'::regclass)
 user_id  | bigint |           | not null | 
 alert_id | bigint |           | not null | 
Indexes:
    "alert_management_alert_assignees_pkey" PRIMARY KEY, btree (id)
    "index_alert_assignees_on_user_id_and_alert_id" UNIQUE, btree (user_id, alert_id)
    "index_alert_assignees_on_alert_id" btree (alert_id)

Rollback table creation

$ rake db:migrate:down VERSION=20200521225327
== 20200521225327 CreateAlertManagementAlertAssignees: reverting ==============
-- drop_table(:alert_management_alert_assignees)
   -> 0.0032s
== 20200521225327 CreateAlertManagementAlertAssignees: reverted (0.0033s) =====

$ bin/rails dbconsole
psql (11.7)
Type "help" for help.

gitlabhq_development=# \d alert_management_alert_assignees
Did not find any relation named "alert_management_alert_assignees".

Backend Review

-----Click here for supplemental backend review materials------
Test output from GraphQL updates Creating assignments via rails console
Screen_Shot_2020-05-19_at_7.39.45_PM 1. From gdk/gitlab, run: rails c
2.a. To add the root user to the most recent alert on your instance, run: AlertManagement::AlertAssignee.create(alert: AlertManagement::Alert.last, assignee: User.first))
2.b. If no alerts exist, refer to https://gitlab.slack.com/archives/C011SEJ6SPR/p1588148985018300 to create some Screen_Shot_2020-05-19_at_7.59.45_PM

Screenshot

Alert Management List
Screenshot_from_2020-05-29_21-51-26

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
Edited by Rémy Coutable

Merge request reports