Skip to content

Commit

Permalink
refactor: throwIfScimUser
Browse files Browse the repository at this point in the history
  • Loading branch information
nunogois committed Apr 11, 2024
1 parent 173133c commit 9b88eb2
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/lib/routes/admin-api/user-admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,23 +730,27 @@ export default class UserAdminController extends Controller {
id,
scimId,
}: Pick<IUser, 'id' | 'scimId'>): Promise<void> {
if (this.isEnterprise && this.flagResolver.isEnabled('scimApi')) {
const { enabled } = await this.settingService.getWithDefault(
'scim',
{ enabled: false },
);
if (!this.isEnterprise) return;
if (!this.flagResolver.isEnabled('scimApi')) return;

if (enabled) {
const isScim =
Boolean(scimId) ||
Boolean((await this.userService.getUser(id)).scimId);
const isScimUser = await this.isScimUser({ id, scimId });
if (!isScimUser) return;

if (isScim) {
throw new ForbiddenError(
'Cannot perform this operation on SCIM users',
);
}
}
}
const { enabled } = await this.settingService.getWithDefault('scim', {
enabled: false,
});
if (!enabled) return;

throw new ForbiddenError('Cannot perform this operation on SCIM users');
}

async isScimUser({
id,
scimId,
}: Pick<IUser, 'id' | 'scimId'>): Promise<boolean> {
return (
Boolean(scimId) ||
Boolean((await this.userService.getUser(id)).scimId)
);
}
}

0 comments on commit 9b88eb2

Please sign in to comment.