Ver Fonte

Filter local admin accounts that not exists in external account

https://youtrack.weseek.co.jp/issue/GW-7958
Mudana-Grune há 2 anos atrás
pai
commit
05771c08b7
1 ficheiros alterados com 13 adições e 1 exclusões
  1. 13 1
      apps/app/src/server/routes/apiv3/security-setting.js

+ 13 - 1
apps/app/src/server/routes/apiv3/security-setting.js

@@ -528,7 +528,19 @@ module.exports = (crowi) => {
 
     // Check if local accounts have admins
     async function checkLocalStrategyHasAdmin() {
-      const adminAccounts = await User.find({ admin: true }).exec();
+      // Get all local admin accounts and filter local admins that are not in external accounts
+      const adminAccounts = await User.aggregate([
+        { $match: { admin: true } },
+        {
+          $lookup: {
+            from: 'externalaccounts',
+            localField: '_id',
+            foreignField: 'user',
+            as: 'externalAccounts',
+          },
+        },
+        { $match: { externalAccounts: [] } },
+      ]);
       return adminAccounts.length > 0;
     }