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