Skip to content

Commit

Permalink
[public-api] only allow optional in update
Browse files Browse the repository at this point in the history
  • Loading branch information
akosyakov committed Nov 8, 2023
1 parent 9f692bb commit 27c1691
Show file tree
Hide file tree
Showing 19 changed files with 577 additions and 517 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ export const useUpdateOrgSettingsMutation = () => {
mutationFn: async ({ workspaceSharingDisabled, defaultWorkspaceImage }) => {
const settings = await organizationClient.updateOrganizationSettings({
organizationId: teamId,
settings: {
workspaceSharingDisabled: workspaceSharingDisabled || false,
defaultWorkspaceImage,
},
workspaceSharingDisabled: workspaceSharingDisabled || false,
defaultWorkspaceImage,
});
return settings.settings || new OrganizationSettings();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ export class JsonRpcOrganizationClient implements PromiseClient<typeof Organizat
throw new ConnectError("id is required", Code.InvalidArgument);
}
await getGitpodService().server.updateOrgSettings(request.organizationId, {
workspaceSharingDisabled: request.settings?.workspaceSharingDisabled,
defaultWorkspaceImage: request.settings?.defaultWorkspaceImage,
workspaceSharingDisabled: request?.workspaceSharingDisabled,
defaultWorkspaceImage: request?.defaultWorkspaceImage,
});
return new UpdateOrganizationSettingsResponse();
}
Expand Down
2 changes: 1 addition & 1 deletion components/gitpod-db/src/team-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface TeamDB extends TransactionalDB<TeamDB> {
deleteTeam(teamId: string): Promise<void>;

findOrgSettings(teamId: string): Promise<OrganizationSettings | undefined>;
setOrgSettings(teamId: string, settings: Partial<OrganizationSettings>): Promise<void>;
setOrgSettings(teamId: string, settings: Partial<OrganizationSettings>): Promise<OrganizationSettings>;

hasActiveSSO(organizationId: string): Promise<boolean>;
}
23 changes: 7 additions & 16 deletions components/gitpod-db/src/typeorm/team-db-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,28 +366,19 @@ export class TeamDBImpl extends TransactionalDBImpl<TeamDB> implements TeamDB {
});
}

