892e47d017
## Multi-Administrator System
- Add role-based access control (RBAC) with predefined roles (Super Admin, Admin, Editor, Viewer)
- Add granular permissions system for all admin operations
- Add admin user management page with invite functionality
- Add email invitation system for new administrators
- Add permission middleware protecting all admin routes
- Add PermissionGate component for frontend permission checks
- Track event creator (created_by) for audit purposes
## Backup & Restore Fixes
- Fix S3 backup: endpoint URL handling, manifest loading, field name compatibility
- Fix S3 restore: add list-backups endpoint, transform S3 config from frontend format
- Fix PostgreSQL compatibility: add .returning('id') for insert operations
- Fix disk space check: use df command, handle unknown space gracefully
- Fix dry-run validation to not block on warnings
- Fix req.user → req.admin in restore routes
## Database Migrations
- 054: Add roles table with predefined roles
- 055: Add permissions table
- 056: Add role_permissions junction table
- 057: Add role_id to admin_users
- 058: Add admin_invitations table
- 059: Add admin email templates
- 060: Add created_by to events table
## Other Improvements
- Update .gitignore to exclude planning docs and local backup directory
- Remove SQLite database file from tracking
- Add i18n translations for user management (EN/DE)
84 lines
2.5 KiB
JavaScript
84 lines
2.5 KiB
JavaScript
const express = require('express');
|
|
const { body, validationResult } = require('express-validator');
|
|
const { db, logActivity } = require('../database/db');
|
|
const { adminAuth } = require('../middleware/auth');
|
|
const { requirePermission } = require('../middleware/permissions');
|
|
const router = express.Router();
|
|
|
|
// Get all CMS pages
|
|
router.get('/pages', adminAuth, requirePermission('cms.view'), async (req, res) => {
|
|
try {
|
|
const pages = await db('cms_pages').select('*').orderBy('slug', 'asc');
|
|
res.json(pages);
|
|
} catch (error) {
|
|
console.error('Error fetching CMS pages:', error);
|
|
res.status(500).json({ error: 'Failed to fetch pages' });
|
|
}
|
|
});
|
|
|
|
// Get a single CMS page
|
|
router.get('/pages/:slug', adminAuth, requirePermission('cms.view'), async (req, res) => {
|
|
try {
|
|
const { slug } = req.params;
|
|
const page = await db('cms_pages').where('slug', slug).first();
|
|
|
|
if (!page) {
|
|
return res.status(404).json({ error: 'Page not found' });
|
|
}
|
|
|
|
res.json(page);
|
|
} catch (error) {
|
|
console.error('Error fetching CMS page:', error);
|
|
res.status(500).json({ error: 'Failed to fetch page' });
|
|
}
|
|
});
|
|
|
|
// Update a CMS page
|
|
router.put('/pages/:slug', adminAuth, requirePermission('cms.edit'), [
|
|
body('title_en').optional().isString(),
|
|
body('title_de').optional().isString(),
|
|
body('content_en').optional().isString(),
|
|
body('content_de').optional().isString()
|
|
], async (req, res) => {
|
|
try {
|
|
const errors = validationResult(req);
|
|
if (!errors.isEmpty()) {
|
|
return res.status(400).json({ errors: errors.array() });
|
|
}
|
|
|
|
const { slug } = req.params;
|
|
const { title_en, title_de, content_en, content_de } = req.body;
|
|
|
|
const page = await db('cms_pages').where('slug', slug).first();
|
|
if (!page) {
|
|
return res.status(404).json({ error: 'Page not found' });
|
|
}
|
|
|
|
// Update the page
|
|
await db('cms_pages')
|
|
.where('slug', slug)
|
|
.update({
|
|
title_en,
|
|
title_de,
|
|
content_en,
|
|
content_de,
|
|
updated_at: new Date()
|
|
});
|
|
|
|
const updated = await db('cms_pages').where('slug', slug).first();
|
|
|
|
// Log activity
|
|
await logActivity('cms_page_updated',
|
|
{ page: slug },
|
|
null,
|
|
{ type: 'admin', id: req.admin.id, name: req.admin.username }
|
|
);
|
|
|
|
res.json(updated);
|
|
} catch (error) {
|
|
console.error('Error updating CMS page:', error);
|
|
res.status(500).json({ error: 'Failed to update page' });
|
|
}
|
|
});
|
|
|
|
module.exports = router; |