@@ -1731,6 +1731,45 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
17311731 return this . teamSubscriptionService . findTeamSubscriptionSlotsBy ( user . id , new Date ( ) ) ;
17321732 }
17331733
1734+ async tsAddMembersToOrg ( ctx : TraceContext , teamSubscriptionId : string , organizationId : string ) : Promise < void > {
1735+ const user = this . checkUser ( "tsAddMembersToOrg" ) ;
1736+
1737+ // Add logging to help us identify trouble with this operation very easily
1738+ try {
1739+ log . info ( { userId : user . id } , "tsAddMembersToOrg: Started" , { teamSubscriptionId, organizationId } ) ;
1740+
1741+ // TeamSubscription
1742+ const ts = await this . teamSubscriptionDB . findTeamSubscriptionById ( teamSubscriptionId ) ;
1743+ if ( ! ts || ts . userId !== user . id ) {
1744+ throw new ResponseError ( ErrorCodes . NOT_FOUND , "Cannot find TeamSubscription" ) ;
1745+ }
1746+
1747+ // Organization
1748+ const { team, members } = await this . guardTeamOperation ( organizationId , "update" , "org_write" ) ;
1749+ const teamOwner = members . find ( ( m ) => m . userId === user . id && m . role === "owner" ) ;
1750+ if ( ! teamOwner ) {
1751+ throw new ResponseError ( ErrorCodes . PERMISSION_DENIED , "You are not an owner of this Organization" ) ;
1752+ }
1753+
1754+ // Take all slots, identify the members, and add to the Organization
1755+ const slots = await this . teamSubscriptionDB . findSlotsByTeamSubscriptionId ( teamSubscriptionId ) ;
1756+ const adds = [ ] ;
1757+ for ( const slot of slots ) {
1758+ if ( ! slot . assigneeId ) {
1759+ // Totally ok, it's just not assigned atm.
1760+ continue ;
1761+ }
1762+ adds . push ( this . teamDB . addMemberToTeam ( slot . assigneeId , team . id ) ) ;
1763+ }
1764+ await Promise . all ( adds ) ;
1765+
1766+ log . info ( { userId : user . id } , "tsAddMembersToOrg: DONE" , { teamSubscriptionId, organizationId } ) ;
1767+ } catch ( err ) {
1768+ log . error ( { userId : user . id } , "tsAddMembersToOrg: ERROR" , err , { teamSubscriptionId, organizationId } ) ;
1769+ throw err ;
1770+ }
1771+ }
1772+
17341773 async tsGetUnassignedSlot (
17351774 ctx : TraceContext ,
17361775 teamSubscriptionId : string ,
0 commit comments