Merge, do not push to develop yet, Listening.tsx is not updated
This commit is contained in:
@@ -1,25 +1,13 @@
|
||||
import {CEFR_STEPS} from "@/resources/grading";
|
||||
import {getUserCorporate} from "@/utils/groups.be";
|
||||
import {User} from "@/interfaces/user";
|
||||
import {Grading} from "@/interfaces";
|
||||
import { CEFR_STEPS } from "@/resources/grading";
|
||||
import { getUserCorporate } from "@/utils/groups.be";
|
||||
import { User } from "@/interfaces/user";
|
||||
import { Grading } from "@/interfaces";
|
||||
import client from "@/lib/mongodb";
|
||||
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
export const getGradingSystem = async (user: User): Promise<Grading> => {
|
||||
const grading = await db.collection("grading").findOne<Grading>({id: user.id});
|
||||
if (!!grading) return grading;
|
||||
|
||||
if (user.type !== "teacher" && user.type !== "student") return {steps: CEFR_STEPS, user: user.id};
|
||||
|
||||
const corporate = await getUserCorporate(user.id);
|
||||
if (!corporate) return {steps: CEFR_STEPS, user: user.id};
|
||||
|
||||
const corporateSnapshot = await db.collection("grading").findOne<Grading>({id: corporate.id});
|
||||
if (!!corporateSnapshot) return corporateSnapshot;
|
||||
|
||||
return {steps: CEFR_STEPS, user: user.id};
|
||||
};
|
||||
|
||||
export const getGradingSystemByEntity = async (id: string) =>
|
||||
(await db.collection("grading").findOne<Grading>({entity: id})) || {steps: CEFR_STEPS, user: ""};
|
||||
(await db.collection("grading").findOne<Grading>({ entity: id })) || { steps: CEFR_STEPS, entity: "" };
|
||||
|
||||
export const getGradingSystemByEntities = async (ids: string[]) =>
|
||||
await db.collection("grading").find<Grading>({ entity: { $in: ids } }).toArray();
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { EntityWithRoles, Role } from "@/interfaces/entity";
|
||||
import {PermissionType} from "@/interfaces/permissions";
|
||||
import {User, Type, userTypes} from "@/interfaces/user";
|
||||
import { PermissionType } from "@/interfaces/permissions";
|
||||
import { User, Type, userTypes } from "@/interfaces/user";
|
||||
import { RolePermission } from "@/resources/entityPermissions";
|
||||
import axios from "axios";
|
||||
import { findBy, mapBy } from ".";
|
||||
import { isAdmin } from "./users";
|
||||
|
||||
export function checkAccess(user: User, types: Type[], permissions?: PermissionType[], permission?: PermissionType) {
|
||||
if (!user) {
|
||||
@@ -50,7 +51,7 @@ export function findAllowedEntitiesSomePermissions(user: User, entities: EntityW
|
||||
}
|
||||
|
||||
export function doesEntityAllow(user: User, entity: EntityWithRoles, permission: RolePermission) {
|
||||
if (["admin", "developer"].includes(user?.type)) return true
|
||||
if (isAdmin(user)) return true
|
||||
|
||||
const userEntity = findBy(user.entities, 'id', entity?.id)
|
||||
if (!userEntity) return false
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Session} from "@/hooks/useSessions";
|
||||
import { Session } from "@/hooks/useSessions";
|
||||
import client from "@/lib/mongodb";
|
||||
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
@@ -6,11 +6,16 @@ const db = client.db(process.env.MONGODB_DB);
|
||||
export const getSessionsByUser = async (id: string, limit = 0, filter = {}) =>
|
||||
await db
|
||||
.collection("sessions")
|
||||
.find<Session>({user: id, ...filter})
|
||||
.find<Session>({ user: id, ...filter })
|
||||
.limit(limit || 0)
|
||||
.toArray();
|
||||
|
||||
export const getSessionByAssignment = async (assignmentID: string) =>
|
||||
await db
|
||||
.collection("sessions")
|
||||
.findOne<Session>({"assignment.id": assignmentID})
|
||||
.collection("sessions")
|
||||
.findOne<Session>({ "assignment.id": assignmentID })
|
||||
|
||||
export const getSessionsByAssignments = async (assignmentIDs: string[]) =>
|
||||
await db
|
||||
.collection("sessions")
|
||||
.find<Session>({ "assignment.id": { $in: assignmentIDs } }).toArray()
|
||||
|
||||
Reference in New Issue
Block a user