@@ -14,6 +14,7 @@ import {
1414 WorkspaceTimeoutDuration ,
1515 OrgMemberRole ,
1616 User ,
17+ MaintenanceNotification ,
1718} from "@gitpod/gitpod-protocol" ;
1819import { IAnalyticsWriter } from "@gitpod/gitpod-protocol/lib/analytics" ;
1920import { 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