FIX: slow mode dialog doesn't remember Enabled Until value (#13076)
If reload a page after enabling slow mode and open the slow mode dialog again it would show a slow mode interval but wouldn't show Enabled Until value. This PR fixes it.
This commit is contained in:
parent
38af28d58b
commit
0df6b0bc47
|
@ -14,7 +14,6 @@ export default Controller.extend(ModalFunctionality, {
|
|||
minutes: null,
|
||||
seconds: null,
|
||||
saveDisabled: false,
|
||||
enabledUntil: null,
|
||||
showCustomSelect: equal("selectedSlowMode", "custom"),
|
||||
durationIsSet: or("hours", "minutes", "seconds"),
|
||||
|
||||
|
@ -87,7 +86,11 @@ export default Controller.extend(ModalFunctionality, {
|
|||
}
|
||||
},
|
||||
|
||||
@discourseComputed("saveDisabled", "durationIsSet", "enabledUntil")
|
||||
@discourseComputed(
|
||||
"saveDisabled",
|
||||
"durationIsSet",
|
||||
"model.slow_mode_enabled_until"
|
||||
)
|
||||
submitDisabled(saveDisabled, durationIsSet, enabledUntil) {
|
||||
return saveDisabled || !durationIsSet || !enabledUntil;
|
||||
},
|
||||
|
@ -121,7 +124,11 @@ export default Controller.extend(ModalFunctionality, {
|
|||
this._parseValue(this.seconds)
|
||||
);
|
||||
|
||||
Topic.setSlowMode(this.model.id, seconds, this.enabledUntil)
|
||||
Topic.setSlowMode(
|
||||
this.model.id,
|
||||
seconds,
|
||||
this.model.slow_mode_enabled_until
|
||||
)
|
||||
.catch(popupAjaxError)
|
||||
.then(() => {
|
||||
this.set("model.slow_mode_seconds", seconds);
|
||||
|
|
|
@ -33,8 +33,8 @@
|
|||
labelClasses="slow-mode-label"
|
||||
includeFarFuture=false
|
||||
clearable=true
|
||||
input=enabledUntil
|
||||
onChangeInput=(action (mut enabledUntil))
|
||||
input=model.slow_mode_enabled_until
|
||||
onChangeInput=(action (mut model.slow_mode_enabled_until))
|
||||
}}
|
||||
</div>
|
||||
{{/d-modal-body}}
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
import {
|
||||
acceptance,
|
||||
exists,
|
||||
query,
|
||||
updateCurrentUser,
|
||||
} from "discourse/tests/helpers/qunit-helpers";
|
||||
import { click, visit } from "@ember/test-helpers";
|
||||
import { test } from "qunit";
|
||||
import I18n from "I18n";
|
||||
import { cloneJSON } from "discourse-common/lib/object";
|
||||
import topicFixtures from "discourse/tests/fixtures/topic";
|
||||
|
||||
acceptance("Topic - Slow Mode - enabled", function (needs) {
|
||||
needs.user();
|
||||
needs.pretender((server, helper) => {
|
||||
server.get("/t/130.json", () => {
|
||||
const json = cloneJSON(topicFixtures["/t/130.json"]);
|
||||
json.slow_mode_seconds = 600;
|
||||
json.slow_mode_enabled_until = "2040-01-01T04:00:00.000Z";
|
||||
|
||||
return helper.response(json);
|
||||
});
|
||||
});
|
||||
|
||||
test("the slow mode dialog loads settings of currently enabled slow mode ", async function (assert) {
|
||||
updateCurrentUser({ moderator: true });
|
||||
await visit("/t/slow-mode-testing/130");
|
||||
await click(".toggle-admin-menu");
|
||||
await click(".topic-admin-slow-mode button");
|
||||
|
||||
await click(".future-date-input-selector-header");
|
||||
|
||||
assert.equal(
|
||||
query(".future-date-input-selector-header").getAttribute("aria-expanded"),
|
||||
"true",
|
||||
"selector is expanded"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
query("div.slow-mode-type span.name").innerText,
|
||||
I18n.t("topic.slow_mode_update.durations.10_minutes"),
|
||||
"slow mode interval is rendered"
|
||||
);
|
||||
|
||||
// unfortunately we can't check exact date and time
|
||||
// but at least we can make sure that components for choosing date and time are rendered
|
||||
// (in case of inactive slow mode it would be only a combo box with text "Select a timeframe",
|
||||
// and date picker and time picker wouldn't be rendered)
|
||||
assert.equal(
|
||||
query("div.enabled-until span.name").innerText,
|
||||
I18n.t("topic.auto_update_input.pick_date_and_time"),
|
||||
"enabled until combobox is switched to the option Pick Date and Time"
|
||||
);
|
||||
|
||||
assert.ok(exists("input.date-picker"), "date picker is rendered");
|
||||
assert.ok(exists("input.time-input"), "time picker is rendered");
|
||||
});
|
||||
});
|
|
@ -538,6 +538,7 @@ class Topic < ActiveRecord::Base
|
|||
def reload(options = nil)
|
||||
@post_numbers = nil
|
||||
@public_topic_timer = nil
|
||||
@slow_mode_topic_timer = nil
|
||||
@is_category_topic = nil
|
||||
super(options)
|
||||
end
|
||||
|
@ -1278,6 +1279,10 @@ class Topic < ActiveRecord::Base
|
|||
@public_topic_timer ||= topic_timers.find_by(deleted_at: nil, public_type: true)
|
||||
end
|
||||
|
||||
def slow_mode_topic_timer
|
||||
@slow_mode_topic_timer ||= topic_timers.find_by(deleted_at: nil, status_type: TopicTimer.types[:clear_slow_mode])
|
||||
end
|
||||
|
||||
def delete_topic_timer(status_type, by_user: Discourse.system_user)
|
||||
options = { status_type: status_type }
|
||||
options.merge!(user: by_user) unless TopicTimer.public_types[status_type]
|
||||
|
|
|
@ -75,7 +75,8 @@ class TopicViewSerializer < ApplicationSerializer
|
|||
:requested_group_name,
|
||||
:thumbnails,
|
||||
:user_last_posted_at,
|
||||
:is_shared_draft
|
||||
:is_shared_draft,
|
||||
:slow_mode_enabled_until
|
||||
)
|
||||
|
||||
has_one :details, serializer: TopicViewDetailsSerializer, root: false, embed: :objects
|
||||
|
@ -298,4 +299,8 @@ class TopicViewSerializer < ApplicationSerializer
|
|||
def include_user_last_posted_at?
|
||||
has_topic_user? && object.topic.slow_mode_seconds.to_i > 0
|
||||
end
|
||||
|
||||
def slow_mode_enabled_until
|
||||
object.topic.slow_mode_topic_timer&.execute_at
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,6 +21,7 @@ class WebHookTopicViewSerializer < TopicViewSerializer
|
|||
details
|
||||
image_url
|
||||
slow_mode_seconds
|
||||
slow_mode_enabled_until
|
||||
}.each do |attr|
|
||||
define_method("include_#{attr}?") do
|
||||
false
|
||||
|
|
Loading…
Reference in New Issue