Vote Anonymous is a Drupal contributed module that enables anonymous users to vote on node entities with configurable restrictions and behavior. It allows site administrators to control voting logic using cookies, preventing duplicate voting and managing voting visibility.

Project link

https://www.drupal.org/project/vote_anon

Comments

dkmishra created an issue. See original summary.

dkmishra’s picture

Status: Active » Needs review
vishal.kadam’s picture

Issue summary: View changes
avpaderno’s picture

Thank you for applying!

Before giving links helpful to understand how the review process works, what to expect from a review, and what to do to avoid a review takes more time than needed, I would like to thank all the reviewers for the work they do.
These applications are volunters-driven, which also means it is not possible to predict when an application will be marked fixed and the applicant will get the permission to opt projects into security advisory policy. While we aim to make an application as quick as possible, it is also important for us that more people review the project used for an application. In this way, we make sure applications do not miss some important points that should be instead reported.
Applications are not meant to be complete debugging sessions that eliminate every existing bug, though. I apologize if sometimes applications seem to go into too-detailed reviews.

Please read Review process for security advisory coverage: What to expect for more details and Security advisory coverage application checklist to understand what reviewers look for. Tips for ensuring a smooth review gives some hints for a smoother review.

The important notes are the following.

  • If you have not done it yet, you should enable GitLab CI for the project and fix the PHP_CodeSniffer errors/warnings it reports.
  • For the time this application is open, only your commits are allowed.
  • The purpose of this application is giving you a new drupal.org role that allows you to opt projects into security advisory coverage, either projects you already created, or projects you will create. The project status will not be changed by this application; once this application is closed, you will be able to change the project status from Not covered to Opt into security advisory coverage. This is possible only 14 days after the project is created.

    Keep in mind that once the project is opted into security advisory coverage, only Security Team members may change coverage.
  • Only the person who created the application will get the permission to opt projects into security advisory coverage. No other person will get the same permission from the same application; that applies also to co-maintainers/maintainers of the project used for the application.
  • We only accept an application per user. If you change your mind about the project to use for this application, or it is necessary to use a different project for the application, please update the issue summary with the link to the correct project and the issue title with the project name and the branch to review.

To the reviewers

Please read How to review security advisory coverage applications, Application workflow, What to cover in an application review, and Tools to use for reviews.

The important notes are the following.

  • It is preferable to wait for a project moderator before posting the first comment on newly created applications. Project moderators will do some preliminary checks that are necessary before any change on the project files is suggested.
  • Reviewers should show the output of a CLI tool only once per application.
  • It may be best to have the applicant fix things before further review.

For new reviewers, I would also suggest to first read In which way the issue queue for coverage applications is different from other project queues.

vishal.kadam’s picture

Status: Needs review » Needs work

1. FILE: vote_anon.module

For a new module that aims to be compatible with Drupal 10 and Drupal 11, I would rather implement hooks as class methods as described in Support for object oriented hook implementations using autowired services.
It would require increasing the minimum Drupal 10 version supported, but Drupal 10.1 is no longer supported.

2. FILE: README.txt

Remove README.txt since README.md is already present.

3. FILE: src/Controller/SingleNodeVoteAjaxController.php

  /**
   * The database connection.
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected Connection $database;

  /**
   * The time service.
   *
   * @var \Drupal\Component\Datetime\TimeInterface
   */
  protected TimeInterface $time;

  /**
   * The user storage.
   *
   * @var \Drupal\user\UserStorageInterface
   */
  protected UserStorageInterface $userStorage;

  /**
   * The node storage.
   *
   * @var \Drupal\node\NodeStorageInterface
   */
  protected NodeStorageInterface $nodeStorage;

  /**
   * Constructs the controller.
   */
  public function __construct(
    Connection $database,
    TimeInterface $time,
    UserStorageInterface $user_storage,
    NodeStorageInterface $node_storage,
  ) {
    $this->database    = $database;
    $this->time        = $time;
    $this->userStorage = $user_storage;
    $this->nodeStorage = $node_storage;
  }

FILE: src/Controller/VoteAjaxController.php

  /**
   * The database connection.
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected Connection $database;

  /**
   * The time service.
   *
   * @var \Drupal\Component\Datetime\TimeInterface
   */
  protected TimeInterface $time;

  /**
   * The node storage.
   *
   * @var \Drupal\node\NodeStorageInterface
   */
  protected NodeStorageInterface $nodeStorage;

  /**
   * Constructs VoteAjaxController.
   */
  public function __construct(
    Connection $database,
    TimeInterface $time,
    NodeStorageInterface $node_storage,
  ) {
    $this->database    = $database;
    $this->time        = $time;
    $this->nodeStorage = $node_storage;
  }

