In this PR - updateWorkspaceMemberRole api was changed to stop allowing null as a valid value for roleId. it is not possible anymore to just unassign a role from a user. instead it is only possible to assign a different role to a user, which will unassign them from their previous role. For this reason in the FE the bins icons next to the workspaceMember on a role page were removed - updateWorkspaceMemberRole will throw if a user attempts to update their own role - tests tests tests!
26 lines
834 B
TypeScript
26 lines
834 B
TypeScript
import {
|
|
ForbiddenError,
|
|
InternalServerError,
|
|
NotFoundError,
|
|
} from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
|
|
import {
|
|
PermissionsException,
|
|
PermissionsExceptionCode,
|
|
} from 'src/engine/metadata-modules/permissions/permissions.exception';
|
|
|
|
export const permissionGraphqlApiExceptionHandler = (
|
|
error: PermissionsException,
|
|
) => {
|
|
switch (error.code) {
|
|
case PermissionsExceptionCode.PERMISSION_DENIED:
|
|
case PermissionsExceptionCode.CANNOT_UNASSIGN_LAST_ADMIN:
|
|
case PermissionsExceptionCode.CANNOT_UPDATE_SELF_ROLE:
|
|
throw new ForbiddenError(error.message);
|
|
case PermissionsExceptionCode.ROLE_NOT_FOUND:
|
|
case PermissionsExceptionCode.USER_WORKSPACE_NOT_FOUND:
|
|
throw new NotFoundError(error.message);
|
|
default:
|
|
throw new InternalServerError(error.message);
|
|
}
|
|
};
|