Skip to content

Commit

Permalink
Merge pull request #38 from CMU-17313Q/anonymousbackend
Browse files Browse the repository at this point in the history
Anonymous Can Now Post as Guest When They Select Anonymous.
  • Loading branch information
khalifat3 authored Oct 9, 2024
2 parents eb5020e + d07cc19 commit b70c30f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions node_modules/nodebb-plugin-composer-default/static/lib/composer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/posts/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const privileges = require('../privileges');
module.exports = function (Posts) {
Posts.create = async function (data) {
// This is an internal method, consider using Topics.reply instead

// Might be a good idea to do some testing here to see what happens, but we'll see
const { uid } = data;
const { tid } = data;
const content = data.content.toString();
Expand Down
8 changes: 8 additions & 0 deletions src/topics/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ module.exports = function (Topics) {
await user.isReadyToPost(uid, data.cid);
}

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

const tid = await Topics.create(data);

let postData = data;
Expand Down Expand Up @@ -193,6 +197,10 @@ module.exports = function (Topics) {
data.timestamp = topicData.lastposttime + 1;
}

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

data.ip = data.req ? data.req.ip : null;
let postData = await posts.create(data);
postData = await onNewPost(postData, data);
Expand Down
2 changes: 2 additions & 0 deletions src/topics/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ module.exports = function (Topics) {
postObj.replies = replies[i];
postObj.selfPost = parseInt(uid, 10) > 0 && parseInt(uid, 10) === postObj.uid;

// Trying to work on this file to try and customize anonymous more

// Username override for guests, if enabled
if (meta.config.allowGuestHandles && postObj.uid === 0 && postObj.handle) {
postObj.user.username = validator.escape(String(postObj.handle));
Expand Down

0 comments on commit b70c30f

Please sign in to comment.