nodebb-plugin-poll 4.0.11 → 4.0.13
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/lib/config.js +1 -1
- package/lib/hooks.js +4 -4
- package/lib/nodebb.js +12 -12
- package/lib/poll.js +2 -2
- package/lib/sockets.js +12 -9
- package/lib/vote.js +2 -2
- package/library.js +4 -4
- package/package.json +3 -3
- package/public/js/poll/creator.js +1 -0
- package/public/js/poll/view.js +4 -4
- package/templates/poll/view/details.tpl +1 -1
- package/upgrades/convert_poll_id_voters_and_options_votes_to_sorted_sets.js +1 -1
- package/upgrades/fix_incorrect_poll_privilege.js +2 -2
- package/upgrades/give_categories_poll_create_privs_to_reg_users.js +1 -1
- package/upgrades/poll-4.0-upgrade.js +2 -2
package/lib/config.js
CHANGED
package/lib/hooks.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const db =
|
|
4
|
-
const topics =
|
|
5
|
-
const posts =
|
|
6
|
-
const privileges =
|
|
3
|
+
const db = nodebb.require('./src/database');
|
|
4
|
+
const topics = nodebb.require('./src/topics');
|
|
5
|
+
const posts = nodebb.require('./src/posts');
|
|
6
|
+
const privileges = nodebb.require('./src/privileges');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
const Config = require('./config');
|
package/lib/nodebb.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = {
|
|
4
|
-
db:
|
|
5
|
-
Settings:
|
|
6
|
-
Meta:
|
|
7
|
-
User:
|
|
8
|
-
Posts:
|
|
9
|
-
Topics:
|
|
10
|
-
Privileges:
|
|
11
|
-
Plugins:
|
|
12
|
-
PluginSockets:
|
|
13
|
-
SocketIndex:
|
|
14
|
-
Translator:
|
|
15
|
-
winston:
|
|
4
|
+
db: nodebb.require('./src/database'),
|
|
5
|
+
Settings: nodebb.require('./src/settings'),
|
|
6
|
+
Meta: nodebb.require('./src/meta'),
|
|
7
|
+
User: nodebb.require('./src/user'),
|
|
8
|
+
Posts: nodebb.require('./src/posts'),
|
|
9
|
+
Topics: nodebb.require('./src/topics'),
|
|
10
|
+
Privileges: nodebb.require('./src/privileges'),
|
|
11
|
+
Plugins: nodebb.require('./src/plugins'),
|
|
12
|
+
PluginSockets: nodebb.require('./src/socket.io/plugins'),
|
|
13
|
+
SocketIndex: nodebb.require('./src/socket.io/index'),
|
|
14
|
+
Translator: nodebb.require('./src/translator'),
|
|
15
|
+
winston: nodebb.require('winston'),
|
|
16
16
|
app: null,
|
|
17
17
|
};
|
package/lib/poll.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const db =
|
|
4
|
-
const privileges =
|
|
3
|
+
const db = nodebb.require('./src/database');
|
|
4
|
+
const privileges = nodebb.require('./src/privileges');
|
|
5
5
|
|
|
6
6
|
const Vote = require('./vote');
|
|
7
7
|
|
package/lib/sockets.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const _ =
|
|
4
|
-
const db =
|
|
5
|
-
const posts =
|
|
6
|
-
const topics =
|
|
7
|
-
const privileges =
|
|
3
|
+
const _ = nodebb.require('lodash');
|
|
4
|
+
const db = nodebb.require('./src/database');
|
|
5
|
+
const posts = nodebb.require('./src/posts');
|
|
6
|
+
const topics = nodebb.require('./src/topics');
|
|
7
|
+
const privileges = nodebb.require('./src/privileges');
|
|
8
8
|
|
|
9
9
|
const NodeBB = require('./nodebb');
|
|
10
10
|
const Config = require('./config');
|
|
@@ -27,7 +27,8 @@ Sockets.get = async function (socket, data) {
|
|
|
27
27
|
return [];
|
|
28
28
|
}
|
|
29
29
|
return await Promise.all(data.pollIds.map(async (pollId) => {
|
|
30
|
-
const
|
|
30
|
+
const withVotes = allowAnon || socket.uid > 0;
|
|
31
|
+
const pollData = await Poll.get(pollId, socket.uid, withVotes);
|
|
31
32
|
if (!pollData) {
|
|
32
33
|
return null;
|
|
33
34
|
}
|
|
@@ -144,18 +145,20 @@ Sockets.removeVote = async function (socket, data) {
|
|
|
144
145
|
};
|
|
145
146
|
|
|
146
147
|
Sockets.getOptionDetails = async function (socket, data) {
|
|
147
|
-
if (!
|
|
148
|
+
if (!data || isNaN(parseInt(data.pollId, 10)) || isNaN(parseInt(data.optionId, 10))) {
|
|
148
149
|
throw new Error('Invalid request');
|
|
149
150
|
}
|
|
150
|
-
const [poll, option] = await Promise.all([
|
|
151
|
+
const [poll, option, settings] = await Promise.all([
|
|
151
152
|
Poll.getInfo(data.pollId),
|
|
152
153
|
Poll.getOption(data.pollId, data.optionId, true),
|
|
154
|
+
Config.getSettings(),
|
|
153
155
|
]);
|
|
154
156
|
if (!poll) {
|
|
155
157
|
throw new Error('[[error:invalid-data]]');
|
|
156
158
|
}
|
|
159
|
+
const allowAnon = settings.allowGuestsToViewResults === 'on';
|
|
157
160
|
const canRead = await privileges.posts.can('topics:read', poll.pid, socket.uid);
|
|
158
|
-
if (!canRead) {
|
|
161
|
+
if (!canRead || (!allowAnon && socket.uid <= 0)) {
|
|
159
162
|
throw new Error('[[error:no-privileges]]');
|
|
160
163
|
}
|
|
161
164
|
if (!option || !option.votes || !option.votes.length) {
|
package/lib/vote.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const db =
|
|
4
|
-
const privileges =
|
|
3
|
+
const db = nodebb.require('./src/database');
|
|
4
|
+
const privileges = nodebb.require('./src/privileges');
|
|
5
5
|
|
|
6
6
|
const Poll = require('./poll');
|
|
7
7
|
|
package/library.js
CHANGED
|
@@ -5,16 +5,16 @@ const Config = require('./lib/config');
|
|
|
5
5
|
const Sockets = require('./lib/sockets');
|
|
6
6
|
const Hooks = require('./lib/hooks');
|
|
7
7
|
const Poll = require('./lib/poll');
|
|
8
|
-
const db =
|
|
9
|
-
const pagination =
|
|
10
|
-
const utils =
|
|
8
|
+
const db = nodebb.require('./src/database');
|
|
9
|
+
const pagination = nodebb.require('./src/pagination');
|
|
10
|
+
const utils = nodebb.require('./src/utils');
|
|
11
11
|
|
|
12
12
|
const Plugin = module.exports;
|
|
13
13
|
|
|
14
14
|
Plugin.hooks = Hooks;
|
|
15
15
|
|
|
16
16
|
Plugin.load = async function (params) {
|
|
17
|
-
const routeHelpers =
|
|
17
|
+
const routeHelpers = nodebb.require('./src/routes/helpers');
|
|
18
18
|
const { router } = params;
|
|
19
19
|
|
|
20
20
|
routeHelpers.setupAdminPageRoute(router, `/admin/plugins/${Config.plugin.id}`, async (req, res) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodebb-plugin-poll",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.13",
|
|
4
4
|
"description": "NodeBB Poll Plugin",
|
|
5
5
|
"main": "library.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"compatibility": "^4.14.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"eslint": "10.0
|
|
33
|
-
"eslint-config-nodebb": "^2.0.
|
|
32
|
+
"eslint": "10.6.0",
|
|
33
|
+
"eslint-config-nodebb": "^2.0.3"
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
// used to identify the poll in the manage modal after creation
|
|
65
65
|
// so we can edit/delete
|
|
66
66
|
pollId: Date.now(),
|
|
67
|
+
title: config.poll.defaultTitle,
|
|
67
68
|
maximumVotesPerUser: config.poll.maximumVotesPerUser,
|
|
68
69
|
}, config.poll).then((newPoll) => {
|
|
69
70
|
if (newPoll) {
|
package/public/js/poll/view.js
CHANGED
|
@@ -258,9 +258,9 @@
|
|
|
258
258
|
};
|
|
259
259
|
|
|
260
260
|
View.prototype.showOptionDetails = function (details) {
|
|
261
|
-
require(['
|
|
262
|
-
|
|
263
|
-
|
|
261
|
+
require(['benchpress', 'modals'], function (benchpress, modals) {
|
|
262
|
+
benchpress.render('poll/view/details', details).then(function (html) {
|
|
263
|
+
modals.dialog({
|
|
264
264
|
title: `[[poll:x-users-voted-for-this-option, ${details.voteCount}]]`,
|
|
265
265
|
message: html,
|
|
266
266
|
backdrop: true,
|
|
@@ -301,7 +301,7 @@
|
|
|
301
301
|
}
|
|
302
302
|
} else {
|
|
303
303
|
this.showVoteButton();
|
|
304
|
-
if (this.pollData
|
|
304
|
+
if (this.pollData?.info?.allowAnonVoting) {
|
|
305
305
|
this.showVoteAnonButton();
|
|
306
306
|
}
|
|
307
307
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const db =
|
|
4
|
-
const privileges =
|
|
3
|
+
const db = nodebb.require('./src/database');
|
|
4
|
+
const privileges = nodebb.require('./src/privileges');
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
|
7
7
|
name: 'Fix incorrectly given poll privilege',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const db =
|
|
4
|
-
const batch =
|
|
3
|
+
const db = nodebb.require('./src/database');
|
|
4
|
+
const batch = nodebb.require('./src/batch');
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
|
7
7
|
name: 'Convert data structures for v4.0',
|