FILE: src/Form/VoteConfigurationForm.php

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected EntityTypeManagerInterface $entityTypeManager;

  /**
   * Constructs the form.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

New modules, which are compatible with Drupal 10 and higher versions are expected to use constructor property promotion.

4. FILE: src/Form/VoteConfigurationForm.php

With Drupal 10 and Drupal 11, there is no longer need to use #default_value for each form element, when the parent class is ConfigFormBase: It is sufficient to use #config_target, as in the following code.

    $form['image_toolkit'] = [
      '#type' => 'radios',
      '#title' => $this->t('Select an image processing toolkit'),
      '#config_target' => 'system.image:toolkit',
      '#options' => [],
    ];

Using that code, it is no longer needed to save the configuration values in the form submission handler: The parent class will take care of that.
For this change, it is necessary to require at least Drupal 10.3, but that is not an issue, since Drupal 10.2.x is no longer supported.

dkmishra’s picture

Thank you for your feedback. I will work on resolving these issues and update you accordingly.

dkmishra’s picture

Status: Needs work » Needs review

All the mentioned issues have been fixed — coding standards, prettier formatting, and docblock corrections. Please review.

vishal.kadam’s picture

Status: Needs review » Needs work

Add .module file

Since the module is declared compatible with Drupal 10.3, removing the function implementing the hook is not possible. The function still needs to be defined, but it calls the method defined by the service class, as described in Support for object oriented hook implementations using autowired services (Backwards-compatible Hook implementation for Drupal versions from 10.1 to 11.0).

avpaderno’s picture

  • The following points are just a start and don't necessarily encompass all of the changes that may be necessary
  • A specific point may just be an example and may apply in other places
  • A review is about code that does not follow the coding standards, contains possible security issue, or does not correctly use the Drupal API
  • The single review points are not ordered, not even by importance

The project is using a master branch.
You should really be working in a release specific branch. The most direct documentation on this is Moving from a master branch to a version branch. For additional resources please see the documentation about release naming conventions and creating a branch in git.

Since the module is declared compatible with Drupal 10.3, removing the function implementing the hook is not possible.
The function still needs to be defined, but it calls the method defined by the service class, as described in Support for object oriented hook implementations using autowired services / Backwards-compatible Hook implementation for Drupal versions from 10.1 to 11.0.

// @phpstan-ignore-next-line
#[LegacyHook]
function node_user_cancel($edit, UserInterface $account, $method) {
  return \Drupal::service(NodeHooks::class)->userCancel($edit, $account, $method);
}

src/Controller/SingleNodeVoteAjaxController.php

Since that class does not use methods from the parent class, or it uses a single method from the parent class, it does not need to use ControllerBase as parent class.

Controllers do not need to have a parent class; as long as they implement \Drupal\Core\DependencyInjection\ContainerInjectionInterface, they are fine.

  /**
   * Constructs the controller.
   */

The documentation comment for the constructor is no longer mandatory; if it added, its short description should be Constructs a new [class name] instance. or Constructs a new [class name] object. where [class name] is the name of the class, including its namespace.

Documentation comments for methods and functions need to also document parameters and return value, if there is any.

    $config            = $this->config('vote_anon.voteconfiguration');
    $already_vote      = Xss::filterAdmin((string) $config->get('warning_for_duplicate_voting'));
    $new_vote          = Xss::filterAdmin((string) $config->get('message_after_voting'));
    $disable_vote_link = (bool) $config->get('disable_vote_link');

As per Drupal coding standards, only a single space is used before and after the assignment operator (and other operators too).

    $config            = $this->config('vote_anon.voteconfiguration');
    $already_vote      = Xss::filterAdmin((string) $config->get('warning_for_duplicate_voting'));
    $new_vote          = Xss::filterAdmin((string) $config->get('message_after_voting'));
    $disable_vote_link = (bool) $config->get('disable_vote_link');
    // Omissis
      $output = '<div id="' . $destination_id . '" class="vote-anon-message vote-anon-message--success">'
        . $new_vote . '</div>';
    }
    else {
      $output = '<div id="' . $destination_id . '" class="vote-anon-message vote-anon-message--warning">'
        . $already_vote . '</div>';
    }

Strings shown in the user interface must be translatable.

Configuration object values are translatable if the module define its schema and has a .config_translation.yml file which says which of the values in a configuration form are translatable. See user.config_translation.yml or
system.config_translation.yml as example of .config_translation.yml files used by Drupal core.

src/Form/VoteConfigurationForm.php

'#description' => $this->t('Allowed characters: <code>A-Z a-z 0-9 _ -'),

It is probably better to say Only letters, numbers, hyphens, and underscores are allowed. like the error message does. A-Z a-z 0-9 _ - is probably not clear to many people.

avpaderno’s picture

Projects like Fivestar already allow anonymous votes. Why did you decide to create a new project instead of joining forces with that project?

dkmishra’s picture

Status: Needs work » Needs review

Thank you for the feedback. I created Vote Anon because my goal is different from Fivestar’s use case. Fivestar is mainly focused on rating-style voting widgets, while Vote Anon is intended to provide a lightweight and reusable anonymous voting mechanism that can be integrated independently of rating UIs.
-No star ratings — just a simple single-click vote
-No dependencies on third-party rating libraries
-Cookie- and session-based tracking without requiring user accounts

I have addressed all the feedback points. Please review again.

avpaderno’s picture

Status: Needs review » Needs work

That is information the project page should give.

dkmishra’s picture

Status: Needs work » Needs review

Thank you for the suggestion. I have updated the project page description to clearly explain the use case and how it differs from other voting modules.

dkmishra’s picture

Please let me know if need any other change.