mirror of
https://github.com/barthuijgen/factorio-sites.git
synced 2025-03-17 21:17:57 +02:00
Added moderator functionality
This commit is contained in:
parent
6af3698389
commit
b88ded4615
@ -196,6 +196,19 @@ export const BlueprintSubPage: React.FC<BlueprintProps> = ({
|
||||
>
|
||||
{string && data && <BlueprintData string={string} data={data} />}
|
||||
</Panel>
|
||||
|
||||
{(auth?.role === "admin" || auth?.role === "moderator") && (
|
||||
<Panel
|
||||
gridColumn={chakraResponsive({ mobile: "1", desktop: "1 / span 4" })}
|
||||
title="Moderation"
|
||||
>
|
||||
<Link href={`/user/blueprint/${blueprint_page.id}`} passHref>
|
||||
<a>
|
||||
<Button>Edit</Button>
|
||||
</a>
|
||||
</Link>
|
||||
</Panel>
|
||||
)}
|
||||
</StyledBlueptintPage>
|
||||
);
|
||||
};
|
||||
|
@ -287,6 +287,19 @@ export const BlueprintBookSubPage: React.FC<BlueprintBookSubPageProps> = ({
|
||||
/>
|
||||
)}
|
||||
</Panel>
|
||||
|
||||
{(auth?.role === "admin" || auth?.role === "moderator") && (
|
||||
<Panel
|
||||
gridColumn={chakraResponsive({ mobile: "1", desktop: "1 / span 4" })}
|
||||
title="Moderation"
|
||||
>
|
||||
<Link href={`/user/blueprint/${blueprint_page.id}`} passHref>
|
||||
<a>
|
||||
<Button>Edit</Button>
|
||||
</a>
|
||||
</Link>
|
||||
</Panel>
|
||||
)}
|
||||
</StyledBlueptintPage>
|
||||
);
|
||||
};
|
||||
|
@ -21,7 +21,9 @@ const handler = apiHandler(async (req, res, { session }) => {
|
||||
if (!existing) {
|
||||
return res.status(404).json({ status: "Blueprint not found" });
|
||||
}
|
||||
if (existing?.user_id !== session.user_id) {
|
||||
|
||||
const isModerator = session.user.role === "admin" || session.user.role === "moderator";
|
||||
if (existing?.user_id !== session.user_id && !isModerator) {
|
||||
return res.status(403).json({ status: "Unauthorised" });
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ const handler = apiHandler(async (_, res, { session }) => {
|
||||
username: session.user.username,
|
||||
email: session.user.email,
|
||||
steam_id: session.user.steam_id,
|
||||
role: session.user.role
|
||||
} as AuthContextProps,
|
||||
});
|
||||
}
|
||||
|
@ -238,7 +238,9 @@ export const getServerSideProps = pageHandler(async (context, { session, redirec
|
||||
|
||||
let selected!: UserBlueprintProps["selected"];
|
||||
|
||||
if (blueprintPage.user_id !== session.user_id) {
|
||||
const isModerator = session.user.role === "admin" || session.user.role === "moderator";
|
||||
|
||||
if (blueprintPage.user_id !== session.user_id && !isModerator) {
|
||||
return redirect("/");
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ export type AuthContextProps = {
|
||||
username: string;
|
||||
email?: string;
|
||||
steam_id?: string;
|
||||
role: "user" | "moderator" | "admin";
|
||||
} | null;
|
||||
|
||||
export const AuthContext = React.createContext<AuthContextProps>(null);
|
||||
|
@ -93,7 +93,7 @@ export const joinValidations = <T>(...validations: Array<(value: T) => string |
|
||||
export const validateBlueprintString = (value: string) => {
|
||||
if (value) {
|
||||
const parsed = parseBlueprintStringClient(value);
|
||||
console.log({ parsed });
|
||||
// console.log({ parsed });
|
||||
|
||||
if (!parsed) {
|
||||
return "Not recognised as a blueprint string";
|
||||
|
Loading…
x
Reference in New Issue
Block a user