MyBB Community Forums

Full Version: Don't show the attachment when moderate is activated
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello
  • Having a forum in latest version (1.8.35) with "Enable Attachment Functionality"
  • Having one admin user A, two users B and C with "Moderate new attachments?" and "Moderate new threads?" on a forum
  • Posting with user B a news thread with one attachment
  • User A approve the thread and then approve the attachment of B
  • C can see the thread of B but not the attachment

Even if all has been approved, C can't see the attachment, that's the problem

If you need more details don't hesitate
Thanks

After investigating in the SQL DB:
When moderating a attachment of a thread, the attachmentcount column in threads is not incremented (and is 0 instead of 1)
(2023-08-19, 11:53 AM)Kcchouette Wrote: [ -> ]C can see the thread of B but not the attachment

Perhaps the "Can download attachments?" permission is set to "No" for C's usergroup either at:

Forums & Posts » Options (Beside the forum in question) » Permissions » Set Custom Permissions (Beside C's usergroup) » Viewing (default tab)

or

Users & Groups » Groups » [Click on C's usergroup] » Forums and Posts (second tab)

(2023-08-19, 11:53 AM)Kcchouette Wrote: [ -> ]After investigating in the SQL DB:
When moderating a attachment of a thread, the attachmentcount column in threads is not incremented (and is 0 instead of 1)

Does running

Tools & Maintenance » Recount & Rebuild » Rebuild Thread Counters

set attachmentcount to the correct value?
(2023-08-20, 01:42 AM)Laird Wrote: [ -> ]Perhaps the "Can download attachments?" permission is set to "No" for C's usergroup either at:

Forums & Posts » Options (Beside the forum in question) » Permissions » Set Custom Permissions (Beside C's usergroup) » Viewing (default tab)

or

Users & Groups » Groups » [Click on C's usergroup] » Forums and Posts (second tab)

No as doing the fix by incrementing the value fix the issue (and moreover if A create a thread with a attachment, C can download it)

(2023-08-20, 01:42 AM)Laird Wrote: [ -> ]Does running

Tools & Maintenance » Recount & Rebuild » Rebuild Thread Counters

set attachmentcount to the correct value?

Yes
Maybe it is related to a similar problem I encountered, that when the attachment is approved in the Mod-CP, the "attachmentcount" in the "_threads" table is not incremented. If there are no other attachments in the respective thread yet, the counter remains at 0 and thus the attachment is not displayed to users without mod permission.

I fixed it by searching in modcp.php for lines 2063-2092:

else if(!empty($mybb->input['attachments']))
{
    $attachments = array_map("intval", array_keys($mybb->input['attachments']));
    $query = $db->query("
        SELECT a.pid, a.aid
        FROM  ".TABLE_PREFIX."attachments a
        LEFT JOIN ".TABLE_PREFIX."posts p ON (a.pid=p.pid)
        LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
        WHERE aid IN (".implode(",", $attachments)."){$tflist_queue_attach}
    ");
    while($attachment = $db->fetch_array($query))
    {
        if(!isset($mybb->input['attachments'][$attachment['aid']]))
        {
            continue;
        }
        $action = $mybb->input['attachments'][$attachment['aid']];
        if($action == "approve")
        {
            $db->update_query("attachments", array("visible" => 1), "aid='{$attachment['aid']}'");
        }
        else if($action == "delete")
        {
            remove_attachment($attachment['pid'], '', $attachment['aid']);
        }
    }

    $plugins->run_hooks("modcp_do_modqueue_end");

    redirect("modcp.php?action=modqueue&type=attachments", $lang->redirect_attachmentsmoderated);
} 

and changing them to:

else if(!empty($mybb->input['attachments']))
{
    $attachments = array_map("intval", array_keys($mybb->input['attachments']));
    $query = $db->query("
        SELECT a.pid, a.aid, t.tid
        FROM  ".TABLE_PREFIX."attachments a
        LEFT JOIN ".TABLE_PREFIX."posts p ON (a.pid=p.pid)
        LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
        WHERE aid IN (".implode(",", $attachments)."){$tflist_queue_attach}
    ");
    while($attachment = $db->fetch_array($query))
    {
        if(!isset($mybb->input['attachments'][$attachment['aid']]))
        {
            continue;
        }
        $action = $mybb->input['attachments'][$attachment['aid']];
        if($action == "approve")
        {
            $db->update_query("attachments", array("visible" => 1), "aid='{$attachment['aid']}'");
            if(isset($attachment['tid']))
            {
                update_thread_counters((int)$attachment['tid'], array("attachmentcount" => "+1"));
            }
        }
        else if($action == "delete")
        {
            remove_attachment($attachment['pid'], '', $attachment['aid']);
            if(isset($attachment['tid']))
            {
                update_thread_counters((int)$attachment['tid'], array("attachmentcount" => "-1"));
            }
        }
    }

    $plugins->run_hooks("modcp_do_modqueue_end");

    redirect("modcp.php?action=modqueue&type=attachments", $lang->redirect_attachmentsmoderated);
} 
(2023-09-10, 12:40 PM)Eldenroot Wrote: [ -> ]https://github.com/mybb/mybb/pull/4749

Thank you for taking care of the problem