2019-11-09 03:13:35 +08:00
|
|
|
import EmberObject from "@ember/object";
|
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2020-11-12 20:07:36 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2023-10-18 18:07:09 +08:00
|
|
|
import I18n from "discourse-i18n";
|
2023-10-11 02:38:59 +08:00
|
|
|
import Setting from "admin/mixins/setting-object";
|
2015-03-03 01:12:19 +08:00
|
|
|
|
2023-03-17 18:18:42 +08:00
|
|
|
export default class SiteSetting extends EmberObject.extend(Setting) {
|
2024-03-18 06:50:39 +08:00
|
|
|
static findAll(params = {}) {
|
|
|
|
return ajax("/admin/site_settings", { data: params }).then(function (
|
|
|
|
settings
|
|
|
|
) {
|
2015-03-03 01:12:19 +08:00
|
|
|
// Group the results by category
|
|
|
|
const categories = {};
|
|
|
|
settings.site_settings.forEach(function (s) {
|
|
|
|
if (!categories[s.category]) {
|
|
|
|
categories[s.category] = [];
|
|
|
|
}
|
2015-11-21 09:27:06 +08:00
|
|
|
categories[s.category].pushObject(SiteSetting.create(s));
|
2015-03-03 01:12:19 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return Object.keys(categories).map(function (n) {
|
|
|
|
return {
|
|
|
|
nameKey: n,
|
|
|
|
name: I18n.t("admin.site_settings.categories." + n),
|
|
|
|
siteSettings: categories[n],
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2015-03-03 01:12:19 +08:00
|
|
|
|
2023-03-17 18:18:42 +08:00
|
|
|
static update(key, value, opts = {}) {
|
2015-03-03 01:12:19 +08:00
|
|
|
const data = {};
|
|
|
|
data[key] = value;
|
2019-10-15 21:11:27 +08:00
|
|
|
|
|
|
|
if (opts["updateExistingUsers"] === true) {
|
2020-09-01 11:07:41 +08:00
|
|
|
data["update_existing_user"] = true;
|
2019-10-15 21:11:27 +08:00
|
|
|
}
|
|
|
|
|
2017-08-07 09:43:09 +08:00
|
|
|
return ajax(`/admin/site_settings/${key}`, { type: "PUT", data });
|
2023-03-17 18:18:42 +08:00
|
|
|
}
|
2015-03-03 01:12:19 +08:00
|
|
|
|
2023-03-17 18:18:42 +08:00
|
|
|
@discourseComputed("setting")
|
|
|
|
staffLogFilter(setting) {
|
|
|
|
if (!setting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
subject: setting,
|
|
|
|
action_name: "change_site_setting",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|