nodebb-plugin-calendar-onekite 11.1.1 → 11.1.3
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 +44 -16
- package/package.json +1 -1
- package/public/admin.js +6 -6
- package/public/client.js +3 -3
package/library.js
CHANGED
|
@@ -8,22 +8,50 @@ 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
|
+
// NodeBB v4 uses the v3 API namespace. We register under /api/v3.
|
|
31
|
+
routeHelpers.setupApiRoute(router, 'get', '/api/v3/calendar-onekite/events', [], api.getEvents);
|
|
32
|
+
routeHelpers.setupApiRoute(router, 'get', '/api/v3/calendar-onekite/items', [], api.getItems);
|
|
33
|
+
|
|
34
|
+
// Authenticated API
|
|
35
|
+
// req.uid is provided by exposeUid; ensureLoggedIn blocks unauthenticated users.
|
|
36
|
+
routeHelpers.setupApiRoute(router, 'post', '/api/v3/calendar-onekite/reservations', mw([exposeUid, ensureLoggedIn]), api.createReservation);
|
|
37
|
+
|
|
38
|
+
// Admin ACP page
|
|
39
|
+
routeHelpers.setupAdminPageRoute(router, '/admin/plugins/calendar-onekite', [], admin.renderAdmin);
|
|
40
|
+
|
|
41
|
+
// Admin API (under /api/v3/admin)
|
|
42
|
+
const adminMiddlewares = mw([
|
|
43
|
+
exposeUid,
|
|
44
|
+
ensureLoggedIn,
|
|
45
|
+
middleware.admin && middleware.admin.checkPrivileges,
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
// Note: setupApiRoute in NodeBB expects the method first (get/post/put/del), then the full path.
|
|
49
|
+
routeHelpers.setupApiRoute(router, 'get', '/api/v3/admin/plugins/calendar-onekite', adminMiddlewares, admin.getSettings);
|
|
50
|
+
routeHelpers.setupApiRoute(router, 'post', '/api/v3/admin/plugins/calendar-onekite', adminMiddlewares, admin.saveSettings);
|
|
51
|
+
routeHelpers.setupApiRoute(router, 'get', '/api/v3/admin/plugins/calendar-onekite/pending', adminMiddlewares, admin.listPending);
|
|
52
|
+
routeHelpers.setupApiRoute(router, 'put', '/api/v3/admin/plugins/calendar-onekite/reservations/:rid/approve', adminMiddlewares, admin.approveReservation);
|
|
53
|
+
routeHelpers.setupApiRoute(router, 'put', '/api/v3/admin/plugins/calendar-onekite/reservations/:rid/refuse', adminMiddlewares, admin.refuseReservation);
|
|
54
|
+
routeHelpers.setupApiRoute(router, 'post', '/api/v3/admin/plugins/calendar-onekite/purge', adminMiddlewares, admin.purgeByYear);
|
|
27
55
|
|
|
28
56
|
// Background cleanup for expired "pending" reservations
|
|
29
57
|
scheduler.start();
|
package/package.json
CHANGED
package/public/admin.js
CHANGED
|
@@ -50,7 +50,7 @@ define('calendar-onekite-admin', function () {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
async function loadPending() {
|
|
53
|
-
const resp = await $.get('/api/admin/plugins/calendar-onekite/pending');
|
|
53
|
+
const resp = await $.get('/api/v3/admin/plugins/calendar-onekite/pending');
|
|
54
54
|
return resp.pending || [];
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -62,7 +62,7 @@ define('calendar-onekite-admin', function () {
|
|
|
62
62
|
const rid = $(this).closest('[data-rid]').data('rid');
|
|
63
63
|
try {
|
|
64
64
|
await $.ajax({
|
|
65
|
-
url: `/api/admin/plugins/calendar-onekite/reservations/${rid}/approve`,
|
|
65
|
+
url: `/api/v3/admin/plugins/calendar-onekite/reservations/${rid}/approve`,
|
|
66
66
|
method: 'PUT',
|
|
67
67
|
});
|
|
68
68
|
app.alertSuccess('Réservation validée, email de paiement envoyé.');
|
|
@@ -77,7 +77,7 @@ define('calendar-onekite-admin', function () {
|
|
|
77
77
|
const note = prompt('Motif (optionnel) :') || '';
|
|
78
78
|
try {
|
|
79
79
|
await $.ajax({
|
|
80
|
-
url: `/api/admin/plugins/calendar-onekite/reservations/${rid}/refuse`,
|
|
80
|
+
url: `/api/v3/admin/plugins/calendar-onekite/reservations/${rid}/refuse`,
|
|
81
81
|
method: 'PUT',
|
|
82
82
|
data: { note },
|
|
83
83
|
});
|
|
@@ -100,7 +100,7 @@ define('calendar-onekite-admin', function () {
|
|
|
100
100
|
const $form = $('#calendar-onekite-settings');
|
|
101
101
|
const $saved = $('#calendar-onekite-saved');
|
|
102
102
|
|
|
103
|
-
const resp = await $.get('/api/admin/plugins/calendar-onekite');
|
|
103
|
+
const resp = await $.get('/api/v3/admin/plugins/calendar-onekite');
|
|
104
104
|
fillForm($form, resp.settings || {});
|
|
105
105
|
|
|
106
106
|
$form.on('submit', async function (e) {
|
|
@@ -110,7 +110,7 @@ define('calendar-onekite-admin', function () {
|
|
|
110
110
|
data.showUsernamesOnCalendar = $('#showUsernamesOnCalendar').prop('checked');
|
|
111
111
|
|
|
112
112
|
try {
|
|
113
|
-
await $.post('/api/admin/plugins/calendar-onekite', data);
|
|
113
|
+
await $.post('/api/v3/admin/plugins/calendar-onekite', data);
|
|
114
114
|
$saved.removeClass('d-none');
|
|
115
115
|
setTimeout(() => $saved.addClass('d-none'), 2000);
|
|
116
116
|
app.alertSuccess('Paramètres enregistrés.');
|
|
@@ -123,7 +123,7 @@ define('calendar-onekite-admin', function () {
|
|
|
123
123
|
e.preventDefault();
|
|
124
124
|
const year = $(this).find('[name="year"]').val();
|
|
125
125
|
try {
|
|
126
|
-
const resp2 = await $.post('/api/admin/plugins/calendar-onekite/purge', { year });
|
|
126
|
+
const resp2 = await $.post('/api/v3/admin/plugins/calendar-onekite/purge', { year });
|
|
127
127
|
$('#calendar-onekite-purge-result').html(`<div class="alert alert-success">Année ${resp2.result.year}: ${resp2.result.purged} réservation(s) supprimée(s).</div>`);
|
|
128
128
|
} catch (err) {
|
|
129
129
|
$('#calendar-onekite-purge-result').html(`<div class="alert alert-danger">${(err.responseJSON && err.responseJSON.error) || 'Erreur'}</div>`);
|
package/public/client.js
CHANGED
|
@@ -7,7 +7,7 @@ define('calendar-onekite', function () {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
async function fetchItems() {
|
|
10
|
-
return await $.get('/api/calendar-onekite/items');
|
|
10
|
+
return await $.get('/api/v3/calendar-onekite/items');
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
function init(opts) {
|
|
@@ -24,7 +24,7 @@ define('calendar-onekite', function () {
|
|
|
24
24
|
right: 'dayGridMonth,timeGridWeek,timeGridDay',
|
|
25
25
|
},
|
|
26
26
|
events: function (info, success, failure) {
|
|
27
|
-
$.get('/api/calendar-onekite/events', { start: info.startStr, end: info.endStr })
|
|
27
|
+
$.get('/api/v3/calendar-onekite/events', { start: info.startStr, end: info.endStr })
|
|
28
28
|
.done(success)
|
|
29
29
|
.fail(function (xhr) {
|
|
30
30
|
failure(xhr);
|
|
@@ -120,7 +120,7 @@ define('calendar-onekite', function () {
|
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
return $.ajax({
|
|
123
|
-
url: '/api/calendar-onekite/reservations',
|
|
123
|
+
url: '/api/v3/calendar-onekite/reservations',
|
|
124
124
|
method: 'POST',
|
|
125
125
|
data: payload,
|
|
126
126
|
}).done(function () {
|