Skip to content

Commit e6da517

Browse files
committed
[server] 4.4.1: impl APIs
1 parent f3ae761 commit e6da517

File tree

2 files changed

+110
-1
lines changed

2 files changed

+110
-1
lines changed

components/server/src/api/organization-service-api.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import {
2222
GetOrganizationResponse,
2323
GetOrganizationSettingsRequest,
2424
GetOrganizationSettingsResponse,
25+
GetScheduledMaintenanceNotificationRequest,
26+
GetScheduledMaintenanceNotificationResponse,
2527
JoinOrganizationRequest,
2628
JoinOrganizationResponse,
2729
ListOrganizationMembersRequest,
@@ -35,6 +37,8 @@ import {
3537
ResetOrganizationInvitationResponse,
3638
SetOrganizationMaintenanceModeRequest,
3739
SetOrganizationMaintenanceModeResponse,
40+
SetScheduledMaintenanceNotificationRequest,
41+
SetScheduledMaintenanceNotificationResponse,
3842
UpdateOrganizationMemberRequest,
3943
UpdateOrganizationMemberResponse,
4044
UpdateOrganizationRequest,
@@ -345,4 +349,43 @@ export class OrganizationServiceAPI implements ServiceImpl<typeof OrganizationSe
345349
enabled,
346350
});
347351
}
352+
353+
async getScheduledMaintenanceNotification(
354+
req: GetScheduledMaintenanceNotificationRequest,
355+
_: HandlerContext,
356+
): Promise<GetScheduledMaintenanceNotificationResponse> {
357+
if (!uuidValidate(req.organizationId)) {
358+
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "organizationId is required");
359+
}
360+
361+
const settings = await this.orgService.getScheduledMaintenanceNotificationSettings(
362+
ctxUserId(),
363+
req.organizationId,
364+
);
365+
return new GetScheduledMaintenanceNotificationResponse({
366+
isEnabled: settings.enabled,
367+
message: settings.message,
368+
});
369+
}
370+
371+
async setScheduledMaintenanceNotification(
372+
req: SetScheduledMaintenanceNotificationRequest,
373+
_: HandlerContext,
374+
): Promise<SetScheduledMaintenanceNotificationResponse> {
375+
if (!uuidValidate(req.organizationId)) {
376+
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "organizationId is required");
377+
}
378+
379+
const settings = await this.orgService.setScheduledMaintenanceNotificationSettings(
380+
ctxUserId(),
381+
req.organizationId,
382+
req.isEnabled,
383+
req.customMessage,
384+
);
385+
386+
return new SetScheduledMaintenanceNotificationResponse({
387+
isEnabled: settings.enabled,
388+
message: settings.message,
389+
});
390+
}
348391
}

components/server/src/orgs/organization-service.ts

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
WorkspaceTimeoutDuration,
1515
OrgMemberRole,
1616
User,
17+
MaintenanceNotification,
1718
} from "@gitpod/gitpod-protocol";
1819
import { IAnalyticsWriter } from "@gitpod/gitpod-protocol/lib/analytics";
1920
import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
@@ -145,7 +146,7 @@ export class OrganizationService {
145146
async updateOrganization(
146147
userId: string,
147148
orgId: string,
148-
changes: Partial<Pick<Organization, "name" | "maintenanceMode">>,
149+
changes: Partial<Pick<Organization, "name" | "maintenanceMode" | "maintenanceNotification">>,
149150
): Promise<Organization> {
150151
await this.auth.checkPermissionOnOrganization(userId, "write_info", orgId);
151152
return this.teamDB.updateTeam(orgId, changes);
@@ -816,4 +817,69 @@ export class OrganizationService {
816817

817818
return enabled;
818819
}
820+
821+
/**
822+
* Gets the scheduled maintenance notification settings for an organization.
823+
*
824+
* @param userId The ID of the user making the request
825+
* @param orgId The ID of the organization
826+
* @returns The notification settings (enabled status and custom message)
827+
*/
828+
public async getScheduledMaintenanceNotificationSettings(
829+
userId: string,
830+
orgId: string,
831+
): Promise<MaintenanceNotification> {
832+
// Using maintenance permission as it's available to owners and installation admins
833+
await this.auth.checkPermissionOnOrganization(userId, "maintenance", orgId);
834+
835+
const team = await this.teamDB.findTeamById(orgId);
836+
if (!team) {
837+
throw new ApplicationError(ErrorCodes.NOT_FOUND, `Organization ${orgId} not found`);
838+
}
839+
840+
// If the maintenanceNotification field doesn't exist or is invalid, return default values
841+
if (!team.maintenanceNotification) {
842+
return { enabled: false, message: undefined };
843+
}
844+
845+
return {
846+
enabled: team.maintenanceNotification.enabled,
847+
message: team.maintenanceNotification.message,
848+
};
849+
}
850+
851+
/**
852+
* Sets the scheduled maintenance notification settings for an organization.
853+
*
854+
* @param userId The ID of the user making the request
855+
* @param orgId The ID of the organization
856+
* @param isEnabled Whether the notification should be enabled
857+
* @param customMessage Optional custom message for the notification
858+
* @returns The updated notification settings
859+
*/
860+
public async setScheduledMaintenanceNotificationSettings(
861+
userId: string,
862+
orgId: string,
863+
isEnabled: boolean,
864+
customMessage?: string,
865+
): Promise<MaintenanceNotification> {
866+
// Using maintenance permission as it's available to owners and installation admins
867+
await this.auth.checkPermissionOnOrganization(userId, "maintenance", orgId);
868+
869+
const team = await this.teamDB.findTeamById(orgId);
870+
if (!team) {
871+
throw new ApplicationError(ErrorCodes.NOT_FOUND, `Organization ${orgId} not found`);
872+
}
873+
874+
// Prepare the new notification config
875+
const newNotificationConfig = {
876+
enabled: isEnabled,
877+
message: customMessage?.trim() || undefined,
878+
};
879+
880+
// Update the team with the new notification config
881+
await this.teamDB.updateTeam(orgId, { maintenanceNotification: newNotificationConfig });
882+
883+
return newNotificationConfig;
884+
}
819885
}

0 commit comments

Comments
 (0)