mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 04:14:38 +08:00
FIX: Remove scheduled DND timings when schedule is disabed (#11814)
This commit is contained in:

committed by
GitHub

parent
6f13d2b039
commit
56294b4fba
@ -18,10 +18,14 @@ class UserNotificationSchedule < ActiveRecord::Base
|
|||||||
scope :enabled, -> { where(enabled: true) }
|
scope :enabled, -> { where(enabled: true) }
|
||||||
|
|
||||||
def create_do_not_disturb_timings(delete_existing: false)
|
def create_do_not_disturb_timings(delete_existing: false)
|
||||||
user.do_not_disturb_timings.where(scheduled: true).destroy_all if delete_existing
|
destroy_scheduled_timings if delete_existing
|
||||||
UserNotificationScheduleProcessor.create_do_not_disturb_timings_for(self)
|
UserNotificationScheduleProcessor.create_do_not_disturb_timings_for(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy_scheduled_timings
|
||||||
|
user.do_not_disturb_timings.where(scheduled: true).destroy_all
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def has_valid_times
|
def has_valid_times
|
||||||
|
@ -200,7 +200,9 @@ class UserUpdater
|
|||||||
|
|
||||||
if saved
|
if saved
|
||||||
if user_notification_schedule
|
if user_notification_schedule
|
||||||
user_notification_schedule.create_do_not_disturb_timings(delete_existing: true)
|
user_notification_schedule.enabled ?
|
||||||
|
user_notification_schedule.create_do_not_disturb_timings(delete_existing: true) :
|
||||||
|
user_notification_schedule.destroy_scheduled_timings
|
||||||
end
|
end
|
||||||
DiscourseEvent.trigger(:user_updated, user)
|
DiscourseEvent.trigger(:user_updated, user)
|
||||||
end
|
end
|
||||||
|
@ -251,6 +251,18 @@ describe UserUpdater do
|
|||||||
updater.update(user_notification_schedule: schedule_attrs)
|
updater.update(user_notification_schedule: schedule_attrs)
|
||||||
}.to change { user.do_not_disturb_timings.count }.by(4)
|
}.to change { user.do_not_disturb_timings.count }.by(4)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "removes do_not_disturb_timings when the schedule is disabled" do
|
||||||
|
updater = UserUpdater.new(acting_user, user)
|
||||||
|
updater.update(user_notification_schedule: schedule_attrs)
|
||||||
|
expect(user.user_notification_schedule.enabled).to eq(true)
|
||||||
|
|
||||||
|
schedule_attrs[:enabled] = false
|
||||||
|
updater.update(user_notification_schedule: schedule_attrs)
|
||||||
|
|
||||||
|
expect(user.user_notification_schedule.enabled).to eq(false)
|
||||||
|
expect(user.do_not_disturb_timings.count).to eq(0)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when sso overrides bio' do
|
context 'when sso overrides bio' do
|
||||||
|
Reference in New Issue
Block a user