Skip to content

Commit

Permalink
anonymization feature working final backend
Browse files Browse the repository at this point in the history
  • Loading branch information
ogometz committed Oct 9, 2024
1 parent 898ab02 commit a7244dd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion public/src/modules/quickreply.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ define('quickreply', [
}

const replyMsg = components.get('topic/quickreply/text').val();
const isAnon = components.get('topic/quickreply/anonymousCheckbox').is(':checked');
const replyData = {
tid: ajaxify.data.tid,
handle: undefined,
handle: isAnon ? 'anonymous' : undefined,
content: replyMsg,
};
const replyLen = replyMsg.length;
Expand Down
3 changes: 2 additions & 1 deletion src/api/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ topicsAPI.reply = async function (caller, data) {
if (!data || !data.tid || (meta.config.minimumPostLength !== 0 && !data.content)) {
throw new Error('[[error:invalid-data]]');
}
const payload = { ...data };
const isAnonymous = data.handle === 'anonymous';
const payload = { ...data, isAnonymous };
apiHelpers.setDefaultPostData(caller, payload);

await meta.blacklist.test(caller.ip);
Expand Down
9 changes: 8 additions & 1 deletion src/posts/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ module.exports = function (Posts) {
const timestamp = data.timestamp || Date.now();
const isMain = data.isMain || false;

if (data.isAnonymous) {
data.uid = 0;
if (!data.handle) {
data.handle = 'Anonymous';
}
}

if (!uid && parseInt(uid, 10) !== 0) {
throw new Error('[[error:invalid-uid]]');
}
Expand All @@ -31,7 +38,7 @@ module.exports = function (Posts) {
const pid = await db.incrObjectField('global', 'nextPid');
let postData = {
pid: pid,
uid: uid,
uid: data.uid,
tid: tid,
content: content,
timestamp: timestamp,
Expand Down
11 changes: 11 additions & 0 deletions src/topics/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ module.exports = function (Topics) {
const { tid } = data;
const { uid } = data;

const isAnonymous = data.isAnonymous;

Check failure on line 171 in src/topics/create.js

View workflow job for this annotation

GitHub Actions / test

Use object destructuring

if (isAnonymous) {
data.handle = 'anonymous';
data.uid = 0;
}

const [topicData, isAdmin] = await Promise.all([
Topics.getTopicData(tid),
privileges.users.isAdministrator(uid),
Expand Down Expand Up @@ -296,6 +303,10 @@ module.exports = function (Topics) {
const { tid, uid } = data;
const { cid, deleted, locked, scheduled } = topicData;

if (uid === 0 && data.isAnonymous) {
return true;
}

const [canReply, canSchedule, isAdminOrMod] = await Promise.all([
privileges.topics.can('topics:reply', tid, uid),
privileges.topics.can('topics:schedule', tid, uid),
Expand Down

0 comments on commit a7244dd

Please sign in to comment.