浏览代码

add autogenerated fe_users to their fe_groups

Olivier Massot 3 年之前
父节点
当前提交
a165c5e08f
共有 2 个文件被更改,包括 25 次插入3 次删除
  1. 0 0
      doc/fe_users.md
  2. 25 3
      ot_connect/Classes/Service/OtAuthenticationService.php

+ 0 - 0
doc/fe_users.md


+ 25 - 3
ot_connect/Classes/Service/OtAuthenticationService.php

@@ -109,7 +109,6 @@ class OtAuthenticationService extends AbstractAuthenticationService
      */
     public function getUser()
     {
-
         // Does the user already have a session on the Opentalent API?
         $username = $this->getAuthenticatedUsername();
 
@@ -293,7 +292,6 @@ class OtAuthenticationService extends AbstractAuthenticationService
      */
     protected function createOrUpdateUser(): bool
     {
-
         // Get user's data from the API
         $userApiData = $this->getUserData();
 
@@ -315,12 +313,36 @@ class OtAuthenticationService extends AbstractAuthenticationService
             'name' => $userApiData['name'],
             'first_name' => $userApiData['first_name'],
             'description' => '[Warning: auto-generated record, do not modify] FE User',
-            'usergroup' => self::GROUP_FE_ALL_UID,
             'deleted' => 0,
             'tx_opentalent_opentalentId' => $userApiData['id'],
             'tx_opentalent_generationDate' => date('Y/m/d H:i:s')
         ];
 
+        $groupsUid = [self::GROUP_FE_ALL_UID];
+        if ($userApiData['accesses']) {
+            foreach ($userApiData['accesses'] as $accessData) {
+                $organizationId = $accessData['organizationId'];
+
+                // get the fe_group for this organization
+                $groupUid = $connection->fetchOne(
+                    "select g.uid
+                     from typo3.fe_groups g
+                     inner join (select uid, ot_website_uid from typo3.pages where is_siteroot) p 
+                     on g.pid = p.uid
+                     inner join typo3.ot_websites w on p.ot_website_uid = w.uid
+                     where w.organization_id=:organizationId;",
+                    ['organizationId' => $organizationId]
+                );
+
+                if ($groupUid) {
+                    $groupsUid[] = $groupUid;
+                } else {
+                    $this->writeLogMessage("Warning: no fe_group found for organization " . $organizationId);
+                }
+            }
+        }
+        $fe_row['usergroup'] = join(',', $groupsUid);
+
         // TODO: log a warning if a user with the same opentalentId exists (the user might have changed of username)
         $q = $connection->select(
             ['uid', 'tx_opentalent_opentalentId'],