Add assignee to alert management list view
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:
- Create sidebar view for alert - !32642 (merged)
- Add assignee to list view
- Add assignee dropdown to sidebar of alert detail view - !33122 (merged)
- 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
alert_id
foreign key constraint
Rollback $ 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
user_id
foreign key constraint
Rollback $ 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 |
---|---|
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 |
Screenshot
Alert Management List |
---|
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) - Documentation to be included with feature flag removal. -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. - [-] Tested in all supported browsers
- [-] Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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