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

if they dont have permission to view votes
This commit is contained in:
Barış Soner Uşaklı
2024-06-07 14:08:48 -04:00
parent 7c2a3a6e13
commit 6bbe3d1c4c
3 changed files with 17 additions and 10 deletions

View File

@@ -382,6 +382,8 @@ get:
type: number
downvote:disabled:
type: number
voteVisibility:
type: string
feeds:disableRSS:
type: number
signatures:hideDuplicates:

View File

@@ -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);
}

View File

@@ -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;