-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #302 from dataforgoodfr/fix/D4G-295-prevent-player…
…-access-to-game-console Fix/d4g 295 prevent player access to game console
- Loading branch information
Showing
16 changed files
with
173 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/client/src/modules/router/components/AuthenticatedApp/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { AuthenticatedApp } from "./AuthenticatedApp"; |
15 changes: 15 additions & 0 deletions
15
packages/client/src/modules/router/components/RouteGuard/RouteGuard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Navigate, Outlet } from "react-router-dom"; | ||
import { useAuth } from "../../../auth/authProvider"; | ||
import { Guard } from "../../types/guard"; | ||
|
||
export { RouteGuard }; | ||
|
||
function RouteGuard({ guard }: { guard: Guard }) { | ||
const { permissions } = useAuth(); | ||
|
||
if (!guard(permissions)) { | ||
return <Navigate to="/" />; | ||
} | ||
|
||
return <Outlet />; | ||
} |
1 change: 1 addition & 0 deletions
1
packages/client/src/modules/router/components/RouteGuard/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { RouteGuard } from "./RouteGuard"; |
10 changes: 5 additions & 5 deletions
10
packages/client/src/UnauthenticatedApp.tsx → ...UnauthenticatedApp/UnauthenticatedApp.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/client/src/modules/router/components/UnauthenticatedApp/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { UnauthenticatedApp } from "./UnauthenticatedApp"; |
6 changes: 6 additions & 0 deletions
6
packages/client/src/modules/router/guards/gameConsoleGuard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Guard } from "../types/guard"; | ||
|
||
export { gameConsoleGuard }; | ||
|
||
const gameConsoleGuard: Guard = (permissions) => | ||
permissions.canAccessGameConsole; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { UserPermissions } from "../../auth/authProvider"; | ||
|
||
export type { Guard }; | ||
|
||
type Guard = (permissions: UserPermissions) => boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/server/src/modules/websocket/router/permissions/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Role, User } from "@prisma/client"; | ||
|
||
export { buildPermissions }; | ||
|
||
function buildPermissions(user: User, role: Role) { | ||
return { | ||
canUpdateGame: ["admin", "teacher"].includes(role.name), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.