Skip to content

Commit d24ae32

Browse files
selfcontainedroboquat
authored andcommitted
Removing ownerId from method params
1 parent 252d76b commit d24ae32

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

components/gitpod-protocol/src/gitpod-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,10 @@ export namespace GitpodServer {
467467
readonly id: string;
468468
}
469469
export interface CreateOrgAuthProviderParams {
470-
readonly entry: AuthProviderEntry.NewEntry;
470+
readonly entry: Omit<AuthProviderEntry.NewEntry, "ownerId">;
471471
}
472472
export interface UpdateOrgAuthProviderParams {
473-
readonly entry: AuthProviderEntry.UpdateEntry;
473+
readonly entry: Omit<AuthProviderEntry.UpdateEntry, "ownerId">;
474474
}
475475
export interface GetOrgAuthProviderParams {
476476
readonly organizationId: string;

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2922,29 +2922,25 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
29222922
): Promise<AuthProviderEntry> {
29232923
traceAPIParams(ctx, {}); // entry contains PII
29242924

2925+
let user = this.checkAndBlockUser("createOrgAuthProvider");
2926+
29252927
// map params to a new provider
29262928
const newProvider = <AuthProviderEntry.NewEntry>{
29272929
host: entry.host,
29282930
type: entry.type,
29292931
clientId: entry.clientId,
29302932
clientSecret: entry.clientSecret,
2931-
ownerId: entry.ownerId,
2933+
ownerId: user.id,
29322934
organizationId: entry.organizationId,
29332935
};
29342936

2935-
let user = this.checkAndBlockUser("createOrgAuthProvider");
29362937
let team = await this.getTeam(ctx, newProvider.organizationId || "");
29372938
if (!team) {
29382939
throw new ResponseError(ErrorCodes.BAD_REQUEST, "Invalid organizationId");
29392940
}
29402941

29412942
await this.guardWithFeatureFlag("orgGitAuthProviders", team);
29422943

2943-
// Since this is a create, ensure they're not creating it as someone else
2944-
if (user.id !== newProvider.ownerId) {
2945-
throw new ResponseError(ErrorCodes.BAD_REQUEST, "Cannot create an auth provider for another owner.");
2946-
}
2947-
29482944
if (!newProvider.host) {
29492945
throw new ResponseError(
29502946
ErrorCodes.BAD_REQUEST,
@@ -2984,28 +2980,24 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
29842980
): Promise<AuthProviderEntry> {
29852981
traceAPIParams(ctx, {}); // entry contains PII
29862982

2983+
const user = this.checkAndBlockUser("updateOrgAuthProvider");
2984+
29872985
// map params to a provider update
29882986
const providerUpdate: AuthProviderEntry.UpdateEntry = {
29892987
id: entry.id,
2988+
ownerId: user.id,
29902989
clientId: entry.clientId,
29912990
clientSecret: entry.clientSecret,
2992-
ownerId: entry.ownerId,
29932991
organizationId: entry.organizationId,
29942992
};
29952993

2996-
const user = this.checkAndBlockUser("updateOrgAuthProvider");
29972994
const team = await this.getTeam(ctx, providerUpdate.organizationId || "");
29982995
if (!team) {
29992996
throw new ResponseError(ErrorCodes.BAD_REQUEST, "Invalid organizationId");
30002997
}
30012998

30022999
await this.guardWithFeatureFlag("orgGitAuthProviders", team);
30033000

3004-
// TODO: What do we want to enforce here for updates? That ownerId is set to last user who updated it, or creator?
3005-
if (user.id !== providerUpdate.ownerId) {
3006-
throw new ResponseError(ErrorCodes.BAD_REQUEST, "Cannot update an auth provider for another owner.");
3007-
}
3008-
30093001
await this.guardTeamOperation(providerUpdate.organizationId, "update");
30103002

30113003
try {

0 commit comments

Comments
 (0)