OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
remove no_self_notified user preference
ulferts1f024e5796b1
diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rbindex 31ae9715758..16db7d30d79 100644--- a/app/mailers/application_mailer.rb+++ b/app/mailers/application_mailer.rb@@ -74,7 +74,7 @@ class ApplicationMailer < ActionMailer::Baseenddef remove_self_notifications(message, author)- if author.pref && author.pref[:no_self_notified] && message.to.present?+ if author.pref && message.to.present?message.to = message.to.reject { |address| address == author.mail }endenddiff --git a/app/models/user_preference.rb b/app/models/user_preference.rbindex 17b86cb0b0d..3c978f8310a 100644--- a/app/models/user_preference.rb+++ b/app/models/user_preference.rb@@ -59,14 +59,6 @@ class UserPreference < ApplicationRecordcomments_sorting == 'desc'end- def self_notified?- !others[:no_self_notified]- end-- def self_notified=(value)- others[:no_self_notified] = !value- end-def auto_hide_popups=(value)others[:auto_hide_popups] = to_boolean(value)end@@ -116,7 +108,7 @@ class UserPreference < ApplicationRecordenddef init_other_preferences- self.others ||= { no_self_notified: true }+ self.others ||= {}enddef time_zone_correctnessdiff --git a/app/services/notifications/create_from_model_service.rb b/app/services/notifications/create_from_model_service.rbindex e0d210d5305..158f64384b2 100644--- a/app/services/notifications/create_from_model_service.rb+++ b/app/services/notifications/create_from_model_service.rb@@ -272,7 +272,7 @@ class Notifications::CreateFromModelServiceenddef remove_self_recipient(receivers)- receivers.delete(user_with_fallback.id) if !user_with_fallback.pref.self_notified?+ receivers.delete(user_with_fallback.id)enddef receivers_hashdiff --git a/app/workers/mails/watcher_job.rb b/app/workers/mails/watcher_job.rbindex b54eab7c644..791d7fca65a 100644--- a/app/workers/mails/watcher_job.rb+++ b/app/workers/mails/watcher_job.rb@@ -54,7 +54,7 @@ class Mails::WatcherJob < Mails::DeliverJobenddef notify_about_watcher_changed?- return false if notify_about_self_watching?+ return false if self_watching?return false unless UserMailer.perform_deliveriessettings = watcher@@ -67,8 +67,8 @@ class Mails::WatcherJob < Mails::DeliverJobsettings.watched || settings.allend- def notify_about_self_watching?- watcher.user == sender && !sender.pref.self_notified?+ def self_watching?+ watcher.user == senderenddef actiondiff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex 1c62709e04b..2c6d64a20d2 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -593,7 +593,6 @@ en:already_selected: 'This project is already selected'remove_projects: 'Remove notifications for projects'title: "Notification settings"- self_notify: "I want to be notified of changes that I make myself"password_confirmation:field_description: 'You need to enter your account password to confirm this change.'diff --git a/docs/api/apiv3/components/schemas/user_preference_model.yml b/docs/api/apiv3/components/schemas/user_preference_model.ymlindex babb938b2bb..50e71fa43fc 100644--- a/docs/api/apiv3/components/schemas/user_preference_model.yml+++ b/docs/api/apiv3/components/schemas/user_preference_model.yml@@ -11,9 +11,6 @@ properties:notifications:type: NotificationSettingdescription: The settings for the notifications to be received by the user- selfNotified:- type: boolean- description: Whether the user wants to be notfified of changes done by the user her/himselftimeZone:type: stringdescription: Current selected time zonediff --git a/docs/api/apiv3/tags/userpreferences.yml b/docs/api/apiv3/tags/userpreferences.ymlindex 776217d5b84..ad964904243 100644--- a/docs/api/apiv3/tags/userpreferences.yml+++ b/docs/api/apiv3/tags/userpreferences.yml@@ -14,7 +14,6 @@ description: |-| autoHidePopups | Whether to hide popups (e.g. success messages) after 5 seconds | Boolean | | READ / WRITE || hideMail | Hide mail address from other users | Boolean | | READ / WRITE || notifications | The settings for the notifications to be received by the user | NotificationSetting | | READ / WRITE |- | selfNotified | Whether the user wants to be notfified of changes done by the user her/himself | Boolean | | READ / WRITE || timeZone | Current selected time zone | String | | READ / WRITE || commentSortDescending | Sort comments in descending order | Boolean | | READ / WRITE || warnOnLeavingUnsaved | Issue warning when leaving a page with unsaved text | Boolean | | READ / WRITE |diff --git a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.html b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.htmlindex 477b729e498..f1248ead9d3 100644--- a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.html+++ b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.html@@ -4,24 +4,6 @@[userId]="userId"></op-notification-settings-table>-<fieldset class="form--fieldset form--section">- <legend class="form--fieldset-legend">- {{ text.advanced_settings }}- </legend>- <op-form-field- class="op-form-field_checkbox"- [noWrapLabel]="false"- [label]="text.self_notify"- >- <input- slot="input"- type="checkbox"- [checked]="(preferences$ | async).selfNotified"- (change)="updateNotified($event.target.checked)"- />- </op-form-field>-</fieldset>-<div class="generic-table--action-buttons"><buttonclass="button -highlight"diff --git a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.tsindex 61121fae3ac..e40c6983eae 100644--- a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts+++ b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts@@ -6,7 +6,6 @@ import { CurrentUserService } from 'core-app/core/current-user/current-user.servimport { take } from 'rxjs/internal/operators/take';import { UIRouterGlobals } from '@uirouter/core';import { UserPreferencesService } from 'core-app/features/user-preferences/state/user-preferences.service';-import { UserPreferencesStore } from 'core-app/features/user-preferences/state/user-preferences.store';import { UserPreferencesQuery } from 'core-app/features/user-preferences/state/user-preferences.query';export const myNotificationsPageComponentSelector = 'op-notifications-page';@@ -19,21 +18,16 @@ export const myNotificationsPageComponentSelector = 'op-notifications-page';export class NotificationsSettingsPageComponent implements OnInit {@Input() userId:string;- preferences$ = this.query.preferences$;-text = {save: this.I18n.t('js.button_save'),email: this.I18n.t('js.notifications.email'),inApp: this.I18n.t('js.notifications.in_app'),default_all_projects: this.I18n.t('js.notifications.settings.default_all_projects'),- advanced_settings: this.I18n.t('js.forms.advanced_settings'),- self_notify: this.I18n.t('js.notifications.settings.self_notify'),};constructor(private I18n:I18nService,private stateService:UserPreferencesService,- private store:UserPreferencesStore,private query:UserPreferencesQuery,private currentUserService:CurrentUserService,private uiRouterGlobals:UIRouterGlobals,@@ -56,8 +50,4 @@ export class NotificationsSettingsPageComponent implements OnInit {const prefs = this.query.getValue();this.stateService.update(this.userId, prefs);}-- updateNotified(checked:boolean) {- this.store.update({ selfNotified: checked });- }}diff --git a/frontend/src/app/features/user-preferences/state/user-preferences.model.ts b/frontend/src/app/features/user-preferences/state/user-preferences.model.tsindex 3921c9501fc..954ba83a521 100644--- a/frontend/src/app/features/user-preferences/state/user-preferences.model.ts+++ b/frontend/src/app/features/user-preferences/state/user-preferences.model.ts@@ -6,6 +6,5 @@ export interface UserPreferencesModel {hideMail:boolean;timeZone:string|null;warnOnLeavingUnsaved:boolean;- selfNotified:boolean;notifications:NotificationSetting[];}diff --git a/frontend/src/app/features/user-preferences/state/user-preferences.store.ts b/frontend/src/app/features/user-preferences/state/user-preferences.store.tsindex 46f1806a726..54177ec6b9f 100644--- a/frontend/src/app/features/user-preferences/state/user-preferences.store.ts+++ b/frontend/src/app/features/user-preferences/state/user-preferences.store.ts@@ -37,7 +37,6 @@ function createInitialState():UserPreferencesModel {hideMail: true,timeZone: null,warnOnLeavingUnsaved: true,- selfNotified: false,notifications: [],};}diff --git a/lib/api/v3/user_preferences/user_preference_representer.rb b/lib/api/v3/user_preferences/user_preference_representer.rbindex da1e4228223..b11e8cd601a 100644--- a/lib/api/v3/user_preferences/user_preference_representer.rb+++ b/lib/api/v3/user_preferences/user_preference_representer.rb@@ -65,12 +65,6 @@ module APIas: :commentSortDescendingproperty :auto_hide_popups- property :self_notified,- getter: ->(*) { self_notified? },- setter: ->(fragment:, represented:, **) do- represented.no_self_notified = !fragment- end-property :notification_settings,as: :notifications,exec_context: :decorator,diff --git a/modules/meeting/app/services/meeting_notification_service.rb b/modules/meeting/app/services/meeting_notification_service.rbindex 9673bb806d2..b6fac97bc10 100644--- a/modules/meeting/app/services/meeting_notification_service.rb+++ b/modules/meeting/app/services/meeting_notification_service.rb@@ -15,11 +15,10 @@ class MeetingNotificationServicedef send_notifications!(content, action, include_author:)author_mail = meeting.author.mail- do_not_notify_author = meeting.author.pref[:no_self_notified] && !include_authorrecipients_with_errors = []meeting.participants.includes(:user).each do |recipient|- next if recipient.mail == author_mail && do_not_notify_author+ next if recipient.mail == author_mail && !include_authorMeetingMailer.send(action, content, content_type, recipient.user).deliver_nowrescue StandardError => ediff --git a/modules/meeting/spec/controllers/meeting_contents_controller_spec.rb b/modules/meeting/spec/controllers/meeting_contents_controller_spec.rbindex e536c47b087..1e2a2ff19b7 100644--- a/modules/meeting/spec/controllers/meeting_contents_controller_spec.rb+++ b/modules/meeting/spec/controllers/meeting_contents_controller_spec.rb@@ -66,32 +66,16 @@ describe MeetingContentsController dodescribe 'notify' dolet(:action) { 'notify' }- context 'when author no_self_notified property is true' do- before do- author.pref[:no_self_notified] = true- author.save!- end-- it_behaves_like 'delivered by mail' do- let(:mail_count) { 2 }- end+ before do+ author.save!end- context 'when author no_self_notified property is false' do- before do- author.pref[:no_self_notified] = false- author.save!- end-- it_behaves_like 'delivered by mail' do- let(:mail_count) { 3 }- end+ it_behaves_like 'delivered by mail' do+ let(:mail_count) { 2 }endcontext 'with an error during deliver' dobefore do- author.pref[:no_self_notified] = false- author.save!allow(MeetingMailer).to receive(:content_for_review).and_raise(Net::SMTPError)end@@ -111,31 +95,16 @@ describe MeetingContentsController dodescribe 'icalendar' dolet(:action) { 'icalendar' }- context 'when author no_self_notified property is true' do- before do- author.pref[:no_self_notified] = true- author.save!- end-- it_behaves_like 'delivered by mail' do- let(:mail_count) { 3 }- end+ before do+ author.save!end- context 'when author no_self_notified property is false' do- before do- author.pref[:no_self_notified] = false- author.save!- end-- it_behaves_like 'delivered by mail' do- let(:mail_count) { 3 }- end+ it_behaves_like 'delivered by mail' do+ let(:mail_count) { 3 }endcontext 'with an error during deliver' dobefore do- author.pref[:no_self_notified] = falseauthor.save!allow(MeetingMailer).to receive(:content_for_review).and_raise(Net::SMTPError)enddiff --git a/modules/meeting/spec/mailers/meeting_mailer_spec.rb b/modules/meeting/spec/mailers/meeting_mailer_spec.rbindex 74c1a428089..d7d63db922f 100644--- a/modules/meeting/spec/mailers/meeting_mailer_spec.rb+++ b/modules/meeting/spec/mailers/meeting_mailer_spec.rb@@ -50,8 +50,6 @@ describe MeetingMailer, type: :mailer doendbefore do- author.pref[:no_self_notified] = false- author.save!meeting.participants.merge([meeting.participants.build(user: watcher1, invited: true, attended: false),meeting.participants.build(user: watcher2, invited: true, attended: false)])meeting.save!diff --git a/spec/controllers/my_controller_spec.rb b/spec/controllers/my_controller_spec.rbindex 91e69b83890..0a7f9593a1c 100644--- a/spec/controllers/my_controller_spec.rb+++ b/spec/controllers/my_controller_spec.rb@@ -155,7 +155,7 @@ describe MyController, type: :controller docontext 'PATCH' dobefore doas_logged_in_user user do- user.pref.self_notified = false+ user.pref.comments_sorting = 'desc'user.pref.auto_hide_popups = truepatch :update_settings, params: { user: { language: 'en' }, pref: { auto_hide_popups: 0 } }@@ -164,7 +164,7 @@ describe MyController, type: :controller doit 'updates the settings appropriately', :aggregate_failures doexpect(assigns(:user).language).to eq 'en'- expect(assigns(:user).pref.self_notified?).to be_falsey+ expect(assigns(:user).pref.comments_sorting).to eql 'desc'expect(assigns(:user).pref.auto_hide_popups?).to be_falseyexpect(request.path).to eq(my_settings_path)diff --git a/spec/controllers/news_controller_spec.rb b/spec/controllers/news_controller_spec.rbindex a915ac5b347..11bad93f601 100644--- a/spec/controllers/news_controller_spec.rb+++ b/spec/controllers/news_controller_spec.rb@@ -34,11 +34,7 @@ describe NewsController, type: :controller doinclude BecomeMemberlet(:user) do- user = FactoryBot.create(:admin)-- FactoryBot.create(:user_preference, user: user, others: { no_self_notified: false })-- user+ FactoryBot.create(:admin)endlet(:project) { FactoryBot.create(:project) }let(:news) { FactoryBot.create(:news) }diff --git a/spec/lib/api/v3/user_preferences/user_preference_representer_parsing_spec.rb b/spec/lib/api/v3/user_preferences/user_preference_representer_parsing_spec.rbindex 9d0ffabf11d..53f494f5367 100644--- a/spec/lib/api/v3/user_preferences/user_preference_representer_parsing_spec.rb+++ b/spec/lib/api/v3/user_preferences/user_preference_representer_parsing_spec.rb@@ -38,30 +38,6 @@ describe ::API::V3::UserPreferences::UserPreferenceRepresenter,subject { representer.from_hash request_body }- describe 'selfNotified' do- let(:request_body) do- {- 'selfNotified' => self_notified- }- end-- context 'with setting true' do- let(:self_notified) { true }-- it 'sets no_self_notified to false' do- expect(subject.no_self_notified).to eq false- end- end-- context 'with setting false' do- let(:self_notified) { false }-- it 'sets no_self_notified to true' do- expect(subject.no_self_notified).to eq true- end- end- end-describe 'notification_settings' dolet(:request_body) do{diff --git a/spec/lib/api/v3/user_preferences/user_preference_representer_rendering_spec.rb b/spec/lib/api/v3/user_preferences/user_preference_representer_rendering_spec.rbindex c1493abdedf..50ae87395cf 100644--- a/spec/lib/api/v3/user_preferences/user_preference_representer_rendering_spec.rb+++ b/spec/lib/api/v3/user_preferences/user_preference_representer_rendering_spec.rb@@ -77,26 +77,6 @@ describe ::API::V3::UserPreferences::UserPreferenceRepresenter,endend- describe 'selfNotified' do- let(:preference) { FactoryBot.build(:user_preference, others: { no_self_notified: no_self_notified }) }-- context 'with setting true' do- let(:no_self_notified) { true }-- it 'renders the property as false' do- is_expected.to be_json_eql(false.to_json).at_path('selfNotified')- end- end-- context 'with setting false' do- let(:no_self_notified) { false }-- it 'renders the property as true' do- is_expected.to be_json_eql(true.to_json).at_path('selfNotified')- end- end- end-describe 'notification_settings' doit 'renders them as a nested array' dois_expected.to have_json_type(Array).at_path('notifications')diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rbindex 1de1440aee3..478160ac80d 100644--- a/spec/mailers/user_mailer_spec.rb+++ b/spec/mailers/user_mailer_spec.rb@@ -91,11 +91,8 @@ describe UserMailer, type: :mailer doendend- shared_examples_for 'does only send mails to author if permitted' do- let(:user_preference) do- FactoryBot.build(:user_preference, others: { no_self_notified: true })- end- let(:user) { FactoryBot.build_stubbed(:user, preference: user_preference) }+ shared_examples_for 'does not send mails to author' do+ let(:user) { FactoryBot.build_stubbed(:user) }context 'when mail is for another user' doit_behaves_like 'mail is sent'@@ -205,7 +202,7 @@ describe UserMailer, type: :mailer doendend- it_behaves_like 'does only send mails to author if permitted'+ it_behaves_like 'does not send mails to author'enddescribe '#work_package_updated' do@@ -251,7 +248,7 @@ describe UserMailer, type: :mailer doendend- it_behaves_like 'does only send mails to author if permitted'+ it_behaves_like 'does not send mails to author'enddescribe '#work_package_watcher_changed' do@@ -278,7 +275,7 @@ describe UserMailer, type: :mailer doit_behaves_like 'mail is sent'- it_behaves_like 'does only send mails to author if permitted'+ it_behaves_like 'does not send mails to author'enddescribe '#wiki_content_updated' do@@ -294,7 +291,7 @@ describe UserMailer, type: :mailer doexpect(deliveries.first.body.encoded).to include 'diff/1'end- it_behaves_like 'does only send mails to author if permitted'+ it_behaves_like 'does not send mails to author'enddescribe '#message_posted' do@@ -328,7 +325,7 @@ describe UserMailer, type: :mailer doendend- it_behaves_like 'does only send mails to author if permitted'+ it_behaves_like 'does not send mails to author'enddescribe '#account_information' do@@ -360,7 +357,7 @@ describe UserMailer, type: :mailer doendend- it_behaves_like 'does only send mails to author if permitted'+ it_behaves_like 'does not send mails to author'enddescribe '#news_comment_added' do@@ -373,7 +370,7 @@ describe UserMailer, type: :mailer doit_behaves_like 'mail is sent'- it_behaves_like 'does only send mails to author if permitted'+ it_behaves_like 'does not send mails to author'enddescribe '#password_lost' do@@ -808,7 +805,7 @@ describe UserMailer, type: :mailer do"en" => 'english header'} } dolet(:recipient) do- FactoryBot.build_stubbed(:user, language: 'de', preferences: { no_self_notified: false })+ FactoryBot.build_stubbed(:user, language: 'de')endbefore do@@ -839,7 +836,7 @@ describe UserMailer, type: :mailer do"en" => 'english header'} } dolet(:recipient) do- FactoryBot.build_stubbed(:user, language: '', preferences: { no_self_notified: false })+ FactoryBot.build_stubbed(:user, language: '')endbefore dodiff --git a/spec/models/mail_handler_spec.rb b/spec/models/mail_handler_spec.rbindex 771ec4f48f4..0c35e9f86b1 100644--- a/spec/models/mail_handler_spec.rb+++ b/spec/models/mail_handler_spec.rb@@ -245,6 +245,16 @@ describe MailHandler, type: :model do.not_to match(/^Start Date:/i)end+ it 'sends notifications' do+ FactoryBot.create(:user, member_in_project: project, member_with_permissions: %i(view_work_packages))++ expect do+ perform_enqueued_jobs do+ subject+ end+ end.to change(ActionMailer::Base.deliveries, :count).by(1)+ end+context 'with a user watching every creation' dolet!(:other_user) doFactoryBot.create(:user,@@ -423,21 +433,23 @@ describe MailHandler, type: :model doallow(OpenProject::Database).to receive(:allows_tsv?).and_return falseend- it 'should update a work package with attachment' do- expect(WorkPackage).to receive(:find_by).with(id: 123).and_return(work_package)+ context 'with attachments to be added' do+ it 'updates a work package with attachment' do+ allow(WorkPackage).to receive(:find_by).with(id: 123).and_return(work_package)- # Mail with two attachemnts, one of which is skipped by signature.asc filename match- submit_email 'update_ticket_with_attachment_and_sig.eml', issue: { project: 'onlinestore' }+ # Mail with two attachemnts, one of which is skipped by signature.asc filename match+ submit_email 'update_ticket_with_attachment_and_sig.eml', issue: { project: 'onlinestore' }- work_package.reload+ work_package.reload- # Expect comment- expect(work_package.journals.last.notes).to eq 'Reply to work package #123'- expect(work_package.journals.last.user).to eq mail_user+ # Expect comment+ expect(work_package.journals.last.notes).to eq 'Reply to work package #123'+ expect(work_package.journals.last.user).to eq mail_user- # Expect filename without signature to be saved- expect(work_package.attachments.count).to eq(1)- expect(work_package.attachments.first.filename).to eq('Photo25.jpg')+ # Expect filename without signature to be saved+ expect(work_package.attachments.count).to eq(1)+ expect(work_package.attachments.first.filename).to eq('Photo25.jpg')+ endendcontext 'with existing attachment' do@@ -445,7 +457,7 @@ describe MailHandler, type: :model doit 'does not replace it (Regression #29722)' dowork_package.reload- expect(WorkPackage).to receive(:find_by).with(id: 123).and_return(work_package)+ allow(WorkPackage).to receive(:find_by).with(id: 123).and_return(work_package)# Mail with two attachemnts, one of which is skipped by signature.asc filename matchsubmit_email 'update_ticket_with_attachment_and_sig.eml', issue: { project: 'onlinestore' }@@ -454,6 +466,30 @@ describe MailHandler, type: :model doendend+ context 'with reply text' do+ include_context 'wp_update_with_quoted_reply_above'++ it_behaves_like 'journal created'++ it 'sends notifications' do+ assignee = FactoryBot.create(:user,+ member_in_project: project,+ member_with_permissions: %i(view_work_packages),+ notification_settings: [FactoryBot.build(:mail_notification_setting,+ all: false,+ involved: true)])++ work_package.update_column(:assigned_to_id, assignee.id)++ # Sends notifications for the assignee and the author who is listening for all changes.+ expect do+ perform_enqueued_jobs do+ subject+ end+ end.to change(ActionMailer::Base.deliveries, :count).by(2)+ end+ end+context 'with a custom field' dolet(:work_package) { FactoryBot.create :work_package, project: project }let(:type) { FactoryBot.create :type }diff --git a/spec/models/user_preference_spec.rb b/spec/models/user_preference_spec.rbindex 3c2ef45e6a5..6313b9489de 100644--- a/spec/models/user_preference_spec.rb+++ b/spec/models/user_preference_spec.rb@@ -29,18 +29,15 @@require 'spec_helper'describe UserPreference do- let(:user) { FactoryBot.build_stubbed(:user) }subject { FactoryBot.build(:user_preference, user: user) }+ let(:user) { FactoryBot.build_stubbed(:user) }+describe 'default settings' doit 'hides the email address' doexpect(subject.hide_mail).to eql(true)end- it 'activates no self notification' do- expect(subject.others[:no_self_notified]).to be_truthy- end-context 'with default setting auto_hide_popups to false', with_settings: { default_auto_hide_popups: false } doit 'disables auto hide popups' doexpect(subject.auto_hide_popups).to be_falsey@@ -131,31 +128,23 @@ describe UserPreference doendend- describe 'self_notified getter/setter' do- it 'has a getter and a setter for self_notified' do- subject.self_notified = false- expect(subject.self_notified?).to be_falsey- expect(subject[:no_self_notified]).to be_truthy- end- end-describe '[]=' dolet(:user) { FactoryBot.create(:user) }- context 'for attributes stored in "others"' do+ context 'with attributes stored in "others"' doit 'will save the values on sending "save"' dosubject.save- value_no_self_notified = !subject[:no_self_notified]+ value_warn_on_leaving_unsaved = !subject[:warn_on_leaving_unsaved]value_auto_hide_popups = !subject[:auto_hide_popups]- subject[:no_self_notified] = value_no_self_notified+ subject[:warn_on_leaving_unsaved] = value_warn_on_leaving_unsavedsubject[:auto_hide_popups] = value_auto_hide_popupssubject.savesubject.reload- expect(subject[:no_self_notified]).to eql(value_no_self_notified)+ expect(subject[:warn_on_leaving_unsaved]).to eql(value_warn_on_leaving_unsaved)expect(subject[:auto_hide_popups]).to eql(value_auto_hide_popups)endenddiff --git a/spec/requests/api/v3/work_packages/create_resource_spec.rb b/spec/requests/api/v3/work_packages/create_resource_spec.rbindex b9023a2034b..325275bac24 100644--- a/spec/requests/api/v3/work_packages/create_resource_spec.rb+++ b/spec/requests/api/v3/work_packages/create_resource_spec.rb@@ -38,19 +38,15 @@ describe 'API v3 Work package resource',FactoryBot.create(:project, identifier: 'test_project', public: false)endlet(:role) { FactoryBot.create(:role, permissions: permissions) }- let(:permissions) { %i[view_work_packages edit_work_packages assign_versions] }+ let(:permissions) { %i[add_work_packages view_project view_work_packages] }current_user do- user = FactoryBot.create(:user, member_in_project: project, member_through_role: role)-- FactoryBot.create(:user_preference, user: user, others: { no_self_notified: false })-- user+ FactoryBot.create(:user, member_in_project: project, member_through_role: role)enddescribe 'POST /api/v3/work_packages' dolet(:path) { api_v3_paths.work_packages }- let(:permissions) { %i[add_work_packages view_project] }+ let(:other_user) { nil }let(:status) { FactoryBot.build(:status, is_default: true) }let(:priority) { FactoryBot.build(:priority, is_default: true) }let(:type) { project.types.first }@@ -71,36 +67,36 @@ describe 'API v3 Work package resource',before dostatus.save!priority.save!+ other_user- FactoryBot.create(:user_preference, user: current_user, others: { no_self_notified: false })perform_enqueued_jobs do- post path, parameters.to_json, 'CONTENT_TYPE' => 'application/json'+ post path, parameters.to_jsonendend- context 'notifications' do- let(:permissions) { %i[add_work_packages view_project view_work_packages] }+ describe 'notifications' do+ let(:other_user) { FactoryBot.create(:user, member_in_project: project, member_with_permissions: permissions) }it 'sends a mail by default' doexpect(ActionMailer::Base.deliveries.size)- .to eql 1+ .to be 1endcontext 'without notifications' dolet(:path) { "#{api_v3_paths.work_packages}?notify=false" }- it 'should not send a mail' do+ it 'sends no mail' doexpect(ActionMailer::Base.deliveries.size)- .to eql 0+ .to be 0endendcontext 'with notifications' dolet(:path) { "#{api_v3_paths.work_packages}?notify=true" }- it 'should send a mail' do+ it 'sends a mail' doexpect(ActionMailer::Base.deliveries.size)- .to eql 1+ .to be 1endendenddiff --git a/spec/requests/api/v3/work_packages/delete_resource_spec.rb b/spec/requests/api/v3/work_packages/delete_resource_spec.rbindex 27f8ab1773b..25517d23656 100644--- a/spec/requests/api/v3/work_packages/delete_resource_spec.rb+++ b/spec/requests/api/v3/work_packages/delete_resource_spec.rb@@ -48,7 +48,7 @@ describe 'API v3 Work package resource',current_user douser = FactoryBot.create(:user, member_in_project: project, member_through_role: role)- FactoryBot.create(:user_preference, user: user, others: { no_self_notified: false })+ FactoryBot.create(:user_preference, user: user)userenddiff --git a/spec/requests/api/v3/work_packages/dependent_errors_spec.rb b/spec/requests/api/v3/work_packages/dependent_errors_spec.rbindex 739b8130fb2..3dee682d839 100644--- a/spec/requests/api/v3/work_packages/dependent_errors_spec.rb+++ b/spec/requests/api/v3/work_packages/dependent_errors_spec.rb@@ -79,11 +79,7 @@ describe 'API v3 Work package resource', type: :request, content_type: :json dolet(:permissions) { %i[view_work_packages edit_work_packages create_work_packages] }let(:current_user) do- user = FactoryBot.create(:user, member_in_project: project, member_through_role: role)-- FactoryBot.create(:user_preference, user: user, others: { no_self_notified: false })-- user+ FactoryBot.create(:user, member_in_project: project, member_through_role: role)endlet(:dependent_error_result) dodiff --git a/spec/requests/api/v3/work_packages/index_resource_spec.rb b/spec/requests/api/v3/work_packages/index_resource_spec.rbindex f8f2c09cf28..8bc332a5f76 100644--- a/spec/requests/api/v3/work_packages/index_resource_spec.rb+++ b/spec/requests/api/v3/work_packages/index_resource_spec.rb@@ -46,11 +46,7 @@ describe 'API v3 Work package resource',let(:permissions) { %i[view_work_packages edit_work_packages assign_versions] }current_user do- user = FactoryBot.create(:user, member_in_project: project, member_through_role: role)-- FactoryBot.create(:user_preference, user: user, others: { no_self_notified: false })-- user+ FactoryBot.create(:user, member_in_project: project, member_through_role: role)enddescribe 'GET /api/v3/work_packages' dodiff --git a/spec/requests/api/v3/work_packages/show_resource_spec.rb b/spec/requests/api/v3/work_packages/show_resource_spec.rbindex de5928ff8f1..ce23840bdc8 100644--- a/spec/requests/api/v3/work_packages/show_resource_spec.rb+++ b/spec/requests/api/v3/work_packages/show_resource_spec.rb@@ -49,11 +49,7 @@ describe 'API v3 Work package resource',let(:role) { FactoryBot.create(:role, permissions: permissions) }let(:permissions) { %i[view_work_packages edit_work_packages assign_versions] }let(:current_user) do- user = FactoryBot.create(:user, member_in_project: project, member_through_role: role)-- FactoryBot.create(:user_preference, user: user, others: { no_self_notified: false })-- user+ FactoryBot.create(:user, member_in_project: project, member_through_role: role)endlet(:unauthorize_user) { FactoryBot.create(:user) }let(:type) { FactoryBot.create(:type) }diff --git a/spec/requests/api/v3/work_packages/update_resource_spec.rb b/spec/requests/api/v3/work_packages/update_resource_spec.rbindex fb8af0aa935..e473c9c9a5e 100644--- a/spec/requests/api/v3/work_packages/update_resource_spec.rb+++ b/spec/requests/api/v3/work_packages/update_resource_spec.rb@@ -46,17 +46,10 @@ describe 'API v3 Work package resource',endlet(:role) { FactoryBot.create(:role, permissions: permissions) }let(:permissions) { %i[view_work_packages edit_work_packages assign_versions] }- let(:current_user) do- user = FactoryBot.create(:user, member_in_project: project, member_through_role: role)-- FactoryBot.create(:user_preference, user: user, others: { no_self_notified: false })-- user- endlet(:type) { FactoryBot.create(:type) }- before do- login_as(current_user)+ current_user do+ FactoryBot.create(:user, member_in_project: project, member_through_role: role)enddescribe 'PATCH /api/v3/work_packages/:id' do@@ -71,9 +64,8 @@ describe 'API v3 Work package resource',subject(:response) { last_response }shared_context 'patch request' do- before(:each) do- allow(User).to receive(:current).and_return current_user- patch patch_path, params.to_json, 'CONTENT_TYPE' => 'application/json'+ before do+ patch patch_path, params.to_jsonendend@@ -114,39 +106,47 @@ describe 'API v3 Work package resource',describe 'notification' dolet(:update_params) { valid_params.merge(subject: 'Updated subject') }+ let(:other_user) do+ FactoryBot.create(:user,+ member_in_project: work_package.project,+ member_with_permissions: %i(view_work_packages))+ end- before(:each) do- allow(User).to receive(:current).and_return current_user+ before do+ other_userwork_package- end- include_context 'patch request'+ perform_enqueued_jobs do+ patch patch_path, params.to_json+ end+ end- context 'not set' do+ context 'without the parameter' dolet(:params) { update_params }- it { expect(Journals::CompletedJob).to have_been_enqueued.at_least(1) }+ it 'sends a mail' do+ expect(ActionMailer::Base.deliveries.length)+ .to eq 1+ endend- context 'disabled' do+ context 'with the parameter disabling notifications' dolet(:patch_path) { "#{api_v3_paths.work_package work_package.id}?notify=false" }let(:params) { update_params }- it do- expect(Journals::CompletedJob)- .to have_been_enqueued- .at_least(1)+ it 'sends no mail' do+ expect(ActionMailer::Base.deliveries)+ .to be_emptyendend- context 'enabled' do+ context 'with the parameter enabling notifications' dolet(:patch_path) { "#{api_v3_paths.work_package work_package.id}?notify=Something" }let(:params) { update_params }- it do- expect(Journals::CompletedJob)- .to have_been_enqueued- .at_least(1)+ it 'sends a mail' do+ expect(ActionMailer::Base.deliveries.length)+ .to eq 1endendenddiff --git a/spec/requests/api/v3/work_packages/work_packages_by_project_resource_spec.rb b/spec/requests/api/v3/work_packages/work_packages_by_project_resource_spec.rbindex c805917fc52..23b9b9ddb55 100644--- a/spec/requests/api/v3/work_packages/work_packages_by_project_resource_spec.rb+++ b/spec/requests/api/v3/work_packages/work_packages_by_project_resource_spec.rb@@ -294,6 +294,7 @@ describe API::V3::WorkPackages::WorkPackagesByProjectAPI, type: :request, contenlet(:permissions) { %i[add_work_packages view_project] }let(:status) { FactoryBot.build(:status, is_default: true) }let(:priority) { FactoryBot.build(:priority, is_default: true) }+ let(:other_user) { nil }let(:parameters) do{subject: 'new work packages',@@ -308,25 +309,25 @@ describe API::V3::WorkPackages::WorkPackagesByProjectAPI, type: :request, contenbefore dostatus.save!priority.save!+ other_user- FactoryBot.create(:user_preference, user: current_user, others: { no_self_notified: false })perform_enqueued_jobs dopost path, parameters.to_jsonendend- context 'notifications' do- let(:permissions) { %i[add_work_packages view_project view_work_packages] }+ describe 'notifications' do+ let(:other_user) { FactoryBot.create(:user, member_in_project: project, member_with_permissions: %i(view_work_packages)) }it 'sends a mail by default' doexpect(ActionMailer::Base.deliveries.length)- .to eql 1+ .to be 1endcontext 'without notifications' dolet(:path) { "#{api_v3_paths.work_packages_by_project(project.id)}?notify=false" }- it 'should not send a mail' do+ it 'sends no mail' doexpect(ActionMailer::Base.deliveries).to be_emptyend@@ -335,9 +336,9 @@ describe API::V3::WorkPackages::WorkPackagesByProjectAPI, type: :request, contencontext 'with notifications' dolet(:path) { "#{api_v3_paths.work_packages_by_project(project.id)}?notify=true" }- it 'should send a mail' do+ it 'sends a mail' doexpect(ActionMailer::Base.deliveries.length)- .to eql 1+ .to be 1endendenddiff --git a/spec/services/notifications/create_from_journal_job_shared.rb b/spec/services/notifications/create_from_journal_job_shared.rbindex f45d2705b78..495bd5a7932 100644--- a/spec/services/notifications/create_from_journal_job_shared.rb+++ b/spec/services/notifications/create_from_journal_job_shared.rb@@ -37,13 +37,9 @@ shared_context 'with CreateFromJournalJob context' donotification_settings: recipient_notification_settings,member_in_project: project,member_through_role: FactoryBot.create(:role, permissions: permissions),- login: recipient_login,- preferences: {- no_self_notified: recipient_no_self_notified- })+ login: recipient_login)endlet(:recipient_login) { "johndoe" }- let(:recipient_no_self_notified) { true }let(:other_user) donotification_settings = [FactoryBot.build(:mail_notification_setting, **notification_settings_all_false),diff --git a/spec/services/notifications/create_from_model_service_work_package_spec.rb b/spec/services/notifications/create_from_model_service_work_package_spec.rbindex 92f4fd10bc8..cba9cac0838 100644--- a/spec/services/notifications/create_from_model_service_work_package_spec.rb+++ b/spec/services/notifications/create_from_model_service_work_package_spec.rb@@ -217,7 +217,7 @@ describe Notifications::CreateFromModelService,it_behaves_like 'creates no notification'end- context 'when assignee has all notifications enabled but made the change himself and has deactivated self notification' do+ context 'when assignee has all notifications enabled but made the change himself' dolet(:recipient_notification_settings) do[FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(involved: true, all: true)),@@ -229,31 +229,6 @@ describe Notifications::CreateFromModelService,it_behaves_like 'creates no notification'end-- context 'when assignee has all notifications enabled, made the change himself and has activated self notification' do- let(:recipient_notification_settings) do- [- FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(involved: true, all: true)),- FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(involved: true, all: true)),- FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(involved: true, all: true))- ]- end- let(:author) { recipient }- let(:recipient_no_self_notified) { false }-- it_behaves_like 'creates notification' do- let(:notification_channel_reasons) do- {- read_ian: false,- reason_ian: :involved,- read_mail: false,- reason_mail: :involved,- read_mail_digest: false,- reason_mail_digest: :involved- }- end- end- endendcontext 'when user is responsible' do@@ -349,7 +324,7 @@ describe Notifications::CreateFromModelService,it_behaves_like 'creates no notification'end- context 'when responsible has all notifications enabled but made the change himself and has deactivated self notification' do+ context 'when responsible has all notifications enabled but made the change himself' dolet(:recipient_notification_settings) do[FactoryBot.build(:mail_notification_setting, involved: true, all: true),@@ -361,31 +336,6 @@ describe Notifications::CreateFromModelService,it_behaves_like 'creates no notification'end-- context 'when responsible has all notifications enabled, made the change himself and has activated self notification' do- let(:recipient_notification_settings) do- [- FactoryBot.build(:mail_notification_setting, involved: true, all: true),- FactoryBot.build(:mail_digest_notification_setting, involved: true, all: true),- FactoryBot.build(:in_app_notification_setting, involved: true, all: true)- ]- end- let(:author) { recipient }- let(:recipient_no_self_notified) { false }-- it_behaves_like 'creates notification' do- let(:notification_channel_reasons) do- {- read_ian: false,- reason_ian: :involved,- read_mail: false,- reason_mail: :involved,- read_mail_digest: false,- reason_mail_digest: :involved- }- end- end- endendcontext 'when user is watcher' do@@ -475,7 +425,7 @@ describe Notifications::CreateFromModelService,it_behaves_like 'creates no notification'end- context 'when watcher has all notifications enabled but made the change himself and has deactivated self notification' do+ context 'when watcher has all notifications enabled but made the change himself' dolet(:recipient_notification_settings) do[FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(watched: true, all: true)),@@ -487,31 +437,6 @@ describe Notifications::CreateFromModelService,it_behaves_like 'creates no notification'end-- context 'when watcher has all notifications enabled, made the change himself and has activated self notification' do- let(:recipient_notification_settings) do- [- FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(watched: true, all: true)),- FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(watched: true, all: true)),- FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(watched: true, all: true))- ]- end- let(:author) { recipient }- let(:recipient_no_self_notified) { false }-- it_behaves_like 'creates notification' do- let(:notification_channel_reasons) do- {- read_ian: false,- reason_ian: :watched,- read_mail: false,- reason_mail: :watched,- read_mail_digest: false,- reason_mail_digest: :watched- }- end- end- endendcontext 'when user is notified about everything' do@@ -644,7 +569,7 @@ describe Notifications::CreateFromModelService,it_behaves_like 'creates no notification'end- context 'when recipient has all notifications enabled but made the change himself and has deactivated self notification' do+ context 'when recipient has all notifications enabled but made the change himself' dolet(:recipient_notification_settings) do[FactoryBot.build(:mail_notification_setting, all: true),@@ -656,31 +581,6 @@ describe Notifications::CreateFromModelService,it_behaves_like 'creates no notification'end-- context 'when recipient has all notifications enabled, made the change himself and has activated self notification' do- let(:recipient_notification_settings) do- [- FactoryBot.build(:mail_notification_setting, all: true),- FactoryBot.build(:mail_digest_notification_setting, all: true),- FactoryBot.build(:in_app_notification_setting, all: true)- ]- end- let(:author) { recipient }- let(:recipient_no_self_notified) { false }-- it_behaves_like 'creates notification' do- let(:notification_channel_reasons) do- {- read_ian: false,- reason_ian: :subscribed,- read_mail: false,- reason_mail: :subscribed,- read_mail_digest: false,- reason_mail_digest: :subscribed- }- end- end- endendcontext 'when a work package is created' do@@ -1248,7 +1148,7 @@ describe Notifications::CreateFromModelService,it_behaves_like 'creates no notification'end- context 'when the mentioned user made the change himself and has deactivated self notification' do+ context 'when the mentioned user made the change himself' dolet(:note) do"Hello user:#{recipient.login}, hey user##{recipient.id}"end@@ -1256,27 +1156,6 @@ describe Notifications::CreateFromModelService,it_behaves_like 'creates no notification'end-- context 'when the mentioned user made the change himself, but has activated self notification' do- let(:note) do- "Hello user:#{recipient.login}, hey user##{recipient.id}"- end- let(:author) { recipient }- let(:recipient_no_self_notified) { false }-- it_behaves_like 'creates notification' do- let(:notification_channel_reasons) do- {- read_ian: false,- reason_ian: :mentioned,- read_mail: false,- reason_mail: :mentioned,- read_mail_digest: false,- reason_mail_digest: :mentioned- }- end- end- endendcontext 'for groups' dodiff --git a/spec/services/users/set_attributes_service_spec.rb b/spec/services/users/set_attributes_service_spec.rbindex db0dd66ed1b..5d9da7d8479 100644--- a/spec/services/users/set_attributes_service_spec.rb+++ b/spec/services/users/set_attributes_service_spec.rb@@ -114,14 +114,14 @@ describe Users::SetAttributesService, type: :model dolet(:params) do{pref: {- self_notified: true+ auto_hide_popups: true}}endit 'initializes the user`s preferences with those attributes' doexpect(call.result.pref)- .to be_self_notified+ .to be_auto_hide_popupsendendenddiff --git a/spec/workers/mails/shared/watcher_job.rb b/spec/workers/mails/shared/watcher_job.rbindex 58e19215555..7460290eb88 100644--- a/spec/workers/mails/shared/watcher_job.rb+++ b/spec/workers/mails/shared/watcher_job.rb@@ -42,21 +42,15 @@ shared_examples "watcher job" do |action|let(:watcher) doFactoryBot.build_stubbed(:watcher, watchable: work_package, user: watching_user)end- let(:self_notified) { true }let(:user_pref) do- pref = FactoryBot.build_stubbed(:user_preference)-- allow(pref).to receive(:self_notified?).and_return(self_notified)-- pref+ FactoryBot.build_stubbed(:user_preference)endlet(:notification_settings) do[FactoryBot.build_stubbed(:mail_notification_setting, all: true)]endlet(:watching_user) doFactoryBot.build_stubbed(:user,- notification_settings: notification_settings,- preference: user_pref).tap do |user|+ notification_settings: notification_settings).tap do |user|allow(user).to receive(:notification_settings).and_return(notification_settings)@@ -113,35 +107,15 @@ shared_examples "watcher job" do |action|endshared_examples_for 'notifies the watcher' do- context 'when added by a different user- and has self_notified activated' do- let(:self_notified) { true }-- it_behaves_like 'sends a mail'- end-- context 'when added by a different user- and has self_notified deactivated' do- let(:self_notified) { false }-+ context 'when added by a different user' doit_behaves_like 'sends a mail'end- context 'but when watcher is added by theirself- and has self_notified deactivated' do+ context 'when watcher is added by theirself' dolet(:watcher_changer) { watching_user }- let(:self_notified) { false }it_behaves_like 'sends no mail'end-- context 'but when watcher is added by theirself- and has self_notified activated' do- let(:watcher_changer) { watching_user }- let(:self_notified) { true }-- it_behaves_like 'sends a mail'- endendshared_examples_for 'does not notify the watcher' do@@ -151,7 +125,6 @@ shared_examples "watcher job" do |action|context 'when watcher is added by theirself' dolet(:watcher_changer) { watching_user }- let(:self_notified) { false }it_behaves_like 'sends no mail'enddiff --git a/spec_legacy/fixtures/user_preferences.yml b/spec_legacy/fixtures/user_preferences.ymlindex 6e3f64f7b3f..bc36d558cd4 100644--- a/spec_legacy/fixtures/user_preferences.yml+++ b/spec_legacy/fixtures/user_preferences.yml@@ -58,7 +58,6 @@ user_preferences_002:user_preferences_003:others: |---- no_self_notified: falseid: 3user_id: 2hide_mail: falsediff --git a/spec_legacy/unit/mail_handler_spec.rb b/spec_legacy/unit/mail_handler_spec.rbindex d41255edbcf..0d4b39327f4 100644--- a/spec_legacy/unit/mail_handler_spec.rb+++ b/spec_legacy/unit/mail_handler_spec.rb@@ -271,16 +271,6 @@ describe MailHandler, type: :model doendend- it 'should add work package should send email notification' do- User.find(2).notification_settings.create(channel: :mail, all: true)-- # This email contains: 'Project: onlinestore'- issue = submit_email('ticket_on_given_project.eml')- assert issue.is_a?(WorkPackage)- # One for the wp creation.- assert_equal 1, ActionMailer::Base.deliveries.size- end-it 'should add work package note' dojournal = submit_email('ticket_reply.eml')assert journal.is_a?(Journal)@@ -320,15 +310,6 @@ describe MailHandler, type: :model doassert !journal.notes.match(/^Start Date:/i)end- it 'should add work package note should send email notification' do- User.find(2).notification_settings.create(channel: :mail, all: true)- User.find(3).notification_settings.create(channel: :mail, involved: true)-- journal = submit_email('ticket_reply.eml')- assert journal.is_a?(Journal)- assert_equal 2, ActionMailer::Base.deliveries.size- end-it 'should add work package note should not set defaults' dojournal = submit_email('ticket_reply.eml', issue: { type: 'Support request', priority: 'High' })assert journal.is_a?(Journal)