|
4 | 4 | * See License.AGPL.txt in the project root for license information. |
5 | 5 | */ |
6 | 6 |
|
7 | | -import { PartialMessage } from "@bufbuild/protobuf"; |
| 7 | +import { PartialMessage, PlainMessage } from "@bufbuild/protobuf"; |
8 | 8 | import { CallOptions, PromiseClient } from "@connectrpc/connect"; |
9 | 9 | import { OrganizationService } from "@gitpod/public-api/lib/gitpod/v1/organization_connect"; |
10 | 10 | import { |
@@ -41,7 +41,6 @@ import { |
41 | 41 | import { getGitpodService } from "./service"; |
42 | 42 | import { converter } from "./public-api"; |
43 | 43 | import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error"; |
44 | | -import { OrgMemberRole, RoleRestrictions } from "@gitpod/gitpod-protocol"; |
45 | 44 |
|
46 | 45 | export class JsonRpcOrganizationClient implements PromiseClient<typeof OrganizationService> { |
47 | 46 | async createOrganization( |
@@ -228,56 +227,62 @@ export class JsonRpcOrganizationClient implements PromiseClient<typeof Organizat |
228 | 227 | if (!request.organizationId) { |
229 | 228 | throw new ApplicationError(ErrorCodes.BAD_REQUEST, "organizationId is required"); |
230 | 229 | } |
231 | | - const update: Partial<OrganizationSettings> = { |
232 | | - workspaceSharingDisabled: request?.workspaceSharingDisabled, |
233 | | - defaultWorkspaceImage: request?.defaultWorkspaceImage, |
234 | | - allowedWorkspaceClasses: request?.allowedWorkspaceClasses, |
235 | | - restrictedEditorNames: request?.restrictedEditorNames, |
236 | | - defaultRole: request?.defaultRole, |
237 | | - }; |
238 | | - if (request.updatePinnedEditorVersions) { |
239 | | - update.pinnedEditorVersions = request.pinnedEditorVersions; |
240 | | - } else if (request.pinnedEditorVersions && Object.keys(request.pinnedEditorVersions).length > 0) { |
| 230 | + |
| 231 | + if ( |
| 232 | + request.restrictedEditorNames && |
| 233 | + request.restrictedEditorNames.length > 0 && |
| 234 | + !request.updateRestrictedEditorNames |
| 235 | + ) { |
241 | 236 | throw new ApplicationError( |
242 | 237 | ErrorCodes.BAD_REQUEST, |
243 | | - "updatePinnedEditorVersions is required to be true to update pinnedEditorVersions", |
| 238 | + "updateRestrictedEditorNames is required to be true to update restrictedEditorNames", |
244 | 239 | ); |
245 | 240 | } |
246 | | - if (request.updateRestrictedEditorNames) { |
247 | | - update.restrictedEditorNames = request.restrictedEditorNames; |
248 | | - } else if (request.restrictedEditorNames && request.restrictedEditorNames.length > 0) { |
| 241 | + |
| 242 | + if ( |
| 243 | + request.allowedWorkspaceClasses && |
| 244 | + request.allowedWorkspaceClasses.length > 0 && |
| 245 | + !request.updateAllowedWorkspaceClasses |
| 246 | + ) { |
249 | 247 | throw new ApplicationError( |
250 | 248 | ErrorCodes.BAD_REQUEST, |
251 | | - "updateRestrictedEditorNames is required to be true to update restrictedEditorNames", |
| 249 | + "updateAllowedWorkspaceClasses is required to be true to update allowedWorkspaceClasses", |
252 | 250 | ); |
253 | 251 | } |
254 | | - const roleRestrictions: RoleRestrictions = {}; |
255 | | - if (request.updateRoleRestrictions) { |
256 | | - for (const roleRestriction of request?.roleRestrictions ?? []) { |
257 | | - if (!roleRestriction.role) { |
258 | | - throw new ApplicationError(ErrorCodes.BAD_REQUEST, "role is required"); |
259 | | - } |
260 | | - const role = converter.fromOrgMemberRole(roleRestriction.role); |
261 | | - const permissions = roleRestriction?.permissions?.map((p) => converter.fromOrganizationPermission(p)); |
262 | 252 |
|
263 | | - roleRestrictions[role] = permissions; |
264 | | - } |
265 | | - } else if (request.roleRestrictions && Object.keys(request.roleRestrictions).length > 0) { |
| 253 | + if ( |
| 254 | + request.pinnedEditorVersions && |
| 255 | + Object.keys(request.pinnedEditorVersions).length > 0 && |
| 256 | + !request.updatePinnedEditorVersions |
| 257 | + ) { |
266 | 258 | throw new ApplicationError( |
267 | 259 | ErrorCodes.BAD_REQUEST, |
268 | | - "updateRoleRestrictions is required to be true to update roleRestrictions", |
| 260 | + "updatePinnedEditorVersions is required to be true to update pinnedEditorVersions", |
269 | 261 | ); |
270 | 262 | } |
271 | 263 |
|
272 | | - await getGitpodService().server.updateOrgSettings(request.organizationId, { |
273 | | - ...update, |
274 | | - defaultRole: request.defaultRole as OrgMemberRole, |
275 | | - timeoutSettings: { |
276 | | - inactivity: converter.toDurationStringOpt(request.timeoutSettings?.inactivity), |
277 | | - denyUserTimeouts: request.timeoutSettings?.denyUserTimeouts, |
278 | | - }, |
279 | | - roleRestrictions, |
280 | | - }); |
| 264 | + if (request.roleRestrictions && request.roleRestrictions.length > 0 && !request.updateRoleRestrictions) { |
| 265 | + throw new ApplicationError( |
| 266 | + ErrorCodes.BAD_REQUEST, |
| 267 | + "updateRoleRestrictions is required to be true when updating roleRestrictions", |
| 268 | + ); |
| 269 | + } |
| 270 | + if ( |
| 271 | + request.onboardingSettings?.recommendedRepositories && |
| 272 | + request.onboardingSettings.recommendedRepositories.length > 0 && |
| 273 | + !request.onboardingSettings.updateRecommendedRepositories |
| 274 | + ) { |
| 275 | + throw new ApplicationError( |
| 276 | + ErrorCodes.BAD_REQUEST, |
| 277 | + "recommendedRepositories can only be set when updateRecommendedRepositories is true", |
| 278 | + ); |
| 279 | + } |
| 280 | + |
| 281 | + // gpl: We accept the little bit of uncertainty here because a) the partial/not-partial mismatch is only about |
| 282 | + // technical/private fields and b) this path should not be exercised anymore anyway. |
| 283 | + const update = converter.fromOrganizationSettings(request as PlainMessage<OrganizationSettings>); |
| 284 | + |
| 285 | + await getGitpodService().server.updateOrgSettings(request.organizationId, update); |
281 | 286 | return new UpdateOrganizationSettingsResponse(); |
282 | 287 | } |
283 | 288 | } |
0 commit comments