mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 12:21:36 +03:00
Fixed EmberObject.create error on Admin start (#1841)
refs https://github.com/TryGhost/Ghost/pull/12632 - The `unsplash` setting has been migrated to a new format - plain boolean value. This is why it's no longer needed to do any serialization dances
This commit is contained in:
parent
2c95cae248
commit
07abb5443a
@ -18,7 +18,7 @@
|
||||
<div class="gh-btn gh-btn-white" data-test-file-input-description><span>{{this.description}}</span></div>
|
||||
</GhFileInput>
|
||||
|
||||
{{#if (and this.allowUnsplash this.settings.unsplash.isActive)}}
|
||||
{{#if (and this.allowUnsplash this.settings.unsplash)}}
|
||||
<div class="gh-image-uploader-unsplash" {{action (toggle "_showUnsplash" this)}}>
|
||||
{{svg-jar "unsplash"}}
|
||||
</div>
|
||||
|
@ -161,7 +161,7 @@ export default Component.extend(ShortcutsMixin, {
|
||||
toolbar.splice(index, 1);
|
||||
}
|
||||
|
||||
if (this.get('settings.unsplash.isActive')) {
|
||||
if (this.get('settings.unsplash')) {
|
||||
let image = toolbar.findBy('name', 'image');
|
||||
let index = toolbar.indexOf(image) + 1;
|
||||
|
||||
|
@ -21,9 +21,9 @@ export default Controller.extend({
|
||||
|
||||
update(value) {
|
||||
if (!this.dirtyAttributes) {
|
||||
this.set('rollbackValue', this.get('unsplashSettings.isActive'));
|
||||
this.set('rollbackValue', this.get('unsplashSettings'));
|
||||
}
|
||||
this.set('unsplashSettings.isActive', value);
|
||||
this.set('unsplashSettings', value);
|
||||
this.set('dirtyAttributes', true);
|
||||
},
|
||||
|
||||
@ -60,7 +60,7 @@ export default Controller.extend({
|
||||
}
|
||||
|
||||
// roll back changes on model props
|
||||
this.set('unsplashSettings.isActive', this.rollbackValue);
|
||||
this.set('unsplashSettings', this.rollbackValue);
|
||||
this.set('dirtyAttributes', false);
|
||||
this.set('rollbackValue', null);
|
||||
|
||||
|
@ -28,11 +28,7 @@ export default Model.extend(ValidationEngine, {
|
||||
ampGtagId: attr('string'),
|
||||
firstpromoter: attr('boolean'),
|
||||
firstpromoterId: attr('string'),
|
||||
unsplash: attr('unsplash-settings', {
|
||||
defaultValue() {
|
||||
return {isActive: true};
|
||||
}
|
||||
}),
|
||||
unsplash: attr('boolean'),
|
||||
metaTitle: attr('string'),
|
||||
metaDescription: attr('string'),
|
||||
twitterTitle: attr('string'),
|
||||
|
@ -1,5 +0,0 @@
|
||||
import EmberObject from '@ember/object';
|
||||
|
||||
export default EmberObject.extend({
|
||||
isActive: false
|
||||
});
|
@ -1,6 +1,5 @@
|
||||
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
||||
import CurrentUserSettings from 'ghost-admin/mixins/current-user-settings';
|
||||
import UnsplashObject from 'ghost-admin/models/unsplash-integration';
|
||||
import {inject as service} from '@ember/service';
|
||||
|
||||
export default AuthenticatedRoute.extend(CurrentUserSettings, {
|
||||
@ -24,11 +23,8 @@ export default AuthenticatedRoute.extend(CurrentUserSettings, {
|
||||
|
||||
// server doesn't have any unsplash settings by default but it can provide
|
||||
// overrides via config:
|
||||
// - isActive: use as default but allow settings override
|
||||
// - applicationId: total override, no field is shown if present
|
||||
let unsplash = UnsplashObject.create({
|
||||
isActive: true
|
||||
});
|
||||
// - unsplash: use as default but allow settings override
|
||||
let unsplash = true;
|
||||
|
||||
settings.set('unsplash', unsplash);
|
||||
});
|
||||
|
@ -142,7 +142,7 @@
|
||||
</div>
|
||||
<div class="gh-card-right">
|
||||
<div class="apps-configured">
|
||||
{{#if this.settings.unsplash.isActive}}
|
||||
{{#if this.settings.unsplash}}
|
||||
<span class="gh-badge" data-test-app-status>Active</span>
|
||||
{{else}}
|
||||
<span data-test-app-status>Configure</span>
|
||||
|
@ -45,7 +45,7 @@
|
||||
<label for="isActive" class="checkbox">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={{this.unsplashSettings.isActive}}
|
||||
checked={{this.unsplashSettings}}
|
||||
id="isActive"
|
||||
name="isActive"
|
||||
onclick={{action "update" value="target.checked"}}
|
||||
|
@ -1,28 +1,25 @@
|
||||
/* eslint-disable camelcase */
|
||||
import Transform from '@ember-data/serializer/transform';
|
||||
import UnsplashObject from 'ghost-admin/models/unsplash-integration';
|
||||
|
||||
const DEFAULT_SETTINGS = {
|
||||
isActive: true
|
||||
};
|
||||
const DEFAULT_VALUE = true;
|
||||
|
||||
export default Transform.extend({
|
||||
deserialize(serialized) {
|
||||
if (serialized) {
|
||||
let settingsObject;
|
||||
try {
|
||||
settingsObject = JSON.parse(serialized) || DEFAULT_SETTINGS;
|
||||
settingsObject = JSON.parse(serialized) || DEFAULT_VALUE;
|
||||
} catch (e) {
|
||||
settingsObject = DEFAULT_SETTINGS;
|
||||
settingsObject = DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
return UnsplashObject.create(settingsObject);
|
||||
return settingsObject;
|
||||
}
|
||||
|
||||
return DEFAULT_SETTINGS;
|
||||
return DEFAULT_VALUE;
|
||||
},
|
||||
|
||||
serialize(deserialized) {
|
||||
return deserialized ? JSON.stringify(deserialized) : JSON.stringify(DEFAULT_SETTINGS);
|
||||
return deserialized ? JSON.stringify(deserialized) : JSON.stringify(DEFAULT_VALUE);
|
||||
}
|
||||
});
|
||||
|
@ -84,7 +84,7 @@ describe('Acceptance: Settings - Integrations - Unsplash', function () {
|
||||
// server should now have an unsplash setting
|
||||
let [setting] = this.server.db.settings.where({key: 'unsplash'});
|
||||
expect(setting, 'unsplash setting after save').to.exist;
|
||||
expect(setting.value).to.equal('{"isActive":true}');
|
||||
expect(setting.value).to.equal(true);
|
||||
|
||||
// disable
|
||||
await click('[data-test-checkbox="unsplash"]');
|
||||
@ -98,7 +98,7 @@ describe('Acceptance: Settings - Integrations - Unsplash', function () {
|
||||
|
||||
// server should have an updated setting
|
||||
[setting] = this.server.db.settings.where({key: 'unsplash'});
|
||||
expect(setting.value).to.equal('{"isActive":false}');
|
||||
expect(setting.value).to.equal(false);
|
||||
});
|
||||
|
||||
it('warns when leaving without saving', async function () {
|
||||
|
@ -1,43 +0,0 @@
|
||||
import {describe, it} from 'mocha';
|
||||
import {expect} from 'chai';
|
||||
import {setupTest} from 'ember-mocha';
|
||||
|
||||
describe('Unit: Transform: unsplash-settings', function () {
|
||||
setupTest();
|
||||
|
||||
it('deserializes to default value when null', function () {
|
||||
let serialized = null;
|
||||
let result = this.owner.lookup('transform:unsplash-settings').deserialize(serialized);
|
||||
expect(result.isActive).to.be.true;
|
||||
});
|
||||
|
||||
it('deserializes to default value when blank string', function () {
|
||||
let serialized = '';
|
||||
let result = this.owner.lookup('transform:unsplash-settings').deserialize(serialized);
|
||||
expect(result.isActive).to.be.true;
|
||||
});
|
||||
|
||||
it('deserializes to default value when invalid JSON', function () {
|
||||
let serialized = 'not JSON';
|
||||
let result = this.owner.lookup('transform:unsplash-settings').deserialize(serialized);
|
||||
expect(result.isActive).to.be.true;
|
||||
});
|
||||
|
||||
it('deserializes valid JSON object', function () {
|
||||
let serialized = '{"isActive":false}';
|
||||
let result = this.owner.lookup('transform:unsplash-settings').deserialize(serialized);
|
||||
expect(result.isActive).to.be.false;
|
||||
});
|
||||
|
||||
it('serializes to JSON string', function () {
|
||||
let deserialized = {isActive: false};
|
||||
let result = this.owner.lookup('transform:unsplash-settings').serialize(deserialized);
|
||||
expect(result).to.equal('{"isActive":false}');
|
||||
});
|
||||
|
||||
it('serializes to default value when blank', function () {
|
||||
let deserialized = '';
|
||||
let result = this.owner.lookup('transform:unsplash-settings').serialize(deserialized);
|
||||
expect(result).to.equal('{"isActive":true}');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user