FEATURE: Option to update category preferences of all users when site setting changed (#8180)

This commit is contained in:
Vinoth Kannan
2019-10-15 18:41:27 +05:30
committed by GitHub
parent c3cc96084c
commit b2f682f35e
8 changed files with 173 additions and 18 deletions

View File

@@ -1,10 +1,54 @@
import BufferedContent from "discourse/mixins/buffered-content";
import SiteSetting from "admin/models/site-setting";
import SettingComponent from "admin/mixins/setting-component";
import showModal from "discourse/lib/show-modal";
import AboutRoute from "discourse/routes/about";
export default Ember.Component.extend(BufferedContent, SettingComponent, {
_save() {
update(key, value, updateExistingUsers = false) {
if (updateExistingUsers) {
return SiteSetting.update(key, value, { updateExistingUsers: true });
} else {
return SiteSetting.update(key, value);
}
},
_save(callback) {
const defaultCategoriesSettings = [
"default_categories_watching",
"default_categories_tracking",
"default_categories_muted",
"default_categories_watching_first_post"
];
const setting = this.buffered;
return SiteSetting.update(setting.get("setting"), setting.get("value"));
const key = setting.get("setting");
const value = setting.get("value");
if (defaultCategoriesSettings.includes(key)) {
AboutRoute.create()
.model()
.then(result => {
const controller = showModal("site-setting-default-categories", {
model: {
count: result.stats.user_count,
key: key.replace(/_/g, " ")
},
admin: true
});
controller.setProperties({
onClose: () => {
const updateExistingUsers = controller.get("updateExistingUsers");
if (updateExistingUsers === true) {
callback(this.update(key, value, true));
} else if (updateExistingUsers === false) {
callback(this.update(key, value));
}
}
});
});
} else {
callback(this.update(key, value));
}
}
});

View File

@@ -0,0 +1,19 @@
import ModalFunctionality from "discourse/mixins/modal-functionality";
export default Ember.Controller.extend(ModalFunctionality, {
onShow() {
this.set("updateExistingUsers", null);
},
actions: {
updateExistingUsers() {
this.set("updateExistingUsers", true);
this.send("closeModal");
},
cancel() {
this.set("updateExistingUsers", false);
this.send("closeModal");
}
}
});

View File

@@ -111,21 +111,23 @@ export default Ember.Mixin.create({
actions: {
save() {
this._save()
.then(() => {
this.set("validationMessage", null);
this.commitBuffer();
if (AUTO_REFRESH_ON_SAVE.includes(this.get("setting.setting"))) {
this.afterSave();
}
})
.catch(e => {
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {
this.set("validationMessage", e.jqXHR.responseJSON.errors[0]);
} else {
this.set("validationMessage", I18n.t("generic_error"));
}
});
this._save(result => {
result
.then(() => {
this.set("validationMessage", null);
this.commitBuffer();
if (AUTO_REFRESH_ON_SAVE.includes(this.get("setting.setting"))) {
this.afterSave();
}
})
.catch(e => {
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {
this.set("validationMessage", e.jqXHR.responseJSON.errors[0]);
} else {
this.set("validationMessage", I18n.t("generic_error"));
}
});
});
},
cancel() {

View File

@@ -25,9 +25,14 @@ SiteSetting.reopenClass({
});
},
update(key, value) {
update(key, value, opts = {}) {
const data = {};
data[key] = value;
if (opts["updateExistingUsers"] === true) {
data["updateExistingUsers"] = true;
}
return ajax(`/admin/site_settings/${key}`, { type: "PUT", data });
}
});

View File

@@ -0,0 +1,8 @@
{{#d-modal-body class="incoming-emails" rawTitle=model.key}}
{{i18n "admin.site_settings.default_categories.modal_description" count=model.count}}
{{/d-modal-body}}
<div class="modal-footer">
{{d-button action=(action "updateExistingUsers") class='btn btn-primary' label='admin.site_settings.default_categories.modal_yes'}}
{{d-button action=(action "cancel") class='btn' label='admin.site_settings.default_categories.modal_no'}}
</div>