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>
55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
import express, {Request, Response} from 'express';
|
|
import {requireAdminAuth} from '../tickets.auth.js';
|
|
import {isReadOnly} from '../../admin/admin.schema.js';
|
|
import {vouchersAdminRouter} from './vouchers.admin.router.js';
|
|
import {redemptionsAdminRouter, voucherHistoryRouter} from './redemptions.admin.router.js';
|
|
import {eventsAdminRouter} from './events.admin.router.js';
|
|
|
|
export const adminRouter = express.Router();
|
|
|
|
// Applied once at the top of the admin router tree - every route below
|
|
// requires a valid admin session (mirrors Feedback's admin.router.ts).
|
|
adminRouter.use(requireAdminAuth);
|
|
|
|
/**
|
|
* @swagger
|
|
* /tickets/admin/me:
|
|
* get:
|
|
* summary: Validate the current admin session
|
|
* tags: [tickets-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 tickets - 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, 'tickets')
|
|
});
|
|
});
|
|
|
|
adminRouter.use('/vouchers', vouchersAdminRouter);
|
|
adminRouter.use('/vouchers', voucherHistoryRouter);
|
|
adminRouter.use('/redemptions', redemptionsAdminRouter);
|
|
adminRouter.use('/events', eventsAdminRouter);
|