granted-group.ts 814 B

123456789101112131415161718192021222324252627
  1. import { type IGrantedGroup, GroupType } from '@growi/core';
  2. import { ObjectIdLike } from '../interfaces/mongoose-utils';
  3. export const divideByType = (grantedGroups: IGrantedGroup[] | null): {
  4. grantedUserGroups: ObjectIdLike[];
  5. grantedExternalUserGroups: ObjectIdLike[];
  6. } => {
  7. const grantedUserGroups: ObjectIdLike[] = [];
  8. const grantedExternalUserGroups: ObjectIdLike[] = [];
  9. if (grantedGroups == null) {
  10. return { grantedUserGroups, grantedExternalUserGroups };
  11. }
  12. grantedGroups.forEach((group) => {
  13. const id = typeof group.item === 'string' ? group.item : group.item._id;
  14. if (group.type === GroupType.userGroup) {
  15. grantedUserGroups.push(id);
  16. }
  17. else {
  18. grantedExternalUserGroups.push(id);
  19. }
  20. });
  21. return { grantedUserGroups, grantedExternalUserGroups };
  22. };