comments icon indicating copy to clipboard operation
comments copied to clipboard

GraphQL - flagging a comment using graphql api does not flag the comment in CP nor sends a notification

Open bzin opened this issue 2 years ago • 6 comments

Describe the bug

I am using comments with GraphQL API, and the feature for flagging a comment is not working properly or as expected.

The GraphQL mutation executes successfully, and I can see the flag in the comments_flag database table. However, neither a notification is sent nor is the control panel updated with the comment flagged.

Steps to reproduce

  1. Enable notifications for comments.
  2. Execute a mutation to flag a comment.
  3. Check the comment in the control panel, which is not flagged in the overview list.
  4. No notification email has been sent to the admin/moderator users.

Craft CMS version

4.3.10

Plugin version

2.0.6

Multi-site?

No

Additional context

I am using Comments in a headless Craft installation that uses Next.js.

bzin avatar Mar 07 '23 17:03 bzin

I can't seem to replicate that, sorry. Flagging a comment via GraphQL is indeed adding the row to the database, which shows up in the comment element index, and email notification is sent.

Anything in your /storage/logs/comments.log file?

engram-design avatar Mar 07 '23 21:03 engram-design

Hi @engram-design not sure why but I just realise that I get this back when flagging a comment via the GraphQL.

"verbb\\comments\\gql\\resolvers\\mutations\\Comment::flagComment(): Return value must be of type ?craft\\base\\ElementInterface, verbb\\comments\\models\\Flag returned"

CleanShot 2023-03-08 at 13 16 25

bzin avatar Mar 08 '23 12:03 bzin

Ah, I haven't tagged a release for these changes yet. Updated in 2.0.7

engram-design avatar Mar 08 '23 23:03 engram-design

Ok, so I updated to 2.0.7 and it does seem that flagging is working but I do not see CP element index being updated nor receive the notification.

I even set the flaggedCommentLimit to be 1 just to make sure the comment is flagged.

On my comments.log I also see:

2023-03-09 11:15:54 [ERROR] Error rendering email template: Variable "emailKey" does not exist. /var/www/html/templates/_email/emailTemplate.twig:58.

I believe I should get comments_flag_notification here right?

Our settings are:

<?php

// See https://verbb.io/craft-plugins/comments/docs/get-started/configuration
return [
    '*' => [
        'indexSidebarLimit' => 25,
        'indexSidebarGroup' => true,
        'indexSidebarIndividualElements' => false,
        'defaultQueryStatus' => ['approved'],

        // General
        'allowGuest' => false,
        'guestNotice' => '',
        'guestRequireEmailName' => true,
        'guestShowEmailName' => true,
        'requireModeration' => false,
        'moderatorUserGroup',
        'autoCloseDays' => '',
        'maxReplyDepth' => '',
        'maxUserComments' => '',

        // Voting
        'allowVoting' => true,
        'allowGuestVoting' => false,
        'downvoteCommentLimit' => 5,
        'hideVotingForThreshold' => true,

        // Flagging
        'allowFlagging' => true,
        'allowGuestFlagging' => false,
        'flaggedCommentLimit' => 1,

        // Templates - Default
        'showAvatar' => true,
        'placeholderAvatar' => '',
        'showTimeAgo' => true,
        'outputDefaultCss' => false,
        'outputDefaultJs' => false,

        // Templates - Custom
        // 'templateFolderOverride' => '',
        // 'templateEmail' => '',

        // Security
        'enableSpamChecks' => false,
        'securityMaxLength' => '',
        'securityFlooding' => '',
        'securityModeration' => '',
        'securitySpamlist' => '',
        'securityBanned' => '',
        'securityMatchExact' => false,
        'recaptchaEnabled' => false,
        'recaptchaKey' => '',
        'recaptchaSecret' => '',
        'recaptchaMinScore' => 0.5,

        // Notifications
        'notificationAuthorEnabled' => true,
        'notificationReplyEnabled' => true,
        'notificationSubscribeAuto' => false,
        'notificationSubscribeDefault' => true,
        'notificationSubscribeEnabled' => true,
        'notificationSubscribeCommentEnabled' => false,
        'notificationModeratorEnabled' => false,
        'notificationModeratorApprovedEnabled' => false,
        'notificationAdmins' => [
            [
                'email' => getenv('COMMENTS_EMAIL'),
                'enabled' => true,
            ],
        ],
        'notificationAdminEnabled' => false,
        'notificationFlaggedEnabled' => true,
        'useQueueForNotifications' => true,

        // Permissions
        'permissions' => [],

        // Custom Fields
        'showCustomFieldNames' => true,
        'showCustomFieldInstructions' => true,

        // CP Sort
        'sortDefaultKey' => 'structure',
        'sortDefaultDirection' => 'asc',
    ]
];


bzin avatar Mar 09 '23 10:03 bzin

Just tried to avoid the emailKey error but I do not have the error but email is not sent:

2023-03-09 12:13:44 [INFO] Prepare Flag Notifications.
2023-03-09 12:13:44 [INFO] Email sent successfully to flag ()
2023-03-09 12:13:44 [INFO] Prepare Flag Notifications.
2023-03-09 12:13:44 [INFO] Email sent successfully to flag ()
2023-03-09 12:13:44 [INFO] Prepare Flag Notifications.
2023-03-09 12:13:44 [INFO] Email sent successfully to flag ()
2023-03-09 12:13:44 [INFO] Prepare Flag Notifications.
2023-03-09 12:13:44 [INFO] Email sent successfully to flag ()
2023-03-09 12:13:44 [INFO] Prepare Flag Notifications.
2023-03-09 12:13:44 [INFO] Email sent successfully to flag ()
2023-03-09 12:13:44 [INFO] Prepare Flag Notifications.
2023-03-09 12:13:44 [INFO] Email sent successfully to flag ()
2023-03-09 12:13:44 [INFO] Request context:
$_GET = [
    'p' => 'admin/actions/queue/run'
    'v' => '1678360422136'
]

$_POST = []

bzin avatar Mar 09 '23 11:03 bzin

Can you let me know the content of your templates/_email/emailTemplate.twig file? That seems to be a custom template.

But that last log looks interesting, it's evaluating your getenv('COMMENTS_EMAIL') to be empty (we better add error handling around having blank values). Are you able to maybe debug that to see if that .env variable is getting set?

I'm not sure what's going on with it not appearing in the element index. To be clear, they should show a red status symbol if flagged image

engram-design avatar Mar 09 '23 21:03 engram-design