|
@@ -16,12 +16,19 @@ module.exports = async (dbName='shop-roles') => {
|
|
|
|
|
|
async save(...params){
|
|
|
console.log(this)
|
|
|
+ let otherUserWithThisLogin = this.login && await SlicedSavable.m.User.findOne({login: this.login})
|
|
|
if (this._id){
|
|
|
+ if (otherUserWithThisLogin && otherUserWithThisLogin._id.toString() !== this._id.toString()){
|
|
|
+ throw new ReferenceError(`User ${this.login} already exists`)
|
|
|
+ }
|
|
|
if (!acl.includes('admin') && this.originalACL.toString() !== this.acl.toString())
|
|
|
throw new ReferenceError(`Not enough permissions for changing acl on ${this.login}`)
|
|
|
else return await super.save(...params)
|
|
|
}
|
|
|
else {
|
|
|
+ if (otherUserWithThisLogin){
|
|
|
+ throw new ReferenceError(`User ${this.login} already exists`)
|
|
|
+ }
|
|
|
await super.save(...params)
|
|
|
this.___owner = this._id.toString()
|
|
|
this.acl = [this.___owner, "user"]
|
|
@@ -113,10 +120,6 @@ module.exports = async (dbName='shop-roles') => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- static get guestRelations(){
|
|
|
- return ["categories", "orderGoods"]
|
|
|
- }
|
|
|
-
|
|
|
static get defaultPermissions(){
|
|
|
return {
|
|
|
create: ['admin'],
|