Add system note for alert when assigning to user
What does this MR do?
This MR adds functionality to create a system note corresponding to when an alert is assigned to a user.
This includes the following items:
-
Adds notes
association toAlertManagement::Alert
-
Adds :alert_user_mentions
table to integrate withNoteable
module -
Exposes notes
in GraphQL API -
FE pieces - !33763 (merged) => Approved & merged into this MR
Context
This MR represents a vertical slice of functionality for assigning alerts to users. This is slice 4/4.
This work will occur in 4 slices:
- Create sidebar view for alert - !32642 (merged)
- Add assignee to list view - !32609 (merged)
- Add assignee dropdown to sidebar of alert detail view - !33122 (merged)
- Add system notes for alert assignment
Slices 2-4 will all be behind a alert_assignee
feature flag. Grouping the work in this way will allow us to deliver functional chunks of work which can be validated individually.
Screenshots
------Click here for supplemental info to database review-----
Note: This migration is based by referencing CreateVulnerabilityUserMentions
.
All up migrations
$ rake db:migrate
== 20200527170649 CreateAlertManagementAlertUserMentions: migrating ===========
-- create_table(:alert_management_alert_user_mentions)
-> 0.0344s
-- add_index(:alert_management_alert_user_mentions, [:note_id], {:where=>"note_id IS NOT NULL", :unique=>true, :name=>"index_alert_user_mentions_on_note_id"})
-> 0.0048s
-- add_index(:alert_management_alert_user_mentions, [:alert_management_alert_id], {:where=>"note_id IS NULL", :unique=>true, :name=>"index_alert_user_mentions_on_alert_id"})
-> 0.0027s
-- add_index(:alert_management_alert_user_mentions, [:alert_management_alert_id, :note_id], {:unique=>true, :name=>"index_alert_user_mentions_on_alert_id_and_note_id"})
-> 0.0025s
== 20200527170649 CreateAlertManagementAlertUserMentions: migrated (0.0447s) ==
== 20200605003204 AddForeignKeyToAlertManagementAlertUserMentions: migrating ==
-- add_foreign_key(:alert_management_alert_user_mentions, :notes, {:column=>:note_id, :on_delete=>:cascade})
-> 0.0128s
== 20200605003204 AddForeignKeyToAlertManagementAlertUserMentions: migrated (0.0209s)
$ bin/rails dbconsole
psql (11.7)
Type "help" for help.
gitlabhq_development=# \d alert_management_alert_user_mentions
Table "public.alert_management_alert_user_mentions"
Column | Type | Collation | Nullable | Default
---------------------------+-----------+-----------+----------+------------------------------------------------------------------
id | bigint | | not null | nextval('alert_management_alert_user_mentions_id_seq'::regclass)
alert_management_alert_id | bigint | | not null |
note_id | bigint | | |
mentioned_users_ids | integer[] | | |
mentioned_projects_ids | integer[] | | |
mentioned_groups_ids | integer[] | | |
Indexes:
"alert_management_alert_user_mentions_pkey" PRIMARY KEY, btree (id)
"index_alert_user_mentions_on_alert_id" UNIQUE, btree (alert_management_alert_id) WHERE note_id IS NULL
"index_alert_user_mentions_on_alert_id_and_note_id" UNIQUE, btree (alert_management_alert_id, note_id)
"index_alert_user_mentions_on_note_id" UNIQUE, btree (note_id) WHERE note_id IS NOT NULL
Foreign-key constraints:
"fk_rails_8e48eca0fe" FOREIGN KEY (alert_management_alert_id) REFERENCES alert_management_alerts(id) ON DELETE CASCADE
"fk_rails_eb2de0cdef" FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE
Down: Note foreign key
$ rake db:migrate:down VERSION=20200605003204
== 20200605003204 AddForeignKeyToAlertManagementAlertUserMentions: reverting ==
-- remove_foreign_key(:alert_management_alert_user_mentions, {:column=>:note_id})
-> 0.0093s
== 20200605003204 AddForeignKeyToAlertManagementAlertUserMentions: reverted (0.0149s)
$ bin/rails dbconsole
psql (11.7)
Type "help" for help.
gitlabhq_development=# \d alert_management_alert_user_mentions
Table "public.alert_management_alert_user_mentions"
Column | Type | Collation | Nullable | Default
---------------------------+-----------+-----------+----------+------------------------------------------------------------------
id | bigint | | not null | nextval('alert_management_alert_user_mentions_id_seq'::regclass)
alert_management_alert_id | bigint | | not null |
note_id | bigint | | |
mentioned_users_ids | integer[] | | |
mentioned_projects_ids | integer[] | | |
mentioned_groups_ids | integer[] | | |
Indexes:
"alert_management_alert_user_mentions_pkey" PRIMARY KEY, btree (id)
"index_alert_user_mentions_on_alert_id" UNIQUE, btree (alert_management_alert_id) WHERE note_id IS NULL
"index_alert_user_mentions_on_alert_id_and_note_id" UNIQUE, btree (alert_management_alert_id, note_id)
"index_alert_user_mentions_on_note_id" UNIQUE, btree (note_id) WHERE note_id IS NOT NULL
Foreign-key constraints:
"fk_rails_8e48eca0fe" FOREIGN KEY (alert_management_alert_id) REFERENCES alert_management_alerts(id) ON DELETE CASCADE
Down: User mentions table
$ rake db:migrate:down VERSION=20200527170649
== 20200527170649 CreateAlertManagementAlertUserMentions: reverting ===========
-- remove_index(:alert_management_alert_user_mentions, {:name=>"index_alert_user_mentions_on_alert_id_and_note_id"})
-> 0.0010s
-- remove_index(:alert_management_alert_user_mentions, {:name=>"index_alert_user_mentions_on_alert_id"})
-> 0.0003s
-- remove_index(:alert_management_alert_user_mentions, {:name=>"index_alert_user_mentions_on_note_id"})
-> 0.0002s
-- drop_table(:alert_management_alert_user_mentions)
-> 0.0012s
== 20200527170649 CreateAlertManagementAlertUserMentions: reverted (0.0048s) ==
$ bin/rails dbconsole
psql (11.7)
Type "help" for help.
gitlabhq_development=# \d alert_management_alert_user_mentions
Did not find any relation named "alert_management_alert_user_mentions".
------Click here for supplemental info to backend review-----
GraphQL query test |
---|
Testing
- Alerts live under Operations > Alerts. Follow instructions in the UI to enable the Generic Alerts Endpoint for your project.
- To create alerts, either actually use the alert endpoint, or create alerts in the rails console.
FactoryBot.create(:alert_management_alert, project: project)
should do the trick. - From
Operations > Alerts
click on an alert item in the list. - Click the Assignee dropdown to change the user.
- From
/-/graphql-explorer
, and alert with an assignee and system note should now be available with a query somewhat like:
{
project(fullPath: <REPLACE ME>) {
id
fullPath
alertManagementAlerts {
nodes {
iid
status
assignees {
username
}
notes {
nodes {
id
confidential
system
body
}
}
}
}
}
}
Note: the system note will not appear in the UI until the FE changes have been incorporated into this MR.
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
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