1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-10 19:34:34 +00:00

chore: throw error when adding permission for admin user

This commit is contained in:
2022-06-24 23:19:19 +05:00
parent 907aa485fd
commit 35439d7d51

View File

@@ -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.')