2016-08-23 15:07:25 +03:00
|
|
|
// # Themes API
|
|
|
|
// RESTful API for Themes
|
2018-09-18 16:59:56 +03:00
|
|
|
const debug = require('ghost-ignition').debug('api:themes'),
|
2017-03-13 23:13:17 +03:00
|
|
|
Promise = require('bluebird'),
|
2016-08-23 15:07:25 +03:00
|
|
|
fs = require('fs-extra'),
|
2017-12-14 00:14:19 +03:00
|
|
|
localUtils = require('./utils'),
|
2018-09-27 17:06:57 +03:00
|
|
|
common = require('../../lib/common'),
|
|
|
|
models = require('../../models'),
|
|
|
|
settingsCache = require('../../services/settings/cache'),
|
2019-06-19 18:58:07 +03:00
|
|
|
themeService = require('../../../frontend/services/themes'),
|
|
|
|
themeList = themeService.list;
|
2018-09-18 16:59:56 +03:00
|
|
|
|
|
|
|
let themes;
|
2016-08-23 15:07:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ## Themes API Methods
|
|
|
|
*
|
2017-12-14 16:13:40 +03:00
|
|
|
* **See:** [API Methods](constants.js.html#api%20methods)
|
2016-08-23 15:07:25 +03:00
|
|
|
*/
|
|
|
|
themes = {
|
2017-10-10 15:36:35 +03:00
|
|
|
/**
|
|
|
|
* Every role can browse all themes. The response contains a list of all available themes in your content folder.
|
|
|
|
* The active theme get's marked as `active:true` and contains an extra object `templates`, which
|
|
|
|
* contains the custom templates of the active theme. These custom templates are used to show a dropdown
|
|
|
|
* in the PSM to be able to choose a custom post template.
|
|
|
|
*/
|
2018-09-18 16:59:56 +03:00
|
|
|
browse(options) {
|
2017-12-14 00:14:19 +03:00
|
|
|
return localUtils
|
2017-12-12 00:47:46 +03:00
|
|
|
// Permissions
|
2017-03-20 21:02:44 +03:00
|
|
|
.handlePermissions('themes', 'browse')(options)
|
|
|
|
// Main action
|
2018-09-18 16:59:56 +03:00
|
|
|
.then(() => {
|
2017-03-20 21:02:44 +03:00
|
|
|
// Return JSON result
|
2019-06-19 18:58:07 +03:00
|
|
|
return themeService.toJSON();
|
2017-03-20 21:02:44 +03:00
|
|
|
});
|
2017-02-21 17:59:03 +03:00
|
|
|
},
|
|
|
|
|
2018-09-18 16:59:56 +03:00
|
|
|
activate(options) {
|
|
|
|
let themeName = options.name,
|
2017-03-08 13:46:03 +03:00
|
|
|
newSettings = [{
|
2017-04-24 20:41:00 +03:00
|
|
|
key: 'active_theme',
|
2017-03-08 13:46:03 +03:00
|
|
|
value: themeName
|
2017-03-13 14:44:44 +03:00
|
|
|
}],
|
|
|
|
loadedTheme,
|
|
|
|
checkedTheme;
|
|
|
|
|
2017-12-14 00:14:19 +03:00
|
|
|
return localUtils
|
2017-12-12 00:47:46 +03:00
|
|
|
// Permissions
|
2017-03-13 14:44:44 +03:00
|
|
|
.handlePermissions('themes', 'activate')(options)
|
2017-03-20 21:02:44 +03:00
|
|
|
// Validation
|
2018-09-18 16:59:56 +03:00
|
|
|
.then(() => {
|
2017-03-13 14:44:44 +03:00
|
|
|
loadedTheme = themeList.get(themeName);
|
|
|
|
|
|
|
|
if (!loadedTheme) {
|
2017-12-12 00:47:46 +03:00
|
|
|
return Promise.reject(new common.errors.ValidationError({
|
|
|
|
message: common.i18n.t('notices.data.validation.index.themeCannotBeActivated', {themeName: themeName}),
|
2019-04-23 10:45:11 +03:00
|
|
|
errorDetails: newSettings
|
2017-03-13 14:44:44 +03:00
|
|
|
}));
|
|
|
|
}
|
2017-03-08 13:46:03 +03:00
|
|
|
|
2019-06-19 18:58:07 +03:00
|
|
|
return themeService.validate.checkSafe(loadedTheme);
|
2017-03-13 14:44:44 +03:00
|
|
|
})
|
2017-03-20 21:02:44 +03:00
|
|
|
// Update setting
|
2018-09-18 16:59:56 +03:00
|
|
|
.then((_checkedTheme) => {
|
2017-03-13 14:44:44 +03:00
|
|
|
checkedTheme = _checkedTheme;
|
|
|
|
// We use the model, not the API here, as we don't want to trigger permissions
|
2018-09-21 16:16:19 +03:00
|
|
|
return models.Settings.edit(newSettings, options);
|
2017-03-13 14:44:44 +03:00
|
|
|
})
|
2017-03-20 21:02:44 +03:00
|
|
|
// Call activate
|
2018-09-18 16:59:56 +03:00
|
|
|
.then(() => {
|
2017-03-13 23:13:17 +03:00
|
|
|
// Activate! (sort of)
|
|
|
|
debug('Activating theme (method B on API "activate")', themeName);
|
2019-06-19 18:58:07 +03:00
|
|
|
themeService.activate(loadedTheme, checkedTheme);
|
2017-03-13 23:13:17 +03:00
|
|
|
|
2017-03-20 21:02:44 +03:00
|
|
|
// Return JSON result
|
2019-06-19 18:58:07 +03:00
|
|
|
return themeService.toJSON(themeName, checkedTheme);
|
2017-03-13 14:44:44 +03:00
|
|
|
});
|
2017-03-08 13:46:03 +03:00
|
|
|
},
|
|
|
|
|
2018-09-18 16:59:56 +03:00
|
|
|
upload(options) {
|
2016-08-23 15:07:25 +03:00
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
// consistent filename uploads
|
|
|
|
options.originalname = options.originalname.toLowerCase();
|
|
|
|
|
2018-09-18 16:59:56 +03:00
|
|
|
let zip = {
|
2016-10-06 15:27:35 +03:00
|
|
|
path: options.path,
|
|
|
|
name: options.originalname,
|
2019-06-19 18:58:07 +03:00
|
|
|
shortName: themeService.storage.getSanitizedFileName(options.originalname.split('.zip')[0])
|
2017-03-13 14:44:44 +03:00
|
|
|
},
|
|
|
|
checkedTheme;
|
2016-08-23 15:07:25 +03:00
|
|
|
|
|
|
|
// check if zip name is casper.zip
|
|
|
|
if (zip.name === 'casper.zip') {
|
2017-12-12 00:47:46 +03:00
|
|
|
throw new common.errors.ValidationError({message: common.i18n.t('errors.api.themes.overrideCasper')});
|
2016-08-23 15:07:25 +03:00
|
|
|
}
|
|
|
|
|
2017-12-14 00:14:19 +03:00
|
|
|
return localUtils
|
2018-08-12 17:31:08 +03:00
|
|
|
// Permissions
|
2017-03-20 21:02:44 +03:00
|
|
|
.handlePermissions('themes', 'add')(options)
|
|
|
|
// Validation
|
2018-09-18 16:59:56 +03:00
|
|
|
.then(() => {
|
2019-06-19 18:58:07 +03:00
|
|
|
return themeService.validate.checkSafe(zip, true);
|
2016-08-23 15:07:25 +03:00
|
|
|
})
|
2017-03-20 21:02:44 +03:00
|
|
|
// More validation (existence check)
|
2018-09-18 16:59:56 +03:00
|
|
|
.then((_checkedTheme) => {
|
2017-03-13 14:44:44 +03:00
|
|
|
checkedTheme = _checkedTheme;
|
2016-08-23 15:07:25 +03:00
|
|
|
|
2019-06-19 18:58:07 +03:00
|
|
|
return themeService.storage.exists(zip.shortName);
|
2016-08-23 15:07:25 +03:00
|
|
|
})
|
2017-03-20 21:02:44 +03:00
|
|
|
// If the theme existed we need to delete it
|
2018-09-18 16:59:56 +03:00
|
|
|
.then((themeExists) => {
|
2016-08-23 15:07:25 +03:00
|
|
|
// delete existing theme
|
|
|
|
if (themeExists) {
|
2019-06-19 18:58:07 +03:00
|
|
|
return themeService.storage.delete(zip.shortName);
|
2016-08-23 15:07:25 +03:00
|
|
|
}
|
|
|
|
})
|
2018-09-18 16:59:56 +03:00
|
|
|
.then(() => {
|
2016-08-23 15:07:25 +03:00
|
|
|
// store extracted theme
|
2019-06-19 18:58:07 +03:00
|
|
|
return themeService.storage.save({
|
2016-08-23 15:07:25 +03:00
|
|
|
name: zip.shortName,
|
2017-03-13 14:44:44 +03:00
|
|
|
path: checkedTheme.path
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
});
|
2016-08-23 15:07:25 +03:00
|
|
|
})
|
2018-09-18 16:59:56 +03:00
|
|
|
.then(() => {
|
2017-03-13 14:44:44 +03:00
|
|
|
// Loads the theme from the filesystem
|
|
|
|
// Sets the theme on the themeList
|
2019-06-19 18:58:07 +03:00
|
|
|
return themeService.loadOne(zip.shortName);
|
2016-08-23 15:07:25 +03:00
|
|
|
})
|
2018-09-18 16:59:56 +03:00
|
|
|
.then((loadedTheme) => {
|
2017-03-13 23:13:17 +03:00
|
|
|
// If this is the active theme, we are overriding
|
|
|
|
// This is a special case of activation
|
2017-04-24 20:41:00 +03:00
|
|
|
if (zip.shortName === settingsCache.get('active_theme')) {
|
2017-03-13 23:13:17 +03:00
|
|
|
// Activate! (sort of)
|
|
|
|
debug('Activating theme (method C, on API "override")', zip.shortName);
|
2019-06-19 18:58:07 +03:00
|
|
|
themeService.activate(loadedTheme, checkedTheme);
|
2017-03-13 23:13:17 +03:00
|
|
|
}
|
|
|
|
|
2019-02-05 19:38:40 +03:00
|
|
|
common.events.emit('theme.uploaded');
|
|
|
|
|
2017-03-13 14:44:44 +03:00
|
|
|
// @TODO: unify the name across gscan and Ghost!
|
2019-06-19 18:58:07 +03:00
|
|
|
return themeService.toJSON(zip.shortName, checkedTheme);
|
2016-08-23 15:07:25 +03:00
|
|
|
})
|
2018-09-18 16:59:56 +03:00
|
|
|
.finally(() => {
|
2017-03-13 14:44:44 +03:00
|
|
|
// @TODO we should probably do this as part of saving the theme
|
2016-08-23 15:07:25 +03:00
|
|
|
// remove extracted dir from gscan
|
|
|
|
// happens in background
|
2017-03-13 14:44:44 +03:00
|
|
|
if (checkedTheme) {
|
2017-12-13 22:03:07 +03:00
|
|
|
fs.remove(checkedTheme.path)
|
2018-09-18 16:59:56 +03:00
|
|
|
.catch((err) => {
|
2017-12-12 00:47:46 +03:00
|
|
|
common.logging.error(new common.errors.GhostError({err: err}));
|
2016-08-23 15:07:25 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-09-18 16:59:56 +03:00
|
|
|
download(options) {
|
|
|
|
let themeName = options.name,
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
theme = themeList.get(themeName);
|
2016-08-23 15:07:25 +03:00
|
|
|
|
|
|
|
if (!theme) {
|
2018-04-18 16:05:20 +03:00
|
|
|
return Promise.reject(new common.errors.BadRequestError({message: common.i18n.t('errors.api.themes.invalidThemeName')}));
|
2016-08-23 15:07:25 +03:00
|
|
|
}
|
|
|
|
|
2017-12-14 00:14:19 +03:00
|
|
|
return localUtils
|
2017-12-12 00:47:46 +03:00
|
|
|
// Permissions
|
2017-03-20 21:02:44 +03:00
|
|
|
.handlePermissions('themes', 'read')(options)
|
2018-09-18 16:59:56 +03:00
|
|
|
.then(() => {
|
2019-06-19 18:58:07 +03:00
|
|
|
return themeService.storage.serve({
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
name: themeName
|
|
|
|
});
|
2016-08-23 15:07:25 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* remove theme zip
|
|
|
|
* remove theme folder
|
|
|
|
*/
|
2018-09-18 16:59:56 +03:00
|
|
|
destroy(options) {
|
|
|
|
let themeName = options.name,
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
theme;
|
2016-08-23 15:07:25 +03:00
|
|
|
|
2017-12-14 00:14:19 +03:00
|
|
|
return localUtils
|
2017-12-12 00:47:46 +03:00
|
|
|
// Permissions
|
2017-03-20 21:02:44 +03:00
|
|
|
.handlePermissions('themes', 'destroy')(options)
|
|
|
|
// Validation
|
2018-09-18 16:59:56 +03:00
|
|
|
.then(() => {
|
2017-03-20 21:02:44 +03:00
|
|
|
if (themeName === 'casper') {
|
2017-12-12 00:47:46 +03:00
|
|
|
throw new common.errors.ValidationError({message: common.i18n.t('errors.api.themes.destroyCasper')});
|
2016-08-23 15:07:25 +03:00
|
|
|
}
|
|
|
|
|
2017-04-24 20:41:00 +03:00
|
|
|
if (themeName === settingsCache.get('active_theme')) {
|
2017-12-12 00:47:46 +03:00
|
|
|
throw new common.errors.ValidationError({message: common.i18n.t('errors.api.themes.destroyActive')});
|
2017-03-13 14:44:44 +03:00
|
|
|
}
|
|
|
|
|
2017-03-20 21:02:44 +03:00
|
|
|
theme = themeList.get(themeName);
|
2016-08-23 15:07:25 +03:00
|
|
|
|
|
|
|
if (!theme) {
|
2017-12-12 00:47:46 +03:00
|
|
|
throw new common.errors.NotFoundError({message: common.i18n.t('errors.api.themes.themeDoesNotExist')});
|
2016-08-23 15:07:25 +03:00
|
|
|
}
|
|
|
|
|
2017-03-20 21:02:44 +03:00
|
|
|
// Actually do the deletion here
|
2019-06-19 18:58:07 +03:00
|
|
|
return themeService.storage.delete(themeName);
|
2016-08-23 15:07:25 +03:00
|
|
|
})
|
2017-03-20 21:02:44 +03:00
|
|
|
// And some extra stuff to maintain state here
|
2018-09-18 16:59:56 +03:00
|
|
|
.then(() => {
|
2017-03-20 21:02:44 +03:00
|
|
|
themeList.del(themeName);
|
2017-03-08 13:46:03 +03:00
|
|
|
// Delete returns an empty 204 response
|
2016-08-23 15:07:25 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = themes;
|