0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Merge pull request #3227 from sebgie/issue#3075

Owner has all user permissions
This commit is contained in:
Hannah Wolfe 2014-07-09 19:07:15 +01:00
commit cdca934da9
2 changed files with 14 additions and 4 deletions

View file

@ -6,13 +6,19 @@ var _ = require('lodash'),
var effective = { var effective = {
user: function (id) { user: function (id) {
return User.findOne({id: id}, { include: ['permissions', 'roles.permissions'] }) return User.findOne({id: id}, { include: ['permissions', 'roles', 'roles.permissions'] })
.then(function (foundUser) { .then(function (foundUser) {
var seenPerms = {}, var seenPerms = {},
rolePerms = _.map(foundUser.related('roles').models, function (role) { rolePerms = _.map(foundUser.related('roles').models, function (role) {
return role.related('permissions').models; return role.related('permissions').models;
}), }),
allPerms = []; allPerms = [],
user = foundUser.toJSON();
// TODO: using 'Owner' as return value is a bit hacky.
if (user.roles[0] && user.roles[0].name === 'Owner') {
return 'Owner';
}
rolePerms.push(foundUser.related('permissions').models); rolePerms.push(foundUser.related('permissions').models);

View file

@ -103,11 +103,15 @@ CanThisResult.prototype.buildObjectTypeHandlers = function (obj_types, act_type,
// TODO: String vs Int comparison possibility here? // TODO: String vs Int comparison possibility here?
return modelId === permObjId; return modelId === permObjId;
}; };
// Check user permissions for matching action, object and id. // Check user permissions for matching action, object and id.
if (!_.isEmpty(userPermissions)) { if (!_.isEmpty(userPermissions)) {
// TODO: using 'Owner' is a bit hacky.
if (userPermissions === 'Owner') {
hasUserPermission = true;
} else {
hasUserPermission = _.any(userPermissions, checkPermission); hasUserPermission = _.any(userPermissions, checkPermission);
} }
}
// Check app permissions if they were passed // Check app permissions if they were passed
hasAppPermission = true; hasAppPermission = true;