diff --git a/app/actions/definitions/collections.tsx b/app/actions/definitions/collections.tsx index 4dca402f7a..0f560e155b 100644 --- a/app/actions/definitions/collections.tsx +++ b/app/actions/definitions/collections.tsx @@ -131,7 +131,7 @@ export const editCollectionPermissions = createAction({ } stores.dialogs.openModal({ - title: t("Share this collection"), + title: t(`Share "{{ itemName }}"`, { itemName: collection.name }), content: ( ); } - -const Select = styled(InputSelect)` - color: ${s("textSecondary")}; -`; diff --git a/app/components/InputSelect.tsx b/app/components/InputSelect.tsx index be7bad7ee1..4de37ffd94 100644 --- a/app/components/InputSelect.tsx +++ b/app/components/InputSelect.tsx @@ -342,7 +342,7 @@ function Option({ <>   - – {option.description} + · {option.description} )} diff --git a/app/components/Sharing/Collection/AccessControlList.tsx b/app/components/Sharing/Collection/AccessControlList.tsx index 814bdbf3e1..892c2e8e88 100644 --- a/app/components/Sharing/Collection/AccessControlList.tsx +++ b/app/components/Sharing/Collection/AccessControlList.tsx @@ -1,5 +1,5 @@ import { observer } from "mobx-react"; -import { UserIcon } from "outline-icons"; +import { PadlockIcon } from "outline-icons"; import * as React from "react"; import { useTranslation } from "react-i18next"; import { toast } from "sonner"; @@ -11,8 +11,9 @@ import type Collection from "~/models/Collection"; import type Share from "~/models/Share"; import { Avatar, GroupAvatar, AvatarSize } from "~/components/Avatar"; import InputMemberPermissionSelect from "~/components/InputMemberPermissionSelect"; -import { InputSelectPermission } from "~/components/InputSelectPermission"; +import { InputSelect, type Option } from "~/components/InputSelect"; import Scrollable from "~/components/Scrollable"; +import TeamLogo from "~/components/TeamLogo"; import useCurrentTeam from "~/hooks/useCurrentTeam"; import useMaxHeight from "~/hooks/useMaxHeight"; import usePolicy from "~/hooks/usePolicy"; @@ -20,7 +21,12 @@ import useRequest from "~/hooks/useRequest"; import useStores from "~/hooks/useStores"; import type { Permission } from "~/types"; import { EmptySelectValue } from "~/types"; -import { Separator, GroupMembersPopover } from "../components"; +import { + SectionHeading, + SmallInputSelect, + Separator, + GroupMembersPopover, +} from "../components"; import { ListItem } from "../components/ListItem"; import { Placeholder } from "../components/Placeholder"; import { PublicAccess } from "./PublicAccess"; @@ -92,6 +98,38 @@ export const AccessControlList = observer( calcMaxHeight(); }); + const accessOptions: Option[] = React.useMemo( + () => [ + { + type: "item", + label: t("Everyone in workspace"), + value: "everyone", + }, + { + type: "item", + label: t("Restricted"), + value: "invited", + }, + ], + [t] + ); + + const permissionOptions: Option[] = React.useMemo( + () => [ + { + type: "item", + label: t("View only"), + value: CollectionPermission.Read, + }, + { + type: "item", + label: t("Can edit"), + value: CollectionPermission.ReadWrite, + }, + ], + [t] + ); + const permissions = React.useMemo( () => [ @@ -126,33 +164,65 @@ export const AccessControlList = observer( }} > <> + General access - - + collection.isPrivate ? ( + + + + ) : ( + + ) + } + title={ + { + if (value === "invited") { + void collection.save({ permission: null }); + } else { + void collection.save({ + permission: CollectionPermission.Read, + }); + } + }} + label={t("Access")} + hideLabel + disabled={!can.update} + short + nude + /> + } + subtitle={ + collection.isPrivate + ? t("Only invited users can access") + : t("All members of {{ itemName }}", { + itemName: team.name, + }) } - title={t("All members")} - subtitle={t("Everyone in the workspace")} actions={
- { - void collection.save({ - permission: value === EmptySelectValue ? null : value, - }); - }} - disabled={!can.update} - value={collection?.permission} - hideLabel - nude - shrink - /> + {collection.permission && ( + { + void collection.save({ + permission: value as CollectionPermission, + }); + }} + label={t("Permission")} + hideLabel + disabled={!can.update} + nude + /> + )}
} /> + People with access {showLoading ? ( ) : ( diff --git a/app/components/Sharing/Collection/PublicAccess.tsx b/app/components/Sharing/Collection/PublicAccess.tsx index 015ed72971..4072016981 100644 --- a/app/components/Sharing/Collection/PublicAccess.tsx +++ b/app/components/Sharing/Collection/PublicAccess.tsx @@ -147,7 +147,7 @@ function InnerPublicAccess( return (
{t("Allow anyone with the link to access")}} image={ diff --git a/app/components/Sharing/Document/AccessControlList.tsx b/app/components/Sharing/Document/AccessControlList.tsx index 3f123b8701..ff0ffb8bfc 100644 --- a/app/components/Sharing/Document/AccessControlList.tsx +++ b/app/components/Sharing/Document/AccessControlList.tsx @@ -1,36 +1,28 @@ import { observer } from "mobx-react"; -import { - PadlockIcon, - MoreIcon, - QuestionMarkIcon, - UserIcon, -} from "outline-icons"; +import { PadlockIcon, MoreIcon, QuestionMarkIcon } from "outline-icons"; import * as React from "react"; -import { useTranslation } from "react-i18next"; +import { useTranslation, Trans } from "react-i18next"; +import { Link } from "react-router-dom"; import styled, { useTheme } from "styled-components"; import Squircle from "@shared/components/Squircle"; import { Pagination } from "@shared/constants"; import { s } from "@shared/styles"; -import { CollectionPermission, IconType } from "@shared/types"; -import { determineIconType } from "@shared/utils/icon"; -import type Collection from "~/models/Collection"; +import { CollectionPermission } from "@shared/types"; import type Document from "~/models/Document"; import type Share from "~/models/Share"; import Flex from "~/components/Flex"; import NudeButton from "~/components/NudeButton"; +import TeamLogo from "~/components/TeamLogo"; import Scrollable from "~/components/Scrollable"; -import Switch from "~/components/Switch"; import Text from "~/components/Text"; import useCurrentTeam from "~/hooks/useCurrentTeam"; -import useCurrentUser from "~/hooks/useCurrentUser"; import useMaxHeight from "~/hooks/useMaxHeight"; import usePolicy from "~/hooks/usePolicy"; import useRequest from "~/hooks/useRequest"; import useStores from "~/hooks/useStores"; import { Avatar, AvatarSize } from "../../Avatar"; -import CollectionIcon from "../../Icons/CollectionIcon"; import Tooltip from "../../Tooltip"; -import { Separator } from "../components"; +import { SectionHeading, Separator, SmallInputSelect } from "../components"; import { ListItem } from "../components/ListItem"; import { Placeholder } from "../components/Placeholder"; import DocumentMemberList from "./DocumentMemberList"; @@ -63,9 +55,7 @@ export const AccessControlList = observer( const { t } = useTranslation(); const theme = useTheme(); const collection = document.collection; - const usersInCollection = useUsersInCollection(collection); - const user = useCurrentUser(); - const { userMemberships, groupMemberships } = useStores(); + const { documents, userMemberships, groupMemberships } = useStores(); const collectionSharingDisabled = document.collection?.sharing === false; const team = useCurrentTeam(); const can = usePolicy(document); @@ -81,10 +71,35 @@ export const AccessControlList = observer( margin: 24, }); - const handleToggleRestricted = React.useCallback(async () => { - const newValue = !document.isPrivate; - await document.save({ isPrivate: newValue }); - }, [document]); + const parentDocument = document.parentDocumentId + ? documents.get(document.parentDocumentId) + : undefined; + const parentIsPrivate = parentDocument?.isPrivate ?? false; + + const handleAccessChange = React.useCallback( + async (value: string) => { + await document.save({ isPrivate: value === "private" }); + }, + [document] + ); + + const accessOptions: Option[] = React.useMemo( + () => [ + { + type: "item" as const, + label: t("Restricted"), + value: "private", + }, + { + type: "item" as const, + label: collection.isPrivate + ? t("Collection members") + : t("Everyone in workspace"), + value: "inherited", + }, + ], + [t] + ); const { loading: userMembershipLoading, request: fetchUserMemberships } = useRequest( @@ -132,45 +147,67 @@ export const AccessControlList = observer( > {!document.isDraft && can.restrict && ( <> + General access - - + document.isPrivate || collection.isPrivate ? ( + + + + ) : ( + + ) } title={ - document.isPrivate - ? t("Access managed independently") - : t("Inherits access") - } - subtitle={ - document.isPrivate - ? t("Only explicitly added members can access") - : collection - ? t("From {{ collectionName }}", { - collectionName: collection.name, - }) - : t("From parent document") - } - actions={ - } + subtitle={ + document.isPrivate ? ( + t("Only invited users can access") + ) : parentIsPrivate ? ( + + Required by{" "} + + parent + + + ) : collection.isPrivate ? ( + t("Members of {{ itemName }} can access", { + itemName: collection.name, + }) + ) : ( + t("All members of {{ itemName }}", { + itemName: team.name, + }) + ) + } + actions={ + document.isPrivate || collection.isPrivate ? null : ( + + {collection.permission === CollectionPermission.Read + ? t("View only") + : t("Can edit")} + + ) + } /> - )} {document.isDraft ? ( <> + People with access } title={document.createdBy?.name} @@ -191,40 +228,7 @@ export const AccessControlList = observer( ) : collection && canCollection.readDocument ? ( <> - {!document.isPrivate && - (collection.permission ? ( - - - - } - title={t("All members")} - subtitle={t("Everyone in the workspace")} - actions={ - - {collection?.permission === - CollectionPermission.ReadWrite - ? t("Can edit") - : t("Can view")} - - } - /> - ) : usersInCollection ? ( - } - title={collection.name} - subtitle={t("Everyone in the collection")} - actions={{t("Can view")}} - /> - ) : ( - } - title={user.name} - subtitle={t("You have full access")} - actions={{t("Can edit")}} - /> - ))} + People with access{" "} {showLoading ? ( ) : ( @@ -303,43 +307,6 @@ const AccessTooltip = ({ ); }; -const CollectionSquircle = ({ collection }: { collection: Collection }) => { - const theme = useTheme(); - const iconType = determineIconType(collection.icon)!; - const squircleColor = - iconType === IconType.SVG ? collection.color! : theme.slateLight; - const iconSize = iconType === IconType.SVG ? 16 : 22; - - return ( - - - - ); -}; - -function useUsersInCollection(collection?: Collection) { - const { users, memberships } = useStores(); - const { request } = useRequest(() => - memberships.fetchPage({ limit: 1, id: collection!.id }) - ); - - React.useEffect(() => { - if (collection && !collection.permission) { - void request(); - } - }, [collection]); - - return collection - ? collection.permission - ? true - : users.inCollection(collection.id).length > 1 - : false; -} - const Wrapper = styled(Flex)` flex-direction: column; `; @@ -350,6 +317,11 @@ const Sticky = styled.div` bottom: 0; `; +const StyledLink = styled(Link)` + color: ${s("textTertiary")}; + text-decoration: underline; +`; + const ScrollableContainer = styled(Scrollable)` padding: 12px 24px; margin: -12px -24px; diff --git a/app/components/Sharing/Document/DocumentMemberListItem.tsx b/app/components/Sharing/Document/DocumentMemberListItem.tsx index a50c3454d9..077352c170 100644 --- a/app/components/Sharing/Document/DocumentMemberListItem.tsx +++ b/app/components/Sharing/Document/DocumentMemberListItem.tsx @@ -99,7 +99,7 @@ const DocumentMemberListItem = ({ ) } actions={ -
+
{sharedParent && !document.isDraft ? ( diff --git a/app/components/Sharing/components/index.tsx b/app/components/Sharing/components/index.tsx index c1c0c9f537..961b3e2680 100644 --- a/app/components/Sharing/components/index.tsx +++ b/app/components/Sharing/components/index.tsx @@ -2,10 +2,13 @@ import { darken } from "polished"; import styled from "styled-components"; import Flex from "@shared/components/Flex"; import { s, hover } from "@shared/styles"; +import { InputSelect } from "~/components/InputSelect"; import NudeButton from "~/components/NudeButton"; import Input, { NativeInput } from "~/components/Input"; +import Text from "~/components/Text"; import { InfoIcon } from "outline-icons"; import { Link } from "react-router-dom"; +import { transparentize } from "polished"; export { GroupMembersPopover } from "./GroupMembersPopover"; @@ -60,7 +63,8 @@ export const HeaderInput = styled(Flex)` top: 0; background: ${s("menuBackground")}; color: ${s("textTertiary")}; - border-bottom: 1px solid ${s("inputBorder")}; + border-bottom: 1px solid + ${(props) => transparentize(0.4, props.theme.inputBorder)}; padding: 0 24px 12px; margin-top: 0; margin-left: -24px; @@ -79,6 +83,41 @@ export const HeaderInput = styled(Flex)` } `; +/** Section heading used in share popovers. */ +export const SectionHeading = styled(Text).attrs({ + as: "div", + type: "secondary", + size: "small", + weight: "bold", +})` + &:not(:first-child) { + margin-top: 16px; + } + + margin-bottom: 2px; +`; + +/** Compact InputSelect for use inline in share popover rows. */ +export const SmallInputSelect = styled(InputSelect)` + width: fit-content; + height: 24px; + margin: -4px -4px 0; + + &:hover:not(:disabled), + &:focus-visible, + &[aria-expanded="true"] { + box-shadow: none; + background: none; + } + + & > * { + min-height: 0; + font-weight: 500; + padding-left: 4px !important; + padding-right: 4px !important; + } +`; + export const presence = { initial: { opacity: 0, diff --git a/app/scenes/Document/components/ShareButton.tsx b/app/scenes/Document/components/ShareButton.tsx index 756d95f804..baed4fa34c 100644 --- a/app/scenes/Document/components/ShareButton.tsx +++ b/app/scenes/Document/components/ShareButton.tsx @@ -1,5 +1,5 @@ import { observer } from "mobx-react"; -import { GlobeIcon } from "outline-icons"; +import { GlobeIcon, PadlockIcon } from "outline-icons"; import { Suspense, useCallback, useState } from "react"; import { useTranslation } from "react-i18next"; import type Document from "~/models/Document"; @@ -44,7 +44,11 @@ function ShareButton({ document }: Props) { return null; } - const icon = document.isPubliclyShared ? : undefined; + const icon = document.isPrivate ? ( + + ) : document.isPubliclyShared ? ( + + ) : undefined; return ( diff --git a/server/queues/processors/WebsocketsProcessor.ts b/server/queues/processors/WebsocketsProcessor.ts index 1c578820ff..859fa10b9d 100644 --- a/server/queues/processors/WebsocketsProcessor.ts +++ b/server/queues/processors/WebsocketsProcessor.ts @@ -234,18 +234,22 @@ export default class WebsocketsProcessor { }, paranoid: false, }); - documents.forEach((document) => { - socketio.to(`collection-${document.collectionId}`).emit("entities", { - event: event.name, - invalidatedPolicies: [document.id], - documentIds: [ - { - id: document.id, - updatedAt: document.updatedAt, - }, - ], + documents + .filter((document) => !document.isPrivate) + .forEach((document) => { + socketio + .to(`collection-${document.collectionId}`) + .emit("entities", { + event: event.name, + invalidatedPolicies: [document.id], + documentIds: [ + { + id: document.id, + updatedAt: document.updatedAt, + }, + ], + }); }); - }); const moveCollections = await Collection.findAll({ where: { id: event.data.collectionIds }, attributes: ["id", "updatedAt"], @@ -970,7 +974,15 @@ export default class WebsocketsProcessor { channels.push(`user-${event.actorId}`); } - if (document.publishedAt) { + // Include collection/team channels for published documents that are not + // restricted. Also include them when the privacy state just changed so that + // clients can react to the transition (e.g. remove from or add to their view). + const changes = ( + event as { changes?: { attributes?: Record } } + ).changes; + const privacyChanged = changes?.attributes?.isPrivate !== undefined; + + if (document.publishedAt && (!document.isPrivate || privacyChanged)) { if (document.collection) { channels.push( ...this.getCollectionEventChannels(event, document.collection) diff --git a/server/routes/api/documents/documents.ts b/server/routes/api/documents/documents.ts index 0fd8bba3e6..3ed9d2a94a 100644 --- a/server/routes/api/documents/documents.ts +++ b/server/routes/api/documents/documents.ts @@ -1365,6 +1365,20 @@ router.post( ); } } else { + // Cannot unrestrict a child of a restricted parent + if (document.parentDocumentId) { + const parentDocument = await Document.unscoped().findOne({ + attributes: ["id", "isPrivate"], + where: { id: document.parentDocumentId }, + transaction, + }); + if (parentDocument?.isPrivate) { + throw ValidationError( + "Cannot remove restriction from a document whose parent is restricted" + ); + } + } + // Unrestrict: clear flag on document and all descendants document.isPrivate = false; if (childDocumentIds.length) { diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index 88a6f8181d..c6cfb7ba1c 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -11,7 +11,7 @@ "Edit collection": "Edit collection", "Permissions": "Permissions", "Collection permissions": "Collection permissions", - "Share this collection": "Share this collection", + "Share \"{{ itemName }}\"": "Share \"{{ itemName }}\"", "Import document": "Import document", "Uploading": "Uploading", "Sort in sidebar": "Sort in sidebar", @@ -63,7 +63,6 @@ "Unpublish": "Unpublish", "Unpublished {{ documentName }}": "Unpublished {{ documentName }}", "Subscription inherited from collection": "Subscription inherited from collection", - "Share this document": "Share this document", "Download": "Download", "Download document": "Download document", "Download as Markdown": "Download as Markdown", @@ -427,15 +426,18 @@ "Current version": "Current version", "{{userName}} edited": "{{userName}} edited", "Revision options": "Revision options", + "Everyone in workspace": "Everyone in workspace", + "Restricted": "Restricted", "Manage": "Manage", - "All members": "All members", - "Everyone in the workspace": "Everyone in the workspace", + "Access": "Access", + "Only invited users can access": "Only invited users can access", + "All members of {{ itemName }}": "All members of {{ itemName }}", "{{ count }} member": "{{ count }} member", "{{ count }} member_plural": "{{ count }} members", "Only lowercase letters, digits and dashes allowed": "Only lowercase letters, digits and dashes allowed", "Sorry, this link has already been used": "Sorry, this link has already been used", "Public link copied to clipboard": "Public link copied to clipboard", - "Web": "Web", + "Publish to web": "Publish to web", "Allow anyone with the link to access": "Allow anyone with the link to access", "Publish to internet": "Publish to internet", "Search engine indexing": "Search engine indexing", @@ -459,16 +461,11 @@ "Editor": "Editor", "Suggestions for invitation": "Suggestions for invitation", "No matches": "No matches", - "Access managed independently": "Access managed independently", - "Inherits access": "Inherits access", - "Only explicitly added members can access": "Only explicitly added members can access", - "From {{ collectionName }}": "From {{ collectionName }}", - "From parent document": "From parent document", - "Restrict access": "Restrict access", + "Collection members": "Collection members", + "Required by <2>parent": "Required by <2>parent", + "Members of {{ itemName }} can access": "Members of {{ itemName }} can access", + "Inherited from collection": "Inherited from collection", "Created the document": "Created the document", - "Can view": "Can view", - "Everyone in the collection": "Everyone in the collection", - "You have full access": "You have full access", "Other people": "Other people", "Other workspace members may have access": "Other workspace members may have access", "This document may be shared with more workspace members through a parent document or collection you do not have access to": "This document may be shared with more workspace members through a parent document or collection you do not have access to",