在Drupal 8中是否可以允许注册的站点用户查看彼此的电子邮件地址?

时间:2019-01-09 01:36:53

标签: drupal-8 drupal-views drupal-permissions

我正在为一个由可信任成员组成的小型志愿者组织开发一个Drupal 8网站。对于那些在网站上具有特定角色的用户,我们希望使用视图来显示所有注册用户信息(仅向其他注册用户显示)。我的“视图”工作正常,但仅向管理员用户显示“电子邮件”字段。

我检查权限无济于事,并且已经阅读了几个小时的帖子,但似乎没有一个答案。

理想情况下是尝试在CMS中解决此问题,但很高兴在必要时使用PHP。

Screenshot of current View output as Admin我正在尝试以注册的非管理员用户身份查看电子邮件字段。

1 个答案:

答案 0 :(得分:0)

最后找到了解决此问题的可行补丁程序-感谢编写者。补丁仅是两个PHP文件中的几行,它们创建了一个新的权限选项,用于查看其他用户的电子邮件地址。

补丁来自this Drupal post

From b0c658e8707f1b851caf700eec9ee4001b6dbbb6 Mon Sep 17 00:00:00 2001
From: Axel Rutz <axel.rutz@machbarmacher.net>
Date: Sat, 22 Dec 2018 02:40:28 +0100
Subject: [PATCH] Issue #2799049 by cilefen, axel.rutz: Add new permission to
 view user email field

---
 core/modules/user/src/UserAccessControlHandler.php | 3 +++
 core/modules/user/user.permissions.yml             | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/core/modules/user/src/UserAccessControlHandler.php b/core/modules/user/src/UserAccessControlHandler.php
index 9e04c3ffda..486ee744a0 100644
--- a/core/modules/user/src/UserAccessControlHandler.php
+++ b/core/modules/user/src/UserAccessControlHandler.php
@@ -120,6 +120,9 @@ protected function checkFieldAccess($operation, FieldDefinitionInterface $field_
         // Allow view access to own mail address and other personalization
         // settings.
         if ($operation == 'view') {
+          if ($field_definition->getName() === 'mail' && $account->hasPermission('view user mail field')) {
+            return AccessResult::allowed()->cachePerPermissions();
+          }
           return $is_own_account ? AccessResult::allowed()->cachePerUser() : AccessResult::neutral();
         }
         // Anyone that can edit the user can also edit this field.
diff --git a/core/modules/user/user.permissions.yml b/core/modules/user/user.permissions.yml
index a295b1f98f..f21f1deea4 100644
--- a/core/modules/user/user.permissions.yml
+++ b/core/modules/user/user.permissions.yml
@@ -11,6 +11,8 @@ administer users:
   restrict access: true
 access user profiles:
   title: 'View user information'
+view user mail field:
+  title: 'View user mail field'
 change own username:
   title: 'Change own username'
 select account cancellation method:
-- 
2.17.1
相关问题