This module provides friendship workflows for Drupal users, enabling users to follow, connect, and manage friendship relationships.

Project link

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

Comments

vitaliyb98 created an issue. See original summary.

vishal.kadam’s picture

Title: [2.0.x] Friendship » [2.x] Friendship

Thank you for applying!

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. See also Policy on the use of AI when contributing to Drupal, which is valid when contributing to Drupal, either by committing code in a project, or by creating a merge request for an existing project.

The important notes are the following.

  • For the purposes of this application, it is not necessary to create releases or pre-releases. It is better to make commits only on a branch, and possibly in the same branch used from the start.
  • 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.

batigolix’s picture

Assigned: Unassigned » batigolix
Status: Needs review » Active
batigolix’s picture

I reviewed the application.

Here is a list of possible improvements.

1. Fix the phpstan warnings as shown in the Gitlab CI pipeline

2. Convert the readme.txt to a README.md conform following the template in https://www.drupal.org/docs/develop/managing-a-drupalorg-theme-module-or...

3. LICENSE.txt is not needed as your module has the same license as Drupal. See https://www.drupal.org/node/1587704#licensingchecks

4. Review the security of the routes. It seems there are no access checks defined on any friendship action routes. Any authenticated user could trigger actions without proper permission verification. Location: friendship.routing.yml - all routes

5. Review the security of the routes. Check if the need csrf_token as requirement. See https://www.drupal.org/docs/8/api/routing-system/access-checking-on-rout...

6. src/Controller/FriendshipController.php . This controller methods accept UserInterface but don't validate if: User exists and is active, User is not the current user, User is not blocked or deleted

7. src/FriendshipService.php use Drupal API to generate token. \Drupal::service('uuid')->generate() instead $id_hash = md5($target_user->id() + rand());

8. Add field descriptions in friendship_schema, because most are empty. E.g.:

      'status' => [
        'description' => '',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],

9. src/FriendshipInterface.php Interface doesn't declare getProcessLink() and getLinkAttributes() methods

10. Improve name and logic of method isHasRelationship. I think it should retun true if there is a relationship?:

  public function isHasRelationship(UserInterface $target_user): bool {
    $result = $this->getFriendshipRow($this->currentUser, $target_user);

    if (empty($result)) {
      $result = $this->getFriendshipRow($target_user, $this->currentUser);

      if (empty($result)) {
        return TRUE;
      }
    }

return FALSE;
}

11. Try resolve as much @todo comments as possible.

12. Automatic tests could be useful to prevent future regressions

13. hook_uninstall does not remove the custom table data

14. friendship/process-link library is missing (see FriendshipService.php):

         '#attached' => [
          'library' => [
            'core/drupal.ajax',
            'friendship/process-link',
          ],

15. Friendship.php refers to a missing Views data handler "views_data" = "Drupal\friendship\Entity\EntityViewsData",

16. Add more inline documentation for more complex method. E.g. in FriendshipService.php

batigolix’s picture

Assigned: batigolix » Unassigned
Status: Active » Needs work
vitaliyb98’s picture

Status: Needs work » Needs review

Hi @batigolix, thanks for your feedback.

I made changes according to your suggestion ( in release 2.1.0):

  1. Fixed
  2. Fixed
  3. Fixed
  4. Fixed
  5. Fixed
  6. Fixed
  7. Fixed
  8. Fixed (Removed that schema, because only the friendship entity used is defined in Friendship.php)
  9. Fixed
  10. Fixed
  11. Fixed
  12. Created issue for it, will make it in next iteration: https://www.drupal.org/project/friendship/issues/3567173
  13. This module doesn't have custom table data, only friendship entity, the old hook scheme does nothing, because the entity with the same name already exists, and the custom table wasn't created
  14. Fixed (removed as it is not actual anymore)
  15. Fixed
  16. Split up complex method into smaller methods
vishal.kadam’s picture

As a side note: These applications do not require that new releases are created after reviews.

It is better not to create new release during these applications, since a review could ask for a change that is not backward compatible with the existing releases. Just using a development version avoids those BC issues.

nkmani’s picture

I reviewed the latest 2.x branch code and following are my comments:

1. friendship.info.yml
Version 9.5 is an unsupported release. Consider dropping support.

2. friendship.permissions.yml
Consistency in naming yml keys; the first line does not need quotes.

3. FriendShipService.php, TotalFollowersNumber.php, TotalFollowingNumber.php, TotalFriendsNumber.php
The query results are not cached; dependence on downstream caching, which is fine. But ...

4. FriendshipSettingsForm.php
In case version 9.5 support is removed, then there is no need for '#default_value'; instead use '#config_target'. Simplifies the form; there is no need for implementing submitForm; that would be handled in the base class.

5. Consider using string constants for often re-used string values.

vishal.kadam’s picture

Status: Needs review » Needs work
vitaliyb98’s picture

Status: Needs work » Needs review

Hi, made changes according to your comments:

1. Introduced a new major branch 3.x which will support Drupal >= 10 https://git.drupalcode.org/project/friendship/-/blob/3.x/friendship.info...

2. Fixed: https://git.drupalcode.org/project/friendship/-/blob/2.x/friendship.perm...

3. Added cache https://git.drupalcode.org/project/friendship/-/blob/2.x/src/Plugin/view...

4. Done (in 3.x): https://git.drupalcode.org/project/friendship/-/blob/3.x/src/Form/Friend...

5. Checked code to detect which string values could be replaced with a constant, introduced this:

  /**
   * Ajax link prefix css selector.
   *
   * @var string
   */
  const AJAX_LINK_PREFIX_SELECTOR = 'friendship-ajax-link-';
vitaliyb98’s picture

Hi guys, any updates?

vishal.kadam’s picture

Priority: Normal » Major

I am changing priority as per Issue priorities.

vishal.kadam’s picture

Priority: Major » Critical

I am changing priority as per Issue priorities.

avpaderno’s picture

Title: [2.x] Friendship » [3.x] Friendship
solideogloria’s picture

Status: Needs review » Needs work

The method isHasRelationship should be named hasRelationship. You want the words in the function name to make grammatical sense. You can deprecate the old function and make it call the new. Similarly, isFollowedYou should be isFollowingYou or hasFollowedYou. isRequestSend should be isRequestSent.

Friendship is a ContentEntityType, but it's using the Annotation instead of the Attribute. I'm not sure what the minimum version requirement for using Drupal\Core\Entity\Attribute\ContentEntityType is, but it's worth looking into whether you can use the attribute instead.

Constructor doc block comments are now optional. Consider removing extraneous comments like this that don't add any new information:

  /**
   * Controller constructor.
   */

Consider making the return type of the controller's access method AccessResultInterface.

solideogloria’s picture

Priority: Critical » Normal
vitaliyb98’s picture

Status: Needs work » Needs review

Hi @solideogloria,

Thank you for your feedback. I appreciate it.
I made changes based on your suggestion and merged them into the 3.x branch: https://git.drupalcode.org/project/friendship/-/tree/3.x?ref_type=heads

vitaliyb98’s picture

Hi, guys, any updates?

vishal.kadam’s picture

Priority: Normal » Major

I am changing priority as per Issue priorities.

avpaderno’s picture

Assigned: Unassigned » avpaderno
avpaderno’s picture

Priority: Major » Normal
Status: Needs review » Needs work
  • 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

src/Controller/FriendshipController.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.

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('friendship.friendship_service'),
    );
  }

