[1.x] Sender.net Integration

Created on 9 February 2024, about 1 year ago

This module facilitates the integration of Drupal with the sender.net service, allowing users to seamlessly connect their Drupal instance with sender.net for enhanced email subscription and management.

Project link

https://www.drupal.org/project/sender_net →

📌 Task
Status

Needs review

Component

module

Created by

🇮🇳India vinaygawade Sawantwadi, Maharashtra

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @vinaygawade
  • 🇮🇳India vishal.kadam Mumbai

    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.

    The important notes are the following.

    • If you have not done it yet, you should run phpcs --standard=Drupal,DrupalPractice on the project, which alone fixes most of what reviewers would report.
    • 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 won't be changed by this application and no other user will be able to opt projects into security advisory policy.
    • 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 Code Review Administrator before commenting on newly created applications. Code Review Administrators 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 → .

  • Status changed to Needs work about 1 year ago
  • 🇮🇳India vishal.kadam Mumbai

    1. master is a wrong name for a branch, which needs to be deleted. Release branch names always end with the literal .x as described in Release branches.

    2. Fix phpcs issue.

    phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml sender_net/
    
    FILE: sender_net/src/SenderNetApi.php                                                                 
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE                                                                                                        
    --------------------------------------------------------------------------------
     246 | ERROR | The array declaration extends to column 91 (the limit is 80). The array content should be split up over multiple lines 
    --------------------------------------------------------------------------------

    3. FILE: src/Plugin/Block/SubscriptionBlock.php

      /**
       * Load services.
       *
       * @param array $configuration
       *   The configuration.
       * @param string $plugin_id
       *   The plugin id.
       * @param mixed $plugin_definition
       *   The plugin definition.
       * @param \Drupal\Core\Form\FormBuilderInterface $formBuilder
       *   The form builder.
       */
      public function __construct(array $configuration, $plugin_id, $plugin_definition, FormBuilderInterface $formBuilder) {

    The documentation comment for constructors is not mandatory anymore, If it is given, the description must be Constructs a new [class name] object. where [class name] includes the class namespace.

  • Status changed to Needs review about 1 year ago
  • 🇮🇳India vinaygawade Sawantwadi, Maharashtra

    Thank you @vishalkadam for addressing the issues. I appreciate your prompt attention to these matters.

    1. The incorrect branch "master" has been deleted, and the appropriate release branch has been created following the convention of ending with ".x".

    2. The phpcs issue regarding the array declaration length has been fixed by splitting the array content over multiple lines, aligning with coding standards and enhancing code readability.

    3. The constructor documentation comment has been adjusted to adhere to the specified format.

    I've made these changes as requested. Could you please review them again to ensure they meet the project's standards? Thank you for your time and cooperation.

  • Status changed to RTBC 11 months ago
  • 🇮🇳India vishal.kadam Mumbai

    Rest looks fine to me.

    Let’s wait for a Code Review Administrator to take a look and if everything goes fine, you will get the role.

  • Status changed to Needs work 11 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    • 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 doesn't follow the coding standards, contains possible security issue, or does not correctly use the Drupal API; the single points are not ordered, not even by importance

    src/Form/SubscriptionForm.php

         $msg = $this->t("Subscriber with email '@email' already exists.", ['@email' => $email]);
    
          // Subscriber already exists.
          $this->logger->warning($msg);
          $this->messenger()->addError($msg);
    

    The first argument of warning() and similar logger methods is a literal string.

        // Check if subscriber already exists.
        $existingSubscriber = $this->senderApi->getSubscriberByEmail($email);
        if ($existingSubscriber) {
          $msg = $this->t("Subscriber with email '@email' already exists.", ['@email' => $email]);
    
          // Subscriber already exists.
          $this->logger->warning($msg);
          $this->messenger()->addError($msg);
        }
    

    Validating the entered values is a task for validateForm().

      /**
       * Configuration manager.
       *
       * @var \Drupal\Core\Config\ConfigFactoryInterface
       */
      protected $config;
    
      /**
       * Logger channel factory.
       *
       * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
       */
      protected $logger;
    

    Since the parent class is FormBase, those properties are not necessary. Instead, the class should use the methods to set the logger factory and the config factory, or to retrieve a logger and a configuration object.

    src/Form/SettingsForm.php

    **
     * Configure sender.net settings.
     */
    class SettingsForm extends ConfigFormBase implements ContainerInjectionInterface {
    

    ContainerInjectionInterface is already implemented by ConfigFormBase; there is no need to re-implement it.

        $form['api_access_tokens'] = [
          '#type' => 'textarea',
          '#title' => $this->t('Enter your API access token'),
          '#default_value' => $apiKey,
          '#description' => $this->t('Get API access tokens from sender.net <a href="https://app.sender.net/settings/tokens" target="_blank">account</a>.'),
          '#required' => TRUE,
        ];
    
        $form['api_base_url'] = [
          '#type' => 'textfield',
          '#title' => $this->t('Base URL'),
          '#default_value' => 'https://api.sender.net/v2/',
          '#description' => $this->t('Get Base URL from sender.net <a href="https://api.sender.net/#introduction" target="_blank">docs</a>.'),
          '#required' => TRUE,
        ];
    

    URLs should be added to translatable strings via placeholders. Translators are not expected to change the used URL when translating strings.

          catch (\Exception $e) {
            $this->messenger->addError($this->t('Unable to load groups. Please check your API access token and try again.'));
            $this->logger->error('Error loading groups: @error', ['@error' => $e->getMessage()]);
          }
    

    To log exceptions, there is watchdog_exception() or the class method described in that documentation page.

  • 🇮🇳India vishal.kadam Mumbai

    I am changing priority as per Issue priorities → .

  • Status changed to Closed: won't fix 7 months ago
  • 🇮🇳India vishal.kadam Mumbai

    This thread has been idle, in the Needs work state with no activity for several months. Therefore, I am assuming that you are no longer pursuing this application, and I marked it as Closed (won't fix).

    If this is incorrect, and you are still pursuing this application, then please feel free to re-open it and set the issue status to Needs work or Needs review, depending on the current status of your code.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs review 4 months ago
  • 🇮🇳India vinaygawade Sawantwadi, Maharashtra

    Thank you for the feedback, and apologies for the late reply.
    please check the 1.x branch for the latest changes and let me know if further adjustments are needed.
    Once all reviews are complete, I will release the newer version.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • 🇮🇳India vishal.kadam Mumbai

    1. FILE: templates/block--subscription.html.twig

    Twig code needs to be correctly indented. Drupal uses two spaces for indentation, not four spaces or tabs.

    2. FILE: sender_net.module

    /**
     * @file
     * Sender.net module implementation.
     */

    The usual description for a .module file is Hook implementations for the [module name] module. where [module name] is the module name given in the .info.yml file.

  • 🇮🇳India vinaygawade Sawantwadi, Maharashtra

    Thank you for the feedback.

    1. The Twig file indentation has been updated to use two spaces as per Drupal standards.
    2. The file header comment in the `.module` file has been revised to match the module name specified in the `.info.yml` file.

    Let me know if any further changes are required.

  • 🇮🇳India vishal.kadam Mumbai

    Rest looks fine to me.

    Let’s wait for a Code Review Administrator to take a look and if everything goes fine, you will get the role.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    src/Form/SettingsForm.php

        $form['api_access_tokens'] = [
          '#type' => 'textarea',
          '#title' => $this->t('Enter your API access token'),
          '#default_value' => $apiKey,
          '#description' => $this->t('Get API access tokens from sender.net <a href="@url" target="_blank">account</a>.', ['@url' => 'https://app.sender.net/settings/tokens']),
          '#required' => TRUE,
        ];
    

    The correct placeholder for URL starts with :. It must also be wrapped on double quotation marks, as reported on FormattableMarkup::placeholderFormat().

    :variable: Return value is escaped with \Drupal\Component\Utility\Html::escape() and filtered for dangerous protocols using UrlHelper::stripDangerousProtocols(). Use this when using the "href" attribute, ensuring the attribute value is always wrapped in quotes

          catch (\Exception $e) {
            watchdog_exception('sender_net', $e);
            $this->messenger->addError($this->t('Unable to load groups. Please check your API access token and try again.'));
          }
    

    Since the module can be installed on Drupal 11 too, it cannot use watchdog_exception(), which does not exist in Drupal 11. The following code needs to replace the line calling watchdog_exception('sender_net', $e).

    \Drupal::logger('sender_net')->log(RfcLogLevel::ERROR, '%type: @message in %function (line %line of %file).', Error::decodeException($e));
    

    Instead of \Drupal::logger() an injected service should be used.

    src/Form/SubscriptionForm.php

    Is there any reason to use a separate class for the plugin form?

    src/SenderNetApi.php

          watchdog_exception('sender_net', $th);
          $this->logger->error('API request failed: @message', ['@message' => $th->getMessage()]);
    

    Only one of those lines is necessary, since both lines log an error message. See also my previous note on watchdog_exception().

  • 🇮🇳India vinaygawade Sawantwadi, Maharashtra

    The changes have been made as per your feedback:

    1. The URL placeholder format now uses the correct syntax with `:variable` and is wrapped in double quotes, ensuring proper escaping and security.
    2. Replaced `watchdog_exception()` with the injected logger service to maintain compatibility with Drupal 11 and follow modern Drupal logging practices.
    3. Removed the redundant error logging to simplify and ensure clarity.

    4. src/Form/SubscriptionForm.php
    Is there any reason to use a separate class for the plugin form?
    Using a separate class for the form ensures clean separation of responsibilities, making the code easier to maintain and reuse. It aligns with Drupal standards, allowing the form to be used in multiple contexts while keeping the block plugin focused on rendering. This approach keeps the module flexible, organized.

  • 🇮🇳India vinaygawade Sawantwadi, Maharashtra
  • 🇦🇹Austria klausi 🇦🇹 Vienna

    manual review:

    1. SettingsForm: Drupal\Component\Utility\Error does not exist, did you mean Drupal\Core\Utility\Error?
    2. SenderNetApi: $entity_type_manager is unused, should it be removed?
    3. SenderNetApi: $logger class variable docs are wrong, this is not the channel but the logger itself?

    But otherwise looks good to me.

    Thanks for your contribution, Vinay!

    I updated your account so you can opt into security advisory coverage now.

    Here are some recommended readings to help with excellent maintainership:

    You can find lots more contributors chatting on Slack → or IRC → in #drupal-contribute. So, come hang out and stay involved → !

    Thanks, also, for your patience with the review process. 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.

    Thanks to the dedicated reviewer(s) as well.

  • 🇮🇳India vinaygawade Sawantwadi, Maharashtra

    Thank you, Klausi, for the review and feedback! I appreciate the account update and recommended readings. Grateful to the reviewers and the supportive Drupal community. Looking forward to staying involved!

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

Production build 0.71.5 2024