permission

This commit is contained in:
Julian Krauser 2024-10-27 15:48:01 +01:00
parent bf701163d6
commit 136da08b70
2 changed files with 74 additions and 31 deletions

View file

@ -11,47 +11,88 @@ import {
deleteCalendarItem,
deleteCalendarType,
} from "../../controller/admin/calendarController";
import PermissionHelper from "../../helpers/permissionHelper";
var router = express.Router({ mergeParams: true });
router.get("/items", async (req: Request, res: Response) => {
await getAllCalendarItems(req, res);
});
router.get(
"/items",
PermissionHelper.passCheckMiddleware("read", "club", "calendar"),
async (req: Request, res: Response) => {
await getAllCalendarItems(req, res);
}
);
router.get("/item/:id", async (req: Request, res: Response) => {
await getCalendarItemById(req, res);
});
router.get(
"/item/:id",
PermissionHelper.passCheckMiddleware("read", "club", "calendar"),
async (req: Request, res: Response) => {
await getCalendarItemById(req, res);
}
);
router.get("/types", async (req: Request, res: Response) => {
await getAllCalendarTypes(req, res);
});
router.get(
"/types",
PermissionHelper.passCheckMiddleware("read", "settings", "calendar_type"),
async (req: Request, res: Response) => {
await getAllCalendarTypes(req, res);
}
);
router.get("/type/:id", async (req: Request, res: Response) => {
await getCalendarTypeById(req, res);
});
router.get(
"/type/:id",
PermissionHelper.passCheckMiddleware("read", "settings", "calendar_type"),
async (req: Request, res: Response) => {
await getCalendarTypeById(req, res);
}
);
router.post("/item", async (req: Request, res: Response) => {
await createCalendarItem(req, res);
});
router.post(
"/item",
PermissionHelper.passCheckMiddleware("create", "club", "calendar"),
async (req: Request, res: Response) => {
await createCalendarItem(req, res);
}
);
router.post("/type", async (req: Request, res: Response) => {
await createCalendarType(req, res);
});
router.post(
"/type",
PermissionHelper.passCheckMiddleware("create", "settings", "calendar_type"),
async (req: Request, res: Response) => {
await createCalendarType(req, res);
}
);
router.patch("/item/:id", async (req: Request, res: Response) => {
await updateCalendarItem(req, res);
});
router.patch(
"/item/:id",
PermissionHelper.passCheckMiddleware("update", "club", "calendar"),
async (req: Request, res: Response) => {
await updateCalendarItem(req, res);
}
);
router.patch("/type/:id", async (req: Request, res: Response) => {
await updateCalendarType(req, res);
});
router.patch(
"/type/:id",
PermissionHelper.passCheckMiddleware("update", "settings", "calendar_type"),
async (req: Request, res: Response) => {
await updateCalendarType(req, res);
}
);
router.delete("/item/:id", async (req: Request, res: Response) => {
await deleteCalendarItem(req, res);
});
router.delete(
"/item/:id",
PermissionHelper.passCheckMiddleware("delete", "club", "calendar"),
async (req: Request, res: Response) => {
await deleteCalendarItem(req, res);
}
);
router.delete("/type/:id", async (req: Request, res: Response) => {
await deleteCalendarType(req, res);
});
router.delete(
"/type/:id",
PermissionHelper.passCheckMiddleware("delete", "settings", "calendar_type"),
async (req: Request, res: Response) => {
await deleteCalendarType(req, res);
}
);
export default router;

View file

@ -10,6 +10,7 @@ export type PermissionModule =
| "executive_position"
| "communication"
| "membership_status"
| "calendar_type"
| "user"
| "role";
@ -45,12 +46,13 @@ export const permissionModules: Array<PermissionModule> = [
"executive_position",
"communication",
"membership_status",
"calendar_type",
"user",
"role",
];
export const permissionTypes: Array<PermissionType> = ["read", "create", "update", "delete"];
export const sectionsAndModules: SectionsAndModulesObject = {
club: ["member", "calendar", "newsletter", "protocoll"],
settings: ["qualification", "award", "executive_position", "communication", "membership_status"],
settings: ["qualification", "award", "executive_position", "communication", "membership_status", "calendar_type"],
user: ["user", "role"],
};