-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEATURE: new "notification level when assigned" user preference #626
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import Component from "@glimmer/component"; | ||
import { service } from "@ember/service"; | ||
import { i18n } from "discourse-i18n"; | ||
import ComboBox from "select-kit/components/combo-box"; | ||
|
||
export default class NotificationLevelWhenAssigned extends Component { | ||
@service siteSettings; | ||
|
||
constructor(owner, args) { | ||
super(...arguments); | ||
if (this.siteSettings.assign_enabled) { | ||
args.outletArgs.customAttrNames.push("notification_level_when_assigned"); | ||
} | ||
} | ||
|
||
get notificationLevelsWhenAssigned() { | ||
// The order matches the "notification level when replying" user preference | ||
return [ | ||
{ | ||
name: i18n("user.notification_level_when_assigned.watch_topic"), | ||
value: "watch_topic", | ||
}, | ||
{ | ||
name: i18n("user.notification_level_when_assigned.track_topic"), | ||
value: "track_topic", | ||
}, | ||
{ | ||
name: i18n("user.notification_level_when_assigned.do_nothing"), | ||
value: "do_nothing", | ||
}, | ||
]; | ||
} | ||
|
||
<template> | ||
{{#if this.siteSettings.assign_enabled}} | ||
<div | ||
class="controls controls-dropdown" | ||
data-setting-name="user-notification-level-when-assigned" | ||
> | ||
<label>{{i18n "user.notification_level_when_assigned.label"}}</label> | ||
<ComboBox | ||
@content={{this.notificationLevelsWhenAssigned}} | ||
@value={{@outletArgs.model.user_option.notification_level_when_assigned}} | ||
@valueProperty="value" | ||
@onChange={{action | ||
(mut @outletArgs.model.user_option.notification_level_when_assigned) | ||
}} | ||
/> | ||
</div> | ||
{{/if}} | ||
</template> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -860,6 +860,8 @@ export default { | |
|
||
api.addUserSearchOption("assignableGroups"); | ||
|
||
api.addSaveableUserOptionField("notification_level_when_assigned"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to "globally" allow this user option to be "saveable" when save a user preference's page. |
||
|
||
api.addBulkActionButton({ | ||
id: "assign-topics", | ||
label: "topics.bulk.assign", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# frozen_string_literal: true | ||
class AddNotificationLevelWhenAssignedUserOption < ActiveRecord::Migration[7.2] | ||
def change | ||
add_column :user_options, :notification_level_when_assigned, :integer, null: false, default: 3 # watch topic | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep the default of "watching" a topic on assign. |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -329,17 +329,19 @@ def assign( | |
publish_assignment(assignment, assign_to, note, status) | ||
|
||
if assignment.assigned_to_user? | ||
if !TopicUser.exists?( | ||
user_id: assign_to.id, | ||
topic_id: topic.id, | ||
notification_level: TopicUser.notification_levels[:watching], | ||
) | ||
TopicUser.change( | ||
assign_to.id, | ||
topic.id, | ||
notification_level: TopicUser.notification_levels[:watching], | ||
notifications_reason_id: TopicUser.notification_reasons[:plugin_changed], | ||
) | ||
if !assign_to.user_option.do_nothing_when_assigned? | ||
notification_level = | ||
if assign_to.user_option.track_topic_when_assigned? | ||
TopicUser.notification_levels[:tracking] | ||
else | ||
TopicUser.notification_levels[:watching] | ||
end | ||
|
||
topic_user = TopicUser.find_by(user_id: assign_to.id, topic:) | ||
if !topic_user || topic_user.notification_level < notification_level | ||
notifications_reason_id = TopicUser.notification_reasons[:plugin_changed] | ||
TopicUser.change(assign_to.id, topic.id, notification_level:, notifications_reason_id:) | ||
end | ||
end | ||
|
||
if SiteSetting.assign_mailer == AssignMailer.levels[:always] || | ||
|
@@ -506,6 +508,7 @@ def add_small_action_post(action_code, assign_to, text) | |
@assigned_by, | ||
text, | ||
bump: false, | ||
auto_track: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need this to prevent the "small action" / "whisper" post that is automatically created when assigning a topic from changing the notification level because the user "replied". |
||
post_type: SiteSetting.assigns_public ? Post.types[:small_action] : Post.types[:whisper], | ||
action_code: action_code, | ||
custom_fields: custom_fields, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module DiscourseAssign | ||
module UserOptionExtension | ||
extend ActiveSupport::Concern | ||
|
||
prepended do | ||
enum :notification_level_when_assigned, | ||
{ do_nothing: 1, track_topic: 2, watch_topic: 3 }, | ||
suffix: "when_assigned" | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
describe "Assign | User Preferences", type: :system, js: true do | ||
fab!(:user) | ||
|
||
let(:selector) { "[data-setting-name='user-notification-level-when-assigned'] .combobox" } | ||
|
||
before { sign_in(user) } | ||
|
||
describe "when discourse-assign is disabled" do | ||
before { SiteSetting.assign_enabled = false } | ||
|
||
it "does not show the 'when assigned' tracking user preference" do | ||
visit "/my/preferences/tracking" | ||
|
||
expect(page).not_to have_css(selector) | ||
end | ||
end | ||
|
||
describe "when discourse-assign is enabled" do | ||
before { SiteSetting.assign_enabled = true } | ||
|
||
let(:when_assigned) { PageObjects::Components::SelectKit.new(selector) } | ||
|
||
it "shows the 'when assigned' tracking user preference" do | ||
visit "/my/preferences/tracking" | ||
|
||
expect(when_assigned).to have_selected_value("watch_topic") | ||
end | ||
|
||
it "supports changing the 'when assigned' tracking user preference" do | ||
visit "/my/preferences/tracking" | ||
|
||
when_assigned.expand | ||
when_assigned.select_row_by_value("track_topic") | ||
|
||
page.find("button.save-changes").click | ||
page.refresh | ||
|
||
expect(when_assigned).to have_selected_value("track_topic") | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the plugin is enabled, we add this user option to the list of options that are saved in the
/my/preferences/tracking
user preferences page.