mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 15:12:58 +03:00
6a9239974f
closes https://github.com/TryGhost/Ghost/issues/9031 - add a default value `unsplash` value to the `setting` model so that Unsplash is activated when the server doesn't return an `unsplash` setting - update the `unsplash-settings` transform to always deserialize or serialize to `{isActive: true}` when the value is blank or not parsable - add acceptance regression test covering API not returning an `unplash` setting - add unit tests for the `unsplash-settings` transform
29 lines
752 B
JavaScript
29 lines
752 B
JavaScript
/* eslint-disable camelcase */
|
|
import Transform from 'ember-data/transform';
|
|
import UnsplashObject from 'ghost-admin/models/unsplash-integration';
|
|
|
|
const DEFAULT_SETTINGS = {
|
|
isActive: true
|
|
};
|
|
|
|
export default Transform.extend({
|
|
deserialize(serialized) {
|
|
if (serialized) {
|
|
let settingsObject;
|
|
try {
|
|
settingsObject = JSON.parse(serialized) || DEFAULT_SETTINGS;
|
|
} catch (e) {
|
|
settingsObject = DEFAULT_SETTINGS;
|
|
}
|
|
|
|
return UnsplashObject.create(settingsObject);
|
|
}
|
|
|
|
return DEFAULT_SETTINGS;
|
|
},
|
|
|
|
serialize(deserialized) {
|
|
return deserialized ? JSON.stringify(deserialized) : JSON.stringify(DEFAULT_SETTINGS);
|
|
}
|
|
});
|