mirror of
https://github.com/sasjs/server.git
synced 2025-12-11 03:34:35 +00:00
chore: throw error when adding permission for admin user
This commit is contained in:
@@ -167,10 +167,14 @@ const createPermission = async ({
|
||||
const userInDB = await User.findOne({ id: principalId })
|
||||
if (!userInDB) throw new Error('User not found.')
|
||||
|
||||
if (userInDB.isAdmin)
|
||||
throw new Error('Can not add permission for admin user.')
|
||||
|
||||
const alreadyExists = await Permission.findOne({
|
||||
uri,
|
||||
user: userInDB._id
|
||||
})
|
||||
|
||||
if (alreadyExists)
|
||||
throw new Error('Permission already exists with provided URI and User.')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user