Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Move activation to themes endpoint #8093

Merged
merged 4 commits into from
Mar 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/server/api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ function apiRoutes() {
api.http(api.themes.upload)
);

apiRouter.put('/themes/:name/activate',
authenticatePrivate,
api.http(api.themes.activate)
);

apiRouter.del('/themes/:name',
authenticatePrivate,
api.http(api.themes.destroy)
Expand Down
25 changes: 19 additions & 6 deletions core/server/api/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ var debug = require('debug')('ghost:api:themes'),
apiUtils = require('./utils'),
utils = require('./../utils'),
i18n = require('../i18n'),
settings = require('./settings'),
settingsCache = require('../settings/cache'),
themeUtils = require('../themes'),
themeList = themeUtils.list,
packageUtils = require('../utils/packages'),
themes;

/**
Expand All @@ -26,11 +27,24 @@ var debug = require('debug')('ghost:api:themes'),
themes = {
browse: function browse() {
debug('browsing');
var result = packageUtils.filterPackages(themeList.getAll());
var result = themeList.toAPI(themeList.getAll(), settingsCache.get('activeTheme'));

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

debug('got result');
return Promise.resolve({themes: result});
},

activate: function activate(options) {

This comment was marked as abuse.

This comment was marked as abuse.

var themeName = options.name,
newSettings = [{
key: 'activeTheme',
value: themeName
}];

return settings.edit({settings: newSettings}, options).then(function () {
var result = themeList.toAPI(themeList.getAll(), themeName);
return Promise.resolve({themes: result});
});
},

upload: function upload(options) {
options = options || {};

Expand Down Expand Up @@ -87,14 +101,12 @@ themes = {
return themeUtils.loadOne(zip.shortName);
})
.then(function (themeObject) {
// @TODO fix this craziness
var toFilter = {};
toFilter[zip.shortName] = themeObject;
themeObject = packageUtils.filterPackages(toFilter);
themeObject = themeList.toAPI(themeObject, settingsCache.get('activeTheme'));
// gscan theme structure !== ghost theme structure
if (theme.results.warning.length > 0) {
themeObject.warnings = _.cloneDeep(theme.results.warning);
}

return {themes: themeObject};
})
.finally(function () {
Expand Down Expand Up @@ -158,6 +170,7 @@ themes = {
.then(function () {
themeList.del(name);
events.emit('theme.deleted', name);
// Delete returns an empty 204 response
});
}
};
Expand Down
13 changes: 13 additions & 0 deletions core/server/themes/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Store themes after loading them from the file system
*/
var _ = require('lodash'),
packages = require('../utils/packages'),
themeListCache = {};

module.exports = {
Expand Down Expand Up @@ -32,5 +33,17 @@ module.exports = {
});

return themeListCache;
},
toAPI: function toAPI(themes, active) {
var toFilter;

if (themes.hasOwnProperty('name')) {
toFilter = {};
toFilter[themes.name] = themes;
} else {
toFilter = themes;
}

return packages.filterPackages(toFilter, active);
}
};
Loading