diff --git a/app/components/Icons/CollectionIcon.tsx b/app/components/Icons/CollectionIcon.tsx index 4b00c2c380..14cf595d58 100644 --- a/app/components/Icons/CollectionIcon.tsx +++ b/app/components/Icons/CollectionIcon.tsx @@ -1,5 +1,5 @@ import { observer } from "mobx-react"; -import { CollectionIcon } from "outline-icons"; +import { CollectionIcon, PrivateCollectionIcon } from "outline-icons"; import { getLuminance } from "polished"; import * as React from "react"; import { colorPalette } from "@shared/utils/collections"; @@ -40,8 +40,11 @@ function ResolvedCollectionIcon({ : "currentColor" : collectionColor); + const Component = collection.isPrivate + ? PrivateCollectionIcon + : CollectionIcon; return ( - = {}) => { - const groupStubs = await Group.scope({ + public groups = (options: FindOptions = {}) => + Group.scope({ method: ["withMembership", this.id], }).findAll({ - attributes: ["id"], where: { teamId: this.teamId, }, ...options, }); - return groupStubs.map((g) => g.id); - }; + /** + * Returns the user's active group ids. + * + * @param options Additional options to pass to the find + * @returns An array of group ids + */ + public groupIds = async (options: FindOptions = {}) => + (await this.groups(options)).map((g) => g.id); /** * Returns the user's active collection ids. This includes collections the user diff --git a/server/routes/api/groups/groups.ts b/server/routes/api/groups/groups.ts index ab4da6b2fc..01ebaf2b6b 100644 --- a/server/routes/api/groups/groups.ts +++ b/server/routes/api/groups/groups.ts @@ -61,6 +61,7 @@ router.post( pagination: ctx.state.pagination, data: { groups: await Promise.all(groups.map(presentGroup)), + // TODO: Deprecated, will remove in the future as language conflicts with GroupMembership groupMemberships: ( await Promise.all( groups.map((group) => diff --git a/server/routes/api/userMemberships/userMemberships.ts b/server/routes/api/userMemberships/userMemberships.ts index 3d773e5ca7..3d67f96a14 100644 --- a/server/routes/api/userMemberships/userMemberships.ts +++ b/server/routes/api/userMemberships/userMemberships.ts @@ -83,6 +83,7 @@ router.post( const { user } = ctx.state.auth; const membership = await UserMembership.findByPk(id, { transaction, + lock: transaction.LOCK.UPDATE, rejectOnEmpty: true, }); authorize(user, "update", membership);