Continued creating the permission system
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
import {Entity, EntityWithRoles, Role} from "@/interfaces/entity";
|
||||
import client from "@/lib/mongodb";
|
||||
import { RolePermission } from "@/resources/entityPermissions";
|
||||
import { v4 } from "uuid";
|
||||
import {getRolesByEntities, getRolesByEntity} from "./roles.be";
|
||||
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
const DEFAULT_PERMISSIONS: RolePermission[] = [
|
||||
"view_students",
|
||||
"view_teachers",
|
||||
"view_assignments",
|
||||
"view_classrooms",
|
||||
"view_entity_roles"
|
||||
]
|
||||
|
||||
export const getEntityWithRoles = async (id: string): Promise<EntityWithRoles | undefined> => {
|
||||
const entity = await getEntity(id);
|
||||
@@ -40,7 +48,7 @@ export const createEntity = async (entity: Entity) => {
|
||||
await db.collection("roles").insertOne({
|
||||
id: v4(),
|
||||
label: "Default",
|
||||
permissions: [],
|
||||
permissions: DEFAULT_PERMISSIONS,
|
||||
entityID: entity.id
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user