public async setOrgSettings(orgId: string, settings: Partial<OrganizationSettings>): Promise<void> {
public async setOrgSettings(orgId: string, settings: Partial<OrganizationSettings>): Promise<OrganizationSettings> {
const repo = await this.getOrgSettingsRepo();
const team = await repo.findOne({ where: { orgId, deleted: false } });
const update: Partial<OrganizationSettings> = {
defaultWorkspaceImage: settings.defaultWorkspaceImage,
workspaceSharingDisabled: settings.workspaceSharingDisabled,
};
// Set to null if defaultWorkspaceImage is empty string, so that it can fallback to default image
if (update.defaultWorkspaceImage?.trim() === "") {
update.defaultWorkspaceImage = null;
}
if (!team) {
await repo.insert({
...update,
return await repo.save({
...settings,
orgId,
});
} else {
await repo.save({
...team,
...update,
});
}
return await repo.save({
...team,
...settings,
});
}

public async hasActiveSSO(organizationId: string): Promise<boolean> {
Expand Down
4 changes: 4 additions & 0 deletions components/gitpod-protocol/src/public-api-converter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ describe("PublicAPIConverter", () => {
},
additionalEnvironmentVariables: [],
region: "dev",
prebuildId: "",
workspaceClass: "g1-standard",
editor: {
name: "code",
Expand Down Expand Up @@ -357,6 +358,7 @@ describe("PublicAPIConverter", () => {
},
additionalEnvironmentVariables: [],
region: "dev",
prebuildId: "",
workspaceClass: "g1-standard",
editor: {
name: "code",
Expand Down Expand Up @@ -497,6 +499,7 @@ describe("PublicAPIConverter", () => {
},
additionalEnvironmentVariables: [],
region: "dev",
prebuildId: "",
workspaceClass: "g1-standard",
editor: {
name: "code",
Expand Down Expand Up @@ -612,6 +615,7 @@ describe("PublicAPIConverter", () => {
},
additionalEnvironmentVariables: [],
region: "dev",
prebuildId: "",
workspaceClass: "g1-standard",
editor: {
name: "code",
Expand Down
42 changes: 23 additions & 19 deletions components/gitpod-protocol/src/public-api-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,27 @@ export class PublicAPIConverter {
phase.lastTransitionTime = Timestamp.fromDate(new Date(lastTransitionTime));

status.instanceId = arg.id;
status.message = arg.status.message;
if (arg.status.message) {
status.message = arg.status.message;
}
status.workspaceUrl = arg.ideUrl;
status.ports = this.toPorts(arg.status.exposedPorts);
status.conditions = this.toWorkspaceConditions(arg.status.conditions);
status.gitStatus = this.toGitStatus(arg, status.gitStatus);
workspace.region = arg.region;
workspace.workspaceClass = arg.workspaceClass;
if (arg.workspaceClass) {
workspace.workspaceClass = arg.workspaceClass;
}
workspace.editor = this.toEditor(arg.configuration.ideConfig);

return workspace;
}

toWorkspaceConditions(conditions: WorkspaceInstanceConditions): WorkspaceConditions {
const result = new WorkspaceConditions();
result.failed = conditions.failed;
result.timeout = conditions.timeout;
return result;
return new WorkspaceConditions({
failed: conditions.failed,
timeout: conditions.timeout,
});
}

toEditor(ideConfig: ConfigurationIdeConfig | undefined): EditorReference | undefined {
Expand Down Expand Up @@ -337,15 +341,15 @@ export class PublicAPIConverter {
}

toOrganizationMember(member: OrgMemberInfo): OrganizationMember {
const result = new OrganizationMember();
result.userId = member.userId;
result.fullName = member.fullName;
result.email = member.primaryEmail;
result.avatarUrl = member.avatarUrl;
result.role = this.toOrgMemberRole(member.role);
result.memberSince = Timestamp.fromDate(new Date(member.memberSince));
result.ownedByOrganization = member.ownedByOrganization;
return result;
return new OrganizationMember({
userId: member.userId,
fullName: member.fullName,
email: member.primaryEmail,
avatarUrl: member.avatarUrl,
role: this.toOrgMemberRole(member.role),
memberSince: Timestamp.fromDate(new Date(member.memberSince)),
ownedByOrganization: member.ownedByOrganization,
});
}

toOrgMemberRole(role: OrgMemberRole): OrganizationRole {
Expand All @@ -371,9 +375,9 @@ export class PublicAPIConverter {
}

toOrganizationSettings(settings: OrganizationSettingsProtocol): OrganizationSettings {
const result = new OrganizationSettings();
result.workspaceSharingDisabled = !!settings.workspaceSharingDisabled;
result.defaultWorkspaceImage = settings.defaultWorkspaceImage || undefined;
return result;
return new OrganizationSettings({
workspaceSharingDisabled: !!settings.workspaceSharingDisabled,
defaultWorkspaceImage: settings.defaultWorkspaceImage || undefined,
});
}
}
2 changes: 2 additions & 0 deletions components/public-api/buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ breaking:
ignore:
# Do not enforce breaking change detection for the experimental package
- gitpod/experimental
# TODO enable again after landing style changes
- gitpod/v1
lint:
use:
- DEFAULT
Expand Down
16 changes: 10 additions & 6 deletions components/public-api/gitpod/v1/organization.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";

package gitpod.v1;

import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";
import "gitpod/v1/pagination.proto";

Expand All @@ -18,9 +19,9 @@ message OrganizationMember {
string user_id = 1;
OrganizationRole role = 2;
google.protobuf.Timestamp member_since = 3;
optional string avatar_url = 4;
optional string full_name = 5;
optional string email = 6;
string avatar_url = 4;
string full_name = 5;
string email = 6;
bool owned_by_organization = 7;
}

Expand All @@ -32,7 +33,7 @@ enum OrganizationRole {

message OrganizationSettings {
bool workspace_sharing_disabled = 1;
optional string default_workspace_image = 2;
string default_workspace_image = 2;
}

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

// settings are the settings to update
OrganizationSettings settings = 2;
google.protobuf.FieldMask reset_mask = 2;

optional bool workspace_sharing_disabled = 3;

optional string default_workspace_image = 4;
}

message UpdateOrganizationSettingsResponse {
Expand Down
16 changes: 8 additions & 8 deletions components/public-api/gitpod/v1/workspace.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ message Workspace {
// Obtain available regions using the ListRegions operation.
//
// +optional defaults to the user's default region
optional string region = 8;
string region = 8;

// workspace_class specifies the workspace class with which to create the
// workspace. Obtain available workspace classes using the ListWorkspaceClass
// operation.
//
// +optional defaults to the class configured on the project or the cluster's
// default class.
optional string workspace_class = 9;
string workspace_class = 9;

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

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

message WorkspaceStatus {
Expand All @@ -77,7 +77,7 @@ message WorkspaceStatus {
WorkspacePhase phase = 1;

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

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

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

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

message WorkspaceEnvironmentVariable {
string name = 1;
optional string value = 2;
string value = 2;
}
Loading

0 comments on commit 27c1691

Please sign in to comment.