Problem/Motivation

The 'Check if this account matches a known spammer' button does not work correctly if the API of stopforumspam.com returns a match.

Steps to reproduce

  • Use 8.x-1.0-alpha3
  • Have an existing user whose email address is found in stopforumspam.com database
  • Use the 'Check if this account matches a known spammer' button
  • Observe that the result message of 'Check if this account matches a known spammer' says that this user is not a spammer
  • Observe in Drupal logs that the response from stopforumspam.com indicates that this account is a spammer

Proposed resolution

With a quick glance, the issue seems to be in SpambotUserspamForm.php.

checkSubmit calls static::sfsRequestDataMessage which looks like this:

  public function sfsRequestDataMessage($request, $data, $field) {
    $messages[] = [
      'text' => $this->t("This account's @field address matches %num times: @link", [
        '@field' => $field,
        '@link' => Link::fromTextAndUrl($request[$field], Url::fromUri('http://www.stopforumspam.com/search?q=' . $request[$field])),
        '%num' => $data[$field]['frequency'],
      ]),
      'type' => 'warning',
    ];

This function does not return anything and the scope of $messages is that function only. So when we later in the checkSubmit try to add the messages to the messenger, $messages will be empty.

Remaining tasks

Why are we making a static call to sfsRequestDataMessage? Shouldn't we just make $messages a class variable and then say $this->messages all over the place?

Or alternatively change sfsRequestDataMessage returning the messages so that those would be appended to $messages where sfsRequestDataMessage is called. The code is kinda a mixture of object oriented and procedural code so either approach should do the trick if we keep the structure of the code like it is without refactoring it too much in the scope of this issue.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

masipila created an issue. See original summary.

masipila’s picture

Issue summary: View changes
danchadwick’s picture

Here's a patch the generates the correct message and also fixes the error of passing a Link object as a substitution to t()/

danchadwick’s picture

Status: Active » Needs review

D'oh. Needs review. Also you won't get a message until you apply the patch that fixes returning errors.

kala4ek’s picture

Assigned: Unassigned » kala4ek

  • DanChadwick authored 4ecca11 on 8.x-1.x
    Issue #3194278 by DanChadwick, masipila, kala4ek: Check if account...
kala4ek’s picture

Version: 8.x-1.0-alpha3 » 8.x-1.x-dev
Assigned: kala4ek » Unassigned
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.