Fixed unknown roles
This commit is contained in:
@@ -20,12 +20,12 @@ class PermissionManager extends role_acl_1.AccessControl {
|
||||
getRouter(resource, opts) {
|
||||
return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
||||
let query = this.can(req);
|
||||
if (opts.context)
|
||||
query = query.context(opts.context);
|
||||
if (opts.action)
|
||||
query = query.execute(opts.action);
|
||||
if (opts.skipConditions)
|
||||
query = query.skipConditions(opts.skipConditions);
|
||||
if (opts === null || opts === void 0 ? void 0 : opts.context)
|
||||
query = query.context(opts === null || opts === void 0 ? void 0 : opts.context);
|
||||
if (opts === null || opts === void 0 ? void 0 : opts.action)
|
||||
query = query.execute(opts === null || opts === void 0 ? void 0 : opts.action);
|
||||
if (opts === null || opts === void 0 ? void 0 : opts.skipConditions)
|
||||
query = query.skipConditions(opts === null || opts === void 0 ? void 0 : opts.skipConditions);
|
||||
const permission = yield query.on(resource);
|
||||
if (permission.granted) {
|
||||
req.permissionDetails = permission;
|
||||
@@ -41,7 +41,7 @@ class PermQuery extends Query_1.Query {
|
||||
constructor(grants, roleOrRequest) {
|
||||
function isRequest(obj) {
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
return typeof obj === 'object' && obj && obj.hasOwnProperty('path') || false;
|
||||
return typeof obj === 'object' && obj && obj.hasOwnProperty('res') || false;
|
||||
}
|
||||
if (isRequest(roleOrRequest)) {
|
||||
super(grants, []);
|
||||
@@ -57,9 +57,13 @@ class PermQuery extends Query_1.Query {
|
||||
});
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
console.log("heee");
|
||||
if (this.resolveRequest) {
|
||||
const userInfo = yield this.resolveRequest.getUserInfo();
|
||||
this.role((_a = userInfo === null || userInfo === void 0 ? void 0 : userInfo.groups) !== null && _a !== void 0 ? _a : []);
|
||||
console.log("huuu", userInfo, typeof userInfo);
|
||||
const availableRoles = Object.keys(this._grants);
|
||||
const roles = ((_a = userInfo === null || userInfo === void 0 ? void 0 : userInfo.groups) !== null && _a !== void 0 ? _a : []).filter(x => availableRoles.includes(x));
|
||||
this.role(roles);
|
||||
}
|
||||
if (typeof this._.role === 'object' && this._.role.includes('noaccess') ||
|
||||
typeof this._.role === 'string' && this._.role === 'noaccess') {
|
||||
|
||||
Reference in New Issue
Block a user