nodebb-plugin-session-sharing 7.2.0 → 7.2.1

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.
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ import serverConfig from 'eslint-config-nodebb';
4
+ import publicConfig from 'eslint-config-nodebb/public';
5
+
6
+ export default [
7
+ ...publicConfig,
8
+ ...serverConfig,
9
+ ];
10
+
package/library.js CHANGED
@@ -14,6 +14,7 @@ const groups = require.main.require('./src/groups');
14
14
  const SocketPlugins = require.main.require('./src/socket.io/plugins');
15
15
  const db = require.main.require('./src/database');
16
16
  const plugins = require.main.require('./src/plugins');
17
+ const routeHelpers = require.main.require('./src/routes/helpers');
17
18
 
18
19
  const controllers = require('./lib/controllers');
19
20
  const nbbAuthController = require.main.require('./src/controllers/authentication');
@@ -61,11 +62,9 @@ payloadKeys.forEach(function (key) {
61
62
  plugin.defaults = Object.freeze({ ...plugin.settings });
62
63
 
63
64
  plugin.init = async (params) => {
64
- var router = params.router;
65
- var hostMiddleware = params.middleware;
65
+ const { router } = params;
66
66
 
67
- router.get('/admin/plugins/session-sharing', hostMiddleware.admin.buildHeader, controllers.renderAdminPage);
68
- router.get('/api/admin/plugins/session-sharing', controllers.renderAdminPage);
67
+ routeHelpers.setupAdminPageRoute(router, '/plugins/session-sharing', controllers.renderAdminPage);
69
68
 
70
69
  router.get('/api/session-sharing/lookup', controllers.retrieveUser);
71
70
  router.post('/api/session-sharing/user', controllers.process);
@@ -101,7 +100,9 @@ SocketPlugins.sessionSharing.showUserIds = async (socket, data) => {
101
100
  throw new Error('no-uids-supplied');
102
101
  }
103
102
 
104
- return Promise.all(uids.map(async (uid) => db.getSortedSetRangeByScore(plugin.settings.name + ':uid', 0, -1, uid, uid)));
103
+ return Promise.all(
104
+ uids.map(async uid => db.getSortedSetRangeByScore(plugin.settings.name + ':uid', 0, -1, uid, uid))
105
+ );
105
106
  };
106
107
 
107
108
  SocketPlugins.sessionSharing.findUserByRemoteId = async (socket, data) => {
@@ -115,7 +116,7 @@ SocketPlugins.sessionSharing.findUserByRemoteId = async (socket, data) => {
115
116
  /* End Websocket Listeners */
116
117
 
117
118
  /*
118
- * Given a remoteId, show user data
119
+ * Given a remoteId, show user data
119
120
  */
120
121
  plugin.getUser = async (remoteId) => {
121
122
  const uid = await db.sortedSetScore(plugin.settings.name + ':uid', remoteId);
@@ -151,7 +152,7 @@ plugin.normalizePayload = async (payload) => {
151
152
 
152
153
  payloadKeys.forEach(function (key) {
153
154
  const propName = plugin.settings['payload:' + key];
154
- if (payload[propName]) {
155
+ if (payload.hasOwnProperty(propName)) {
155
156
  userData[key] = payload[propName];
156
157
  }
157
158
  });
@@ -160,8 +161,10 @@ plugin.normalizePayload = async (payload) => {
160
161
  winston.warn('[session-sharing] No user id was given in payload');
161
162
  throw new Error('payload-invalid');
162
163
  }
163
-
164
- userData.fullname = (userData.fullname || [userData.firstName, userData.lastName].join(' ')).trim();
164
+ const setFullname = userData.hasOwnProperty('fullname') || userData.hasOwnProperty('firstName') || userData.hasOwnProperty('lastName');
165
+ if (setFullname) {
166
+ userData.fullname = (userData.fullname || [userData.firstName, userData.lastName].join(' ')).trim();
167
+ }
165
168
 
166
169
  if (!userData.username) {
167
170
  userData.username = userData.fullname;
@@ -313,12 +316,12 @@ plugin.updateUserGroups = async (uid, userData) => {
313
316
  // Retrieve user groups
314
317
  let [userGroups] = await groups.getUserGroupsFromSet('groups:createtime', [uid]);
315
318
  // Normalize user group data to just group names
316
- userGroups = userGroups.map((groupObj) => groupObj.name);
319
+ userGroups = userGroups.map(groupObj => groupObj.name);
317
320
 
318
321
  // Build join and leave arrays
319
- let join = userData.groups.filter((name) => !userGroups.includes(name));
322
+ let join = userData.groups.filter(name => !userGroups.includes(name));
320
323
  if (plugin.settings.syncGroupList === 'on') {
321
- join = join.filter((group) => plugin.settings.syncGroups.includes(group));
324
+ join = join.filter(group => plugin.settings.syncGroups.includes(group));
322
325
  }
323
326
 
324
327
  let leave = userGroups.filter((name) => {
@@ -330,7 +333,7 @@ plugin.updateUserGroups = async (uid, userData) => {
330
333
  return !userData.groups.includes(name);
331
334
  });
332
335
  if (plugin.settings.syncGroupList === 'on') {
333
- leave = leave.filter((group) => plugin.settings.syncGroups.includes(group));
336
+ leave = leave.filter(group => plugin.settings.syncGroups.includes(group));
334
337
  }
335
338
 
336
339
  await executeJoinLeave(uid, join, leave);
@@ -343,14 +346,14 @@ async function executeJoinLeave(uid, join, leave) {
343
346
  return;
344
347
  }
345
348
 
346
- await Promise.all(join.map((name) => groups.join(name, uid)));
349
+ await Promise.all(join.map(name => groups.join(name, uid)));
347
350
  })(),
348
351
  (async () => {
349
352
  if (plugin.settings.syncGroupLeave !== 'on') {
350
353
  return;
351
354
  }
352
355
 
353
- await Promise.all(leave.map((name) => groups.leave(name, uid)));
356
+ await Promise.all(leave.map(name => groups.leave(name, uid)));
354
357
  })(),
355
358
  ]);
356
359
  }
@@ -395,13 +398,13 @@ plugin.addMiddleware = async function ({ req, res }) {
395
398
  const hasLoginLock = req.session.hasOwnProperty('loginLock');
396
399
 
397
400
  if (
398
- !plugin.ready || // plugin not ready
399
- (plugin.settings.behaviour === 'trust' && hasSession) || // user logged in + "trust" behaviour
401
+ !plugin.ready || // plugin not ready
402
+ (plugin.settings.behaviour === 'trust' && hasSession) || // user logged in + "trust" behaviour
400
403
  ((plugin.settings.behaviour === 'revalidate' || plugin.settings.behaviour === 'update') && hasLoginLock) ||
401
- req.originalUrl.startsWith(nconf.get('relative_path') + '/api') // api routes
404
+ req.originalUrl.startsWith(nconf.get('relative_path') + '/api') // api routes
402
405
  ) {
403
406
  // Let requests through under "update" or "revalidate" behaviour only if they're logging in for the first time
404
- delete req.session.loginLock; // remove login lock for "update" or "revalidate" logins
407
+ delete req.session.loginLock; // remove login lock for "update" or "revalidate" logins
405
408
 
406
409
  return;
407
410
  }
@@ -429,7 +432,9 @@ plugin.addMiddleware = async function ({ req, res }) {
429
432
  return handleGuest.call(null, req, res);
430
433
  }
431
434
 
432
- if (Object.keys(req.cookies).length && req.cookies.hasOwnProperty(plugin.settings.cookieName) && req.cookies[plugin.settings.cookieName].length) {
435
+ if (Object.keys(req.cookies).length &&
436
+ req.cookies.hasOwnProperty(plugin.settings.cookieName) &&
437
+ req.cookies[plugin.settings.cookieName].length) {
433
438
  try {
434
439
  const uid = await plugin.process(req.cookies[plugin.settings.cookieName]);
435
440
  if (uid === req.uid) {
@@ -448,16 +453,16 @@ plugin.addMiddleware = async function ({ req, res }) {
448
453
  let handleAsGuest = false;
449
454
 
450
455
  switch (error.message) {
451
- case 'payload-invalid':
452
- winston.warn('[session-sharing] The passed-in payload was invalid and could not be processed');
453
- break;
454
- case 'no-match':
455
- winston.info('[session-sharing] Payload valid, but local account not found. Assuming guest.');
456
- handleAsGuest = true;
457
- break;
458
- default:
459
- winston.warn('[session-sharing] Error encountered while parsing token: ' + error.message);
460
- break;
456
+ case 'payload-invalid':
457
+ winston.warn('[session-sharing] The passed-in payload was invalid and could not be processed');
458
+ break;
459
+ case 'no-match':
460
+ winston.info('[session-sharing] Payload valid, but local account not found. Assuming guest.');
461
+ handleAsGuest = true;
462
+ break;
463
+ default:
464
+ winston.warn('[session-sharing] Error encountered while parsing token: ' + error.message);
465
+ break;
461
466
  }
462
467
 
463
468
  const data = await plugins.hooks.fire('filter:sessionSharing.error', {
@@ -600,10 +605,10 @@ plugin.appendTemplate = async (data) => {
600
605
 
601
606
  plugin.saveReverseToken = async ({ req, userData: data }) => {
602
607
  if (!plugin.ready || !data || plugin.settings.reverseToken !== 'on') {
603
- return; // no reverse token if secret not set
608
+ return; // no reverse token if secret not set
604
609
  }
605
610
 
606
- const res = req.res;
611
+ const { res } = req;
607
612
  const userData = await user.getUserFields(data.uid, ['uid', 'username', 'picture', 'reputation', 'postcount', 'banned']);
608
613
  userData.groups = (await groups.getUserGroups([data.uid])).pop();
609
614
  const token = jwt.sign(userData, plugin.settings.secret);
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "nodebb-plugin-session-sharing",
3
- "version": "7.2.0",
3
+ "version": "7.2.1",
4
4
  "description": "Allows login sessions from your app to persist in NodeBB",
5
5
  "main": "library.js",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/julianlam/nodebb-plugin-session-sharing"
9
9
  },
10
+ "scripts": {
11
+ "lint": "eslint ."
12
+ },
10
13
  "keywords": [
11
14
  "nodebb",
12
15
  "plugin"
@@ -21,7 +24,7 @@
21
24
  },
22
25
  "readmeFilename": "README.md",
23
26
  "nbbpm": {
24
- "compatibility": "^3.0.0"
27
+ "compatibility": "^3.2.0 || ^4.x"
25
28
  },
26
29
  "husky": {
27
30
  "hooks": {
@@ -38,7 +41,6 @@
38
41
  "dependencies": {
39
42
  "@commitlint/cli": "^9.1.2",
40
43
  "async": "^3",
41
- "eslint": "^7.7.0",
42
44
  "jsonwebtoken": "^8.5.1",
43
45
  "lint-staged": "^10.0.9",
44
46
  "lodash": "^4.17.14"
@@ -46,10 +48,8 @@
46
48
  "devDependencies": {
47
49
  "@commitlint/cli": "^9.1.2",
48
50
  "@commitlint/config-angular": "^7.1.2",
49
- "eslint": "8.x",
50
- "eslint-config-airbnb-base": "14.2.1",
51
- "eslint-config-nodebb": "0.1.1",
52
- "eslint-plugin-import": "2.x",
51
+ "eslint": "9.26.0",
52
+ "eslint-config-nodebb": "^1.1.4",
53
53
  "husky": "^2.4.0",
54
54
  "lint-staged": "^10.0.9",
55
55
  "request": "^2.88.2",
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- /* globals define, $, socket, config */
4
-
5
3
  define('admin/plugins/session-sharing', ['settings'], function (Settings) {
6
4
  var ACP = {};
7
5
 
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- /* globals document, $, window, config, ajaxify, bootbox */
4
-
5
3
  $(document).ready(function () {
6
4
  if (config.sessionSharing && config.sessionSharing.hostWhitelist) {
7
5
  var hosts = config.sessionSharing.hostWhitelist.split(',') || [config.sessionSharing.hostWhitelist];
package/test/index.js CHANGED
@@ -10,7 +10,6 @@ const url = require('url');
10
10
  const util = require('util');
11
11
  const request = require('request-promise-native');
12
12
 
13
- // eslint-disable-next-line no-unused-vars
14
13
  const db = require.main.require('./test/mocks/databasemock');
15
14
 
16
15
  const nconf = require.main.require('nconf');
package/.eslintrc DELETED
@@ -1,137 +0,0 @@
1
- {
2
- "extends": "airbnb-base",
3
- "parserOptions": {
4
- "sourceType": "script"
5
- },
6
-
7
- "rules": {
8
- // Customized
9
- "handle-callback-err": [ "error","^(e$|(e|(.*(_e|E)))rr)" ],
10
- "comma-dangle": ["error", {
11
- "arrays": "always-multiline",
12
- "objects": "always-multiline",
13
- "imports": "always-multiline",
14
- "exports": "always-multiline",
15
- "functions": "never"
16
- }],
17
- "no-empty": ["error", { "allowEmptyCatch": true }],
18
- "no-underscore-dangle": "off",
19
- "no-console": "off",
20
- "no-mixed-operators": ["error", { "allowSamePrecedence": true }],
21
- "strict": ["error", "global"],
22
- "consistent-return": "off",
23
- "func-names": "off",
24
- "no-tabs": "off",
25
- "indent": ["error", "tab"],
26
- "no-eq-null": "off",
27
- "camelcase": "off",
28
- "no-new": "off",
29
- "no-shadow": "off",
30
- "no-use-before-define": ["error", "nofunc"],
31
- "no-prototype-builtins": "off",
32
- "new-cap": "off",
33
- "no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
34
- "object-curly-newline": "off",
35
- "no-restricted-globals": "off",
36
- "function-paren-newline": "off",
37
- "import/no-unresolved": "error",
38
- "quotes": ["error", "single", {
39
- "avoidEscape": true,
40
- "allowTemplateLiterals": true
41
- }],
42
- "no-else-return": [ "error", { "allowElseIf": true } ],
43
- "operator-linebreak": [ "error", "after" ],
44
-
45
- // ES6
46
- "prefer-rest-params": "off",
47
- "prefer-spread": "off",
48
- "prefer-arrow-callback": "off",
49
- "prefer-template": "off",
50
- "no-var": "off",
51
- "object-shorthand": "off",
52
- "vars-on-top": "off",
53
- "prefer-destructuring": "off",
54
-
55
- // TODO
56
- "import/no-extraneous-dependencies": "off",
57
- "import/no-dynamic-require": "off",
58
- "import/newline-after-import": "off",
59
- "no-bitwise": "off",
60
- "global-require": "off",
61
- "max-len": "off",
62
- "no-param-reassign": "off",
63
- "no-restricted-syntax": "off",
64
- "no-script-url": "off",
65
- "default-case": "off",
66
- "linebreak-style": "off",
67
-
68
- // "no-multi-assign": "off",
69
- // "one-var": "off",
70
- // "no-undef": "off",
71
- // "max-nested-callbacks": "off",
72
- // "no-mixed-requires": "off",
73
- // "brace-style": "off",
74
- // "max-statements-per-line": "off",
75
- // "no-unused-vars": "off",
76
- // "no-mixed-spaces-and-tabs": "off",
77
- // "no-useless-concat": "off",
78
- // "require-jsdoc": "off",
79
- // "eqeqeq": "off",
80
- // "no-negated-condition": "off",
81
- // "one-var-declaration-per-line": "off",
82
- // "no-lonely-if": "off",
83
- // "radix": "off",
84
- // "no-else-return": "off",
85
- // "no-useless-escape": "off",
86
- // "block-scoped-var": "off",
87
- // "operator-assignment": "off",
88
- // "yoda": "off",
89
- // "no-loop-func": "off",
90
- // "no-void": "off",
91
- // "valid-jsdoc": "off",
92
- // "no-cond-assign": "off",
93
- // "no-redeclare": "off",
94
- // "no-unreachable": "off",
95
- // "no-nested-ternary": "off",
96
- // "operator-linebreak": "off",
97
- // "guard-for-in": "off",
98
- // "no-unneeded-ternary": "off",
99
- // "no-sequences": "off",
100
- // "no-extend-native": "off",
101
- // "no-shadow-restricted-names": "off",
102
- // "no-extra-boolean-cast": "off",
103
- // "no-path-concat": "off",
104
- // "no-unused-expressions": "off",
105
- // "no-return-assign": "off",
106
- // "no-restricted-modules": "off",
107
- // "object-curly-spacing": "off",
108
- // "indent": "off",
109
- // "padded-blocks": "off",
110
- // "eol-last": "off",
111
- // "lines-around-directive": "off",
112
- // "strict": "off",
113
- // "comma-dangle": "off",
114
- // "no-multi-spaces": "off",
115
- // "quotes": "off",
116
- // "keyword-spacing": "off",
117
- // "no-mixed-operators": "off",
118
- // "comma-spacing": "off",
119
- // "no-trailing-spaces": "off",
120
- // "key-spacing": "off",
121
- // "no-multiple-empty-lines": "off",
122
- // "spaced-comment": "off",
123
- // "space-in-parens": "off",
124
- // "block-spacing": "off",
125
- // "quote-props": "off",
126
- // "space-unary-ops": "off",
127
- // "no-empty": "off",
128
- // "dot-notation": "off",
129
- // "func-call-spacing": "off",
130
- // "array-bracket-spacing": "off",
131
- // "object-property-newline": "off",
132
- // "no-continue": "off",
133
- // "no-extra-semi": "off",
134
- // "no-spaced-func": "off",
135
- // "no-useless-return": "off"
136
- }
137
- }