Merge branch 'develop' into activitypub

This commit is contained in:
Barış Soner Uşaklı
2024-07-25 11:26:29 -04:00
63 changed files with 486 additions and 244 deletions

View File

@@ -331,12 +331,19 @@ postsAPI.getVoters = async function (caller, data) {
}
const { pid } = data;
const cid = await posts.getCidByPid(pid);
if (!await canSeeVotes(caller.uid, cid)) {
const [canSeeUpvotes, canSeeDownvotes] = await Promise.all([
canSeeVotes(caller.uid, cid, 'upvoteVisibility'),
canSeeVotes(caller.uid, cid, 'downvoteVisibility'),
]);
if (!canSeeUpvotes && !canSeeDownvotes) {
throw new Error('[[error:no-privileges]]');
}
const showDownvotes = !meta.config['downvote:disabled'];
const repSystemDisabled = meta.config['reputation:disabled'];
const showUpvotes = canSeeUpvotes && !repSystemDisabled;
const showDownvotes = canSeeDownvotes && !meta.config['downvote:disabled'] && !repSystemDisabled;
const [upvoteUids, downvoteUids] = await Promise.all([
db.getSetMembers(`pid:${data.pid}:upvote`),
showUpvotes ? db.getSetMembers(`pid:${data.pid}:upvote`) : [],
showDownvotes ? db.getSetMembers(`pid:${data.pid}:downvote`) : [],
]);
@@ -348,6 +355,7 @@ postsAPI.getVoters = async function (caller, data) {
return {
upvoteCount: upvoters.length,
downvoteCount: downvoters.length,
showUpvotes: showUpvotes,
showDownvotes: showDownvotes,
upvoters: upvoters,
downvoters: downvoters,
@@ -360,7 +368,7 @@ postsAPI.getUpvoters = async function (caller, data) {
}
const { pid } = data;
const cid = await posts.getCidByPid(pid);
if (!await canSeeVotes(caller.uid, cid)) {
if (!await canSeeVotes(caller.uid, cid, 'upvoteVisibility')) {
throw new Error('[[error:no-privileges]]');
}
@@ -415,7 +423,7 @@ postsAPI.getAnnouncers = async (caller, data) => {
};
};
async function canSeeVotes(uid, cids) {
async function canSeeVotes(uid, cids, type) {
const isArray = Array.isArray(cids);
if (!isArray) {
cids = [cids];
@@ -434,8 +442,8 @@ async function canSeeVotes(uid, cids) {
(
cidToAllowed[cid] &&
(
meta.config.voteVisibility === 'all' ||
(meta.config.voteVisibility === 'loggedin' && parseInt(uid, 10) > 0)
meta.config[type] === 'all' ||
(meta.config[type] === 'loggedin' && parseInt(uid, 10) > 0)
)
)
);

View File

@@ -97,7 +97,8 @@ 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.upvoteVisibility = meta.config.upvoteVisibility;
topicData.downvoteVisibility = meta.config.downvoteVisibility;
topicData['feeds:disableRSS'] = meta.config['feeds:disableRSS'] || 0;
topicData['signatures:hideDuplicates'] = meta.config['signatures:hideDuplicates'];
topicData.bookmarkThreshold = meta.config.bookmarkThreshold;

View File

@@ -15,7 +15,7 @@ function setupWinston() {
}
const formats = [];
if (nconf.get('log-colorize') !== 'false') {
if (nconf.get('log-colorize') !== 'false' && nconf.get('log-colorize') !== false) {
formats.push(winston.format.colorize());
}

View File

@@ -0,0 +1,20 @@
/* eslint-disable no-await-in-loop */
'use strict';
const db = require('../../database');
module.exports = {
name: 'Add downvote visibility config field',
timestamp: Date.UTC(2024, 6, 17),
method: async function () {
const current = await db.getObjectField('config', 'voteVisibility');
if (current) {
await db.setObject('config', {
upvoteVisibility: current,
downvoteVisibility: current,
});
await db.deleteObjectField('config', 'voteVisibility');
}
},
};

View File

@@ -1,28 +1,28 @@
<div class="hooks-list panel-group px-lg-4" id="accordion" role="tablist" aria-multiselectable="true">
<div class="hooks-list px-lg-4" id="accordion" role="tablist" aria-multiselectable="true">
{{{ each hooks }}}
<div class="card">
<div class="card-header" role="tab">
<h6 class="mb-0">
<a style="text-transform: none;" class="text-reset text-decoration-none" role="button" data-bs-toggle="collapse" data-bs-parent="#accordion" data-bs-target="#{hooks.index}" aria-expanded="true" aria-controls="{hooks.index}">{hooks.hookName}</a>
<span class="float-end">{hooks.count} hooks</span>
<div class="mb-3 border rounded p-2">
<div class="" role="tab">
<h6 class="mb-0 ps-2 d-flex justify-content-between align-items-center">
<span>{hooks.hookName}</span>
<button class="btn-ghost-sm" data-bs-toggle="collapse" data-bs-parent="#accordion" data-bs-target="#{hooks.index}" aria-expanded="true" aria-controls="{hooks.index}">View hooks ({hooks.count})</button>
</h6>
</div>
<div id="{hooks.index}" class="accordion-collapse collapse" role="tabpanel">
<div class="card-body">
{{{ each hooks.methods }}}
<div class="mb-3">
<strong>{hooks.methods.id}</strong>
Priority: {hooks.methods.priority}
<div class="d-flex flex-column mt-3 ms-3">
{{{ each hooks.methods }}}
<div class="mb-3">
<strong>{hooks.methods.id}</strong>
<span class="text-secondary text-sm">Priority: {hooks.methods.priority}</span>
<button class="btn btn-primary btn-sm float-end" type="button" data-bs-toggle="collapse" data-bs-target="#{hooks.methods.index}" aria-expanded="false" aria-controls="{hooks.methods.index}">
Show Code <i class="fa fa-eye"></i>
</button>
<button class="btn btn-light btn-sm float-end" type="button" data-bs-toggle="collapse" data-bs-target="#{hooks.methods.index}" aria-expanded="false" aria-controls="{hooks.methods.index}">
<i class="fa fa-eye"></i> Show Code
</button>
</div>
<div class="collapse" id="{hooks.methods.index}">
<pre class="p-3 text-bg-light border rounded">{hooks.methods.method}</pre>
</div>
{{{ end }}}
</div>
<div class="collapse" id="{hooks.methods.index}">
<pre class="p-3 text-bg-light border border-secondary rounded">{hooks.methods.method}</pre>
</div>
{{{ end }}}
</div>
</div>
</div>
{{{ end }}}

View File

@@ -14,12 +14,20 @@
<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="mb-3">
<label for="upvoteVisibility" class="form-check-label">[[admin/settings/reputation:upvote-visibility]]</label>
<select id="upvoteVisibility" data-field="upvoteVisibility" class="form-select">
<option value="all">[[admin/settings/reputation:upvote-visibility-all]]</option>
<option value="loggedin">[[admin/settings/reputation:upvote-visibility-loggedin]]</option>
<option value="privileged">[[admin/settings/reputation:upvote-visibility-privileged]]</option>
</select>
</div>
<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>
<label for="downvoteVisibility" class="form-check-label">[[admin/settings/reputation:downvote-visibility]]</label>
<select id="downvoteVisibility" data-field="downvoteVisibility" class="form-select">
<option value="all">[[admin/settings/reputation:downvote-visibility-all]]</option>
<option value="loggedin">[[admin/settings/reputation:downvote-visibility-loggedin]]</option>
<option value="privileged">[[admin/settings/reputation:downvote-visibility-privileged]]</option>
</select>
</div>
</div>

View File

@@ -1,9 +1,11 @@
{{{ if showUpvotes }}}
<div class="mb-3">
<h4>[[global:upvoters]] <small>({upvoteCount})</small></h4>
{{{ each upvoters }}}
<a class="text-decoration-none" href="{config.relative_path}/user/{./userslug}">{buildAvatar(@value, "24px", true)}</a>
{{{ end }}}
</div>
{{{ end }}}
{{{ if showDownvotes }}}
<div>
<h4>[[global:downvoters]] <small>({downvoteCount})</small></h4>

View File

@@ -41,11 +41,13 @@ async function renderLocation(location, data, uid, options) {
return [];
}
const renderedWidgets = await Promise.all(widgetsAtLocation.map(widget => renderWidget(widget, uid, options)));
const renderedWidgets = await Promise.all(
widgetsAtLocation.map(widget => renderWidget(widget, uid, options, location))
);
return renderedWidgets;
}
async function renderWidget(widget, uid, options) {
async function renderWidget(widget, uid, options, location) {
if (!widget || !widget.data || (!!widget.data['hide-mobile'] && options.req.useragent.isMobile)) {
return;
}
@@ -69,6 +71,7 @@ async function renderWidget(widget, uid, options) {
data: widget.data,
req: options.req,
res: options.res,
location,
});
if (!data) {