mirror of
https://github.com/sasjs/server.git
synced 2026-01-08 07:00:04 +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 })
|
const userInDB = await User.findOne({ id: principalId })
|
||||||
if (!userInDB) throw new Error('User not found.')
|
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({
|
const alreadyExists = await Permission.findOne({
|
||||||
uri,
|
uri,
|
||||||
user: userInDB._id
|
user: userInDB._id
|
||||||
})
|
})
|
||||||
|
|
||||||
if (alreadyExists)
|
if (alreadyExists)
|
||||||
throw new Error('Permission already exists with provided URI and User.')
|
throw new Error('Permission already exists with provided URI and User.')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user