nodebb-plugin-facebook-post 1.0.14 → 1.0.15

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/library.js +15 -3
  2. package/package.json +1 -1
package/library.js CHANGED
@@ -159,6 +159,11 @@ function parseAllowedGroupsList() {
159
159
  return s.split(',').map(v => v.trim()).filter(Boolean);
160
160
  }
161
161
 
162
+
163
+ function getUidFromReq(req) {
164
+ return req && (req.uid || (req.user && req.user.uid) || (req.session && req.session.uid));
165
+ }
166
+
162
167
  async function userIsAllowed(uid) {
163
168
  const allowed = parseAllowedGroupsList();
164
169
  if (!allowed.length) return false;
@@ -355,9 +360,16 @@ Plugin.init = async function (params) {
355
360
  try {
356
361
  await loadSettings();
357
362
  if (!settings.enabled) return res.json({ allowed: false, reason: 'disabled' });
358
-
359
- const ok = await userIsAllowed(req.uid);
360
- return res.json({ allowed: ok });
363
+ const uid = getUidFromReq(req);
364
+ if (!uid) return res.json({ allowed: false, reason: 'no_uid' });
365
+ const allowedGroups = parseAllowedGroupsList();
366
+ if (!allowedGroups.length) return res.json({ allowed: false, reason: 'no_groups_configured' });
367
+ const ok = await userIsAllowed(uid);
368
+ return res.json({ allowed: ok, reason: ok ? 'ok' : 'not_in_group' });
369
+ } catch {
370
+ return res.json({ allowed: false, reason: 'error' });
371
+ }
372
+ });
361
373
  } catch {
362
374
  return res.json({ allowed: false });
363
375
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-facebook-post",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "Auto-post new NodeBB topics to a fixed Facebook Page (text + NodeBB uploads + place id).",
5
5
  "main": "library.js",
6
6
  "dependencies": {