From 68c28d46f03c6a5edb6120e2e74f38c254c86055 Mon Sep 17 00:00:00 2001 From: "theodoros.suliotis" Date: Tue, 11 Jul 2023 10:59:34 +0200 Subject: [PATCH] [EICNET-2946]fix: If group is archived do not notified invitation --- config/sync/views.view.my_invitations.yml | 61 ++++++++++++++++++- .../src/EventSubscriber/GinviteSubscriber.php | 38 ++++++++++-- .../eic_groups/src/Hooks/CronOperations.php | 4 +- lib/modules/eic_user/src/UserHelper.php | 10 +-- 4 files changed, 100 insertions(+), 13 deletions(-) diff --git a/config/sync/views.view.my_invitations.yml b/config/sync/views.view.my_invitations.yml index 1d748575b7..13edc2fbd1 100644 --- a/config/sync/views.view.my_invitations.yml +++ b/config/sync/views.view.my_invitations.yml @@ -4,7 +4,9 @@ status: true dependencies: config: - field.storage.group_content.group_roles + - workflows.workflow.groups module: + - content_moderation - eic_user - group - user @@ -675,6 +677,59 @@ display: value: '0' group: 1 exposed: false + expose: + operator_id: invitation_status_value_op + label: 'Invitation status (invitation_status)' + description: '' + use_operator: false + operator: invitation_status_value_op + operator_limit_selection: false + operator_list: { } + identifier: invitation_status_value + required: false + remember: false + multiple: false + remember_roles: + authenticated: authenticated + anonymous: '0' + trusted_user: '0' + sensitive: '0' + content_administrator: '0' + service_authentication: '0' + site_admin: '0' + administrator: '0' + min_placeholder: '' + max_placeholder: '' + placeholder: '' + is_grouped: false + group_info: + label: '' + description: '' + identifier: '' + optional: true + widget: select + multiple: false + remember: false + default_group: All + default_group_multiple: { } + group_items: { } + moderation_state: + id: moderation_state + table: groups_field_data + field: moderation_state + relationship: gid + group_type: group + admin_label: '' + entity_type: group + plugin_id: moderation_state_filter + operator: in + value: + groups-refused: groups-refused + groups-draft: groups-draft + groups-published: groups-published + groups-pending: groups-pending + group: 1 + exposed: false expose: operator_id: '' label: '' @@ -689,9 +744,7 @@ display: multiple: false remember_roles: authenticated: authenticated - min_placeholder: '' - max_placeholder: '' - placeholder: '' + reduce: false is_grouped: false group_info: label: '' @@ -833,6 +886,7 @@ display: - url.query_args tags: - 'config:field.storage.group_content.group_roles' + - 'config:workflow_list' page_1: id: page_1 display_title: Page @@ -859,3 +913,4 @@ display: - url.query_args tags: - 'config:field.storage.group_content.group_roles' + - 'config:workflow_list' diff --git a/lib/modules/eic_groups/src/EventSubscriber/GinviteSubscriber.php b/lib/modules/eic_groups/src/EventSubscriber/GinviteSubscriber.php index 79ba630019..931f15b242 100644 --- a/lib/modules/eic_groups/src/EventSubscriber/GinviteSubscriber.php +++ b/lib/modules/eic_groups/src/EventSubscriber/GinviteSubscriber.php @@ -6,6 +6,8 @@ use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; +use Drupal\eic_content\Constants\DefaultContentModerationStates; +use Drupal\ginvite\GroupInvitation; use Drupal\ginvite\GroupInvitationLoader; use Drupal\ginvite\EventSubscriber\GinviteSubscriber as GinviteSubscriberBase; use Symfony\Component\HttpKernel\Event\GetResponseEvent; @@ -34,7 +36,12 @@ public function __construct( MessengerInterface $messenger, LoggerChannelFactoryInterface $logger_factory ) { - parent::__construct($invitation_loader, $current_user, $messenger, $logger_factory); + parent::__construct( + $invitation_loader, + $current_user, + $messenger, + $logger_factory + ); $this->ginviteSubscriber = $ginvite_subscriber_inner_service; } @@ -42,6 +49,10 @@ public function __construct( * {@inheritdoc} */ public function notifyAboutPendingInvitations(GetResponseEvent $event) { + if (!$event->isMasterRequest()) { + return; + } + // Exclude routes where this info is redundant or will generate a // misleading extra message on the next request. $route_exclusions = [ @@ -52,6 +63,19 @@ public function notifyAboutPendingInvitations(GetResponseEvent $event) { ]; $route = $event->getRequest()->get('_route'); + /** @var \Drupal\ginvite\GroupInvitation[] $invitations */ + $invitations = $this->groupInvitationLoader->loadByUser(); + + //Do not system notify when the group is archived. + $disallowed_states = [DefaultContentModerationStates::ARCHIVED_STATE]; + $invitations = array_filter( + $invitations, + fn(GroupInvitation $groupInvitation) => !in_array( + $groupInvitation->getGroup()->get('moderation_state')->value, + $disallowed_states + ) + ); + // @todo Doing this should already improve some performance however, we // should create a function to query the invitations and limit the results // to 1. This will avoid querying the whole table when we just want to know @@ -63,11 +87,17 @@ public function notifyAboutPendingInvitations(GetResponseEvent $event) { if ( !empty($route) && !in_array($route, $route_exclusions) && - $this->groupInvitationLoader->loadByUser() + $invitations ) { - $destination = Url::fromRoute('view.my_invitations.page_1', ['user' => $this->currentUser->id()])->toString(); + $destination = Url::fromRoute( + 'view.my_invitations.page_1', + ['user' => $this->currentUser->id()] + )->toString(); $replace = ['@url' => $destination]; - $message = $this->t('You have pending group invitations. Visit your profile to see them.', $replace); + $message = $this->t( + 'You have pending group invitations. Visit your profile to see them.', + $replace + ); $this->messenger->addMessage($message, 'warning', FALSE); } } diff --git a/lib/modules/eic_groups/src/Hooks/CronOperations.php b/lib/modules/eic_groups/src/Hooks/CronOperations.php index 72b85c4b94..d79cc6e34e 100644 --- a/lib/modules/eic_groups/src/Hooks/CronOperations.php +++ b/lib/modules/eic_groups/src/Hooks/CronOperations.php @@ -12,6 +12,7 @@ use Drupal\Core\Queue\SuspendQueueException; use Drupal\Core\Site\Settings; use Drupal\Core\State\StateInterface; +use Drupal\eic_content\Constants\DefaultContentModerationStates; use Drupal\eic_groups\GroupsModerationHelper; use Drupal\eic_groups\Plugin\GroupContentEnabler\GroupInvitation as GroupContentEnablerGroupInvitation; use Drupal\eic_messages\Service\MessageBus; @@ -373,7 +374,8 @@ private function processGroupInvitationsReminder() { if ( !$group instanceof GroupInterface || !$invitee instanceof UserInterface || - !$group_content instanceof GroupContent + !$group_content instanceof GroupContent || + $group->get('moderation_state')->value === DefaultContentModerationStates::ARCHIVED_STATE ) { continue; } diff --git a/lib/modules/eic_user/src/UserHelper.php b/lib/modules/eic_user/src/UserHelper.php index 7c45bf7cb6..19771534f0 100644 --- a/lib/modules/eic_user/src/UserHelper.php +++ b/lib/modules/eic_user/src/UserHelper.php @@ -184,6 +184,11 @@ public function getSitePowerUsers(bool $active_only = TRUE) { * TRUE if user is a power user. */ public static function isPowerUser(AccountInterface $account, GroupInterface $group_related = null) { + // User 1 is always considered power user. + if ((int) $account->id() === 1) { + return TRUE; + } + if ($group_related) { $group_flex_group = \Drupal::service('group_flex.group'); $group_visibility = $group_flex_group->getGroupVisibility($group_related); @@ -193,11 +198,6 @@ public static function isPowerUser(AccountInterface $account, GroupInterface $gr } } - // User 1 is always considered power user. - if ((int) $account->id() === 1) { - return TRUE; - } - foreach ($account->getRoles(TRUE) as $role) { switch ($role) { case static::ROLE_DRUPAL_ADMINISTRATOR: