1
0
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:
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 }) 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.')