Skip to content

Commit a8bd622

Browse files
committed
[public-api] only allow optional in update
1 parent 9f692bb commit a8bd622

20 files changed

+657
-522
lines changed

components/dashboard/src/data/organizations/update-org-settings-mutation.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ export const useUpdateOrgSettingsMutation = () => {
2323
mutationFn: async ({ workspaceSharingDisabled, defaultWorkspaceImage }) => {
2424
const settings = await organizationClient.updateOrganizationSettings({
2525
organizationId: teamId,
26-
settings: {
27-
workspaceSharingDisabled: workspaceSharingDisabled || false,
28-
defaultWorkspaceImage,
29-
},
26+
workspaceSharingDisabled: workspaceSharingDisabled || false,
27+
defaultWorkspaceImage,
3028
});
3129
return settings.settings || new OrganizationSettings();
3230
},

components/dashboard/src/service/json-rpc-organization-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ export class JsonRpcOrganizationClient implements PromiseClient<typeof Organizat
211211
throw new ConnectError("id is required", Code.InvalidArgument);
212212
}
213213
await getGitpodService().server.updateOrgSettings(request.organizationId, {
214-
workspaceSharingDisabled: request.settings?.workspaceSharingDisabled,
215-
defaultWorkspaceImage: request.settings?.defaultWorkspaceImage,
214+
workspaceSharingDisabled: request?.workspaceSharingDisabled,
215+
defaultWorkspaceImage: request?.defaultWorkspaceImage,
216216
});
217217
return new UpdateOrganizationSettingsResponse();
218218
}

components/gitpod-db/src/team-db.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export interface TeamDB extends TransactionalDB<TeamDB> {
4040
deleteTeam(teamId: string): Promise<void>;
4141

4242
findOrgSettings(teamId: string): Promise<OrganizationSettings | undefined>;
43-
setOrgSettings(teamId: string, settings: Partial<OrganizationSettings>): Promise<void>;
43+
setOrgSettings(teamId: string, settings: Partial<OrganizationSettings>): Promise<OrganizationSettings>;
4444

4545
hasActiveSSO(organizationId: string): Promise<boolean>;
4646
}

components/gitpod-db/src/typeorm/team-db-impl.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -366,28 +366,19 @@ export class TeamDBImpl extends TransactionalDBImpl<TeamDB> implements TeamDB {
366366
});
367367
}
368368

