Skip to content

Commit

Permalink
[server] Minor Refactor for RepositoryResourceGuard
Browse files Browse the repository at this point in the history
  • Loading branch information
geropl authored and roboquat committed Jun 28, 2022
1 parent 67b73c2 commit 2ab9b97
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions components/server/src/auth/resource-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,16 +463,26 @@ export class RepositoryResourceGuard implements ResourceAccessGuard {
constructor(protected readonly user: User, protected readonly hostContextProvider: HostContextProvider) {}

async canAccess(resource: GuardedResource, operation: ResourceAccessOp): Promise<boolean> {
if (resource.kind !== "workspaceLog" && resource.kind !== "snapshot") {
return false;
}
// only get operations are supported
// Only get operations are supported
if (operation !== "get") {
return false;
}

// Get Workspace from GuardedResource
let workspace: Workspace;
switch (resource.kind) {
case "workspaceLog":
workspace = resource.subject;
break;
case "snapshot":
workspace = resource.workspace;
break;
default:
// We do not handle resource kinds here!
return false;
}

// Check if user has at least read access to the repository
const workspace = resource.kind === "snapshot" ? resource.workspace : resource.subject;
const repos: Repository[] = [];
if (CommitContext.is(workspace.context)) {
repos.push(workspace.context.repository);
Expand Down

0 comments on commit 2ab9b97

Please sign in to comment.