Ver código fonte

return mixedUsernames

Shun Miyazawa 3 anos atrás
pai
commit
bf4f3f20dc

+ 8 - 0
packages/app/src/server/routes/apiv3/users.js

@@ -967,6 +967,14 @@ module.exports = (crowi) => {
         Object.assign(data, { activitySnapshotUser: activitySnapshotUserData });
         Object.assign(data, { activitySnapshotUser: activitySnapshotUserData });
       }
       }
 
 
+      // eslint-disable-next-line max-len
+      const canIncludeMixedUsernames = (options.isIncludeMixedUsernames && req.user.admin) || (options.isIncludeMixedUsernames && !options.isIncludeActivitySnapshotUsernames);
+      if (canIncludeMixedUsernames) {
+        const allUsernames = [...data.activeUser?.usernames || [], ...data.inactiveUser?.usernames || [], ...data?.activitySnapshotUser?.usernames || []];
+        const distinctUsernames = Array.from(new Set(allUsernames));
+        Object.assign(data, { mixedUsernames: distinctUsernames });
+      }
+
       return res.apiv3(data);
       return res.apiv3(data);
     }
     }
     catch (err) {
     catch (err) {

+ 2 - 0
packages/app/src/stores/user.tsx

@@ -20,6 +20,7 @@ type usernameRequertOptions = {
   isIncludeActiveUsernames?: boolean,
   isIncludeActiveUsernames?: boolean,
   isIncludeInactiveUsernames?: boolean,
   isIncludeInactiveUsernames?: boolean,
   isIncludeActivitySnapshotUsernames?: boolean,
   isIncludeActivitySnapshotUsernames?: boolean,
+  isIncludeMixedUsernames?: boolean,
 }
 }
 
 
 type userData = {
 type userData = {
@@ -31,6 +32,7 @@ type usernameResponse = {
   activeUser?: userData
   activeUser?: userData
   inactiveUser?: userData
   inactiveUser?: userData
   activitySnapshotUser?: userData
   activitySnapshotUser?: userData
+  mixedUsernames: string[]
 }
 }
 
 
 export const useSWRxUsernames = (q: string, offset?: number, limit?: number, options?: usernameRequertOptions): SWRResponse<usernameResponse, Error> => {
 export const useSWRxUsernames = (q: string, offset?: number, limit?: number, options?: usernameRequertOptions): SWRResponse<usernameResponse, Error> => {