nodebb-plugin-calendar-onekite 12.0.12 → 12.0.14

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.
Files changed (2) hide show
  1. package/lib/api.js +34 -5
  2. package/package.json +1 -1
package/lib/api.js CHANGED
@@ -8,6 +8,7 @@ const nconf = require.main.require('nconf');
8
8
  const user = require.main.require('./src/user');
9
9
  const groups = require.main.require('./src/groups');
10
10
  const db = require.main.require('./src/database');
11
+ const logger = require.main.require('./src/logger');
11
12
 
12
13
  const dbLayer = require('./db');
13
14
 
@@ -173,16 +174,42 @@ async function resolveAllowedGroups(list) {
173
174
  }
174
175
 
175
176
 
177
+ async function expandGroupCandidates(rawList) {
178
+ const out = [];
179
+ for (const raw of (rawList || [])) {
180
+ const g = String(raw || '').trim();
181
+ if (!g) continue;
182
+ out.push(g);
183
+ const mapped = await resolveGroupName(g);
184
+ if (mapped && mapped !== g) out.push(mapped);
185
+ }
186
+ return [...new Set(out)];
187
+ }
188
+
189
+ async function checkAnyMembership(uid, rawList, fnLabel) {
190
+ const candidates = await expandGroupCandidates(rawList);
191
+ for (const g of candidates) {
192
+ try {
193
+ const ok = await groups.isMember(uid, g);
194
+ if (ok) return { ok: true, matched: g, candidates };
195
+ } catch (e) {
196
+ logger.warn('[calendar-onekite] auth check error', { uid, group: g, fn: fnLabel, err: String(e && e.message || e) });
197
+ }
198
+ }
199
+ return { ok: false, matched: '', candidates };
200
+ }
201
+
202
+
176
203
  function autoFormSlugForYear(year) {
177
204
  return `locations-materiel-${year}`;
178
205
  }
179
206
 
180
207
  async function canRequest(uid, settings, startTs) {
181
- if (!uid) return false;
208
+ if (!uid) return { ok: false, allowed: [], candidates: [], startTs };
182
209
 
183
210
  // Always allow administrators to create.
184
211
  try {
185
- if (await groups.isMember(uid, 'administrators')) return true;
212
+ if (await groups.isMember(uid, 'administrators')) return { ok: true, allowed: [], candidates: [], startTs };
186
213
  } catch (e) {}
187
214
 
188
215
  const year = yearFromTs(startTs);
@@ -194,9 +221,11 @@ async function canRequest(uid, settings, startTs) {
194
221
 
195
222
  const allowed = [defaultGroup, ...extraGroups].filter(Boolean);
196
223
 
197
- // Enforce membership in at least one allowed group.
198
- // Use groups.isMember so hidden groups still work.
199
- return await isMemberOfAnyGroup(uid, allowed);
224
+ const chk = await checkAnyMembership(uid, allowed, 'canRequest');
225
+ if (chk.ok) return { ok: true, allowed, candidates: chk.candidates, startTs };
226
+
227
+ logger.warn('[calendar-onekite] not-allowed in canRequest', { uid, startTs, allowed, candidates: chk.candidates, raw });
228
+ return { ok: false, allowed, candidates: chk.candidates, startTs };
200
229
  }
201
230
 
202
231
  async function canValidate(uid, settings) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-calendar-onekite",
3
- "version": "12.0.12",
3
+ "version": "12.0.14",
4
4
  "description": "FullCalendar-based equipment reservation workflow with admin approval & HelloAsso payment for NodeBB",
5
5
  "main": "library.js",
6
6
  "license": "MIT",