Skip to content

Commit 4bac2d4

Browse files
committed
[server] implement organization API
1 parent 211745a commit 4bac2d4

File tree

15 files changed

+5084
-501
lines changed

15 files changed

+5084
-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/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
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-debug": "mocha --inspect-brk './**/*.spec.js' --exclude './node_modules/**' --exit",
4646
"watch": "leeway exec --package .:lib --transitive-dependencies --filter-type yarn --components --parallel -- tsc -w --preserveWatchOutput"
4747
},
4848
"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: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
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+
service OrganizationService {
34+
// CreateOrganization creates a new Organization.
35+
rpc CreateOrganization(CreateOrganizationRequest) returns (CreateOrganizationResponse) {};
36+
37+
// GetOrganization retrieves a single Organization.
38+
rpc GetOrganization(GetOrganizationRequest) returns (GetOrganizationResponse) {}
39+
40+
// ListOrganizations lists all organization the caller has access to.
41+
rpc ListOrganizations(ListOrganizationsRequest) returns (ListOrganizationsResponse) {};
42+
43+
// DeleteOrganization deletes the specified organization.
44+
rpc DeleteOrganization(DeleteOrganizationRequest) returns (DeleteOrganizationResponse) {};
45+
46+
// GetOrganizationInvitation retrieves the invitation for a Organization.
47+
rpc GetOrganizationInvitation(GetOrganizationInvitationRequest) returns (GetOrganizationInvitationResponse) {};
48+
49+
// JoinOrganization makes the caller a OrganizationMember of the Organization.
50+
rpc JoinOrganization(JoinOrganizationRequest) returns (JoinOrganizationResponse) {};
51+
52+
// ResetOrganizationInvitation resets the invitation_id for a Organization.
53+
rpc ResetOrganizationInvitation(ResetOrganizationInvitationRequest) returns (ResetOrganizationInvitationResponse) {};
54+
55+
// ListOrganizationMembers lists the members of a Organization.
56+
rpc ListOrganizationMembers(ListOrganizationMembersRequest) returns (ListOrganizationMembersResponse) {};
57+
58+
// UpdateOrganizationMember updates organization membership properties.
59+
rpc UpdateOrganizationMember(UpdateOrganizationMemberRequest) returns (UpdateOrganizationMemberResponse) {};
60+
61+
// DeleteOrganizationMember removes a OrganizationMember from the Organization.
62+
rpc DeleteOrganizationMember(DeleteOrganizationMemberRequest) returns (DeleteOrganizationMemberResponse) {};
63+
}
64+
65+
message CreateOrganizationRequest {
66+
// name is the organization name
67+
string name = 1;
68+
}
69+
70+
message CreateOrganizationResponse {
71+
Organization organization = 1;
72+
}
73+
74+
message GetOrganizationRequest {
75+
// organization_id is the unique identifier of the Organization to retreive.
76+
string organization_id = 1;
77+
}
78+
79+
message GetOrganizationResponse {
80+
Organization organization = 1;
81+
}
82+
83+
message ListOrganizationsRequest {
84+
PaginationRequest pagination = 1;
85+
}
86+
87+
message ListOrganizationsResponse {
88+
repeated Organization organizations = 1;
89+
PaginationResponse pagination = 2;
90+
}
91+
92+
message DeleteOrganizationRequest {
93+
// organization_id is the ID of the organization to delete
94+
string organization_id = 1;
95+
}
96+
97+
message DeleteOrganizationResponse {
98+
}
99+
100+
message GetOrganizationInvitationRequest {
101+
string organization_id = 1;
102+
}
103+
104+
message GetOrganizationInvitationResponse {
105+
// invitation_id is the invitation ID for an Organization
106+
string invitation_id = 1;
107+
}
108+
109+
message JoinOrganizationRequest {
110+
// invitation_id is the invitation ID for an Organization
111+
string invitation_id = 1;
112+
}
113+
114+
message JoinOrganizationResponse {
115+
// organization_id is the id of the organization the user has just joined
116+
string organization_id = 1;
117+
}
118+
119+
message ResetOrganizationInvitationRequest {
120+
string organization_id = 1;
121+
}
122+
123+
message ResetOrganizationInvitationResponse {
124+
// invitation_id is the new invitation id for the organization.
125+
string invitation_id = 1;
126+
}
127+
128+
message ListOrganizationMembersRequest {
129+
// organization_id is the ID of the organization that contains the members to list
130+
string organization_id = 1;
131+
PaginationRequest pagination = 2;
132+
}
133+
134+
message ListOrganizationMembersResponse {
135+
// members are the organization members of this Organization
136+
repeated OrganizationMember members = 1;
137+
PaginationResponse pagination = 2;
138+
}
139+
140+
message UpdateOrganizationMemberRequest {
141+
// organization_id is the ID of the organization in which the role is to be updated
142+
string organization_id = 1;
143+
144+
// user_id is the user for which the membership shall be updated.
145+
string user_id = 2;
146+
147+
// role is the new role for the user in the organization
148+
OrganizationRole role = 3;
149+
}
150+
151+
message UpdateOrganizationMemberResponse {
152+
}
153+
154+
message DeleteOrganizationMemberRequest {
155+
// organization_id is the ID of the organization in which a member should be deleted.
156+
string organization_id = 1;
157+
158+
// user_id is the ID of the user that should be deleted from the organization.
159+
string user_id = 2;
160+
}
161+
162+
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)