fix: Assorted fixes from group memberships branch (tom/document-group-permissions)

This commit is contained in:
Tom Moor
2024-08-31 10:11:11 -04:00
parent 0a4d67d96f
commit fefb9200f1
4 changed files with 19 additions and 9 deletions

View File

@@ -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 (
<CollectionIcon
<Component
color={color}
expanded={expanded}
size={size}

View File

@@ -406,24 +406,29 @@ class User extends ParanoidModel<
false;
/**
* Returns the user's active group ids.
* Returns the user's active groups.
*
* @param options Additional options to pass to the find
* @returns An array of group ids
* @returns An array of groups
*/
public groupIds = async (options: FindOptions<Group> = {}) => {
const groupStubs = await Group.scope({
public groups = (options: FindOptions<Group> = {}) =>
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<Group> = {}) =>
(await this.groups(options)).map((g) => g.id);
/**
* Returns the user's active collection ids. This includes collections the user

View File

@@ -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) =>

View File

@@ -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);