Skip to content

Commit

Permalink
add modify role and permission method
Browse files Browse the repository at this point in the history
  • Loading branch information
lidianhao123 committed Nov 13, 2017
1 parent 8512ed8 commit 4b9c978
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions lib/mongoose/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ module.exports = exports = class mongooseStorage {
});
}

addPermission(_id, permissionIds) {
return this.Role.updateOne({ _id }, { $addToSet: { grants: { $each: permissionIds } } });
}

newPermission({ name, alias }) {
return this.Permission.findOne({ name })
.then(oldPermission => {
Expand All @@ -43,6 +39,33 @@ module.exports = exports = class mongooseStorage {
});
}

modifyRoleAlias(_id, alias) {
return this.Role.updateOne({ _id }, { $set: { alias } });
}

modifyPermissionAlias(_id, alias) {
return this.Permission.updateOne({ _id }, { $set: { alias } });
}

removeRole(_id) {
return this.Role.remove({ _id });
}

removePermission(_id) {
return Promise.all([
this.Permission.remove({ _id }),
this.Role.update({}, { $pull: { grants: _id } }),
]);
}

addPermission(_id, permissionIds) {
return this.Role.updateOne({ _id }, { $addToSet: { grants: { $each: permissionIds } } });
}

removePermissions(_id, permissionIds) {
return this.Role.updateOne({ _id }, { $pull: { grants: { $in: permissionIds } } });
}

insertManyPermission(permissions) {
return this.Permission.insertMany(permissions)
.then(result => {
Expand Down

0 comments on commit 4b9c978

Please sign in to comment.