Commit f3571f65 authored by Eulyeon Ko's avatar Eulyeon Ko

Add notification graphql fields to issue type

Add "emailsDiabled" field that indicates whether the project
associated with an issue has emails notifications enabled or not.

Add "subscribeDisabledDescription" field that contains the message
to display when the project associated with an issue has
emails notifications disabled.
parent a86581ac
...@@ -73,6 +73,10 @@ module Types ...@@ -73,6 +73,10 @@ module Types
field :participants, Types::UserType.connection_type, null: true, complexity: 5, field :participants, Types::UserType.connection_type, null: true, complexity: 5,
description: 'List of participants in the issue' description: 'List of participants in the issue'
field :emails_disabled, GraphQL::BOOLEAN_TYPE, method: :project_emails_disabled?, null: false, complexity: 5,
description: 'Indicates if a project has email notifications disabled'
field :subscribe_disabled_description, GraphQL::STRING_TYPE, method: :subscribe_disabled_description, null: false,
description: 'The message to display when a project has emails notifications disabled'
field :subscribed, GraphQL::BOOLEAN_TYPE, method: :subscribed?, null: false, complexity: 5, field :subscribed, GraphQL::BOOLEAN_TYPE, method: :subscribed?, null: false, complexity: 5,
description: 'Indicates the currently logged in user is subscribed to the issue' description: 'Indicates the currently logged in user is subscribed to the issue'
field :time_estimate, GraphQL::INT_TYPE, null: false, field :time_estimate, GraphQL::INT_TYPE, null: false,
......
# frozen_string_literal: true # frozen_string_literal: true
class IssuePresenter < Gitlab::View::Presenter::Delegated class IssuePresenter < Gitlab::View::Presenter::Delegated
include NotificationsHelper
presents :issue presents :issue
def issue_path def issue_path
...@@ -10,6 +12,14 @@ class IssuePresenter < Gitlab::View::Presenter::Delegated ...@@ -10,6 +12,14 @@ class IssuePresenter < Gitlab::View::Presenter::Delegated
def subscribed? def subscribed?
issue.subscribed?(current_user, issue.project) issue.subscribed?(current_user, issue.project)
end end
def project_emails_disabled?
issue.project.emails_disabled?
end
def subscribe_disabled_description
notification_description(:owner_disabled)
end
end end
IssuePresenter.prepend_if_ee('EE::IssuePresenter') IssuePresenter.prepend_if_ee('EE::IssuePresenter')
---
title: Add emailsDisabled and subscribeDisabledescription fields for issue type
merge_request: 46947
author:
type: changed
...@@ -7360,6 +7360,11 @@ type EpicIssue implements CurrentUserTodos & Noteable { ...@@ -7360,6 +7360,11 @@ type EpicIssue implements CurrentUserTodos & Noteable {
""" """
dueDate: Time dueDate: Time
"""
Indicates if a project has email notifications disabled
"""
emailsDisabled: Boolean!
""" """
Epic to which this issue belongs Epic to which this issue belongs
""" """
...@@ -7520,6 +7525,11 @@ type EpicIssue implements CurrentUserTodos & Noteable { ...@@ -7520,6 +7525,11 @@ type EpicIssue implements CurrentUserTodos & Noteable {
""" """
statusPagePublishedIncident: Boolean statusPagePublishedIncident: Boolean
"""
The message to display when a project has emails notifications disabled
"""
subscribeDisabledDescription: String!
""" """
Indicates the currently logged in user is subscribed to the issue Indicates the currently logged in user is subscribed to the issue
""" """
...@@ -9879,6 +9889,11 @@ type Issue implements CurrentUserTodos & Noteable { ...@@ -9879,6 +9889,11 @@ type Issue implements CurrentUserTodos & Noteable {
""" """
dueDate: Time dueDate: Time
"""
Indicates if a project has email notifications disabled
"""
emailsDisabled: Boolean!
""" """
Epic to which this issue belongs Epic to which this issue belongs
""" """
...@@ -10029,6 +10044,11 @@ type Issue implements CurrentUserTodos & Noteable { ...@@ -10029,6 +10044,11 @@ type Issue implements CurrentUserTodos & Noteable {
""" """
statusPagePublishedIncident: Boolean statusPagePublishedIncident: Boolean
"""
The message to display when a project has emails notifications disabled
"""
subscribeDisabledDescription: String!
""" """
Indicates the currently logged in user is subscribed to the issue Indicates the currently logged in user is subscribed to the issue
""" """
......
...@@ -20316,6 +20316,24 @@ ...@@ -20316,6 +20316,24 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{
"name": "emailsDisabled",
"description": "Indicates if a project has email notifications disabled",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "epic", "name": "epic",
"description": "Epic to which this issue belongs", "description": "Epic to which this issue belongs",
...@@ -20728,6 +20746,24 @@ ...@@ -20728,6 +20746,24 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{
"name": "subscribeDisabledDescription",
"description": "The message to display when a project has emails notifications disabled",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "subscribed", "name": "subscribed",
"description": "Indicates the currently logged in user is subscribed to the issue", "description": "Indicates the currently logged in user is subscribed to the issue",
...@@ -26955,6 +26991,24 @@ ...@@ -26955,6 +26991,24 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{
"name": "emailsDisabled",
"description": "Indicates if a project has email notifications disabled",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "epic", "name": "epic",
"description": "Epic to which this issue belongs", "description": "Epic to which this issue belongs",
...@@ -27339,6 +27393,24 @@ ...@@ -27339,6 +27393,24 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{
"name": "subscribeDisabledDescription",
"description": "The message to display when a project has emails notifications disabled",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "subscribed", "name": "subscribed",
"description": "Indicates the currently logged in user is subscribed to the issue", "description": "Indicates the currently logged in user is subscribed to the issue",
...@@ -1214,6 +1214,7 @@ Relationship between an epic and an issue. ...@@ -1214,6 +1214,7 @@ Relationship between an epic and an issue.
| `discussions` | DiscussionConnection! | All discussions on this noteable | | `discussions` | DiscussionConnection! | All discussions on this noteable |
| `downvotes` | Int! | Number of downvotes the issue has received | | `downvotes` | Int! | Number of downvotes the issue has received |
| `dueDate` | Time | Due date of the issue | | `dueDate` | Time | Due date of the issue |
| `emailsDisabled` | Boolean! | Indicates if a project has email notifications disabled |
| `epic` | Epic | Epic to which this issue belongs | | `epic` | Epic | Epic to which this issue belongs |
| `epicIssueId` | ID! | ID of the epic-issue relation | | `epicIssueId` | ID! | ID of the epic-issue relation |
| `healthStatus` | HealthStatus | Current health status. Returns null if `save_issuable_health_status` feature flag is disabled. | | `healthStatus` | HealthStatus | Current health status. Returns null if `save_issuable_health_status` feature flag is disabled. |
...@@ -1233,6 +1234,7 @@ Relationship between an epic and an issue. ...@@ -1233,6 +1234,7 @@ Relationship between an epic and an issue.
| `slaDueAt` | Time | Timestamp of when the issue SLA expires. | | `slaDueAt` | Time | Timestamp of when the issue SLA expires. |
| `state` | IssueState! | State of the issue | | `state` | IssueState! | State of the issue |
| `statusPagePublishedIncident` | Boolean | Indicates whether an issue is published to the status page | | `statusPagePublishedIncident` | Boolean | Indicates whether an issue is published to the status page |
| `subscribeDisabledDescription` | String! | The message to display when a project has emails notifications disabled |
| `subscribed` | Boolean! | Indicates the currently logged in user is subscribed to the issue | | `subscribed` | Boolean! | Indicates the currently logged in user is subscribed to the issue |
| `taskCompletionStatus` | TaskCompletionStatus! | Task completion status of the issue | | `taskCompletionStatus` | TaskCompletionStatus! | Task completion status of the issue |
| `timeEstimate` | Int! | Time estimate of the issue | | `timeEstimate` | Int! | Time estimate of the issue |
...@@ -1480,6 +1482,7 @@ Represents a recorded measurement (object count) for the Admins. ...@@ -1480,6 +1482,7 @@ Represents a recorded measurement (object count) for the Admins.
| `discussions` | DiscussionConnection! | All discussions on this noteable | | `discussions` | DiscussionConnection! | All discussions on this noteable |
| `downvotes` | Int! | Number of downvotes the issue has received | | `downvotes` | Int! | Number of downvotes the issue has received |
| `dueDate` | Time | Due date of the issue | | `dueDate` | Time | Due date of the issue |
| `emailsDisabled` | Boolean! | Indicates if a project has email notifications disabled |
| `epic` | Epic | Epic to which this issue belongs | | `epic` | Epic | Epic to which this issue belongs |
| `healthStatus` | HealthStatus | Current health status. Returns null if `save_issuable_health_status` feature flag is disabled. | | `healthStatus` | HealthStatus | Current health status. Returns null if `save_issuable_health_status` feature flag is disabled. |
| `humanTimeEstimate` | String | Human-readable time estimate of the issue | | `humanTimeEstimate` | String | Human-readable time estimate of the issue |
...@@ -1497,6 +1500,7 @@ Represents a recorded measurement (object count) for the Admins. ...@@ -1497,6 +1500,7 @@ Represents a recorded measurement (object count) for the Admins.
| `slaDueAt` | Time | Timestamp of when the issue SLA expires. | | `slaDueAt` | Time | Timestamp of when the issue SLA expires. |
| `state` | IssueState! | State of the issue | | `state` | IssueState! | State of the issue |
| `statusPagePublishedIncident` | Boolean | Indicates whether an issue is published to the status page | | `statusPagePublishedIncident` | Boolean | Indicates whether an issue is published to the status page |
| `subscribeDisabledDescription` | String! | The message to display when a project has emails notifications disabled |
| `subscribed` | Boolean! | Indicates the currently logged in user is subscribed to the issue | | `subscribed` | Boolean! | Indicates the currently logged in user is subscribed to the issue |
| `taskCompletionStatus` | TaskCompletionStatus! | Task completion status of the issue | | `taskCompletionStatus` | TaskCompletionStatus! | Task completion status of the issue |
| `timeEstimate` | Int! | Time estimate of the issue | | `timeEstimate` | Int! | Time estimate of the issue |
......
...@@ -16,7 +16,7 @@ RSpec.describe GitlabSchema.types['Issue'] do ...@@ -16,7 +16,7 @@ RSpec.describe GitlabSchema.types['Issue'] do
it 'has specific fields' do it 'has specific fields' do
fields = %i[id iid title description state reference author assignees updated_by participants labels milestone due_date fields = %i[id iid title description state reference author assignees updated_by participants labels milestone due_date
confidential discussion_locked upvotes downvotes user_notes_count user_discussions_count web_path web_url relative_position confidential discussion_locked upvotes downvotes user_notes_count user_discussions_count web_path web_url relative_position
subscribed time_estimate total_time_spent human_time_estimate human_total_time_spent closed_at created_at updated_at task_completion_status emails_disabled subscribe_disabled_description subscribed time_estimate total_time_spent human_time_estimate human_total_time_spent closed_at created_at updated_at task_completion_status
designs design_collection alert_management_alert severity current_user_todos] designs design_collection alert_management_alert severity current_user_todos]
fields.each do |field_name| fields.each do |field_name|
......
...@@ -35,6 +35,31 @@ RSpec.describe IssuePresenter do ...@@ -35,6 +35,31 @@ RSpec.describe IssuePresenter do
end end
end end
describe '#project_emails_disabled' do
subject { presenter.project_emails_disabled? }
it 'returns false when emails notifications is enabled for project' do
is_expected.to be(false)
end
context 'when emails notifications is disabled for project' do
before do
allow(project).to receive(:emails_disabled?).and_return(true)
end
it 'returns true' do
is_expected.to be(true)
end
end
end
describe '#subscribe_disabled_description' do
subject { presenter.subscribe_disabled_description }
it 'returns correct message' do
is_expected.to equal('Notifications have been disabled by the project or group owner')
end
end
describe '#issue_path' do describe '#issue_path' do
it 'returns correct path' do it 'returns correct path' do
expect(presenter.issue_path).to eq("/#{group.name}/#{project.name}/-/issues/#{issue.iid}") expect(presenter.issue_path).to eq("/#{group.name}/#{project.name}/-/issues/#{issue.iid}")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment