2019-11-08 14:13:35 -05:00
|
|
|
import EmberObject from "@ember/object";
|
2025-01-06 12:02:46 +08:00
|
|
|
import { alias } from "@ember/object/computed";
|
2019-11-08 14:13:35 -05:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2025-01-13 13:02:49 +00:00
|
|
|
import discourseComputed from "discourse/lib/decorators";
|
2024-11-19 20:45:18 +00:00
|
|
|
import { i18n } from "discourse-i18n";
|
2025-01-06 12:02:46 +08:00
|
|
|
import SettingObjectHelper from "admin/lib/setting-object-helper";
|
2015-03-02 12:12:19 -05:00
|
|
|
|
2025-01-06 12:02:46 +08:00
|
|
|
export default class SiteSetting extends EmberObject {
|
2024-03-18 08:50:39 +10:00
|
|
|
static findAll(params = {}) {
|
|
|
|
return ajax("/admin/site_settings", { data: params }).then(function (
|
|
|
|
settings
|
|
|
|
) {
|
2015-03-02 12:12:19 -05:00
|
|
|
// Group the results by category
|
|
|
|
const categories = {};
|
|
|
|
settings.site_settings.forEach(function (s) {
|
|
|
|
if (!categories[s.category]) {
|
|
|
|
categories[s.category] = [];
|
|
|
|
}
|
2015-11-21 12:27:06 +11:00
|
|
|
categories[s.category].pushObject(SiteSetting.create(s));
|
2015-03-02 12:12:19 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
return Object.keys(categories).map(function (n) {
|
|
|
|
return {
|
|
|
|
nameKey: n,
|
2024-11-19 20:45:18 +00:00
|
|
|
name: i18n("admin.site_settings.categories." + n),
|
2015-03-02 12:12:19 -05:00
|
|
|
siteSettings: categories[n],
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
2023-03-17 10:18:42 +00:00
|
|
|
}
|
2015-03-02 12:12:19 -05:00
|
|
|
|
2023-03-17 10:18:42 +00:00
|
|
|
static update(key, value, opts = {}) {
|
2015-03-02 12:12:19 -05:00
|
|
|
const data = {};
|
|
|
|
data[key] = value;
|
2019-10-15 18:41:27 +05:30
|
|
|
|
|
|
|
if (opts["updateExistingUsers"] === true) {
|
2020-09-01 13:07:41 +10:00
|
|
|
data["update_existing_user"] = true;
|
2019-10-15 18:41:27 +05:30
|
|
|
}
|
|
|
|
|
2017-08-07 10:43:09 +09:00
|
|
|
return ajax(`/admin/site_settings/${key}`, { type: "PUT", data });
|
2023-03-17 10:18:42 +00:00
|
|
|
}
|
2015-03-02 12:12:19 -05:00
|
|
|
|
2025-01-06 12:02:46 +08:00
|
|
|
settingObjectHelper = new SettingObjectHelper(this);
|
|
|
|
|
|
|
|
@alias("settingObjectHelper.overridden") overridden;
|
|
|
|
@alias("settingObjectHelper.computedValueProperty") computedValueProperty;
|
|
|
|
@alias("settingObjectHelper.computedNameProperty") computedNameProperty;
|
|
|
|
@alias("settingObjectHelper.validValues") validValues;
|
|
|
|
@alias("settingObjectHelper.allowsNone") allowsNone;
|
|
|
|
@alias("settingObjectHelper.anyValue") anyValue;
|
|
|
|
|
2023-03-17 10:18:42 +00:00
|
|
|
@discourseComputed("setting")
|
|
|
|
staffLogFilter(setting) {
|
|
|
|
if (!setting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
subject: setting,
|
|
|
|
action_name: "change_site_setting",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|