When site require approvals for users, email replies do not get sent to staged users

AI-generated summary

A bug was reported where email replies are not sent to staged users when a site requires approvals for users. The issue lies in the notification_emailer.rb file, specifically in the perform_enqueue method. The line return if SiteSetting.must_approve_users? && !user.approved? blocks staged users from receiving reply emails because they are, by definition, not approved.

codinghorror notes that staged users can only be notified of and reply to the topics they started or were invited in, but the current code prevents this.

sam agreed to write a test for this issue and later reported that it has been fixed (sam).

In notification_emailer.rb:

    def perform_enqueue(type, delay)
      user = notification.user
      return unless user.active? || user.staged?
      return if SiteSetting.must_approve_users? && !user.approved?

      return unless EMAILABLE_POST_TYPES.include?(post_type)

      Jobs.enqueue_in(delay, :user_email, self.class.notification_params(notification, type))
    end

The line:

return if SiteSetting.must_approve_users? && !user.approved?

is suspect because staged users are obviously NOT approved… it would be rather strange for a user to be staged but then approved.

Therefore the whole thing falls apart if the forum is set to require approval.

I’m pretty sure the code should be:

return if SiteSetting.must_approve_users? && !user.staged? && !user.approved?
3 « J'aime »

Are they not getting notified of replies to topics they started as a staged user?

Quite possibly, what do you think @sam?

Correct. Even if they originated the topics via rmail, they won’t get reply emails. The return statement blocks it.

1 « J'aime »

Will write a test for this later today

2 « J'aime »

Fixed per:

https://github.com/discourse/discourse/commit/50203794e6d338d48746b087d70c83f775233e3d

Thanks for the report!

6 « J'aime »