@@ -39,6 +39,8 @@ import {
39
39
import { PublicAPIConverter } from "@gitpod/gitpod-protocol/lib/public-api-converter" ;
40
40
import { OrganizationService } from "../orgs/organization-service" ;
41
41
import { PaginationResponse } from "@gitpod/public-api/lib/gitpod/v1/pagination_pb" ;
42
+ import { ctx , userId } from "../util/request-context" ;
43
+ import { ApplicationError , ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error" ;
42
44
43
45
@injectable ( )
44
46
export class OrganizationServiceAPI implements ServiceImpl < typeof OrganizationServiceInterface > {
@@ -49,18 +51,20 @@ export class OrganizationServiceAPI implements ServiceImpl<typeof OrganizationSe
49
51
private readonly apiConverter : PublicAPIConverter ,
50
52
) { }
51
53
52
- async createOrganization (
53
- req : CreateOrganizationRequest ,
54
- context : HandlerContext ,
55
- ) : Promise < CreateOrganizationResponse > {
56
- const org = await this . orgService . createOrganization ( context . user . id , req . name ) ;
54
+ async createOrganization ( req : CreateOrganizationRequest , _ : HandlerContext ) : Promise < CreateOrganizationResponse > {
55
+ // TODO(gpl) This mimicks the current behavior of adding the subjectId as owner
56
+ const ownerId = ctx ( ) . subjectId ?. userId ( ) ;
57
+ if ( ! ownerId ) {
58
+ throw new ApplicationError ( ErrorCodes . BAD_REQUEST , "No userId available" ) ;
59
+ }
60
+ const org = await this . orgService . createOrganization ( ownerId , req . name ) ;
57
61
const response = new CreateOrganizationResponse ( ) ;
58
62
response . organization = this . apiConverter . toOrganization ( org ) ;
59
63
return response ;
60
64
}
61
65
62
- async getOrganization ( req : GetOrganizationRequest , context : HandlerContext ) : Promise < GetOrganizationResponse > {
63
- const org = await this . orgService . getOrganization ( context . user . id , req . organizationId ) ;
66
+ async getOrganization ( req : GetOrganizationRequest , _ : HandlerContext ) : Promise < GetOrganizationResponse > {
67
+ const org = await this . orgService . getOrganization ( userId ( ) , req . organizationId ) ;
64
68
const response = new GetOrganizationResponse ( ) ;
65
69
response . organization = this . apiConverter . toOrganization ( org ) ;
66
70
return response ;
@@ -70,7 +74,7 @@ export class OrganizationServiceAPI implements ServiceImpl<typeof OrganizationSe
70
74
req : UpdateOrganizationRequest ,
71
75
context : HandlerContext ,
72
76
) : Promise < UpdateOrganizationResponse > {
73
- const org = await this . orgService . updateOrganization ( context . user . id , req . organizationId , {
77
+ const org = await this . orgService . updateOrganization ( userId ( ) , req . organizationId , {
74
78
name : req . name ,
75
79
} ) ;
76
80
return new UpdateOrganizationResponse ( {
@@ -83,7 +87,7 @@ export class OrganizationServiceAPI implements ServiceImpl<typeof OrganizationSe
83
87
context : HandlerContext ,
84
88
) : Promise < ListOrganizationsResponse > {
85
89
const orgs = await this . orgService . listOrganizations (
86
- context . user . id ,
90
+ userId ( ) ,
87
91
{
88
92
limit : req . pagination ?. pageSize || 100 ,
89
93
offset : ( req . pagination ?. page || 0 ) * ( req . pagination ?. pageSize || 0 ) ,
@@ -97,46 +101,43 @@ export class OrganizationServiceAPI implements ServiceImpl<typeof OrganizationSe
97
101
return response ;
98
102
}
99
103
100
- async deleteOrganization (
101
- req : DeleteOrganizationRequest ,
102
- context : HandlerContext ,
103
- ) : Promise < DeleteOrganizationResponse > {
104
- await this . orgService . deleteOrganization ( context . user . id , req . organizationId ) ;
104
+ async deleteOrganization ( req : DeleteOrganizationRequest , _ : HandlerContext ) : Promise < DeleteOrganizationResponse > {
105
+ await this . orgService . deleteOrganization ( userId ( ) , req . organizationId ) ;
105
106
return new DeleteOrganizationResponse ( ) ;
106
107
}
107
108
108
109
async getOrganizationInvitation (
109
110
req : GetOrganizationInvitationRequest ,
110
- context : HandlerContext ,
111
+ _ : HandlerContext ,
111
112
) : Promise < GetOrganizationInvitationResponse > {
112
- const invitation = await this . orgService . getOrCreateInvite ( context . user . id , req . organizationId ) ;
113
+ const invitation = await this . orgService . getOrCreateInvite ( userId ( ) , req . organizationId ) ;
113
114
const response = new GetOrganizationInvitationResponse ( ) ;
114
115
response . invitationId = invitation . id ;
115
116
return response ;
116
117
}
117
118
118
- async joinOrganization ( req : JoinOrganizationRequest , context : HandlerContext ) : Promise < JoinOrganizationResponse > {
119
- const orgId = await this . orgService . joinOrganization ( context . user . id , req . invitationId ) ;
119
+ async joinOrganization ( req : JoinOrganizationRequest , _ : HandlerContext ) : Promise < JoinOrganizationResponse > {
120
+ const orgId = await this . orgService . joinOrganization ( userId ( ) , req . invitationId ) ;
120
121
const result = new JoinOrganizationResponse ( ) ;
121
122
result . organizationId = orgId ;
122
123
return result ;
123
124
}
124
125
125
126
async resetOrganizationInvitation (
126
127
req : ResetOrganizationInvitationRequest ,
127
- context : HandlerContext ,
128
+ _ : HandlerContext ,
128
129
) : Promise < ResetOrganizationInvitationResponse > {
129
- const inviteId = await this . orgService . resetInvite ( context . user . id , req . organizationId ) ;
130
+ const inviteId = await this . orgService . resetInvite ( userId ( ) , req . organizationId ) ;
130
131
const result = new ResetOrganizationInvitationResponse ( ) ;
131
132
result . invitationId = inviteId . id ;
132
133
return result ;
133
134
}
134
135
135
136
async listOrganizationMembers (
136
137
req : ListOrganizationMembersRequest ,
137
- context : HandlerContext ,
138
+ _ : HandlerContext ,
138
139
) : Promise < ListOrganizationMembersResponse > {
139
- const members = await this . orgService . listMembers ( context . user . id , req . organizationId ) ;
140
+ const members = await this . orgService . listMembers ( userId ( ) , req . organizationId ) ;
140
141
//TODO pagination
141
142
const response = new ListOrganizationMembersResponse ( ) ;
142
143
response . members = members . map ( ( member ) => this . apiConverter . toOrganizationMember ( member ) ) ;
@@ -147,16 +148,16 @@ export class OrganizationServiceAPI implements ServiceImpl<typeof OrganizationSe
147
148
148
149
async updateOrganizationMember (
149
150
req : UpdateOrganizationMemberRequest ,
150
- context : HandlerContext ,
151
+ _ : HandlerContext ,
151
152
) : Promise < UpdateOrganizationMemberResponse > {
152
153
await this . orgService . addOrUpdateMember (
153
- context . user . id ,
154
+ userId ( ) ,
154
155
req . organizationId ,
155
156
req . userId ,
156
157
this . apiConverter . fromOrgMemberRole ( req . role ) ,
157
158
) ;
158
159
const member = await this . orgService
159
- . listMembers ( context . user . id , req . organizationId )
160
+ . listMembers ( userId ( ) , req . organizationId )
160
161
. then ( ( members ) => members . find ( ( member ) => member . userId === req . userId ) ) ;
161
162
return new UpdateOrganizationMemberResponse ( {
162
163
member : member && this . apiConverter . toOrganizationMember ( member ) ,
@@ -165,27 +166,27 @@ export class OrganizationServiceAPI implements ServiceImpl<typeof OrganizationSe
165
166
166
167
async deleteOrganizationMember (
167
168
req : DeleteOrganizationMemberRequest ,
168
- context : HandlerContext ,
169
+ _ : HandlerContext ,
169
170
) : Promise < DeleteOrganizationMemberResponse > {
170
- await this . orgService . removeOrganizationMember ( context . user . id , req . organizationId , req . userId ) ;
171
+ await this . orgService . removeOrganizationMember ( userId ( ) , req . organizationId , req . userId ) ;
171
172
return new DeleteOrganizationMemberResponse ( ) ;
172
173
}
173
174
174
175
async getOrganizationSettings (
175
176
req : GetOrganizationSettingsRequest ,
176
- context : HandlerContext ,
177
+ _ : HandlerContext ,
177
178
) : Promise < GetOrganizationSettingsResponse > {
178
- const settings = await this . orgService . getSettings ( context . user . id , req . organizationId ) ;
179
+ const settings = await this . orgService . getSettings ( userId ( ) , req . organizationId ) ;
179
180
const response = new GetOrganizationSettingsResponse ( ) ;
180
181
response . settings = this . apiConverter . toOrganizationSettings ( settings ) ;
181
182
return response ;
182
183
}
183
184
184
185
async updateOrganizationSettings (
185
186
req : UpdateOrganizationSettingsRequest ,
186
- context : HandlerContext ,
187
+ _ : HandlerContext ,
187
188
) : Promise < UpdateOrganizationSettingsResponse > {
188
- const settings = await this . orgService . updateSettings ( context . user . id , req . organizationId , {
189
+ const settings = await this . orgService . updateSettings ( userId ( ) , req . organizationId , {
189
190
workspaceSharingDisabled : req . settings ?. workspaceSharingDisabled ,
190
191
defaultWorkspaceImage : req . settings ?. defaultWorkspaceImage ,
191
192
} ) ;
0 commit comments