Skip to content
Permalink
1f7335f031
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
55 lines (46 sloc) 1.15 KB
export async function onBeforeRender(pageContext: PageContext) {
const { current_user: currentUser } = pageContext;
if (!currentUser)
return {
pageContext: {
logged_in: false,
},
status: 401,
};
const typePermissions = {
appeal: [1 << 0, 1 << 1],
gma: [1 << 5],
report: [1 << 5],
};
const typeNames: { [k: string]: string } = {
appeal: "Discord Appeals",
gma: "Game Appeals",
report: "Game Reports",
};
const { searchParams } = new URL(
pageContext.urlOriginal,
"http://localhost:8788"
);
const allowedTypes = [];
for (const [type, ints] of Object.entries(typePermissions)) {
if (ints.find((i) => currentUser.permissions & i))
allowedTypes.push({ name: typeNames[type], value: type });
}
if (!allowedTypes.length)
return {
pageContext: {
entry_types: [],
},
status: 403,
};
const includeClosed = searchParams.get("includeClosed");
const type = searchParams.get("type");
const sort = searchParams.get("sort") ?? "asc";
return {
pageContext: {
pageProps: {
entry_types: allowedTypes,
},
},
};
}