@@ -45,7 +45,6 @@ import { PaginationResponse } from "@gitpod/public-api/lib/gitpod/v1/pagination_
4545import { validate as uuidValidate } from "uuid" ;
4646import { ctxUserId } from "../util/request-context" ;
4747import { ApplicationError , ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error" ;
48- import { EntitlementService } from "../billing/entitlement-service" ;
4948
5049@injectable ( )
5150export class OrganizationServiceAPI implements ServiceImpl < typeof OrganizationServiceInterface > {
@@ -54,8 +53,6 @@ export class OrganizationServiceAPI implements ServiceImpl<typeof OrganizationSe
5453 private readonly orgService : OrganizationService ,
5554 @inject ( PublicAPIConverter )
5655 private readonly apiConverter : PublicAPIConverter ,
57- @inject ( EntitlementService )
58- private readonly entitlementService : EntitlementService ,
5956 ) { }
6057
6158 async listOrganizationWorkspaceClasses (
@@ -266,16 +263,14 @@ export class OrganizationServiceAPI implements ServiceImpl<typeof OrganizationSe
266263 "updateRestrictedEditorNames is required to be true to update restrictedEditorNames" ,
267264 ) ;
268265 }
269- if ( typeof req . workspaceSharingDisabled === "boolean" ) {
270- update . workspaceSharingDisabled = req . workspaceSharingDisabled ;
271- }
272- if ( typeof req . defaultWorkspaceImage === "string" ) {
273- update . defaultWorkspaceImage = req . defaultWorkspaceImage ;
274- }
266+
267+ update . workspaceSharingDisabled = req . workspaceSharingDisabled ;
268+ update . defaultWorkspaceImage = req . defaultWorkspaceImage ;
275269 update . allowedWorkspaceClasses = req . allowedWorkspaceClasses ;
276- if ( req . updatePinnedEditorVersions ) {
277- update . pinnedEditorVersions = req . pinnedEditorVersions ;
278- }
270+ update . pinnedEditorVersions = req . pinnedEditorVersions ;
271+ update . annotateGitCommits = req . annotateGitCommits ;
272+ update . maxParallelRunningWorkspaces = req . maxParallelRunningWorkspaces ;
273+
279274 if ( typeof req . defaultRole === "string" && req . defaultRole !== "" ) {
280275 switch ( req . defaultRole ) {
281276 case "owner" :
@@ -288,13 +283,8 @@ export class OrganizationServiceAPI implements ServiceImpl<typeof OrganizationSe
288283 }
289284 }
290285
291- if ( typeof req . timeoutSettings ?. denyUserTimeouts === "boolean" ) {
292- update . timeoutSettings = update . timeoutSettings || { } ;
293- update . timeoutSettings . denyUserTimeouts = req . timeoutSettings . denyUserTimeouts ;
294- }
295- if ( typeof req . timeoutSettings ?. inactivity === "object" ) {
296- update . timeoutSettings = update . timeoutSettings || { } ;
297- update . timeoutSettings . inactivity = this . apiConverter . toDurationString ( req . timeoutSettings . inactivity ) ;
286+ if ( req . timeoutSettings ) {
287+ update . timeoutSettings = this . apiConverter . fromTimeoutSettings ( req . timeoutSettings ) ;
298288 }
299289
300290 if ( req . roleRestrictions . length > 0 && ! req . updateRoleRestrictions ) {
@@ -304,35 +294,7 @@ export class OrganizationServiceAPI implements ServiceImpl<typeof OrganizationSe
304294 ) ;
305295 }
306296 if ( req . updateRoleRestrictions ) {
307- update . roleRestrictions = update . roleRestrictions ?? { } ;
308- for ( const roleRestriction of req . roleRestrictions ) {
309- const role = this . apiConverter . fromOrgMemberRole ( roleRestriction . role ) ;
310- const permissions = roleRestriction . permissions . map ( ( p ) =>
311- this . apiConverter . fromOrganizationPermission ( p ) ,
312- ) ;
313- update . roleRestrictions [ role ] = permissions ;
314- }
315- }
316-
317- if ( typeof req . maxParallelRunningWorkspaces === "number" ) {
318- if ( req . maxParallelRunningWorkspaces < 0 ) {
319- throw new ApplicationError ( ErrorCodes . BAD_REQUEST , "maxParallelRunningWorkspaces must be >= 0" ) ;
320- }
321- const maxAllowance = await this . entitlementService . getMaxParallelWorkspaces (
322- ctxUserId ( ) ,
323- req . organizationId ,
324- ) ;
325- if ( maxAllowance && req . maxParallelRunningWorkspaces > maxAllowance ) {
326- throw new ApplicationError (
327- ErrorCodes . BAD_REQUEST ,
328- `maxParallelRunningWorkspaces must be <= ${ maxAllowance } ` ,
329- ) ;
330- }
331- if ( ! Number . isInteger ( req . maxParallelRunningWorkspaces ) ) {
332- throw new ApplicationError ( ErrorCodes . BAD_REQUEST , "maxParallelRunningWorkspaces must be an integer" ) ;
333- }
334-
335- update . maxParallelRunningWorkspaces = req . maxParallelRunningWorkspaces ;
297+ update . roleRestrictions = this . apiConverter . fromRoleRestrictions ( req . roleRestrictions ) ;
336298 }
337299
338300 if ( req . onboardingSettings ) {
@@ -349,10 +311,6 @@ export class OrganizationServiceAPI implements ServiceImpl<typeof OrganizationSe
349311 }
350312 }
351313
352- if ( req . annotateGitCommits !== undefined ) {
353- update . annotateGitCommits = req . annotateGitCommits ;
354- }
355-
356314 if ( Object . keys ( update ) . length === 0 ) {
357315 throw new ApplicationError ( ErrorCodes . BAD_REQUEST , "nothing to update" ) ;
358316 }
0 commit comments