1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/transforms/unsplash-settings.js
Kevin Ansfield 92e43b7514 Fixed missing Unsplash icons when API doesn't return an unsplash setting (#865)
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
2017-09-21 11:13:31 +02:00

28 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);
}
});