From f3afeeab2fcb091264ce58d1bc1dfdcc4e20c8b9 Mon Sep 17 00:00:00 2001 From: sophiefeng18 <149734868+sophiefeng18@users.noreply.github.com> Date: Wed, 9 Oct 2024 20:45:06 -0400 Subject: [PATCH] Redefine permission logic and Add tests for anonymous field and permissions (#49) * add demp.rdb * updated f24 brach from team repository * dump.rdb issues * Updating permission logic * implementing the logic in src/posts/summary.js instead of src/middleware/user.js * fixing lint test errors * fixing more lint test errors * demp.rdb issue * fixing test case errors * npm install to solve test errors * minor changes to check test suites * minor changes to get around a flaky test * dump.rdb file change due to npm build tpl * Added test for anonymous field and permissions, debugged to pass test * resolving conflict with the main branch * resolving conflicts * resolving conflicts * resolving conflicts * resolving conflicts * resolving conflicts in summary.js * resolving conflicts in summary.js * resolving conflicts in summary.js * resolving conflicts in summary.js * resolving conflicts in summary.js * resolving conflicts in summary.js * resolving conflicts in summary.js * resolving conflicts in create.js * resolving conflicts in create.js * resolving conflicts in create.js * resolving conflicts in create.js * changes to pass some test cases and cleaning up * commenting out unneeded code as addressed in code review * commenting out unneeded code as addressed in code review --- dump.rdb | Bin 47354 -> 55278 bytes src/api/posts.js | 9 ++++++ src/controllers/admin/privileges.js | 1 + src/controllers/search.js | 7 ++++ src/middleware/user.js | 10 ++++++ src/posts/summary.js | 9 +++++- src/upgrades/1.4.4/sound_settings.js | 2 +- test/posts.js | 46 +++++++++++++++++++++++++++ 8 files changed, 82 insertions(+), 2 deletions(-) diff --git a/dump.rdb b/dump.rdb index b6576cb959e7ebcf1da01601e37d8900810da3da..f3ce27bc8ff8d2fda3908ab943ca2a7477520b8a 100644 GIT binary patch delta 13225 zcmb_?33yx8mGFD=lQ(&h`x%ZxP?%D78{U@@IUQRk;sxj(Q27jMAEDCOeU+`bP@Y{Ok_o;l)V{r1K z5M@4N{$T%*RW%^<^E&j_W0|S#OLa>bhT+gAcb=_z>(AGnWEBjPc8quXy#cQn882e8 zV@wg7c2kuW3W^cY7V^4ta$t#!VcD527w`&(LH9ki4L!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>O=#Pr8(|90q>!D~OhK+EthLe(##124RS}A`Rt&|DuM(6&VC6 zjzoo_P}V}@u-)DPfu2J}so&^K6CfKm;-bzHY^MV#cU8f^S5?A4Y&Wn*K;{{28Put4 zf8mc%6mYS-gZBH9_!|Q*yN!o<@>`TtT=}YHJc~49XDk6(*FHGlp#4#!KMO)fP0;(2 zsr@@iKaV&f>%ibuEf(5-Sp=Lf#?6VzkOrm+yUtqp;n9Vbamp+%e>@ma$XcHRFL$n9 z06WZJS)Y$eVp`hm&S3#){#e%0iQn2w GuKYjrkcSHZ diff --git a/src/api/posts.js b/src/api/posts.js index 4e3917a008..79c8726358 100644 --- a/src/api/posts.js +++ b/src/api/posts.js @@ -40,6 +40,10 @@ 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; }; @@ -62,6 +66,11 @@ 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]; }; diff --git a/src/controllers/admin/privileges.js b/src/controllers/admin/privileges.js index 28833b5562..b00a5f3587 100644 --- a/src/controllers/admin/privileges.js +++ b/src/controllers/admin/privileges.js @@ -36,6 +36,7 @@ privilegesController.get = async function (req, res) { } } }); + if (!selectedCategory) { selectedCategory = await categories.getCategoryFields(cid, ['cid', 'name', 'icon', 'bgColor', 'color']); } diff --git a/src/controllers/search.js b/src/controllers/search.js index 8b21189e7d..4a8c11a8df 100644 --- a/src/controllers/search.js +++ b/src/controllers/search.js @@ -78,6 +78,13 @@ 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 || '')); diff --git a/src/middleware/user.js b/src/middleware/user.js index dd27a8c650..0bd463500d 100644 --- a/src/middleware/user.js +++ b/src/middleware/user.js @@ -36,6 +36,16 @@ 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) { diff --git a/src/posts/summary.js b/src/posts/summary.js index b8cbd45e4c..e2231897e2 100644 --- a/src/posts/summary.js +++ b/src/posts/summary.js @@ -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', 'deleted', 'upvotes', 'downvotes', 'replies', 'handle'].concat(options.extraFields); + const fields = ['pid', 'tid', 'content', 'uid', 'timestamp', 'anonymous', 'deleted', 'upvotes', 'downvotes', 'replies', 'handle'].concat(options.extraFields); let posts = await Posts.getPostsFields(pids, fields); posts = posts.filter(Boolean); @@ -44,6 +44,13 @@ 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]; diff --git a/src/upgrades/1.4.4/sound_settings.js b/src/upgrades/1.4.4/sound_settings.js index 9b029a78e6..4880d84a19 100644 --- a/src/upgrades/1.4.4/sound_settings.js +++ b/src/upgrades/1.4.4/sound_settings.js @@ -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']; diff --git a/test/posts.js b/test/posts.js index 20403e24cf..cba1b7832f 100644 --- a/test/posts.js +++ b/test/posts.js @@ -696,11 +696,57 @@ 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,