-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DELETE endpoint for UserChangemakerPermission
This endpoint makes it possible for a user with appropriate permissions to remove a changemaker permission for a given user. Issue #1250 Support associations between users and organizational entities
- Loading branch information
Showing
9 changed files
with
355 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from './createOrUpdateUserChangemakerPermission'; | ||
export * from './loadUserChangemakerPermission'; | ||
export * from './removeUserChangemakerPermission'; |
37 changes: 37 additions & 0 deletions
37
src/database/operations/userChangemakerPermissions/loadUserChangemakerPermission.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { db } from '../../db'; | ||
import { NotFoundError } from '../../../errors'; | ||
import { | ||
keycloakUserIdToString, | ||
type Id, | ||
type JsonResultSet, | ||
type KeycloakUserId, | ||
type Permission, | ||
type UserChangemakerPermission, | ||
} from '../../../types'; | ||
|
||
export const loadUserChangemakerPermission = async ( | ||
userKeycloakUserId: KeycloakUserId, | ||
changemakerId: Id, | ||
permission: Permission, | ||
): Promise<UserChangemakerPermission> => { | ||
const result = await db.sql<JsonResultSet<UserChangemakerPermission>>( | ||
'userChangemakerPermissions.selectByPrimaryKey', | ||
{ | ||
userKeycloakUserId, | ||
changemakerId, | ||
permission, | ||
}, | ||
); | ||
const object = result.rows[0]?.object; | ||
if (object === undefined) { | ||
throw new NotFoundError(`Entity not found`, { | ||
entityType: 'UserchangemakerPermission', | ||
entityPrimaryKey: { | ||
userKeycloakUserId: keycloakUserIdToString(userKeycloakUserId), | ||
changemakerId, | ||
permission, | ||
}, | ||
}); | ||
} | ||
return object; | ||
}; |
32 changes: 32 additions & 0 deletions
32
src/database/operations/userChangemakerPermissions/removeUserChangemakerPermission.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { NotFoundError } from '../../../errors'; | ||
import { keycloakUserIdToString } from '../../../types'; | ||
import { db } from '../../db'; | ||
import type { KeycloakUserId, Permission } from '../../../types'; | ||
|
||
const removeUserChangemakerPermission = async ( | ||
userKeycloakUserId: KeycloakUserId, | ||
changemakerId: string, | ||
permission: Permission, | ||
): Promise<void> => { | ||
const result = await db.sql('userChangemakerPermissions.deleteOne', { | ||
userKeycloakUserId, | ||
permission, | ||
changemakerId, | ||
}); | ||
|
||
if (result.row_count === 0) { | ||
throw new NotFoundError( | ||
'The item did not exist and could not be deleted.', | ||
{ | ||
entityType: 'UserChangemakerPermission', | ||
entityPrimaryKey: { | ||
userKeycloakUserId: keycloakUserIdToString(userKeycloakUserId), | ||
permission, | ||
changemakerId, | ||
}, | ||
}, | ||
); | ||
} | ||
}; | ||
|
||
export { removeUserChangemakerPermission }; |
4 changes: 4 additions & 0 deletions
4
src/database/queries/userChangemakerPermissions/deleteOne.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DELETE FROM user_changemaker_permissions | ||
WHERE user_keycloak_user_id = :userKeycloakUserId | ||
AND permission = :permission::permission_t | ||
AND changemaker_id = :changemakerId; |
5 changes: 5 additions & 0 deletions
5
src/database/queries/userChangemakerPermissions/selectByPrimaryKey.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SELECT user_changemaker_permission_to_json(user_changemaker_permissions.*) AS "object" | ||
FROM user_changemaker_permissions | ||
WHERE user_keycloak_user_id = :userKeycloakUserId | ||
AND changemaker_id = :changemakerId | ||
AND permission = :permission |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.