Skip to content

Commit

Permalink
fix: permission checks for updating or viewing projects in orgs
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Jul 22, 2024
1 parent 9d821a6 commit de8dbfd
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions services/api/src/resources/project/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,44 @@ export const Helpers = (sqlClientPool: Pool) => {
// then falling through to the default project view for general users
const rows = await query(sqlClientPool, Sql.selectProject(pid));
const project = rows[0];
if (project.organization != null) {
try {
try {
// finally check the user view:project permission
await hasPermission('project', 'view', {
project: project.id
});
return
} catch (err) {
if (project.organization != null) {
await hasPermission('organization', 'viewProject', {
organization: project.organization
});
// if the organization owner has permission to view project, return
return
} catch (err) {
// otherwise fall through to project view permission check
}
throw err
}
// finally check the user view:project permission
await hasPermission('project', 'view', {
project: project.id
});
}
}
const checkOrgProjectUpdatePermission = async (hasPermission, pid) => {
// helper checks the permission to updateProject:organization
// or the update:project permission
const rows = await query(sqlClientPool, Sql.selectProject(pid));
const project = rows[0];
if (project.organization != null) {
// if the project is in an organization, only the organization owner should be able to do this
await hasPermission('organization', 'updateProject', {
organization: project.organization
});
} else {
// if not in a project, follow the standard rbac
try {
// finally check the user update:project permission
await hasPermission('project', 'update', {
project: project.id
});
return
} catch (err) {
if (project.organization != null) {
await hasPermission('organization', 'updateProject', {
organization: project.organization
});
// if the organization owner has permission to update project, return
return
}
throw err
}
}

Expand Down

0 comments on commit de8dbfd

Please sign in to comment.