Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .devcontainer/devcontainer-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"features": {
"ghcr.io/code-fabrik/features/dokku-cli:latest": {
"version": "1.0.0",
"resolved": "ghcr.io/code-fabrik/features/dokku-cli@sha256:0b9310bde4357b589013feefe05039c60ffb68894bf60e784e9201134e93c2e3",
"integrity": "sha256:0b9310bde4357b589013feefe05039c60ffb68894bf60e784e9201134e93c2e3"
},
"ghcr.io/devcontainers/features/github-cli:1": {
"version": "1.1.0",
"resolved": "ghcr.io/devcontainers/features/github-cli@sha256:d22f50b70ed75339b4eed1ba9ecde3a1791f90e88d37936517e3bace0bbad671",
"integrity": "sha256:d22f50b70ed75339b4eed1ba9ecde3a1791f90e88d37936517e3bace0bbad671"
},
"ghcr.io/georglauterbach/dev-container-features/cache-vscode-extensions:0": {
"version": "0.4.0",
"resolved": "ghcr.io/georglauterbach/dev-container-features/cache-vscode-extensions@sha256:ed8a67c7a52a72df51086cebccc3df50eb09af3025c54ae2d0410737db81e2ba",
"integrity": "sha256:ed8a67c7a52a72df51086cebccc3df50eb09af3025c54ae2d0410737db81e2ba"
},
"ghcr.io/rails/devcontainer/features/postgres-client": {
"version": "1.1.3",
"resolved": "ghcr.io/rails/devcontainer/features/postgres-client@sha256:dc995acf6d691de8fc2dcc88fede02c55df608aa9de17cfa4b38de06903d7715",
"integrity": "sha256:dc995acf6d691de8fc2dcc88fede02c55df608aa9de17cfa4b38de06903d7715"
}
}
}
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"type": "module",
"scripts": {
"dev": "cross-env NODE_ENV=development nodemon -r tsconfig-paths/register --exec tsx ./src/server.ts",
"dev": "cross-env NODE_ENV=development nodemon -r tsconfig-paths/register --exec \"tsx --env-file=.env\" ./src/server.ts",
"build": "yarn run prisma generate && tsc --build ./tsconfig.build.json",
"start": "cross-env NODE_ENV=production node --import ./dist/src/instrumentation.js ./dist/src/server.js",
"lint": "eslint . --ignore-pattern node_modules --fix",
Expand All @@ -25,7 +25,7 @@
"@better-auth/sso": "^1.4.9",
"@prisma/adapter-pg": "^7.2.0",
"@prisma/client": "^7.2.0",
"@sentry/node": "^10.8.0",
"@sentry/node": "^10.63.0",
"better-auth": "^1.4.9",
"cors": "^2.8.5",
"cross-env": "^10.0.0",
Expand All @@ -39,7 +39,7 @@
"winston": "^3.19.0"
},
"devDependencies": {
"@sentry/cli": "^3.0.1",
"@sentry/cli": "^3.6.0",
"@types/cors": "^2.8.17",
"@types/express": "^5.0.6",
"@types/js-yaml": "^4.0.9",
Expand All @@ -51,23 +51,23 @@
"dotenv-cli": "^7.4.2",
"eslint": "^9.36.0",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.4",
"eslint-plugin-prettier": "^5.5.6",
"js-yaml": "^4.1.1",
"minimist": "^1.2.8",
"nodemon": "^3.1.10",
"prettier": "^3.6.2",
"prettier": "^3.9.4",
"prisma": "^7.2.0",
"prisma-dbml-generator": "^0.12.0",
"prisma-docs-generator": "^0.8.0",
"prisma-erd-generator": "^2.4.2",
"tsconfig-paths": "^4.2.0",
"tsx": "^4.21.0",
"typescript": "^5.9.2"
"tsx": "^4.23.0",
"typescript": "^6.0.3"
},
"engines": {
"node": "24.12.x || 24.13.x || 24.14.x"
"node": "24.12.x || 24.13.x || 24.14.x || 24.16.x || 24.18.x"
},
"optionalDependencies": {
"puppeteer": "^24.34.0"
}
}
}
58 changes: 57 additions & 1 deletion src/controllers/admins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { HTTP403Error } from '../utils/errors/Errors.js';
import prisma from '../prisma.js';
import { auth } from '../auth.js';
import { fromNodeHeaders } from 'better-auth/node';
import User, { hasElevatedAccess } from '../models/User.js';
import User, { hasElevatedAccess, Role } from '../models/User.js';

