Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function defineAbilitiesFor(user) {
const { rules, can } = AbilityBuilder.extract()
can('create',['users'])
can('read', ['posts', 'comments'])
if (user) {
can('manage', ['posts', 'comments'], { author: user._id })
can(['read', 'update'], 'users', { _id: user._id })
}
if (process.env.NODE_ENV !== 'production') {
can('create', ['users'])
}
return new Ability(rules, { subjectName })
}
function defineAbilitiesFor(user) {
const { rules, can } = AbilityBuilder.extract();
can('read', ['Post', 'Comment']);
can('create', 'User');
if (user) {
can(['create', 'delete', 'update'], ['Post', 'Comment'], { author: user._id });
can(['read', 'update'], 'User', { _id: user.id });
}
return new Ability(rules);
}
function defineRulesFor(user){
var ref$, rules, can, i$, len$, module, actions, j$, len1$, action;
ref$ = AbilityBuilder.extract(), rules = ref$.rules, can = ref$.can;
if (user.permissions && typeof user.permissions === 'object') {
for (i$ = 0, len$ = (ref$ = Object.keys(user.permissions)).length; i$ < len$; ++i$) {
module = ref$[i$];
actions = eval('(' + user.permissions[module] + ')');
for (j$ = 0, len1$ = actions.length; j$ < len1$; ++j$) {
action = actions[j$];
can(action, module);
}
}
}
return rules;
};
export function defineAbilitiesFor(permissions: UserPermissions) {
const { rules, can: allow, cannot: forbid } = AbilityBuilder.extract();
if (permissions.isAuthorized) {
allow(Action.Create, [Subject.Token]);
}
if (permissions.readPermission || permissions.writePermission || permissions.managementPermission) {
allow(Action.Read, [Subject.Product, Subject.Flag, Subject.Toggle]);
}
if (permissions.writePermission || permissions.managementPermission) {
allow(Action.Create, [Subject.Product, Subject.Flag, Subject.Toggle]);
allow(Action.Update, [Subject.Product, Subject.Flag, Subject.Toggle]);
allow(Action.Delete, [Subject.Product, Subject.Flag, Subject.Toggle]);
}
if (permissions.managementPermission) {