2020-05-13 16:23:41 -04:00
|
|
|
import I18n from "I18n";
|
2016-06-30 13:55:44 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2018-03-04 19:04:23 -05:00
|
|
|
import Setting from "admin/mixins/setting-object";
|
2019-11-08 14:13:35 -05:00
|
|
|
import EmberObject from "@ember/object";
|
2015-03-02 12:12:19 -05:00
|
|
|
|
2019-11-08 14:13:35 -05:00
|
|
|
const SiteSetting = EmberObject.extend(Setting, {});
|
2015-03-02 12:12:19 -05:00
|
|
|
|
|
|
|
SiteSetting.reopenClass({
|
|
|
|
findAll() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/site_settings").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-20 20:27:06 -05: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,
|
|
|
|
name: I18n.t("admin.site_settings.categories." + n),
|
|
|
|
siteSettings: categories[n],
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-10-15 09:11:27 -04:00
|
|
|
update(key, value, opts = {}) {
|
2015-03-02 12:12:19 -05:00
|
|
|
const data = {};
|
|
|
|
data[key] = value;
|
2019-10-15 09:11:27 -04:00
|
|
|
|
|
|
|
if (opts["updateExistingUsers"] === true) {
|
2020-08-31 23:07:41 -04:00
|
|
|
data["update_existing_user"] = true;
|
2019-10-15 09:11:27 -04:00
|
|
|
}
|
|
|
|
|
2017-08-06 21:43:09 -04:00
|
|
|
return ajax(`/admin/site_settings/${key}`, { type: "PUT", data });
|
2015-03-02 12:12:19 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export default SiteSetting;
|