mirror of
https://github.com/discourse/discourse.git
synced 2025-02-06 03:18:23 +00:00
FIX: Ensure Theme#settings
are instances of ThemeSettings
(#26481)
Why this change? Instead of dealing with a generic object for `Theme#settings`, we want to always be dealing with `ThemeSettings` objects.` Previously, we converted the generic objects to `ThemeSettings` objects in the theme's adapter `afterFindAll` function. This is not correct because updating or saving the theme individual reverted the `Theme#settings` back to an array of generic object. To fix this problem, the proper way with our REST models is to overwrite the static `munge` method and create `ThemeSettings` instances there.
This commit is contained in:
parent
ba04fc6a01
commit
0eda1c96f1
@ -1,8 +1,8 @@
|
|||||||
import RestAdapter from "discourse/adapters/rest";
|
import RestAdapter from "discourse/adapters/rest";
|
||||||
import ThemeSettings from "admin/models/theme-settings";
|
|
||||||
|
|
||||||
export default class Theme extends RestAdapter {
|
export default class Theme extends RestAdapter {
|
||||||
jsonMode = true;
|
jsonMode = true;
|
||||||
|
|
||||||
basePath() {
|
basePath() {
|
||||||
return "/admin/";
|
return "/admin/";
|
||||||
}
|
}
|
||||||
@ -22,13 +22,6 @@ export default class Theme extends RestAdapter {
|
|||||||
let mappedParents = theme.get("parent_themes") || [];
|
let mappedParents = theme.get("parent_themes") || [];
|
||||||
mappedParents = mappedParents.map((t) => map[t.id]);
|
mappedParents = mappedParents.map((t) => map[t.id]);
|
||||||
theme.set("parentThemes", mappedParents);
|
theme.set("parentThemes", mappedParents);
|
||||||
|
|
||||||
if (theme.settings) {
|
|
||||||
theme.set(
|
|
||||||
"settings",
|
|
||||||
theme.settings.map((setting) => ThemeSettings.create(setting))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
|
@ -5,6 +5,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
|
|||||||
import RestModel from "discourse/models/rest";
|
import RestModel from "discourse/models/rest";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import I18n from "discourse-i18n";
|
import I18n from "discourse-i18n";
|
||||||
|
import ThemeSettings from "admin/models/theme-settings";
|
||||||
|
|
||||||
const THEME_UPLOAD_VAR = 2;
|
const THEME_UPLOAD_VAR = 2;
|
||||||
const FIELDS_IDS = [0, 1, 5];
|
const FIELDS_IDS = [0, 1, 5];
|
||||||
@ -14,6 +15,16 @@ export const COMPONENTS = "components";
|
|||||||
const SETTINGS_TYPE_ID = 5;
|
const SETTINGS_TYPE_ID = 5;
|
||||||
|
|
||||||
class Theme extends RestModel {
|
class Theme extends RestModel {
|
||||||
|
static munge(json) {
|
||||||
|
if (json.settings) {
|
||||||
|
json.settings = json.settings.map((setting) =>
|
||||||
|
ThemeSettings.create(setting)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
@or("default", "user_selectable") isActive;
|
@or("default", "user_selectable") isActive;
|
||||||
@gt("remote_theme.commits_behind", 0) isPendingUpdates;
|
@gt("remote_theme.commits_behind", 0) isPendingUpdates;
|
||||||
@gt("editedFields.length", 0) hasEditedFields;
|
@gt("editedFields.length", 0) hasEditedFields;
|
||||||
|
@ -1,10 +1,32 @@
|
|||||||
import { getOwner } from "@ember/application";
|
import { getOwner } from "@ember/application";
|
||||||
import { setupTest } from "ember-qunit";
|
import { setupTest } from "ember-qunit";
|
||||||
import { module, test } from "qunit";
|
import { module, test } from "qunit";
|
||||||
|
import ThemeSettings from "admin/models/theme-settings";
|
||||||
|
|
||||||
module("Unit | Model | theme", function (hooks) {
|
module("Unit | Model | theme", function (hooks) {
|
||||||
setupTest(hooks);
|
setupTest(hooks);
|
||||||
|
|
||||||
|
test("create munges settings property to ThemeSettings instances", function (assert) {
|
||||||
|
const store = getOwner(this).lookup("service:store");
|
||||||
|
|
||||||
|
const theme = store.createRecord("theme", {
|
||||||
|
settings: [
|
||||||
|
{ id: 1, name: "setting1" },
|
||||||
|
{ id: 2, name: "setting2" },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.ok(
|
||||||
|
theme.settings[0] instanceof ThemeSettings,
|
||||||
|
"should be an instance of ThemeSettings"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.ok(
|
||||||
|
theme.settings[1] instanceof ThemeSettings,
|
||||||
|
"should be an instance of ThemeSettings"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("can add an upload correctly", function (assert) {
|
test("can add an upload correctly", function (assert) {
|
||||||
const store = getOwner(this).lookup("service:store");
|
const store = getOwner(this).lookup("service:store");
|
||||||
const theme = store.createRecord("theme");
|
const theme = store.createRecord("theme");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user