verbb / comments

A Craft CMS plugin for managing comments directly within the CMS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

bzin opened this issue · 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.

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?

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

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

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',
    ]
];

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 = []

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