A grant can now be `read` instead of `access`: requireAppAccess lets it through for GET/HEAD/OPTIONS and answers 403 to every other method, so new write routes are covered without being marked. `read` and `access` on the same app are rejected together; user management has no read role. /tickets/admin/me and /feedback/admin/me report `readOnly`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
103 lines
3.7 KiB
TypeScript
103 lines
3.7 KiB
TypeScript
/**
|
|
* Required External Modules and Interfaces
|
|
*/
|
|
import express, {Request, Response} from 'express';
|
|
import {requireAdminAuth} from '../feedback.auth.js';
|
|
import {isReadOnly} from '../../admin/admin.schema.js';
|
|
import {sendServerError} from '../feedback.errors.js';
|
|
import {eventsAdminRouter} from './events.admin.router.js';
|
|
import {songsAdminRouter} from './songs.admin.router.js';
|
|
import {questionsAdminRouter} from './questions.admin.router.js';
|
|
import {reportsAdminRouter} from './reports.admin.router.js';
|
|
import * as ReportsAdminService from './reports.admin.service.js';
|
|
|
|
/**
|
|
* Router Definition
|
|
*/
|
|
export const adminRouter = express.Router();
|
|
|
|
// Applied once at the top of the admin router tree - every route below
|
|
// requires a valid admin session.
|
|
adminRouter.use(requireAdminAuth);
|
|
|
|
/**
|
|
* @swagger
|
|
* /feedback/admin/me:
|
|
* get:
|
|
* summary: Validate the current admin session
|
|
* description: Used by the Next.js middleware/proxy to gate /admin. Returns the authenticated admin's identity.
|
|
* tags: [feedback-admin]
|
|
* security:
|
|
* - AdminSessionCookie: []
|
|
* responses:
|
|
* 200:
|
|
* description: Success
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* type: object
|
|
* properties:
|
|
* email:
|
|
* type: string
|
|
* fullName:
|
|
* type: string
|
|
* readOnly:
|
|
* type: boolean
|
|
* description: Holds only the read role for feedback - every write answers 403.
|
|
* 401:
|
|
* description: Unauthorized
|
|
* 403:
|
|
* description: Signed in without the permission for this app, or account disabled
|
|
*/
|
|
adminRouter.get('/me', (req: Request, res: Response) => {
|
|
res.status(200).send({
|
|
email: res.locals.admin.email,
|
|
fullName: res.locals.admin.displayName,
|
|
// Lets the frontend hide what the API would refuse anyway.
|
|
readOnly: isReadOnly(res.locals.admin.permissions, 'feedback')
|
|
});
|
|
});
|
|
|
|
/**
|
|
* @swagger
|
|
* /feedback/admin/submissions/{submissionId}:
|
|
* delete:
|
|
* summary: Delete a single submission
|
|
* description: Removes the submission and everything under it (its answers, guest book entry, newsletter signup) - for removing an individual abusive or inappropriate entry. Not a bulk moderation tool.
|
|
* tags: [feedback-admin]
|
|
* security:
|
|
* - AdminSessionCookie: []
|
|
* parameters:
|
|
* - in: path
|
|
* name: submissionId
|
|
* required: true
|
|
* schema:
|
|
* type: integer
|
|
* responses:
|
|
* 204:
|
|
* description: Deleted
|
|
* 404:
|
|
* description: Unknown submission
|
|
* 401:
|
|
* description: Unauthorized
|
|
* 403:
|
|
* description: Signed in without the permission for this app, or account disabled
|
|
*/
|
|
adminRouter.delete('/submissions/:submissionId', async (req: Request, res: Response) => {
|
|
try {
|
|
const deleted = await ReportsAdminService.deleteSubmission(Number(req.params.submissionId));
|
|
if (!deleted) {
|
|
res.status(404).send({status: 'NOT_FOUND'});
|
|
return;
|
|
}
|
|
res.status(204).send();
|
|
} catch (e: any) {
|
|
sendServerError(res, e);
|
|
}
|
|
});
|
|
|
|
adminRouter.use('/events', eventsAdminRouter);
|
|
adminRouter.use('/events', reportsAdminRouter);
|
|
adminRouter.use('/songs', songsAdminRouter);
|
|
adminRouter.use('/questions', questionsAdminRouter);
|