Skip to content

Commit 3db0be3

Browse files
committed
[server] implement organization API
1 parent c7f8c35 commit 3db0be3

File tree

16 files changed

+6211
-501
lines changed

16 files changed

+6211
-501
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"mochaExplorer.files": [
3+
"dist/**/*.spec.js",
4+
"dist/**/*.spec.db.js"
5+
],
6+
"mochaExplorer.require": [
7+
"source-map-support/register",
8+
"reflect-metadata/Reflect"
9+
],
10+
"mochaExplorer.watch": [
11+
"dist/**/*.spec.js",
12+
"dist/**/*.spec.db.js"
13+
],
14+
"mochaExplorer.exit": true,
15+
"mochaExplorer.timeout": 60000
16+
}

components/gitpod-protocol/BUILD.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ packages:
2020
packaging: library
2121
yarnLock: ${coreYarnLockBase}/yarn.lock
2222
tsconfig: tsconfig.json
23+
commands:
24+
# leeway executes the build and test step in the wrong order, so we need to call a special script that builds before testing
25+
test: ["yarn", "test:leeway"]
2326
- name: gitpod-schema
2427
type: generic
2528
srcs:

components/gitpod-protocol/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@
4141
"build": "yarn lint && tsc",
4242
"lint": "yarn eslint src/*.ts src/**/*.ts",
4343
"lint:fix": "yarn eslint src/*.ts src/**/*.ts --fix",
44-
"test": "mocha './**/*.spec.ts' --exclude './node_modules/**'",
45-
"test-debug": "mocha --inspect-brk './**/*.spec.ts' --exclude './node_modules/**' --exit",
44+
"test": "mocha './**/*.spec.js' --exclude './node_modules/**' --exit",
45+
"test:leeway": "yarn build && yarn test",
46+
"test-debug": "mocha --inspect-brk './**/*.spec.js' --exclude './node_modules/**' --exit",
4647
"watch": "leeway exec --package .:lib --transitive-dependencies --filter-type yarn --components --parallel -- tsc -w --preserveWatchOutput"
4748
},
4849
"mocha": {

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

Lines changed: 550 additions & 499 deletions
Large diffs are not rendered by default.

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ import {
2020
WorkspacePort_Protocol,
2121
WorkspaceStatus,
2222
} from "@gitpod/public-api/lib/gitpod/experimental/v2/workspace_pb";
23+
import {
24+
Organization,
25+
OrganizationMember,
26+
OrganizationRole,
27+
} from "@gitpod/public-api/lib/gitpod/experimental/v2/organization_pb";
2328
import { ApplicationError, ErrorCode, ErrorCodes } from "./messaging/error";
2429
import {
2530
CommitContext,
@@ -39,6 +44,7 @@ import {
3944
} from "./workspace-instance";
4045
import { ContextURL } from "./context-url";
4146
import { TrustedValue } from "./util/scrubbing";
47+
import { Organization as ProtocolOrganization, OrgMemberInfo, OrgMemberRole } from "./teams-projects-protocol";
4248

4349
const applicationErrorCode = "application-error-code";
4450
const applicationErrorData = "application-error-data";
@@ -314,4 +320,46 @@ export class PublicAPIConverter {
314320
}
315321
return WorkspacePhase_Phase.UNSPECIFIED;
316322
}
323+
324+
toOrganization(org: ProtocolOrganization): Organization {
325+
const result = new Organization();
326+
result.id = org.id;
327+
result.name = org.name;
328+
result.creationTime = Timestamp.fromDate(new Date(org.creationTime));
329+
return result;
330+
}
331+
332+
toOrganizationMember(member: OrgMemberInfo): OrganizationMember {
333+
const result = new OrganizationMember();
334+
result.userId = member.userId;
335+
result.fullName = member.fullName;
336+
result.primaryEmail = member.primaryEmail;
337+
result.avatarUrl = member.avatarUrl;
338+
result.role = this.toOrgMemberRole(member.role);
339+
result.memberSince = Timestamp.fromDate(new Date(member.memberSince));
340+
result.ownedByOrganization = member.ownedByOrganization;
341+
return result;
342+
}
343+
344+
toOrgMemberRole(role: OrgMemberRole): OrganizationRole {
345+
switch (role) {
346+
case "owner":
347+
return OrganizationRole.OWNER;
348+
case "member":
349+
return OrganizationRole.MEMBER;
350+
default:
351+
throw new Error(`unknown org member role ${role}`);
352+
}
353+
}
354+
355+
fromOrgMemberRole(role: OrganizationRole): OrgMemberRole {
356+
switch (role) {
357+
case OrganizationRole.OWNER:
358+
return "owner";
359+
case OrganizationRole.MEMBER:
360+
return "member";
361+
default:
362+
throw new Error(`unknown org member role ${role}`);
363+
}
364+
}
317365
}
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
syntax = "proto3";
2+
3+
package gitpod.experimental.v2;
4+
5+
import "google/protobuf/timestamp.proto";
6+
import "gitpod/experimental/v2/pagination.proto";
7+
8+
option go_package = "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v2";
9+
10+
11+
message Organization {
12+
string id = 1;
13+
string name = 2;
14+
google.protobuf.Timestamp creation_time = 3;
15+
}
16+
17+
message OrganizationMember {
18+
string user_id = 1;
19+
OrganizationRole role = 2;
20+
google.protobuf.Timestamp member_since = 3;
21+
optional string avatar_url = 4;
22+
optional string full_name = 5;
23+
optional string primary_email = 6;
24+
bool owned_by_organization = 7;
25+
}
26+
27+
enum OrganizationRole {
28+
ORGANIZATION_ROLE_UNSPECIFIED = 0;
29+
ORGANIZATION_ROLE_OWNER = 1;
30+
ORGANIZATION_ROLE_MEMBER = 2;
31+
}
32+
33+
message OrganizationSettings {
34+
bool workspace_sharing_disabled = 1;
35+
optional string default_workspace_image = 2;
36+
}
37+
38+
service OrganizationService {
39+
// CreateOrganization creates a new Organization.
40+
rpc CreateOrganization(CreateOrganizationRequest) returns (CreateOrganizationResponse) {};
41+
42+
// GetOrganization retrieves a single Organization.
43+
rpc GetOrganization(GetOrganizationRequest) returns (GetOrganizationResponse) {}
44+
45+
// UpdateOrganization updates the properties of an Organization.
46+
rpc UpdateOrganization(UpdateOrganizationRequest) returns (UpdateOrganizationResponse) {};
47+
48+
// ListOrganizations lists all organization the caller has access to.
49+
rpc ListOrganizations(ListOrganizationsRequest) returns (ListOrganizationsResponse) {};
50+
51+
// DeleteOrganization deletes the specified organization.
52+
rpc DeleteOrganization(DeleteOrganizationRequest) returns (DeleteOrganizationResponse) {};
53+
54+
// GetOrganizationInvitation retrieves the invitation for a Organization.
55+
rpc GetOrganizationInvitation(GetOrganizationInvitationRequest) returns (GetOrganizationInvitationResponse) {};
56+
57+
// JoinOrganization makes the caller a OrganizationMember of the Organization.
58+
rpc JoinOrganization(JoinOrganizationRequest) returns (JoinOrganizationResponse) {};
59+
60+
// ResetOrganizationInvitation resets the invitation_id for a Organization.
61+
rpc ResetOrganizationInvitation(ResetOrganizationInvitationRequest) returns (ResetOrganizationInvitationResponse) {};
62+
63+
// ListOrganizationMembers lists the members of a Organization.
64+
rpc ListOrganizationMembers(ListOrganizationMembersRequest) returns (ListOrganizationMembersResponse) {};
65+
66+
// UpdateOrganizationMember updates organization membership properties.
67+
rpc UpdateOrganizationMember(UpdateOrganizationMemberRequest) returns (UpdateOrganizationMemberResponse) {};
68+
69+
// DeleteOrganizationMember removes a OrganizationMember from the Organization.
70+
rpc DeleteOrganizationMember(DeleteOrganizationMemberRequest) returns (DeleteOrganizationMemberResponse) {};
71+
72+
// GetOrganizationSettings retrieves the settings of a Organization.
73+
rpc GetOrganizationSettings(GetOrganizationSettingsRequest) returns (GetOrganizationSettingsResponse) {};
74+
75+
// UpdateOrganizationSettings updates the settings of a Organization.
76+
rpc UpdateOrganizationSettings(UpdateOrganizationSettingsRequest) returns (UpdateOrganizationSettingsResponse) {};
77+
}
78+
79+
message UpdateOrganizationRequest {
80+
// organization_id is the ID of the organization to update the settings for.
81+
string organization_id = 1;
82+
83+
// name is the new name of the organization
84+
string name = 2;
85+
}
86+
87+
message UpdateOrganizationResponse {
88+
}
89+
90+
message UpdateOrganizationSettingsRequest {
91+
// organization_id is the ID of the organization to update the settings for.
92+
string organization_id = 1;
93+
94+
// settings are the settings to update
95+
OrganizationSettings settings = 2;
96+
}
97+
98+
message UpdateOrganizationSettingsResponse {
99+
}
100+
101+
message GetOrganizationSettingsRequest {
102+
// organization_id is the ID of the organization to retrieve the settings for.
103+
string organization_id = 1;
104+
}
105+
106+
message GetOrganizationSettingsResponse {
107+
// settings are the settings of the organization
108+
OrganizationSettings settings = 1;
109+
}
110+
111+
message CreateOrganizationRequest {
112+
// name is the organization name
113+
string name = 1;
114+
}
115+
116+
message CreateOrganizationResponse {
117+
Organization organization = 1;
118+
}
119+
120+
message GetOrganizationRequest {
121+
// organization_id is the unique identifier of the Organization to retreive.
122+
string organization_id = 1;
123+
}
124+
125+
message GetOrganizationResponse {
126+
Organization organization = 1;
127+
}
128+
129+
message ListOrganizationsRequest {
130+
PaginationRequest pagination = 1;
131+
}
132+
133+
message ListOrganizationsResponse {
134+
repeated Organization organizations = 1;
135+
PaginationResponse pagination = 2;
136+
}
137+
138+
message DeleteOrganizationRequest {
139+
// organization_id is the ID of the organization to delete
140+
string organization_id = 1;
141+
}
142+
143+
message DeleteOrganizationResponse {
144+
}
145+
146+
message GetOrganizationInvitationRequest {
147+
string organization_id = 1;
148+
}
149+
150+
message GetOrganizationInvitationResponse {
151+
// invitation_id is the invitation ID for an Organization
152+
string invitation_id = 1;
153+
}
154+
155+
message JoinOrganizationRequest {
156+
// invitation_id is the invitation ID for an Organization
157+
string invitation_id = 1;
158+
}
159+
160+
message JoinOrganizationResponse {
161+
// organization_id is the id of the organization the user has just joined
162+
string organization_id = 1;
163+
}
164+
165+
message ResetOrganizationInvitationRequest {
166+
string organization_id = 1;
167+
}
168+
169+
message ResetOrganizationInvitationResponse {
170+
// invitation_id is the new invitation id for the organization.
171+
string invitation_id = 1;
172+
}
173+
174+
message ListOrganizationMembersRequest {
175+
// organization_id is the ID of the organization that contains the members to list
176+
string organization_id = 1;
177+
PaginationRequest pagination = 2;
178+
}
179+
180+
message ListOrganizationMembersResponse {
181+
// members are the organization members of this Organization
182+
repeated OrganizationMember members = 1;
183+
PaginationResponse pagination = 2;
184+
}
185+
186+
message UpdateOrganizationMemberRequest {
187+
// organization_id is the ID of the organization in which the role is to be updated
188+
string organization_id = 1;
189+
190+
// user_id is the user for which the membership shall be updated.
191+
string user_id = 2;
192+
193+
// role is the new role for the user in the organization
194+
OrganizationRole role = 3;
195+
}
196+
197+
message UpdateOrganizationMemberResponse {
198+
}
199+
200+
message DeleteOrganizationMemberRequest {
201+
// organization_id is the ID of the organization in which a member should be deleted.
202+
string organization_id = 1;
203+
204+
// user_id is the ID of the user that should be deleted from the organization.
205+
string user_id = 2;
206+
}
207+
208+
message DeleteOrganizationMemberResponse {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
syntax = "proto3";
2+
3+
package gitpod.experimental.v2;
4+
5+
option go_package = "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v2";
6+
7+
message PaginationRequest {
8+
// Page size is the maximum number of results to retrieve per page.
9+
// Defaults to 25. Maximum 100.
10+
int32 page_size = 1;
11+
12+
// Page is the page number of results to retrieve.
13+
// The first page starts at 1.
14+
// Defaults to 1.
15+
int32 page = 2;
16+
}
17+
18+
message PaginationResponse {
19+
// Total is the total number of results available.
20+
int32 total = 1;
21+
}

0 commit comments

Comments
 (0)