Skip to content

Commit

Permalink
Revert "Redefine permission logic and Add tests for anonymous field a…
Browse files Browse the repository at this point in the history
…nd permi…" (#55)

This reverts commit f3afeea.
  • Loading branch information
anna-mat authored Oct 22, 2024
1 parent a0efdbe commit c74c713
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 82 deletions.
Binary file modified dump.rdb
Binary file not shown.
9 changes: 0 additions & 9 deletions src/api/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ postsAPI.get = async function (caller, data) {
post.content = '[[topic:post-is-deleted]]';
}

// Reference to ChatGPT
// Add the anonymous field to the response
// post.anonymous = post.anonymous || false;

return post;
};

Expand All @@ -66,11 +62,6 @@ postsAPI.getSummary = async (caller, { pid }) => {

const postsData = await posts.getPostSummaryByPids([pid], caller.uid, { stripTags: false });
posts.modifyPostByPrivilege(postsData[0], topicPrivileges);

// Reference to ChatGPT
// Add the anonymous field to the post summary
// postsData[0].anonymous = postsData[0].anonymous || false;

return postsData[0];
};

Expand Down
1 change: 0 additions & 1 deletion src/controllers/admin/privileges.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ privilegesController.get = async function (req, res) {
}
}
});

if (!selectedCategory) {
selectedCategory = await categories.getCategoryFields(cid, ['cid', 'name', 'icon', 'bgColor', 'color']);
}
Expand Down
7 changes: 0 additions & 7 deletions src/controllers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ searchController.search = async function (req, res, next) {
recordSearch(data),
]);

// Reference to ChatGPT
// Add anonymous field to each post
searchData.posts = searchData.posts.map((post) => {
post.anonymous = post.anonymous ? 'Anonymous User' : '';
return post;
});

searchData.pagination = pagination.create(page, searchData.pageCount, req.query);
searchData.multiplePages = searchData.pageCount > 1;
searchData.search_query = validator.escape(String(req.query.term || ''));
Expand Down
10 changes: 0 additions & 10 deletions src/middleware/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ const passportAuthenticateAsync = function (req, res) {
});
};

// permisssions for admin to see username on anonymous posts
// const showUsername = async (userId, currentUser) => {
// const isAdmin = await user.isAdministrator(currentUser.uid);

// if (isAnonymous && !isAdmin) {
// return 'Anonymous User';
// }

// return user.getDisplayName(userId);
// };

module.exports = function (middleware) {
async function authenticate(req, res) {
Expand Down
9 changes: 1 addition & 8 deletions src/posts/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function (Posts) {
options.parse = options.hasOwnProperty('parse') ? options.parse : true;
options.extraFields = options.hasOwnProperty('extraFields') ? options.extraFields : [];

const fields = ['pid', 'tid', 'content', 'uid', 'timestamp', 'anonymous', 'deleted', 'upvotes', 'downvotes', 'replies', 'handle'].concat(options.extraFields);
const fields = ['pid', 'tid', 'content', 'uid', 'timestamp', 'deleted', 'upvotes', 'downvotes', 'replies', 'handle'].concat(options.extraFields);

let posts = await Posts.getPostsFields(pids, fields);
posts = posts.filter(Boolean);
Expand All @@ -44,13 +44,6 @@ module.exports = function (Posts) {
post.uid = 0;
}
post.user = uidToUser[post.uid];
// Check if the post is anonymous
// Reference to ChatGPT
if (post.anonymous && !user.isAdministrator(uid)) {
post.user.username = 'Anonymous User';
} else {
post.user.username = users.find(u => u.uid === post.uid).username;
}
Posts.overrideGuestHandle(post, post.handle);
post.handle = undefined;
post.topic = tidToTopic[post.tid];
Expand Down
2 changes: 1 addition & 1 deletion src/upgrades/1.4.4/sound_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const map = {
'waterdrop-low.mp3': 'Default | Water drop (low)',
};

// console.log('Sophie Feng');
console.log('Sophie Feng');
function soundSettings(cb) {
const keys = ['chat-incoming', 'chat-outgoing', 'notification'];

Expand Down
46 changes: 0 additions & 46 deletions test/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,57 +696,11 @@ describe('Post\'s', () => {
assert(data[0].user);
assert(data[0].topic);
assert(data[0].category);
assert(data[0].anonymous); // Anonymous data field exists
done();
});
});
});

// tests for admin permission to see anonymous poster's user name
// Reference to ChatGPT
describe('Post Anonymity', () => {
let uid;
let postData;
let adminUid;
let uid2;

before(async () => {
// Create two regular user
uid = await user.create({ username: 'regularuser' });
uid2 = await user.create({ username: 'regularuser2' });

// Create an admin user
adminUid = await user.create({ username: 'adminuser' });
await groups.join('administrators', adminUid); // Make the user an admin

// Create an anonymous post
({ postData } = await topics.post({
uid: uid,
cid: cid,
title: 'Anonymous Post Test',
content: 'This is an anonymous post',
anonymous: true,
}));
});

it('should display "Anonymous User" if the post is anonymous and the user is not an admin', async () => {
// Simulate a request by a non-admin user
const postSummary = await posts.getPostSummaryByPids([postData.pid], uid2, {});
// console.log(postSummary[0]);

// Check that the username is set to "Anonymous User"
assert.strictEqual(postSummary[0].user.username, 'Anonymous User');
});

it('should display the real username if the post is anonymous but the user is an admin', async () => {
// Simulate a request by an admin user
const postSummary = await posts.getPostSummaryByPids([postData.pid], adminUid, {});
// console.log(postSummary[0]);
// Check that the username is the actual user's username
assert.strictEqual(postSummary[0].user.username, 'regularuser');
});
});

it('should get recent poster uids', (done) => {
topics.reply({
uid: voterUid,
Expand Down

0 comments on commit c74c713

Please sign in to comment.