Skip to content

Node.js based forum software built for the modern web

fix: dont show error alert when user user mouse overs votes

Barış Soner Uşaklı6bbe3d1c4cef
diff --git a/public/openapi/read/topic/topic_id.yaml b/public/openapi/read/topic/topic_id.yaml
index 20ef21a031..366ff32675 100644
--- a/public/openapi/read/topic/topic_id.yaml
+++ b/public/openapi/read/topic/topic_id.yaml
@@ -382,6 +382,8 @@ get:
type: number
downvote:disabled:
type: number
+ voteVisibility:
+ type: string
feeds:disableRSS:
type: number
signatures:hideDuplicates:
diff --git a/public/src/client/topic/votes.js b/public/src/client/topic/votes.js
index 29876ac148..d78d197f27 100644
--- a/public/src/client/topic/votes.js
+++ b/public/src/client/topic/votes.js
@@ -9,10 +9,19 @@ define('forum/topic/votes', [
Votes.addVoteHandler = function () {
_showTooltip = {};
- components.get('topic').on('mouseenter', '[data-pid] [component="post/vote-count"]', loadDataAndCreateTooltip);
- components.get('topic').on('mouseleave', '[data-pid] [component="post/vote-count"]', destroyTooltip);
+ if (canSeeVotes()) {
+ components.get('topic').on('mouseenter', '[data-pid] [component="post/vote-count"]', loadDataAndCreateTooltip);
+ components.get('topic').on('mouseleave', '[data-pid] [component="post/vote-count"]', destroyTooltip);
+ }
};
+ function canSeeVotes() {
+ const { voteVisibility, privileges } = ajaxify.data;
+ return privileges.isAdminOrMod ||
+ voteVisibility === 'all' ||
+ (voteVisibility === 'loggedin' && config.loggedIn);
+ }
+
function destroyTooltip() {
const $this = $(this);
const pid = $this.parents('[data-pid]').attr('data-pid');
@@ -37,9 +46,6 @@ define('forum/topic/votes', [
api.get(`/posts/${pid}/upvoters`, {}, function (err, data) {
if (err) {
- if (err.message === '[[error:no-privileges]]') {
- return;
- }
return alerts.error(err);
}
if (_showTooltip[pid] && data) {
@@ -101,13 +107,11 @@ define('forum/topic/votes', [
};
Votes.showVotes = function (pid) {
+ if (!canSeeVotes()) {
+ return;
+ }
api.get(`/posts/${pid}/voters`, {}, function (err, data) {
if (err) {
- if (err.message === '[[error:no-privileges]]') {
- return;
- }
-
- // Only show error if it's an unexpected error.
return alerts.error(err);
}
diff --git a/src/controllers/topics.js b/src/controllers/topics.js
index 9ea025e038..1d8c49205e 100644
--- a/src/controllers/topics.js
+++ b/src/controllers/topics.js
@@ -96,6 +96,7 @@ topicsController.get = async function getTopic(req, res, next) {
topicData.topicStaleDays = meta.config.topicStaleDays;
topicData['reputation:disabled'] = meta.config['reputation:disabled'];
topicData['downvote:disabled'] = meta.config['downvote:disabled'];
+ topicData.voteVisibility = meta.config.voteVisibility;
topicData['feeds:disableRSS'] = meta.config['feeds:disableRSS'] || 0;
topicData['signatures:hideDuplicates'] = meta.config['signatures:hideDuplicates'];
topicData.bookmarkThreshold = meta.config.bookmarkThreshold;