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