Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EICNET-2946]fix: If group is archived do not notified invitation #2184

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 58 additions & 3 deletions config/sync/views.view.my_invitations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ status: true
dependencies:
config:
- field.storage.group_content.group_roles
- workflows.workflow.groups
module:
- content_moderation
- eic_user
- group
- user
Expand Down Expand Up @@ -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: ''
Expand All @@ -689,9 +744,7 @@ display:
multiple: false
remember_roles:
authenticated: authenticated
min_placeholder: ''
max_placeholder: ''
placeholder: ''
reduce: false
is_grouped: false
group_info:
label: ''
Expand Down Expand Up @@ -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
Expand All @@ -859,3 +913,4 @@ display:
- url.query_args
tags:
- 'config:field.storage.group_content.group_roles'
- 'config:workflow_list'
38 changes: 34 additions & 4 deletions lib/modules/eic_groups/src/EventSubscriber/GinviteSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,14 +36,23 @@ 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;
}

/**
* {@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 = [
Expand All @@ -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
Expand All @@ -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. <a href="@url">Visit your profile</a> to see them.', $replace);
$message = $this->t(
'You have pending group invitations. <a href="@url">Visit your profile</a> to see them.',
$replace
);
$this->messenger->addMessage($message, 'warning', FALSE);
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/modules/eic_groups/src/Hooks/CronOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions lib/modules/eic_user/src/UserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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:
Expand Down
Loading