mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-17 21:41:49 +03:00
20fec74c73
closes #5492 - remove core/server/require-tree.js and split it into modules - add read-directory module to recursively read directories - add validate-themes module to scan themes and return errors/warnings - add parse-package-json module to parse json and validate requirements - rewrite core/server/models/index.js to manually require models
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
|
|
var fs = require('fs'),
|
|
Promise = require('bluebird'),
|
|
path = require('path'),
|
|
parsePackageJson = require('../utils/parse-package-json').parsePackageJson;
|
|
|
|
function AppPermissions(appPath) {
|
|
this.appPath = appPath;
|
|
this.packagePath = path.join(this.appPath, 'package.json');
|
|
}
|
|
|
|
AppPermissions.prototype.read = function () {
|
|
var self = this;
|
|
|
|
return this.checkPackageContentsExists().then(function (exists) {
|
|
if (!exists) {
|
|
// If no package.json, return default permissions
|
|
return Promise.resolve(AppPermissions.DefaultPermissions);
|
|
}
|
|
|
|
// Read and parse the package.json
|
|
return self.getPackageContents().then(function (parsed) {
|
|
// If no permissions in the package.json then return the default permissions.
|
|
if (!(parsed.ghost && parsed.ghost.permissions)) {
|
|
return Promise.resolve(AppPermissions.DefaultPermissions);
|
|
}
|
|
|
|
// TODO: Validation on permissions object?
|
|
|
|
return Promise.resolve(parsed.ghost.permissions);
|
|
});
|
|
});
|
|
};
|
|
|
|
AppPermissions.prototype.checkPackageContentsExists = function () {
|
|
var self = this;
|
|
|
|
// Mostly just broken out for stubbing in unit tests
|
|
return new Promise(function (resolve) {
|
|
fs.stat(self.packagePath, function (err) {
|
|
var exists = !err;
|
|
resolve(exists);
|
|
});
|
|
});
|
|
};
|
|
|
|
// Get the contents of the package.json in the appPath root
|
|
AppPermissions.prototype.getPackageContents = function () {
|
|
return parsePackageJson(this.packagePath);
|
|
};
|
|
|
|
// Default permissions for an App.
|
|
AppPermissions.DefaultPermissions = {
|
|
posts: ['browse', 'read']
|
|
};
|
|
|
|
module.exports = AppPermissions;
|