简体   繁体   English

Typo3:如何获取后端用户的所有用户组,反之亦然

[英]Typo3: How do I get all user groups for a backend-user and vice versa

I am trying to write an extension where backend users can write emails to users of the same group. 我正在尝试编写一个扩展,后端用户可以在其中向同一个组的用户发送电子邮件。 I know how to find backend users and also groups. 我知道如何找到后端用户以及组。 But I can not find any way to find out which group a user belongs to and which other users are in this group. 但是我找不到任何方法来找出用户所属的组以及该组中的其他用户。 I hope someone here can help me. 我希望这里有人可以帮助我。 Thanks in advance. 提前致谢。

Edit: I inject the backend user repositiory in my controller 编辑:我在控制器中注入后端用户存储库

/**
 * beUserRepository
 *
 * @var \TYPO3\CMS\Extbase\Domain\Repository\BackendUserRepository
 * @inject
 */
protected $beUserRepository = null;

And get all Backend-User with this statement: 并使用以下语句获取所有后端用户:

$allUsers = $this->beUserRepository->findAll();

I thougth i could get all UserGroups by something like: 我想我可以通过以下方式获取所有UserGroup:

foreach ($allUsers as $user)
    {   
        $groups = $user->getUserGroup();
        ...
    }

But it seems nothing like this exists. 但是似乎不存在这种情况。

There is a database table field be_users.usergroup which contains a comma separated list of be_groups.uid . 有一个数据库表字段be_users.usergroup ,其中包含一个用逗号分隔的be_groups.uid列表。

You could use that for a database lookup. 您可以将其用于数据库查找。 Often ppl use a SQL query like 通常ppl使用SQL查询,例如

WHERE usergroup LIKE "<myid>,%" OR usergroup LIKE "%,<myid>,%" OR usergroup LIKE "%,<myid>" OR usergroup = "<myid>"

to check if a comma separated field includes (although some SQL dialects might have easier ways). 检查是否包含逗号分隔的字段(尽管某些SQL方言可能具有更简单的方法)。

To get an idea how and where things are stored from other tables a look into the TCA files might help, eg https://github.com/TYPO3/TYPO3.CMS/blob/master/typo3/sysext/core/Configuration/TCA/be_users.php#L63 为了了解其他表中存储内容的方式和位置,可以参考一下TCA文件,例如https://github.com/TYPO3/TYPO3.CMS/blob/master/typo3/sysext/core/Configuration/TCA /be_users.php#L63

Concerning your update: 关于您的更新:

https://docs.typo3.org/typo3cms/CoreApiReference/8.7/ApiOverview/BackendUserObject/ points to the API class https://api.typo3.org/typo3cms/8/html/class_t_y_p_o3_1_1_c_m_s_1_1_core_1_1_authentication_1_1_backend_user_authentication.html where you can find some functions concerning similar tasks to extract a best practice. https://docs.typo3.org/typo3cms/CoreApiReference/8.7/ApiOverview/BackendUserObject/指向API类https://api.typo3.org/typo3cms/8/html/class_t_y_p_o3_1_1_c_m_s_1_1_core_1_1_authentication_1_1_backend_user_cation可以在其中找到某些功能。关于类似任务的最佳实践。

Keep in mind that non-admin users won't have access to much information, thus you need to leave the user context (ie you can't use BackendUserAuthentication , but need to use the underlying methods). 请记住,非管理员用户将无法访问很多信息,因此您需要离开用户上下文(即,您不能使用BackendUserAuthentication ,而需要使用基础方法)。

Concerning your general idea: 关于您的总体思路:

Keep in mind that groups can be arranged in a complex hierarchy with inheritance. 请记住,可以通过继承将组安排在复杂的层次结构中。 Thus it might not be easy to list "other group users", as depending on the scenario you might need to add users of parent-groups or child-groups. 因此,列出“其他组用户”可能并不容易,因为根据情况,您可能需要添加父组或子组的用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM