Skip to content

Commit

Permalink
feat: add demo user to api hasura roles (#3877)
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 authored Oct 30, 2024
1 parent 817ac43 commit c986c1d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions api.planx.uk/modules/auth/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const getAllowedRolesForUser = (user: User): Role[] => {
const teamRoles = user.teams.map((teamRole) => teamRole.role);
const allowedRoles: Role[] = [
"public", // Allow public access
"teamEditor", // Least privileged role for authenticated users - required for Editor access
...teamRoles, // User specific roles
];
if (user.isPlatformAdmin) allowedRoles.push("platformAdmin");
Expand All @@ -60,7 +59,15 @@ const getAllowedRolesForUser = (user: User): Role[] => {
* This is the role of least privilege for the user
*/
const getDefaultRoleForUser = (user: User): Role => {
return user.isPlatformAdmin ? "platformAdmin" : "teamEditor";
if (user.isPlatformAdmin) return "platformAdmin";

const isTeamEditor = user.teams.find((team) => team.role === "teamEditor");
if (isTeamEditor) return "teamEditor";

const isTeamViewer = user.teams.find((team) => team.role === "teamViewer");
if (isTeamViewer) return "teamViewer";

return "demoUser";
};

export const checkUserCanAccessEnv = async (
Expand Down

0 comments on commit c986c1d

Please sign in to comment.