Skip to content

Commit

Permalink
when sharing is enabled just check if the user has access to the cred…
Browse files Browse the repository at this point in the history
…ential and not that they are the owner
  • Loading branch information
netroy committed Feb 1, 2024
1 parent a43b4e9 commit e5cc6be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 6 additions & 2 deletions packages/cli/src/UserManagement/PermissionChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ export class PermissionChecker {

if (user.hasGlobalScope('workflow:execute')) return;

const isSharingEnabled = this.license.isSharingEnabled();

// allow if all creds used in this workflow are a subset of
// all creds accessible to users who have access to this workflow

let workflowUserIds = [userId];

if (workflow.id && this.license.isSharingEnabled()) {
if (workflow.id && isSharingEnabled) {
const workflowSharings = await this.sharedWorkflowRepository.find({
relations: ['workflow'],
where: { workflowId: workflow.id },
Expand All @@ -54,7 +56,9 @@ export class PermissionChecker {
}

const credentialSharings =
await this.sharedCredentialsRepository.findOwnedSharings(workflowUserIds);
await this.sharedCredentialsRepository[
isSharingEnabled ? 'findAccessibleSharings' : 'findOwnedSharings'
](workflowUserIds);

const accessibleCredIds = credentialSharings.map((s) => s.credentialsId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ export class SharedCredentialsRepository extends Repository<SharedCredentials> {
return sharings.map((s) => s.credentialsId);
}

async findAccessibleSharings(userIds: string[]) {
return await this.findBy({
userId: In(userIds),
});
}

async findOwnedSharings(userIds: string[]) {
return await this.find({
where: {
userId: In(userIds),
role: 'credential:owner',
},
return await this.findBy({
userId: In(userIds),
role: 'credential:owner',
});
}

Expand Down

0 comments on commit e5cc6be

Please sign in to comment.