diff --git a/src/lib/routes/admin-api/user-admin.ts b/src/lib/routes/admin-api/user-admin.ts index 10a834f0829f..909e87f8fbc6 100644 --- a/src/lib/routes/admin-api/user-admin.ts +++ b/src/lib/routes/admin-api/user-admin.ts @@ -730,23 +730,27 @@ export default class UserAdminController extends Controller { id, scimId, }: Pick): Promise { - 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): Promise { + return ( + Boolean(scimId) || + Boolean((await this.userService.getUser(id)).scimId) + ); } }