Olivier Massot 4 vuotta sitten
vanhempi
commit
a4d1590371

+ 2 - 2
ot_admin/Classes/Command/ResetBeUserPermsCommand.php

@@ -97,12 +97,12 @@ class ResetBeUserPermsCommand extends Command
                 try {
                     $siteController->resetBeUserPermsAction($org_id, $create);
                 } catch (\Throwable $e) {
-                    $io->error('Organization Id: ' . $org_id . ' - ' . sprintf($e));
+                    $io->error('Organization Id: ' . $org_id . ' - ' . $e->getMessage());
                 }
                 $io->progressAdvance(1);
             }
             $io->progressFinish();
-            
+
             $io->success(sprintf("Be users permissions were reset for every website"));
         } else {
             $rootUid = $siteController->resetBeUserPermsAction($org_id, $create);

+ 14 - 8
ot_admin/Classes/Controller/SiteController.php

@@ -2233,7 +2233,7 @@ class SiteController extends ActionController
      * for this website
      *
      * @param int $rootUid
-     * @param bool $withRestrictions
+     * @param bool $withRestrictions  If false, the default restrictions won't apply, meaning this could return a deleted record
      * @return int
      * @throws NoSuchRecordException
      */
@@ -2251,7 +2251,6 @@ class SiteController extends ActionController
             ->select('uid', 'subgroup')
             ->from('be_groups')
             ->where('FIND_IN_SET(' . $rootUid . ', db_mountpoints) > 0')
-//            ->andWhere($queryBuilder->expr()->eq('deleted', 0))
             ->execute()
             ->fetchAll();
 
@@ -2276,8 +2275,10 @@ class SiteController extends ActionController
      * for this website
      *
      * @param int $rootUid
+     * @param bool $withRestrictions If false, the default restrictions won't apply, meaning this could return a deleted record
      * @return int
      * @throws NoSuchRecordException
+     * @throws NoSuchWebsiteException
      */
     protected function findAdminBeUserUid(int $rootUid, bool $withRestrictions=true): int {
         $adminGroups = [
@@ -2295,7 +2296,6 @@ class SiteController extends ActionController
             ->select('uid', 'usergroup')
             ->from('be_users')
             ->where('FIND_IN_SET(' . $rootUid . ', db_mountpoints) > 0')
-//            ->andWhere($queryBuilder->expr()->eq('deleted', 0))
             ->execute()
             ->fetchAll();
 
@@ -2326,14 +2326,20 @@ class SiteController extends ActionController
             $expectedUsername = $extraData['admin']['username'];
 
             $queryBuilder = $this->connectionPool->getQueryBuilderForTable('be_users');
-            $adminUid = $queryBuilder
-                ->select('uid')
+            if (!$withRestrictions) {
+                $queryBuilder->getRestrictions()->removeAll();
+            }
+            $row = $queryBuilder
+                ->select('uid', 'db_mountpoints')
                 ->from('be_users')
                 ->where($queryBuilder->expr()->eq('username', $queryBuilder->expr()->literal($expectedUsername)))
-                ->andWhere($queryBuilder->expr()->eq('db_mountpoints', $rootUid))
-                ->andWhere($queryBuilder->expr()->eq('deleted', 0))
                 ->execute()
-                ->fetchColumn(0);
+                ->fetch();
+
+            if ((string)$rootUid != (string)$row['db_mountpoints']) {
+                throw new \RuntimeException("The be_user named '" . $expectedUsername . "' has unexpected mounted website(s)");
+            }
+            $adminUid = $row['uid'];
         }
 
         if ($adminUid == null) {