• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CMU-17313Q / fall23-nodebb-inshallah-a / 6239420468

19 Sep 2023 06:18PM UTC coverage: 77.199% (+0.01%) from 77.188%
6239420468

push

github

web-flow
Merge pull request #59 from CMU-17313Q/Adding-isAnonymous-if-conditions

Adding is anonymous if conditions

9091 of 13356 branches covered (0.0%)

Branch coverage included in aggregate %.

20876 of 25462 relevant lines covered (81.99%)

2463.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

17.57
/src/socket.io/posts/tools.js
1
'use strict';
2

3
const nconf = require('nconf');
4✔
4

5
const db = require('../../database');
4✔
6
const posts = require('../../posts');
4✔
7
const flags = require('../../flags');
4✔
8
const events = require('../../events');
4✔
9
const privileges = require('../../privileges');
4✔
10
const plugins = require('../../plugins');
4✔
11
const social = require('../../social');
4✔
12
const user = require('../../user');
4✔
13
const utils = require('../../utils');
4✔
14

15
module.exports = function (SocketPosts) {
4✔
16
    SocketPosts.loadPostTools = async function (socket, data) {
4✔
17
        if (!data || !data.pid || !data.cid) {
×
18
            throw new Error('[[error:invalid-data]]');
×
19
        }
20

21
        const results = await utils.promiseParallel({
×
22
            posts: posts.getPostFields(data.pid, ['deleted', 'bookmarks', 'uid', 'ip', 'flagId']),
23
            isAdmin: user.isAdministrator(socket.uid),
24
            isGlobalMod: user.isGlobalModerator(socket.uid),
25
            isModerator: user.isModerator(socket.uid, data.cid),
26
            canEdit: privileges.posts.canEdit(data.pid, socket.uid),
27
            canDelete: privileges.posts.canDelete(data.pid, socket.uid),
28
            canPurge: privileges.posts.canPurge(data.pid, socket.uid),
29
            canFlag: privileges.posts.canFlag(data.pid, socket.uid),
30
            flagged: flags.exists('post', data.pid, socket.uid), // specifically, whether THIS calling user flagged
31
            bookmarked: posts.hasBookmarked(data.pid, socket.uid),
32
            postSharing: social.getActivePostSharing(),
33
            history: posts.diffs.exists(data.pid),
34
            canViewInfo: privileges.global.can('view:users:info', socket.uid),
35
        });
36

37
        const postData = results.posts;
×
38
        postData.absolute_url = `${nconf.get('url')}/post/${data.pid}`;
×
39
        postData.bookmarked = results.bookmarked;
×
40
        postData.selfPost = socket.uid && socket.uid === postData.uid;
×
41
        postData.display_edit_tools = results.canEdit.flag;
×
42
        postData.display_delete_tools = results.canDelete.flag;
×
43
        postData.display_purge_tools = results.canPurge;
×
44
        postData.display_flag_tools = socket.uid && results.canFlag.flag;
×
45
        postData.display_moderator_tools = postData.display_edit_tools || postData.display_delete_tools;
×
46
        postData.display_move_tools = results.isAdmin || results.isModerator;
×
47
        postData.display_change_owner_tools = results.isAdmin || results.isModerator;
×
48
        postData.display_ip_ban = (results.isAdmin || results.isGlobalMod) && !postData.selfPost;
×
49
        postData.display_history = results.history;
×
50
        postData.flags = {
×
51
            flagId: parseInt(results.posts.flagId, 10) || null,
×
52
            can: results.canFlag.flag,
53
            exists: !!results.posts.flagId,
54
            flagged: results.flagged,
55
            state: await db.getObjectField(`flag:${postData.flagId}`, 'state'),
56
        };
57

58
        if (!results.isAdmin && !results.canViewInfo) {
×
59
            postData.ip = undefined;
×
60
        }
61
        const { tools } = await plugins.hooks.fire('filter:post.tools', {
×
62
            pid: data.pid,
63
            post: postData,
64
            uid: socket.uid,
65
            tools: [],
66
        });
67
        postData.tools = tools;
×
68

69
        return results;
×
70
    };
71

72
    SocketPosts.changeOwner = async function (socket, data) {
4✔
73
        if (!data || !Array.isArray(data.pids) || !data.toUid) {
×
74
            throw new Error('[[error:invalid-data]]');
×
75
        }
76
        const isAdminOrGlobalMod = await user.isAdminOrGlobalMod(socket.uid);
×
77
        if (!isAdminOrGlobalMod) {
×
78
            throw new Error('[[error:no-privileges]]');
×
79
        }
80

81
        const postData = await posts.changeOwner(data.pids, data.toUid);
×
82
        const logs = postData.map(({ pid, uid, cid }) => (events.log({
×
83
            type: 'post-change-owner',
84
            uid: socket.uid,
85
            ip: socket.ip,
86
            targetUid: data.toUid,
87
            pid: pid,
88
            originalUid: uid,
89
            cid: cid,
90
        })));
91

92
        await Promise.all(logs);
×
93
    };
94
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc