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.
- package/library.js +15 -3
- 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
|
-
|
|
360
|
-
|
|
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