export const createAllowedAction: RequestHandler<any, any, Prisma.AllowedActionCreateInput> = async (
req,
Expand Down Expand Up @@ -130,3 +130,59 @@ export const revokeUserPassword: RequestHandler<{ id: string }> = async (req, re
}
res.status(204).send();
};

export const exportData: RequestHandler<
any,
any,
{ userIds: string; ignoredDocumentTypes?: string[] }
> = async (req, res, next) => {
if (!hasElevatedAccess(req.user?.role)) {
throw new HTTP403Error('cannot export data');
}
const { userIds, ignoredDocumentTypes } = req.body;
if (!userIds || !Array.isArray(userIds) || userIds.length === 0) {
throw new HTTP403Error('no user ids provided');
}
const excludedTypes = Array.isArray(ignoredDocumentTypes) ? ignoredDocumentTypes : [];
const requestedUsers = await prisma.user
.findMany({
where: { id: { in: userIds } }
})
.then((users) =>
users.map((u) => ({
id: u.id,
name: u.name,
firstName: u.firstName,
lastName: u.lastName,
email: u.email,
createdAt: u.createdAt,
updatedAt: u.updatedAt
}))
);
const allowedUserIds = new Set(requestedUsers.map((u) => u.id));
if (req.user.role === Role.TEACHER) {
// ensure the teacher owns a student group that the requested users are part of
const teacherGroups = await prisma.studentGroup.findMany({
where: { users: { some: { userId: req.user.id, isAdmin: true } } },
include: { users: true }
});
allowedUserIds.clear();
teacherGroups.flatMap((g) => g.users.map((u) => u.userId)).forEach((id) => allowedUserIds.add(id));
}
const promise = userIds
.filter((id) => allowedUserIds.has(id))
.map((id) => {
return prisma.document
.findMany({
where: { authorId: id, type: { notIn: excludedTypes } }
})
.then((docs) => {
return {
user: requestedUsers.find((u) => u.id === id),
documents: docs
};
});
});
const results = await Promise.all(promise);
res.status(200).send(results);
};
12 changes: 5 additions & 7 deletions src/models/Document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,11 @@ function Document(db: PrismaClient['document']) {
/**
* TODO: Should we allow creating children on documents where actor only has RO access?
*/
if (
!(
parent.document.authorId === actor.id ||
elevatedAccess ||
RWAccess.has(parent.highestPermission)
)
) {
if (!(
parent.document.authorId === actor.id ||
elevatedAccess ||
RWAccess.has(parent.highestPermission)
)) {
throw new HTTP403Error('Insufficient access permission');
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/routes/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
allowedActions,
createAllowedAction,
destroyAllowedAction,
exportData,
linkUserPassword,
revokeUserPassword
} from '../controllers/admins.js';
Expand Down Expand Up @@ -129,6 +130,7 @@ router.post('/admin/allowedActions', createAllowedAction);
router.delete('/admin/allowedActions/:id', destroyAllowedAction);
router.post('/admin/users/:id/linkUserPassword', linkUserPassword);
router.post('/admin/users/:id/revokeUserPassword', revokeUserPassword);
router.post('/admin/export', exportData);

router.get('/cms/settings', findCmsSettings);
router.put('/cms/settings', updateCmsSettings);
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"moduleResolution": "nodenext",
// "allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"ignoreDeprecations": "6.0",
"baseUrl": ".",
"outDir": "dist",
"sourceMap": true,
Expand Down
Loading
Loading