Add Notifications Widget to WorkItems
Related to #389443 (closed)
What does this MR do and why?
Adds a new widget to the work items GraphQL endpoint.
This widget is called Notifications
and returns if the current user is subscribed to the work item's notifications.
This functionality is needed for implementing the notifications toggle in work items.
- DB migration to add new records for this widget in the
work_item_widget_definitions
table - Add model and GraphQL type for the new widget
- Add widget to
Types::WorkItems::WidgetInterface
- Update
WorkItems::WidgetDefinition
to include a new enum value for the widget - Update
WorkItems::BaseTypeImporter
- Modify
Subscribable
concern to search for the correctsubscribable_type
when querying work items subscriptions
Database migration
structure.sql
DB migration output
❯ rake db:migrate VERSION=20230228142350
main: == 20230228142350 AddNotificationsWorkItemWidget: migrating ===================
main: == 20230228142350 AddNotificationsWorkItemWidget: migrated (0.0250s) ==========
ci: == 20230228142350 AddNotificationsWorkItemWidget: migrating ===================
ci: -- The migration is skipped since it modifies the schemas: [:gitlab_main].
ci: -- This database can only apply migrations in one of the following schemas: [:gitlab_ci, :gitlab_shared, :gitlab_internal].
ci: == 20230228142350 AddNotificationsWorkItemWidget: migrated (0.0069s) ==========
❯ rake db:migrate:down:main db:migrate:down:ci VERSION=20230228142350
main: == 20230228142350 AddNotificationsWorkItemWidget: reverting ===================
main: == 20230228142350 AddNotificationsWorkItemWidget: reverted (0.0144s) ==========
ci: == 20230228142350 AddNotificationsWorkItemWidget: reverting ===================
ci: -- The migration is skipped since it modifies the schemas: [:gitlab_main].
ci: -- This database can only apply migrations in one of the following schemas: [:gitlab_ci, :gitlab_shared, :gitlab_internal].
ci: == 20230228142350 AddNotificationsWorkItemWidget: reverted (0.0191s) ==========
How to set up and validate locally
- In rails console create a new work item
project, user1, user2 = Project.first, User.first, User.last wi = WorkItem.create!(author: user1, project: project, title: 'Test Work Item', work_item_type_id: 1) wi.subscribed?(user1, project) #=> true wi.subscribed?(user2, project) #=> false
- Visit
http://gdk.test:3000/-/graphql-explorer
and test the following queries
GQL queries
query getWorkItems {
project(fullPath: "gitlab-org/gitlab-test") {
workItems(last: 1) {
edges {
node {
id
widgets {
... on WorkItemWidgetNotifications {
subscribed
}
}
}
}
}
}
}
query getSingleWorkItem {
workItem(id: "gid://gitlab/WorkItem/$WORK_ITEM_ID"){
widgets {
... on WorkItemWidgetNotifications {
subscribed
}
}
}
}
- Expected response should include
"subscribed": true
when logged in asuser1
and"subscribed": false
when logged in asuser2
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Eugenia Grieff