forked from canonical/ubuntu.com
-
Notifications
You must be signed in to change notification settings - Fork 0
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 canonical#14195 from canonical/WD-14039-restrict-d…
…ashboard-permissions feat: restrict cred dashboard permissions
- Loading branch information
Showing
10 changed files
with
173 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export const getBulkBadgesCredly = () => ["credlyIssuedBadgesBulk"]; | ||
export const postIssueCredlyBadge = () => ["credlyIssueBadge"]; | ||
export const getUserPermissionsKey = () => ["userPermissions"]; |
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 |
---|---|---|
@@ -1,37 +1,10 @@ | ||
import { createRoot } from "react-dom/client"; | ||
import * as Sentry from "@sentry/react"; | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
import { ReactQueryDevtools } from "@tanstack/react-query-devtools"; | ||
import Exams from "./routes/Exams"; | ||
import Credly from "./routes/Credly"; | ||
import Keys from "./routes/Keys"; | ||
|
||
import UpcomingExams from "./components/UpcomingExams/UpcomingExams"; | ||
import ExamResults from "./components/ExamResults/ExamResults"; | ||
import KeysList from "./components/KeysList/KeysList"; | ||
import TestTakers from "./components/TestTakers/TestTakers"; | ||
import CertificationIssued from "./components/CertificationsIssued/CertificationIssued"; | ||
import BadgeTracking from "./components/BadgeTracking/BadgeTracking"; | ||
import QueryClient from "./components/QueryClient/QueryClient"; | ||
import Routes from "./components/Routes/Routes"; | ||
import Sidebar from "./components/Sidebar/Sidebar"; | ||
import { | ||
BrowserRouter as Router, | ||
Routes, | ||
Route, | ||
Navigate, | ||
} from "react-router-dom"; | ||
|
||
const oneHour = 1000 * 60 * 60; | ||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
refetchOnWindowFocus: false, | ||
refetchOnMount: false, | ||
refetchOnReconnect: false, | ||
staleTime: oneHour, | ||
retryOnMount: false, | ||
}, | ||
}, | ||
}); | ||
import { BrowserRouter as Router } from "react-router-dom"; | ||
|
||
Sentry.init({ | ||
dsn: "https://[email protected]//13", | ||
|
@@ -43,37 +16,17 @@ function App() { | |
return ( | ||
<Router basename="/credentials/dashboard"> | ||
<Sentry.ErrorBoundary> | ||
<QueryClientProvider client={queryClient}> | ||
<QueryClient> | ||
<ReactQueryDevtools initialIsOpen={false} /> | ||
<div className="l-application"> | ||
<Sidebar /> | ||
<main className="l-main"> | ||
<section style={{ padding: "2rem" }}> | ||
<Routes> | ||
<Route path="/" element={<Navigate to="/exams/upcoming" />} /> | ||
<Route path="/exams" element={<Exams />}> | ||
<Route path="/exams/upcoming" element={<UpcomingExams />} /> | ||
<Route path="/exams/results" element={<ExamResults />} /> | ||
</Route> | ||
<Route path="/keys" element={<Keys />}> | ||
<Route path="/keys/list" element={<KeysList />} /> | ||
</Route> | ||
<Route path="/credly" element={<Credly />}> | ||
<Route | ||
path="/credly/issued" | ||
element={<CertificationIssued />} | ||
/> | ||
<Route | ||
path="/credly/badge-tracking" | ||
element={<BadgeTracking />} | ||
/> | ||
</Route> | ||
<Route path="/test-taker-stats" element={<TestTakers />} /> | ||
</Routes> | ||
<Routes /> | ||
</section> | ||
</main> | ||
</div> | ||
</QueryClientProvider> | ||
</QueryClient> | ||
</Sentry.ErrorBoundary> | ||
</Router> | ||
); | ||
|
31 changes: 31 additions & 0 deletions
31
static/js/src/advantage/credentials/dashboard/components/QueryClient/QueryClient.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,31 @@ | ||
import { | ||
QueryClient as Client, | ||
QueryClientProvider, | ||
} from "@tanstack/react-query"; | ||
|
||
const oneHour = 1000 * 60 * 60; | ||
const queryClient = new Client({ | ||
defaultOptions: { | ||
queries: { | ||
refetchOnWindowFocus: false, | ||
refetchOnMount: false, | ||
refetchOnReconnect: false, | ||
staleTime: oneHour, | ||
retryOnMount: false, | ||
}, | ||
}, | ||
}); | ||
|
||
type Props = { | ||
children: React.ReactNode; | ||
}; | ||
|
||
const QueryClient = (props: Props) => { | ||
return ( | ||
<QueryClientProvider client={queryClient}> | ||
{props.children} | ||
</QueryClientProvider> | ||
); | ||
}; | ||
|
||
export default QueryClient; |
42 changes: 42 additions & 0 deletions
42
static/js/src/advantage/credentials/dashboard/components/Routes/Routes.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,42 @@ | ||
import { Routes as RouterRoutes, Route, Navigate } from "react-router-dom"; | ||
import UpcomingExams from "../UpcomingExams/UpcomingExams"; | ||
import ExamResults from "../ExamResults/ExamResults"; | ||
import KeysList from "../KeysList/KeysList"; | ||
import TestTakers from "../TestTakers/TestTakers"; | ||
import CertificationIssued from "../CertificationsIssued/CertificationIssued"; | ||
import BadgeTracking from "../BadgeTracking/BadgeTracking"; | ||
import Exams from "../../routes/Exams"; | ||
import Credly from "../../routes/Credly"; | ||
import Keys from "../../routes/Keys"; | ||
import { getUserPermissions } from "../../api/queryFns"; | ||
import { getUserPermissionsKey } from "../../api/queryKeys"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
|
||
const Routes = () => { | ||
const { data: permissions } = useQuery({ | ||
queryKey: getUserPermissionsKey(), | ||
queryFn: getUserPermissions, | ||
}); | ||
|
||
return ( | ||
<RouterRoutes> | ||
<Route path="/" element={<Navigate to="/exams/upcoming" />} /> | ||
<Route path="/exams" element={<Exams />}> | ||
<Route path="/exams/upcoming" element={<UpcomingExams />} /> | ||
{permissions?.is_credentials_admin && ( | ||
<Route path="/exams/results" element={<ExamResults />} /> | ||
)} | ||
</Route> | ||
<Route path="/keys" element={<Keys />}> | ||
<Route path="/keys/list" element={<KeysList />} /> | ||
</Route> | ||
<Route path="/credly" element={<Credly />}> | ||
<Route path="/credly/issued" element={<CertificationIssued />} /> | ||
<Route path="/credly/badge-tracking" element={<BadgeTracking />} /> | ||
</Route> | ||
<Route path="/test-taker-stats" element={<TestTakers />} /> | ||
</RouterRoutes> | ||
); | ||
}; | ||
|
||
export default Routes; |
23 changes: 18 additions & 5 deletions
23
static/js/src/advantage/credentials/dashboard/routes/Exams.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
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