From 67a8eb2305d97e4697c176d40dd1710146bf6e9c Mon Sep 17 00:00:00 2001 From: arismag Date: Thu, 8 Feb 2024 15:09:46 +0200 Subject: [PATCH 1/4] EICNET-3000: Rephrase username in teaser for anonymous user so we have some elevated information privacy. --- .../includes/preprocess/content/node--wiki.inc | 6 ++++++ lib/themes/eic_community/includes/preprocess/users/user.inc | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/themes/eic_community/includes/preprocess/content/node--wiki.inc b/lib/themes/eic_community/includes/preprocess/content/node--wiki.inc index 5189de289a..aff839beeb 100644 --- a/lib/themes/eic_community/includes/preprocess/content/node--wiki.inc +++ b/lib/themes/eic_community/includes/preprocess/content/node--wiki.inc @@ -38,6 +38,7 @@ function eic_community_preprocess_node__wiki_page(array &$variables) { case 'mail_teaser': case 'teaser': $teaser = _eic_community_prepare_node_teaser_array($node); + // TODO: $teaser['description'] = Unicode::truncate(strip_tags($node->get('field_body')->value), 300, TRUE, TRUE); $teaser['type'] = [ 'label' => $node->type->entity->label(), @@ -50,6 +51,11 @@ function eic_community_preprocess_node__wiki_page(array &$variables) { // Remove unwanted items. $teaser['stats'] = []; + // Privacy information. If current user is anonymous remove the author. + if (\Drupal::currentUser()->isAnonymous()) { + $teaser['author'] = NULL; + } + $variables['story_item'] = $teaser; break; diff --git a/lib/themes/eic_community/includes/preprocess/users/user.inc b/lib/themes/eic_community/includes/preprocess/users/user.inc index 58df3b80d5..d6f7ac3fcb 100644 --- a/lib/themes/eic_community/includes/preprocess/users/user.inc +++ b/lib/themes/eic_community/includes/preprocess/users/user.inc @@ -287,8 +287,11 @@ function _get_profile_image_array(EntityInterface $user, $relative_url = TRUE): * @throws \Drupal\Core\TypedData\Exception\MissingDataException */ function eic_community_get_teaser_user_display(UserInterface $user, $picture_image_style = 'crop_36x36') { + $current_user = \Drupal::currentUser(); + + // Privacy information. If current user is anonymous set user to 'Someone'. $author = [ - 'name' => $user->getDisplayName(), + 'name' => $current_user->isAnonymous() ? t('Someone') : $user->getDisplayName(), ]; // We add the user profile page URL if the current user has access to it. @@ -296,7 +299,6 @@ function eic_community_get_teaser_user_display(UserInterface $user, $picture_ima $author['path'] = $user->toUrl()->toString(); } - $current_user = \Drupal::currentUser(); if (!$user->get('field_media')->isEmpty() && !$current_user->isAnonymous()) { $media_entity = $user->get('field_media')->entity; if ($media_entity) { From ace696a42276db392c9f702ddef4fcb46302c2fa Mon Sep 17 00:00:00 2001 From: David Bash Date: Mon, 19 Feb 2024 13:10:35 +0200 Subject: [PATCH 2/4] EICNET-3000: Unset author/owner variable from teaser view modes in groups, discussions, events, news and stories, wikis and home page view new and stories, when user is anonymous. --- .../includes/preprocess/content/node--discussion.inc | 5 +++++ .../includes/preprocess/content/node--document.inc | 5 +++++ .../includes/preprocess/content/node--event.inc | 5 +++++ .../includes/preprocess/content/node--news--story.inc | 5 +++++ .../eic_community/includes/preprocess/content/node--wiki.inc | 3 +-- .../eic_community/includes/preprocess/groups/group.inc | 5 +++++ lib/themes/eic_community/includes/preprocess/views.inc | 5 +++++ 7 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/themes/eic_community/includes/preprocess/content/node--discussion.inc b/lib/themes/eic_community/includes/preprocess/content/node--discussion.inc index 084512a318..df7c65955e 100644 --- a/lib/themes/eic_community/includes/preprocess/content/node--discussion.inc +++ b/lib/themes/eic_community/includes/preprocess/content/node--discussion.inc @@ -130,5 +130,10 @@ function _preprocess_discussion_teaser(&$variables, $discussion_type, $node) { ]; } + // Privacy information, if current user is anonymous remove the author. + if (\Drupal::currentUser()->isAnonymous()) { + $teaser['author'] = NULL; + } + $variables['discussion_item'] = $teaser; } diff --git a/lib/themes/eic_community/includes/preprocess/content/node--document.inc b/lib/themes/eic_community/includes/preprocess/content/node--document.inc index 737f62010c..a5d9c59c9b 100644 --- a/lib/themes/eic_community/includes/preprocess/content/node--document.inc +++ b/lib/themes/eic_community/includes/preprocess/content/node--document.inc @@ -43,6 +43,11 @@ function eic_community_preprocess_node__document(array &$variables) { $variables['#attached']['library'][] = 'flag/flag.link_ajax'; } + // Privacy information, if current user is anonymous remove the author. + if (\Drupal::currentUser()->isAnonymous()) { + $teaser['author'] = NULL; + } + $variables['document_item'] = $teaser; break; diff --git a/lib/themes/eic_community/includes/preprocess/content/node--event.inc b/lib/themes/eic_community/includes/preprocess/content/node--event.inc index 5bc8b53fca..5043a15570 100644 --- a/lib/themes/eic_community/includes/preprocess/content/node--event.inc +++ b/lib/themes/eic_community/includes/preprocess/content/node--event.inc @@ -45,6 +45,11 @@ function eic_community_preprocess_node__event(array &$variables) { } } + // Privacy information, if current user is anonymous remove the author. + if (\Drupal::currentUser()->isAnonymous()) { + $teaser['author'] = NULL; + } + // Get the start date of the event. $start_date = 0; $end_date = 0; diff --git a/lib/themes/eic_community/includes/preprocess/content/node--news--story.inc b/lib/themes/eic_community/includes/preprocess/content/node--news--story.inc index 820a775a22..b3d0b88c5b 100644 --- a/lib/themes/eic_community/includes/preprocess/content/node--news--story.inc +++ b/lib/themes/eic_community/includes/preprocess/content/node--news--story.inc @@ -112,6 +112,11 @@ function _eic_community_preprocess_node_news_story(array &$variables) { } $variables['stats'] = $stats; + + // Privacy information, if current user is anonymous remove the author. + if (\Drupal::currentUser()->isAnonymous()) { + $item['author'] = NULL; + } } $variables['story_item'] = $item; diff --git a/lib/themes/eic_community/includes/preprocess/content/node--wiki.inc b/lib/themes/eic_community/includes/preprocess/content/node--wiki.inc index aff839beeb..ff2d8848b5 100644 --- a/lib/themes/eic_community/includes/preprocess/content/node--wiki.inc +++ b/lib/themes/eic_community/includes/preprocess/content/node--wiki.inc @@ -38,7 +38,6 @@ function eic_community_preprocess_node__wiki_page(array &$variables) { case 'mail_teaser': case 'teaser': $teaser = _eic_community_prepare_node_teaser_array($node); - // TODO: $teaser['description'] = Unicode::truncate(strip_tags($node->get('field_body')->value), 300, TRUE, TRUE); $teaser['type'] = [ 'label' => $node->type->entity->label(), @@ -51,7 +50,7 @@ function eic_community_preprocess_node__wiki_page(array &$variables) { // Remove unwanted items. $teaser['stats'] = []; - // Privacy information. If current user is anonymous remove the author. + // Privacy information, if current user is anonymous remove the author. if (\Drupal::currentUser()->isAnonymous()) { $teaser['author'] = NULL; } diff --git a/lib/themes/eic_community/includes/preprocess/groups/group.inc b/lib/themes/eic_community/includes/preprocess/groups/group.inc index 4e68ec586d..5b002df10c 100644 --- a/lib/themes/eic_community/includes/preprocess/groups/group.inc +++ b/lib/themes/eic_community/includes/preprocess/groups/group.inc @@ -95,6 +95,11 @@ function eic_community_preprocess_group__group(array &$variables) { // @todo Get the real last activity. $item['timestamp']['label'] = eic_community_get_teaser_time_display($group->get('changed')->value); + // Privacy information, if current user is anonymous remove the author. + if (\Drupal::currentUser()->isAnonymous()) { + $item['owner'] = NULL; + } + // Get group statistics. $group_statistics = \Drupal::service('eic_group_statistics.helper')->loadGroupStatistics($group); $item['stats'] = [ diff --git a/lib/themes/eic_community/includes/preprocess/views.inc b/lib/themes/eic_community/includes/preprocess/views.inc index 161734e03f..8ae46117a3 100644 --- a/lib/themes/eic_community/includes/preprocess/views.inc +++ b/lib/themes/eic_community/includes/preprocess/views.inc @@ -327,6 +327,11 @@ function _eic_community_preprocess_views__latest_news_and_stories__homepage(&$va 'stats' => $stats, ]; + // Privacy information, if current user is anonymous remove the author. + if (\Drupal::currentUser()->isAnonymous()) { + $item['author'] = NULL; + } + if (!$node_translation->get('field_image')->isEmpty()) { /** @var \Drupal\media\Entity\Media $media */ $media = \Drupal::service('entity.repository')->getTranslationFromContext($node_translation->get('field_image')->entity, $current_langcode); From 93ad363a94591da5f32f7a942c1da429d116f983 Mon Sep 17 00:00:00 2001 From: David Bash Date: Mon, 19 Feb 2024 13:47:18 +0200 Subject: [PATCH 3/4] EICNET-3000: Coding standards. --- .../includes/preprocess/content/node--news--story.inc | 2 +- lib/themes/eic_community/includes/preprocess/views.inc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/themes/eic_community/includes/preprocess/content/node--news--story.inc b/lib/themes/eic_community/includes/preprocess/content/node--news--story.inc index b3d0b88c5b..aa2d08ca6b 100644 --- a/lib/themes/eic_community/includes/preprocess/content/node--news--story.inc +++ b/lib/themes/eic_community/includes/preprocess/content/node--news--story.inc @@ -115,7 +115,7 @@ function _eic_community_preprocess_node_news_story(array &$variables) { // Privacy information, if current user is anonymous remove the author. if (\Drupal::currentUser()->isAnonymous()) { - $item['author'] = NULL; + $item['author'] = NULL; } } diff --git a/lib/themes/eic_community/includes/preprocess/views.inc b/lib/themes/eic_community/includes/preprocess/views.inc index 8ae46117a3..afc1236a21 100644 --- a/lib/themes/eic_community/includes/preprocess/views.inc +++ b/lib/themes/eic_community/includes/preprocess/views.inc @@ -329,7 +329,7 @@ function _eic_community_preprocess_views__latest_news_and_stories__homepage(&$va // Privacy information, if current user is anonymous remove the author. if (\Drupal::currentUser()->isAnonymous()) { - $item['author'] = NULL; + $item['author'] = NULL; } if (!$node_translation->get('field_image')->isEmpty()) { From bd52d31c089ddb02db49de523026163ba1a1750c Mon Sep 17 00:00:00 2001 From: David Bash Date: Tue, 20 Feb 2024 12:06:57 +0200 Subject: [PATCH 4/4] EICNET-3000: Remove author from video and gallery CTs in their tease view mode. --- .../includes/preprocess/content/node--gallery.inc | 5 +++++ .../includes/preprocess/content/node--video.inc | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/lib/themes/eic_community/includes/preprocess/content/node--gallery.inc b/lib/themes/eic_community/includes/preprocess/content/node--gallery.inc index 524d81aded..22a4afc25d 100644 --- a/lib/themes/eic_community/includes/preprocess/content/node--gallery.inc +++ b/lib/themes/eic_community/includes/preprocess/content/node--gallery.inc @@ -152,6 +152,11 @@ function eic_community_preprocess_node__gallery(array &$variables) { $teaser['flags'] = []; } + // Privacy information, if current user is anonymous remove the author. + if (\Drupal::currentUser()->isAnonymous()) { + $teaser['author'] = NULL; + } + $teaser['images'] = $images; $teaser['type'] = [ 'label' => $node->type->entity->label(), diff --git a/lib/themes/eic_community/includes/preprocess/content/node--video.inc b/lib/themes/eic_community/includes/preprocess/content/node--video.inc index bff0441b71..53ab5c930e 100644 --- a/lib/themes/eic_community/includes/preprocess/content/node--video.inc +++ b/lib/themes/eic_community/includes/preprocess/content/node--video.inc @@ -69,6 +69,11 @@ function eic_community_preprocess_node__video(array &$variables) { $teaser['flags'] = []; } + // Privacy information, if current user is anonymous remove the author. + if (\Drupal::currentUser()->isAnonymous()) { + $teaser['author'] = NULL; + } + // If we have flags, attach the js library. if (!empty($teaser['flags'])) { $variables['#attached']['library'][] = 'flag/flag.link_ajax';