Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anonymization uid approach #19

Open
wants to merge 2 commits into
base: f24
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added node_modules/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions node_modules/nodebb-theme-aawaa
Submodule nodebb-theme-aawaa added at 71a76e
6 changes: 6 additions & 0 deletions public/src/modules/quickreply.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,17 @@
}

const replyMsg = components.get('topic/quickreply/text').val();
const anonCheckbox = document.getElementById('anonymousCheckbox').checked ? 'true' : 'false';

Check failure on line 62 in public/src/modules/quickreply.js

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed
const replyData = {
tid: ajaxify.data.tid,
handle: undefined,
content: replyMsg,
anon: anonCheckbox,
};

console.log('Reply data being sent:', replyData);

const replyLen = replyMsg.length;
if (replyLen < parseInt(config.minimumPostLength, 10)) {
return alerts.error('[[error:content-too-short, ' + config.minimumPostLength + ']]');
Expand Down
12 changes: 8 additions & 4 deletions src/api/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
const events = require('../events');

exports.setDefaultPostData = function (reqOrSocket, data) {
data.uid = reqOrSocket.uid;
data.req = exports.buildReqObject(reqOrSocket, { ...data });
data.timestamp = Date.now();
data.fromQueue = false;
if (data.anon === 'true') {

Check failure on line 14 in src/api/helpers.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 1 tab but found 4 spaces
data.uid = 100; // Set uid to 0 for anonymous posts

Check failure on line 15 in src/api/helpers.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 2 tabs but found 8 spaces
} else {

Check failure on line 16 in src/api/helpers.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 1 tab but found 4 spaces
data.uid = reqOrSocket.uid; // Otherwise, use the uid from reqOrSocket

Check failure on line 17 in src/api/helpers.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 2 tabs but found 8 spaces
}

Check failure on line 18 in src/api/helpers.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 1 tab but found 4 spaces
data.req = exports.buildReqObject(reqOrSocket, { ...data });

Check failure on line 19 in src/api/helpers.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 1 tab but found 4 spaces
data.timestamp = Date.now();

Check failure on line 20 in src/api/helpers.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 1 tab but found 4 spaces
data.fromQueue = false;

Check failure on line 21 in src/api/helpers.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 1 tab but found 4 spaces
};

// creates a slimmed down version of the request object
Expand Down
11 changes: 10 additions & 1 deletion src/api/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,17 @@
throw new Error('[[error:invalid-data]]');
}
const payload = { ...data };
apiHelpers.setDefaultPostData(caller, payload);

if (data.anon === 'true') {
payload.username = 'Anonymous User';

Check failure on line 93 in src/api/topics.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 2 tabs but found 8 spaces
payload.userslug = null;
payload.uid = 100;
console.log('Anonymous post detected, making it anonymous');
}
console.log('This is the payload', payload)
apiHelpers.setDefaultPostData(caller, payload);
console.log('Payload being sent to topics.reply:', payload);

await meta.blacklist.test(caller.ip);
const shouldQueue = await posts.shouldQueue(caller.uid, payload);
if (shouldQueue) {
Expand Down
16 changes: 14 additions & 2 deletions src/controllers/write/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,20 @@ Topics.create = async (req, res) => {
};

Topics.reply = async (req, res) => {
const id = await lockPosting(req, '[[error:already-posting]]');
try {
const id = await lockPosting(req, '[[error:already-posting]]');
try {
const isAnonymous = req.body.anon === 'true' || req.body.anon === 'on';
console.log("Anonymous flag received:", isAnonymous);
let replyData = { ...req.body, tid: req.params.tid };
if (isAnonymous) {
console.log("Post is anonymous. Modifying the username, userslug, and setting uid to 0.");
replyData.username = 'Anonymous User';
replyData.userslug = null;
replyData.uid = 100; // Set uid to 100 to mark the post as anonymous
} else {
console.log("Post is not anonymous.");
}
console.log("Final reply data being sent:", replyData);
const payload = await api.topics.reply(req, { ...req.body, tid: req.params.tid });
helpers.formatApiResponse(200, res, payload);
} finally {
Expand Down
Loading