369-
public async setOrgSettings(orgId: string, settings: Partial<OrganizationSettings>): Promise<void> {
369+
public async setOrgSettings(orgId: string, settings: Partial<OrganizationSettings>): Promise<OrganizationSettings> {
370370
const repo = await this.getOrgSettingsRepo();
371371
const team = await repo.findOne({ where: { orgId, deleted: false } });
372-
const update: Partial<OrganizationSettings> = {
373-
defaultWorkspaceImage: settings.defaultWorkspaceImage,
374-
workspaceSharingDisabled: settings.workspaceSharingDisabled,
375-
};
376-
// Set to null if defaultWorkspaceImage is empty string, so that it can fallback to default image
377-
if (update.defaultWorkspaceImage?.trim() === "") {
378-
update.defaultWorkspaceImage = null;
379-
}
380372
if (!team) {
381-
await repo.insert({
382-
...update,
373+
return await repo.save({
374+
...settings,
383375
orgId,
384376
});
385-
} else {
386-
await repo.save({
387-
...team,
388-
...update,
389-
});
390377
}
378+
return await repo.save({
379+
...team,
380+
...settings,
381+
});
391382
}
392383

393384
public async hasActiveSSO(organizationId: string): Promise<boolean> {

components/gitpod-protocol/src/public-api-converter.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ describe("PublicAPIConverter", () => {
228228
},
229229
additionalEnvironmentVariables: [],
230230
region: "dev",
231+
prebuildId: "",
231232
workspaceClass: "g1-standard",
232233
editor: {
233234
name: "code",
@@ -357,6 +358,7 @@ describe("PublicAPIConverter", () => {
357358
},
358359
additionalEnvironmentVariables: [],
359360
region: "dev",
361+
prebuildId: "",
360362
workspaceClass: "g1-standard",
361363
editor: {
362364
name: "code",
@@ -497,6 +499,7 @@ describe("PublicAPIConverter", () => {
497499
},
498500
additionalEnvironmentVariables: [],
499501
region: "dev",
502+
prebuildId: "",
500503
workspaceClass: "g1-standard",
501504
editor: {
502505
name: "code",
@@ -612,6 +615,7 @@ describe("PublicAPIConverter", () => {
612615
},
613616
additionalEnvironmentVariables: [],
614617
region: "dev",
618+
prebuildId: "",
615619
workspaceClass: "g1-standard",
616620
editor: {
617621
name: "code",

components/gitpod-protocol/src/public-api-converter.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,27 @@ export class PublicAPIConverter {
121121
phase.lastTransitionTime = Timestamp.fromDate(new Date(lastTransitionTime));
122122

123123
status.instanceId = arg.id;
124-
status.message = arg.status.message;
124+
if (arg.status.message) {
125+
status.message = arg.status.message;
126+
}
125127
status.workspaceUrl = arg.ideUrl;
126128
status.ports = this.toPorts(arg.status.exposedPorts);
127129
status.conditions = this.toWorkspaceConditions(arg.status.conditions);
128130
status.gitStatus = this.toGitStatus(arg, status.gitStatus);
129131
workspace.region = arg.region;
130-
workspace.workspaceClass = arg.workspaceClass;
132+
if (arg.workspaceClass) {
133+
workspace.workspaceClass = arg.workspaceClass;
134+
}
131135
workspace.editor = this.toEditor(arg.configuration.ideConfig);
132136

133137
return workspace;
134138
}
135139

136140
toWorkspaceConditions(conditions: WorkspaceInstanceConditions): WorkspaceConditions {
137-
const result = new WorkspaceConditions();
138-
result.failed = conditions.failed;
139-
result.timeout = conditions.timeout;
140-
return result;
141+
return new WorkspaceConditions({
142+
failed: conditions.failed,
143+
timeout: conditions.timeout,
144+
});
141145
}
142146

143147
toEditor(ideConfig: ConfigurationIdeConfig | undefined): EditorReference | undefined {
@@ -337,15 +341,15 @@ export class PublicAPIConverter {
337341
}
338342

339343
toOrganizationMember(member: OrgMemberInfo): OrganizationMember {
340-
const result = new OrganizationMember();
341-
result.userId = member.userId;
342-
result.fullName = member.fullName;
343-
result.email = member.primaryEmail;
344-
result.avatarUrl = member.avatarUrl;
345-
result.role = this.toOrgMemberRole(member.role);
346-
result.memberSince = Timestamp.fromDate(new Date(member.memberSince));
347-
result.ownedByOrganization = member.ownedByOrganization;
348-
return result;
344+
return new OrganizationMember({
345+
userId: member.userId,
346+
fullName: member.fullName,
347+
email: member.primaryEmail,
348+
avatarUrl: member.avatarUrl,
349+
role: this.toOrgMemberRole(member.role),
350+
memberSince: Timestamp.fromDate(new Date(member.memberSince)),
351+
ownedByOrganization: member.ownedByOrganization,
352+
});
349353
}
350354

351355
toOrgMemberRole(role: OrgMemberRole): OrganizationRole {
@@ -371,9 +375,9 @@ export class PublicAPIConverter {
371375
}
372376

373377
toOrganizationSettings(settings: OrganizationSettingsProtocol): OrganizationSettings {
374-
const result = new OrganizationSettings();
375-
result.workspaceSharingDisabled = !!settings.workspaceSharingDisabled;
376-
result.defaultWorkspaceImage = settings.defaultWorkspaceImage || undefined;
377-
return result;
378+
return new OrganizationSettings({
379+
workspaceSharingDisabled: !!settings.workspaceSharingDisabled,
380+
defaultWorkspaceImage: settings.defaultWorkspaceImage || undefined,
381+
});
378382
}
379383
}

components/public-api/buf.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ breaking:
55
ignore:
66
# Do not enforce breaking change detection for the experimental package
77
- gitpod/experimental
8+
# TODO enable again after landing style changes
9+
- gitpod/v1
810
lint:
911
use:
1012
- DEFAULT

components/public-api/gitpod/v1/organization.proto

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ syntax = "proto3";
22

33
package gitpod.v1;
44

5+
import "google/protobuf/field_mask.proto";
56
import "google/protobuf/timestamp.proto";
67
import "gitpod/v1/pagination.proto";
78

@@ -18,9 +19,9 @@ message OrganizationMember {
1819
string user_id = 1;
1920
OrganizationRole role = 2;
2021
google.protobuf.Timestamp member_since = 3;
21-
optional string avatar_url = 4;
22-
optional string full_name = 5;
23-
optional string email = 6;
22+
string avatar_url = 4;
23+
string full_name = 5;
24+
string email = 6;
2425
bool owned_by_organization = 7;
2526
}
2627

@@ -32,7 +33,7 @@ enum OrganizationRole {
3233

3334
message OrganizationSettings {
3435
bool workspace_sharing_disabled = 1;
35-
optional string default_workspace_image = 2;
36+
string default_workspace_image = 2;
3637
}
3738

3839
service OrganizationService {
@@ -107,8 +108,11 @@ message UpdateOrganizationSettingsRequest {
107108
// organization_id is the ID of the organization to update the settings for.
108109
string organization_id = 1;
109110

110-
// settings are the settings to update
111-
OrganizationSettings settings = 2;
111+
google.protobuf.FieldMask reset_mask = 2;
112+
113+
optional bool workspace_sharing_disabled = 3;
114+
115+
optional string default_workspace_image = 4;
112116
}
113117

114118
message UpdateOrganizationSettingsResponse {

components/public-api/gitpod/v1/workspace.proto

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,21 @@ message Workspace {
4343
// Obtain available regions using the ListRegions operation.
4444
//
4545
// +optional defaults to the user's default region
46-
optional string region = 8;
46+
string region = 8;
4747

4848
// workspace_class specifies the workspace class with which to create the
4949
// workspace. Obtain available workspace classes using the ListWorkspaceClass
5050
// operation.
5151
//
5252
// +optional defaults to the class configured on the project or the cluster's
5353
// default class.
54-
optional string workspace_class = 9;
54+
string workspace_class = 9;
5555

5656
// editor specifies the editor that will be used with this workspace.
5757
// Obtain available editors using the EditorService.ListEditors operation.
5858
//
5959
// +optional defaults to the default editor of the user
60-
optional EditorReference editor = 10;
60+
EditorReference editor = 10;
6161

6262
// context_url is the normalized URL from which the workspace was created
6363
// TODO(ak) replace with resolveContextURL API
@@ -66,7 +66,7 @@ message Workspace {
6666
// Prebuild ID is the unique identifier of the prebuild
6767
// from which this workspace was created
6868
// +optional if empty then this workspace was not created from a prebuild
69-
optional string prebuild_id = 12;
69+
string prebuild_id = 12;
7070
}
7171

7272
message WorkspaceStatus {
@@ -77,7 +77,7 @@ message WorkspaceStatus {
7777
WorkspacePhase phase = 1;
7878

7979
// message is an optional human-readable message detailing the current phase
80-
optional string message = 2;
80+
string message = 2;
8181

8282
// workspace_url is the URL of the workspace. Only present when the phase is
8383
// running.
@@ -104,11 +104,11 @@ message WorkspaceStatus {
104104
message WorkspaceConditions {
105105
// failed contains technical details for the failure of the workspace.
106106
// +optional If this field is empty, the workspace has not failed.
107-
optional string failed = 1;
107+
string failed = 1;
108108

109109
// timeout contains the reason the workspace has timed out.
110110
// +optional If this field is empty, the workspace has not timed out.
111-
optional string timeout = 2;
111+
string timeout = 2;
112112
}
113113

114114
// Admission level describes who can access a workspace instance and its ports.
@@ -256,5 +256,5 @@ message EditorReference {
256256

257257
message WorkspaceEnvironmentVariable {
258258
string name = 1;
259-
optional string value = 2;
259+
string value = 2;
260260
}

0 commit comments

Comments
 (0)