With Drupal 10.2.x and higher versions, a controller class does not need to implement create(); using AutowireTrait, it just needs to implement the class constructor.

src/Entity/Friendship.php

Projects that are compatible with Drupal 10 or higher versions should use attributes instead of annotations. This means requiring at least Drupal 10.3, but this is not an issue, considering which Drupal core versions are nowadays supported.

src/Form/FriendshipSettingsForm.php

    $form['button_settings']['follow_button_text'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Follow text'),
      '#config_target' => 'friendship.settings:button.follow_text',
    ];

As described in #config_target in ConfigFormBase: using validation constraints for editing simple config, that code only works starting with Drupal 10.2.x. The project needs to explicitly require Drupal 10.2.x or any higher version.

src/FriendshipService.php

Services can be autowired starting with Drupal 9.3.x. This means that it is no longer necessary to give a list of service arguments in the .services.yml file; they will be retrieved from the constructor definition.

$this->config = $configFactory->get('friendship.settings');

Using a class property for the configuration object is considered an anti-pattern. Instead, the class property should be for the configuration factory.

  /**
   * {@inheritdoc}
   */
  public function isRequestSent(UserInterface $target_user): bool {
    $status = $this->getFriendshipStatusBetweenUsers($this->currentUser, $target_user);

    if ($status === FriendshipStatus::Following) {
      $status = $this->getFriendshipStatusBetweenUsers($target_user, $this->currentUser);

      return $status === FriendshipStatus::Follower;
    }

    return FALSE;
  }

  /**
   * Check if the request is already sent.
   *
   * @param \Drupal\user\UserInterface $target_user
   *   Target user.
   *
   * @return bool
   *   Indicates if the request was sent.
   *
   * @deprecated in friendship:3.0.0 and is removed from friendship:4.0.0.
   *   Use \Drupal\friendship\FriendshipService::isRequestSent() instead.
   *
   * @see https://www.drupal.org/project/friendship/issues/3608224
   */
  public function isRequestSend(UserInterface $target_user): bool {
    @trigger_error('isRequestSend() is deprecated in friendship:3.0.0 and is removed from friendship:4.0.0. Use isRequestSent() instead. See https://www.drupal.org/project/friendship/issues/3608224', E_USER_DEPRECATED);
    return $this->isRequestSent($target_user);
  }

Deprecating that method has been done in the correct way. 👍

src/FriendshipInterface.php

Deprecated methods should still be listed in that interface, but use the @deprecated tag. As consequence of this, the documentation comments need to be moved from the service class to the interface.

friendship.module

A new module that aims to be compatible with latest Drupal releases is expected to implement hooks as class methods as described in Support for object oriented hook implementations using autowired services.
It requires increasing the minimum required Drupal version, but that is not an issue, since not all the Drupal releases are supported.

friendship.services.yml

Services can be autowired starting with Drupal 9.3.x. This means that it is no longer necessary to give a list of service arguments in the .services.yml file; they will be retrieved from the constructor definition.

avpaderno’s picture

Assigned: avpaderno » Unassigned
vitaliyb98’s picture

Status: Needs work » Needs review

Hi @avpaderno

Thank you for your feedback!

I decided that for the next major version of the module (the 3.x branch), we should support Drupal 11.1+ since the Drupal 12 release is coming soon anyway.

This will also give us more freedom to drop support for legacy features and compatibility with Drupal 10.

Users who are still on Drupal 10 will be able to continue using the 2.x version.

I made changes according to your feedback

These changes will also make the transition to Drupal 12 easier and faster.

avpaderno’s picture

Assigned: Unassigned » avpaderno
Status: Needs review » Reviewed & tested by the community

Thank you for your contribution and for your patience with the review process!

I am going to update your account so you can opt into security advisory coverage any project you create, including the projects you already created.

These are some recommended readings to help you with maintainership:

You can find more contributors chatting on Slack or IRC in #drupal-contribute. So, come hang out and stay involved!
Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

I thank also all the reviewers for helping with these applications.

avpaderno’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.