Skip to content

Commit ae26fdf

Browse files
committed
[server] OrganizationService: block createTeam consistently for org-owned users
1 parent 129b0ed commit ae26fdf

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

components/server/src/orgs/organization-service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { StripeService } from "../billing/stripe-service";
3333
import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution";
3434
import { UsageService } from "./usage-service";
3535
import { CostCenter_BillingStrategy } from "@gitpod/gitpod-protocol/lib/usage";
36+
import { UserAuthentication } from "../user/user-authentication";
3637

3738
@injectable()
3839
export class OrganizationService {
@@ -49,6 +50,7 @@ export class OrganizationService {
4950
@inject(UsageService) private readonly usageService: UsageService,
5051
@inject(DefaultWorkspaceImageValidator)
5152
private readonly validateDefaultWorkspaceImage: DefaultWorkspaceImageValidator,
53+
@inject(UserAuthentication) private readonly userAuthentication: UserAuthentication,
5254
) {}
5355

5456
async listOrganizations(
@@ -145,6 +147,19 @@ export class OrganizationService {
145147
}
146148

147149
async createOrganization(userId: string, name: string): Promise<Organization> {
150+
// TODO(gpl): Should we use the authorization layer to make this decision?
151+
const user = await this.userDB.findUserById(userId);
152+
if (!user) {
153+
throw new ApplicationError(ErrorCodes.NOT_AUTHENTICATED, `User not authenticated. Please login.`);
154+
}
155+
const mayCreateOrganization = await this.userAuthentication.mayCreateOrJoinOrganization(user);
156+
if (!mayCreateOrganization) {
157+
throw new ApplicationError(
158+
ErrorCodes.PERMISSION_DENIED,
159+
"Organizational accounts are not allowed to create new organizations",
160+
);
161+
}
162+
148163
let result: Organization;
149164
try {
150165
result = await this.teamDB.transaction(async (db) => {

components/server/src/workspace/gitpod-server-impl.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,15 +1433,6 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
14331433

14341434
// Note: this operation is per-user only, hence needs no resource guard
14351435
const user = await this.checkAndBlockUser("createTeam");
1436-
1437-
const mayCreateOrganization = await this.userAuthentication.mayCreateOrJoinOrganization(user);
1438-
if (!mayCreateOrganization) {
1439-
throw new ApplicationError(
1440-
ErrorCodes.PERMISSION_DENIED,
1441-
"Organizational accounts are not allowed to create new organizations",
1442-
);
1443-
}
1444-
14451436
const org = await this.organizationService.createOrganization(user.id, name);
14461437
// create a cost center
14471438
await this.usageService.getCostCenter(user.id, org.id);

0 commit comments

Comments
 (0)