Skip to content

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.

Summary of changes:

  • 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 correct subscribable_type when querying work items subscriptions

🚧 The ability to update this subscription will be implemented in Allow updating user subscriptions on a work ite... (!112587 - merged)

Database migration

No changes in 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

  1. 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
  2. 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        
       }
     }
   }
 }
  1. Expected response should include "subscribed": true when logged in as user1 and "subscribed": false when logged in as user2

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Eugenia Grieff

Merge request reports

Loading