nodebb-plugin-calendar-onekite 11.1.1 → 11.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/library.js +43 -16
- package/package.json +1 -1
package/library.js
CHANGED
|
@@ -8,22 +8,49 @@ const scheduler = require('./lib/scheduler');
|
|
|
8
8
|
const Plugin = {};
|
|
9
9
|
|
|
10
10
|
Plugin.init = async function (params) {
|
|
11
|
-
const { router } = params;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
11
|
+
const { router, middleware } = params;
|
|
12
|
+
const routeHelpers = require.main.require('./src/routes/helpers');
|
|
13
|
+
|
|
14
|
+
// Some middleware names changed across NodeBB versions.
|
|
15
|
+
// Use what exists so we don't register undefined handlers (Express throws).
|
|
16
|
+
const exposeUid = middleware.exposeUid;
|
|
17
|
+
const ensureLoggedIn = middleware.ensureLoggedIn || middleware.authenticate || function (req, res, next) {
|
|
18
|
+
if (req.uid) return next();
|
|
19
|
+
res.status(401).json({ error: 'Unauthorized' });
|
|
20
|
+
};
|
|
21
|
+
const buildHeader = middleware.buildHeader;
|
|
22
|
+
|
|
23
|
+
const fn = (f) => (typeof f === 'function' ? f : null);
|
|
24
|
+
const mw = (arr) => arr.map(fn).filter(Boolean);
|
|
25
|
+
|
|
26
|
+
// Page route (calendar UI)
|
|
27
|
+
routeHelpers.setupPageRoute(router, '/calendar', mw([buildHeader]), controllers.renderCalendar);
|
|
28
|
+
|
|
29
|
+
// Public API (read-only)
|
|
30
|
+
routeHelpers.setupApiRoute(router, '/calendar-onekite/events', [], api.getEvents);
|
|
31
|
+
routeHelpers.setupApiRoute(router, '/calendar-onekite/items', [], api.getItems);
|
|
32
|
+
|
|
33
|
+
// Authenticated API
|
|
34
|
+
// req.uid is provided by exposeUid; ensureLoggedIn blocks unauthenticated users.
|
|
35
|
+
routeHelpers.setupApiRoute(router, '/calendar-onekite/reservations', mw([exposeUid, ensureLoggedIn]), api.createReservation, 'post');
|
|
36
|
+
|
|
37
|
+
// Admin ACP page
|
|
38
|
+
routeHelpers.setupAdminPageRoute(router, '/admin/plugins/calendar-onekite', [], admin.renderAdmin);
|
|
39
|
+
|
|
40
|
+
// Admin API (under /api)
|
|
41
|
+
const adminMiddlewares = mw([
|
|
42
|
+
exposeUid,
|
|
43
|
+
ensureLoggedIn,
|
|
44
|
+
middleware.admin && middleware.admin.checkPrivileges,
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
// setupApiRoute automatically prefixes with /api, so don't include it here.
|
|
48
|
+
routeHelpers.setupApiRoute(router, '/admin/plugins/calendar-onekite', adminMiddlewares, admin.getSettings);
|
|
49
|
+
routeHelpers.setupApiRoute(router, '/admin/plugins/calendar-onekite', adminMiddlewares, admin.saveSettings, 'post');
|
|
50
|
+
routeHelpers.setupApiRoute(router, '/admin/plugins/calendar-onekite/pending', adminMiddlewares, admin.listPending);
|
|
51
|
+
routeHelpers.setupApiRoute(router, '/admin/plugins/calendar-onekite/reservations/:rid/approve', adminMiddlewares, admin.approveReservation, 'put');
|
|
52
|
+
routeHelpers.setupApiRoute(router, '/admin/plugins/calendar-onekite/reservations/:rid/refuse', adminMiddlewares, admin.refuseReservation, 'put');
|
|
53
|
+
routeHelpers.setupApiRoute(router, '/admin/plugins/calendar-onekite/purge', adminMiddlewares, admin.purgeByYear, 'post');
|
|
27
54
|
|
|
28
55
|
// Background cleanup for expired "pending" reservations
|
|
29
56
|
scheduler.start();
|