Node.js based forum software built for the modern web
feat: convert "All Votes Are Public" toggle to vote visibility
Barış Soner Uşaklıe0515080a087
diff --git a/install/data/defaults.json b/install/data/defaults.jsonindex 6884f351b5..076a1435d0 100644--- a/install/data/defaults.json+++ b/install/data/defaults.json@@ -137,7 +137,7 @@"sitemapTopics": 500,"maintenanceMode": 0,"maintenanceModeStatus": 503,- "votesArePublic": 0,+ "voteVisibility": "privileged","maximumInvites": 0,"username:disableEdit": 0,"email:disableEdit": 0,diff --git a/public/language/en-GB/admin/settings/reputation.json b/public/language/en-GB/admin/settings/reputation.jsonindex e4fff22620..a78d0e3fd5 100644--- a/public/language/en-GB/admin/settings/reputation.json+++ b/public/language/en-GB/admin/settings/reputation.json@@ -2,7 +2,10 @@"reputation": "Reputation Settings","disable": "Disable Reputation System","disable-down-voting": "Disable Down Voting",- "votes-are-public": "All Votes Are Public",+ "vote-visibility": "Vote visibility",+ "vote-visibility-all": "Everyone can see votes",+ "vote-visibility-loggedin": "Only logged in users can see votes",+ "vote-visibility-privileged": "Only privileged users like admins & moderators can see votes","thresholds": "Activity Thresholds","min-rep-upvote": "Minimum reputation to upvote posts","upvotes-per-day": "Upvotes per day (set to 0 for unlimited upvotes)",diff --git a/src/socket.io/posts/votes.js b/src/socket.io/posts/votes.jsindex 05e2ce5198..cd0b6f3b9b 100644--- a/src/socket.io/posts/votes.js+++ b/src/socket.io/posts/votes.js@@ -91,7 +91,14 @@ module.exports = function (SocketPosts) {]);const cidToAllowed = _.zipObject(uniqCids, canRead);const checks = cids.map(- (cid, index) => isAdmin || isMod[index] || (cidToAllowed[cid] && !!meta.config.votesArePublic)+ (cid, index) => isAdmin || isMod[index] ||+ (+ cidToAllowed[cid] &&+ (+ meta.config.voteVisibility === 'all' ||+ (meta.config.voteVisibility === 'loggedin' && parseInt(uid, 10) > 0)+ )+ ));return isArray ? checks : checks[0];}diff --git a/src/upgrades/3.8.2/vote-visibility-config.js b/src/upgrades/3.8.2/vote-visibility-config.jsnew file mode 100644index 0000000000..e39b8738fa--- /dev/null+++ b/src/upgrades/3.8.2/vote-visibility-config.js@@ -0,0 +1,16 @@+/* eslint-disable no-await-in-loop */++'use strict';++const db = require('../../database');++module.exports = {+ name: 'Add vote visibility config field',+ timestamp: Date.UTC(2024, 4, 24),+ method: async function () {+ const current = await db.getObjectField('config', 'votesArePublic');+ const isPublic = parseInt(current, 10) === 1;+ await db.setObjectField('config', 'voteVisibility', isPublic ? 'all' : 'privileged');+ await db.deleteObjectField('config', 'votesArePublic');+ },+};diff --git a/src/views/admin/settings/reputation.tpl b/src/views/admin/settings/reputation.tplindex 1786596c30..b086439498 100644--- a/src/views/admin/settings/reputation.tpl+++ b/src/views/admin/settings/reputation.tpl@@ -14,9 +14,13 @@<input type="checkbox" class="form-check-input" id="downvote:disabled" data-field="downvote:disabled"><label for="downvote:disabled" class="form-check-label">[[admin/settings/reputation:disable-down-voting]]</label></div>- <div class="form-check form-switch mb-3">- <input type="checkbox" class="form-check-input" id="votesArePublic" data-field="votesArePublic">- <label for="votesArePublic" class="form-check-label">[[admin/settings/reputation:votes-are-public]]</label>+ <div>+ <label for="voteVisibility" class="form-check-label">[[admin/settings/reputation:vote-visibility]]</label>+ <select id="voteVisibility" data-field="voteVisibility" class="form-select">+ <option value="all">[[admin/settings/reputation:vote-visibility-all]]</option>+ <option value="loggedin">[[admin/settings/reputation:vote-visibility-loggedin]]</option>+ <option value="privileged">[[admin/settings/reputation:vote-visibility-privileged]]</option>+ </select></div></div>