mirror of
https://github.com/outline/outline.git
synced 2026-11-22 22:02:35 +03:00
Merge branch 'main' into hmacr/7340-collection-subscription
This commit is contained in:
commit
02b07b2aed
126 files changed
+2181
-1059
No files matched your search
@@ -107,6 +107,7 @@ jobs:
|
||||
name: Send bundle stats to RelativeCI
|
||||
command: npx relative-ci-agent
|
||||
build-image:
|
||||
resource_class: xlarge
|
||||
executor: docker-publisher
|
||||
steps:
|
||||
- checkout
|
||||
|
||||
@@ -3,8 +3,8 @@ Business Source License 1.1
|
||||
Parameters
|
||||
|
||||
Licensor: General Outline, Inc.
|
||||
Licensed Work: Outline 0.81.0
|
||||
The Licensed Work is (c) 2024 General Outline, Inc.
|
||||
Licensed Work: Outline 0.82.0
|
||||
The Licensed Work is (c) 2025 General Outline, Inc.
|
||||
Additional Use Grant: You may make use of the Licensed Work, provided that
|
||||
you may not use the Licensed Work for a Document
|
||||
Service.
|
||||
@@ -15,7 +15,7 @@ Additional Use Grant: You may make use of the Licensed Work, provided that
|
||||
Licensed Work by creating teams and documents
|
||||
controlled by such third parties.
|
||||
|
||||
Change Date: 2028-11-11
|
||||
Change Date: 2029-02-15
|
||||
|
||||
Change License: Apache License, Version 2.0
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import copy from "copy-to-clipboard";
|
||||
import {
|
||||
BeakerIcon,
|
||||
CopyIcon,
|
||||
EditIcon,
|
||||
ToolsIcon,
|
||||
TrashIcon,
|
||||
UserIcon,
|
||||
@@ -83,6 +84,38 @@ export const copyId = createAction({
|
||||
},
|
||||
});
|
||||
|
||||
function generateRandomText() {
|
||||
const characters =
|
||||
"abcdefghijklmno pqrstuvwxyzABCDEFGHIJKL MNOPQRSTUVWXYZ 0123456789\n";
|
||||
let text = "";
|
||||
for (let i = 0; i < Math.floor(Math.random() * 10) + 1; i++) {
|
||||
text += characters.charAt(Math.floor(Math.random() * characters.length));
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
export const startTyping = createAction({
|
||||
name: "Start automatic typing",
|
||||
icon: <EditIcon />,
|
||||
section: DeveloperSection,
|
||||
visible: ({ activeDocumentId }) =>
|
||||
!!activeDocumentId && env.ENVIRONMENT === "development",
|
||||
perform: () => {
|
||||
const intervalId = setInterval(() => {
|
||||
const text = generateRandomText();
|
||||
document.execCommand("insertText", false, text);
|
||||
}, 250);
|
||||
|
||||
window.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Escape") {
|
||||
intervalId && clearInterval(intervalId);
|
||||
}
|
||||
});
|
||||
|
||||
toast.info("Automatic typing started, press Escape to stop");
|
||||
},
|
||||
});
|
||||
|
||||
export const clearIndexedDB = createAction({
|
||||
name: ({ t }) => t("Clear IndexedDB cache"),
|
||||
icon: <TrashIcon />,
|
||||
@@ -169,6 +202,7 @@ export const developer = createAction({
|
||||
createToast,
|
||||
createTestUsers,
|
||||
clearIndexedDB,
|
||||
startTyping,
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
@@ -125,6 +125,20 @@ export const createDocument = createAction({
|
||||
}),
|
||||
});
|
||||
|
||||
export const createDraftDocument = createAction({
|
||||
name: ({ t }) => t("New draft"),
|
||||
analyticsName: "New document",
|
||||
section: DocumentSection,
|
||||
icon: <NewDocumentIcon />,
|
||||
keywords: "create document",
|
||||
visible: ({ currentTeamId, stores }) =>
|
||||
!!currentTeamId && stores.policies.abilities(currentTeamId).createDocument,
|
||||
perform: ({ sidebarContext }) =>
|
||||
history.push(newDocumentPath(), {
|
||||
sidebarContext,
|
||||
}),
|
||||
});
|
||||
|
||||
export const createDocumentFromTemplate = createAction({
|
||||
name: ({ t }) => t("New from template"),
|
||||
analyticsName: "New document",
|
||||
@@ -1181,6 +1195,7 @@ export const rootDocumentActions = [
|
||||
openDocument,
|
||||
archiveDocument,
|
||||
createDocument,
|
||||
createDraftDocument,
|
||||
createNestedDocument,
|
||||
createTemplateFromDocument,
|
||||
deleteDocument,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { getLuminance } from "polished";
|
||||
import styled from "styled-components";
|
||||
import { s } from "@shared/styles";
|
||||
import Flex from "~/components/Flex";
|
||||
@@ -15,7 +16,10 @@ const Initials = styled(Flex)<{
|
||||
border-radius: 50%;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
color: ${s("white75")};
|
||||
color: ${(props) =>
|
||||
getLuminance(props.color ?? props.theme.textTertiary) > 0.5
|
||||
? s("black50")
|
||||
: s("white75")};
|
||||
background-color: ${(props) => props.color ?? props.theme.textTertiary};
|
||||
width: ${(props) => props.size}px;
|
||||
height: ${(props) => props.size}px;
|
||||
|
||||
@@ -7,6 +7,9 @@ import {
|
||||
PublishIcon,
|
||||
MoveIcon,
|
||||
UnpublishIcon,
|
||||
RestoreIcon,
|
||||
UserIcon,
|
||||
CrossIcon,
|
||||
} from "outline-icons";
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -14,32 +17,61 @@ import { useLocation } from "react-router-dom";
|
||||
import styled, { css } from "styled-components";
|
||||
import EventBoundary from "@shared/components/EventBoundary";
|
||||
import { s, hover } from "@shared/styles";
|
||||
import { RevisionHelper } from "@shared/utils/RevisionHelper";
|
||||
import Document from "~/models/Document";
|
||||
import Event from "~/models/Event";
|
||||
import { Avatar, AvatarSize } from "~/components/Avatar";
|
||||
import Item, { Actions, Props as ItemProps } from "~/components/List/Item";
|
||||
import Item, { Actions } from "~/components/List/Item";
|
||||
import Time from "~/components/Time";
|
||||
import { useLocationSidebarContext } from "~/hooks/useLocationSidebarContext";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import RevisionMenu from "~/menus/RevisionMenu";
|
||||
import Logger from "~/utils/Logger";
|
||||
import { documentHistoryPath } from "~/utils/routeHelpers";
|
||||
import Text from "./Text";
|
||||
|
||||
export type RevisionEvent = {
|
||||
name: "revisions.create";
|
||||
latest: boolean;
|
||||
};
|
||||
|
||||
export type DocumentEvent = {
|
||||
name:
|
||||
| "documents.publish"
|
||||
| "documents.unpublish"
|
||||
| "documents.archive"
|
||||
| "documents.unarchive"
|
||||
| "documents.delete"
|
||||
| "documents.restore"
|
||||
| "documents.add_user"
|
||||
| "documents.remove_user"
|
||||
| "documents.move";
|
||||
userId: string;
|
||||
};
|
||||
|
||||
export type Event = { id: string; actorId: string; createdAt: string } & (
|
||||
| RevisionEvent
|
||||
| DocumentEvent
|
||||
);
|
||||
|
||||
type Props = {
|
||||
document: Document;
|
||||
event: Event<Document>;
|
||||
latest?: boolean;
|
||||
event: Event;
|
||||
};
|
||||
|
||||
const EventListItem = ({ event, latest, document, ...rest }: Props) => {
|
||||
const EventListItem = ({ event, document, ...rest }: Props) => {
|
||||
const { t } = useTranslation();
|
||||
const { revisions } = useStores();
|
||||
const { revisions, users } = useStores();
|
||||
const actor = "actorId" in event ? users.get(event.actorId) : undefined;
|
||||
const user = "userId" in event ? users.get(event.userId) : undefined;
|
||||
const location = useLocation();
|
||||
const sidebarContext = useLocationSidebarContext();
|
||||
const revisionLoadedRef = React.useRef(false);
|
||||
const opts = {
|
||||
userName: event.actor.name,
|
||||
userName: actor?.name,
|
||||
};
|
||||
const isRevision = event.name === "revisions.create";
|
||||
const isDerivedFromDocument =
|
||||
event.id === RevisionHelper.latestId(document.id);
|
||||
let meta, icon, to: LocationDescriptor | undefined;
|
||||
|
||||
const ref = React.useRef<HTMLAnchorElement>(null);
|
||||
@@ -50,23 +82,32 @@ const EventListItem = ({ event, latest, document, ...rest }: Props) => {
|
||||
};
|
||||
|
||||
const prefetchRevision = async () => {
|
||||
if (event.name === "revisions.create" && event.modelId) {
|
||||
await revisions.fetch(event.modelId);
|
||||
if (
|
||||
!document.isDeleted &&
|
||||
event.name === "revisions.create" &&
|
||||
!isDerivedFromDocument &&
|
||||
!revisionLoadedRef.current
|
||||
) {
|
||||
await revisions.fetch(event.id, { force: true });
|
||||
revisionLoadedRef.current = true;
|
||||
}
|
||||
};
|
||||
|
||||
switch (event.name) {
|
||||
case "revisions.create":
|
||||
icon = <EditIcon size={16} />;
|
||||
meta = latest ? (
|
||||
meta = event.latest ? (
|
||||
<>
|
||||
{t("Current version")} · {event.actor.name}
|
||||
{t("Current version")} · {actor?.name}
|
||||
</>
|
||||
) : (
|
||||
t("{{userName}} edited", opts)
|
||||
);
|
||||
to = {
|
||||
pathname: documentHistoryPath(document, event.modelId || "latest"),
|
||||
pathname: documentHistoryPath(
|
||||
document,
|
||||
isDerivedFromDocument ? "latest" : event.id
|
||||
),
|
||||
state: {
|
||||
sidebarContext,
|
||||
retainScrollPosition: true,
|
||||
@@ -75,47 +116,51 @@ const EventListItem = ({ event, latest, document, ...rest }: Props) => {
|
||||
break;
|
||||
|
||||
case "documents.archive":
|
||||
icon = <ArchiveIcon size={16} />;
|
||||
icon = <ArchiveIcon />;
|
||||
meta = t("{{userName}} archived", opts);
|
||||
break;
|
||||
|
||||
case "documents.unarchive":
|
||||
icon = <RestoreIcon />;
|
||||
meta = t("{{userName}} restored", opts);
|
||||
break;
|
||||
|
||||
case "documents.delete":
|
||||
icon = <TrashIcon size={16} />;
|
||||
icon = <TrashIcon />;
|
||||
meta = t("{{userName}} deleted", opts);
|
||||
break;
|
||||
case "documents.add_user":
|
||||
icon = <UserIcon />;
|
||||
meta = t("{{userName}} added {{addedUserName}}", {
|
||||
...opts,
|
||||
addedUserName: event.user?.name ?? t("a user"),
|
||||
addedUserName: user?.name ?? t("a user"),
|
||||
});
|
||||
break;
|
||||
case "documents.remove_user":
|
||||
icon = <CrossIcon />;
|
||||
meta = t("{{userName}} removed {{removedUserName}}", {
|
||||
...opts,
|
||||
removedUserName: event.user?.name ?? t("a user"),
|
||||
removedUserName: user?.name ?? t("a user"),
|
||||
});
|
||||
break;
|
||||
|
||||
case "documents.restore":
|
||||
icon = <RestoreIcon />;
|
||||
meta = t("{{userName}} moved from trash", opts);
|
||||
break;
|
||||
|
||||
case "documents.publish":
|
||||
icon = <PublishIcon size={16} />;
|
||||
icon = <PublishIcon />;
|
||||
meta = t("{{userName}} published", opts);
|
||||
break;
|
||||
|
||||
case "documents.unpublish":
|
||||
icon = <UnpublishIcon size={16} />;
|
||||
icon = <UnpublishIcon />;
|
||||
meta = t("{{userName}} unpublished", opts);
|
||||
break;
|
||||
|
||||
case "documents.move":
|
||||
icon = <MoveIcon size={16} />;
|
||||
icon = <MoveIcon />;
|
||||
meta = t("{{userName}} moved", opts);
|
||||
break;
|
||||
|
||||
@@ -136,8 +181,8 @@ const EventListItem = ({ event, latest, document, ...rest }: Props) => {
|
||||
to = undefined;
|
||||
}
|
||||
|
||||
return (
|
||||
<BaseItem
|
||||
return event.name === "revisions.create" ? (
|
||||
<RevisionItem
|
||||
small
|
||||
exact
|
||||
to={to}
|
||||
@@ -153,17 +198,12 @@ const EventListItem = ({ event, latest, document, ...rest }: Props) => {
|
||||
onClick={handleTimeClick}
|
||||
/>
|
||||
}
|
||||
image={<Avatar model={event.actor} size={AvatarSize.Large} />}
|
||||
subtitle={
|
||||
<Subtitle>
|
||||
{icon}
|
||||
{meta}
|
||||
</Subtitle>
|
||||
}
|
||||
image={<Avatar model={actor} size={AvatarSize.Large} />}
|
||||
subtitle={meta}
|
||||
actions={
|
||||
isRevision && isActive && event.modelId && !latest ? (
|
||||
isRevision && isActive && !event.latest ? (
|
||||
<StyledEventBoundary>
|
||||
<RevisionMenu document={document} revisionId={event.modelId} />
|
||||
<RevisionMenu document={document} revisionId={event.id} />
|
||||
</StyledEventBoundary>
|
||||
) : undefined
|
||||
}
|
||||
@@ -171,63 +211,100 @@ const EventListItem = ({ event, latest, document, ...rest }: Props) => {
|
||||
ref={ref}
|
||||
{...rest}
|
||||
/>
|
||||
) : (
|
||||
<EventItem>
|
||||
<IconWrapper size="xsmall" type="secondary">
|
||||
{icon}
|
||||
</IconWrapper>
|
||||
<Text size="xsmall" type="secondary">
|
||||
{meta} ·{" "}
|
||||
<Time dateTime={event.createdAt} relative shorten addSuffix />
|
||||
</Text>
|
||||
</EventItem>
|
||||
);
|
||||
};
|
||||
|
||||
const BaseItem = React.forwardRef(function _BaseItem(
|
||||
{ to, ...rest }: ItemProps,
|
||||
ref?: React.Ref<HTMLAnchorElement>
|
||||
) {
|
||||
return <ListItem to={to} ref={ref} {...rest} />;
|
||||
});
|
||||
const lineStyle = css`
|
||||
&::before {
|
||||
content: "";
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: -8px;
|
||||
left: 22px;
|
||||
width: 1px;
|
||||
height: calc(50% - 14px + 8px);
|
||||
background: ${s("divider")};
|
||||
mix-blend-mode: multiply;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
&:first-child::before {
|
||||
display: none;
|
||||
}
|
||||
|
||||
&:nth-child(2)::before {
|
||||
display: none;
|
||||
}
|
||||
|
||||
&::after {
|
||||
content: "";
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: calc(50% + 14px);
|
||||
left: 22px;
|
||||
width: 1px;
|
||||
height: calc(50% - 14px);
|
||||
background: ${s("divider")};
|
||||
mix-blend-mode: multiply;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
&:last-child::after {
|
||||
display: none;
|
||||
}
|
||||
|
||||
h3 + &::before {
|
||||
display: none;
|
||||
}
|
||||
`;
|
||||
|
||||
const IconWrapper = styled(Text)`
|
||||
height: 24px;
|
||||
`;
|
||||
|
||||
const EventItem = styled.li`
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
list-style: none;
|
||||
margin: 8px 0;
|
||||
padding: 4px 10px;
|
||||
white-space: nowrap;
|
||||
position: relative;
|
||||
|
||||
time {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
svg {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
${lineStyle}
|
||||
`;
|
||||
|
||||
const StyledEventBoundary = styled(EventBoundary)`
|
||||
height: 24px;
|
||||
`;
|
||||
|
||||
const Subtitle = styled.span`
|
||||
svg {
|
||||
margin: -3px;
|
||||
margin-right: 2px;
|
||||
}
|
||||
`;
|
||||
|
||||
const ItemStyle = css`
|
||||
const RevisionItem = styled(Item)`
|
||||
border: 0;
|
||||
position: relative;
|
||||
margin: 8px 0;
|
||||
padding: 8px;
|
||||
border-radius: 8px;
|
||||
|
||||
img {
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
&::before {
|
||||
content: "";
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: -4px;
|
||||
left: 23px;
|
||||
width: 2px;
|
||||
height: calc(100% + 8px);
|
||||
background: ${s("textSecondary")};
|
||||
opacity: 0.25;
|
||||
}
|
||||
|
||||
&:nth-child(2)::before {
|
||||
height: 50%;
|
||||
top: auto;
|
||||
bottom: -4px;
|
||||
}
|
||||
|
||||
&:last-child::before {
|
||||
height: 50%;
|
||||
}
|
||||
|
||||
&:first-child:last-child::before {
|
||||
display: none;
|
||||
}
|
||||
${lineStyle}
|
||||
|
||||
${Actions} {
|
||||
opacity: 0.5;
|
||||
@@ -238,8 +315,4 @@ const ItemStyle = css`
|
||||
}
|
||||
`;
|
||||
|
||||
const ListItem = styled(Item)`
|
||||
${ItemStyle}
|
||||
`;
|
||||
|
||||
export default observer(EventListItem);
|
||||
@@ -48,7 +48,8 @@ export type Props = Omit<ButtonProps<any>, "onChange"> & {
|
||||
options: Option[];
|
||||
/** @deprecated Removing soon, do not use. */
|
||||
note?: React.ReactNode;
|
||||
onChange?: (value: string | null) => void;
|
||||
/** Callback function that is called when the value changes. Return false to cancel the change. */
|
||||
onChange?: (value: string | null) => void | Promise<boolean | void>;
|
||||
style?: React.CSSProperties;
|
||||
/**
|
||||
* Set to true if this component is rendered inside a Modal.
|
||||
@@ -165,9 +166,18 @@ const InputSelect = (props: Props, ref: React.RefObject<InputSelectRef>) => {
|
||||
if (previousValue.current === select.selectedValue) {
|
||||
return;
|
||||
}
|
||||
const previous = previousValue.current;
|
||||
previousValue.current = select.selectedValue;
|
||||
|
||||
onChange?.(select.selectedValue);
|
||||
const response = onChange?.(select.selectedValue);
|
||||
if (response && response instanceof Promise) {
|
||||
void response.then((success) => {
|
||||
if (success === false) {
|
||||
select.selectedValue = previous;
|
||||
select.setSelectedValue(previous);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, [onChange, select.selectedValue]);
|
||||
|
||||
React.useLayoutEffect(() => {
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
import * as React from "react";
|
||||
import styled from "styled-components";
|
||||
import Document from "~/models/Document";
|
||||
import Event from "~/models/Event";
|
||||
import PaginatedList from "~/components/PaginatedList";
|
||||
import EventListItem from "./EventListItem";
|
||||
import EventListItem, { type Event } from "./EventListItem";
|
||||
|
||||
type Props = {
|
||||
events: Event<Document>[];
|
||||
events: Event[];
|
||||
document: Document;
|
||||
fetch: (
|
||||
options: Record<string, any> | undefined
|
||||
) => Promise<Event<Document>[]>;
|
||||
fetch: (options: Record<string, any> | undefined) => Promise<Event[]>;
|
||||
options?: Record<string, any>;
|
||||
heading?: React.ReactNode;
|
||||
empty?: React.ReactNode;
|
||||
@@ -32,13 +29,8 @@ const PaginatedEventList = React.memo<Props>(function PaginatedEventList({
|
||||
heading={heading}
|
||||
fetch={fetch}
|
||||
options={options}
|
||||
renderItem={(item: Event<Document>, index) => (
|
||||
<EventListItem
|
||||
key={item.id}
|
||||
event={item}
|
||||
document={document}
|
||||
latest={index === 0}
|
||||
/>
|
||||
renderItem={(item: Event) => (
|
||||
<EventListItem key={item.id} event={item} document={document} />
|
||||
)}
|
||||
renderHeading={(name) => <Heading>{name}</Heading>}
|
||||
{...rest}
|
||||
|
||||
@@ -60,7 +60,7 @@ class PaginatedList<T extends PaginatedItem> extends React.PureComponent<
|
||||
fetchCounter = 0;
|
||||
|
||||
@observable
|
||||
renderCount = 15;
|
||||
renderCount = Pagination.defaultLimit;
|
||||
|
||||
@observable
|
||||
offset = 0;
|
||||
@@ -108,13 +108,16 @@ class PaginatedList<T extends PaginatedItem> extends React.PureComponent<
|
||||
...this.props.options,
|
||||
});
|
||||
|
||||
if (this.offset !== 0) {
|
||||
this.renderCount += limit;
|
||||
}
|
||||
|
||||
if (results && (results.length === 0 || results.length < limit)) {
|
||||
this.allowLoadMore = false;
|
||||
} else {
|
||||
this.offset += limit;
|
||||
}
|
||||
|
||||
this.renderCount += limit;
|
||||
this.isFetchingInitial = false;
|
||||
} catch (err) {
|
||||
this.error = err;
|
||||
@@ -248,7 +251,9 @@ class PaginatedList<T extends PaginatedItem> extends React.PureComponent<
|
||||
}}
|
||||
</ArrowKeyNavigation>
|
||||
{this.allowLoadMore && (
|
||||
<Waypoint key={this.renderCount} onEnter={this.loadMoreResults} />
|
||||
<div style={{ height: "1px" }}>
|
||||
<Waypoint key={this.renderCount} onEnter={this.loadMoreResults} />
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@ import { observer } from "mobx-react";
|
||||
import { UserIcon } from "outline-icons";
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
import styled, { useTheme } from "styled-components";
|
||||
import Squircle from "@shared/components/Squircle";
|
||||
import { CollectionPermission } from "@shared/types";
|
||||
@@ -167,18 +168,24 @@ export const AccessControlList = observer(
|
||||
| CollectionPermission
|
||||
| typeof EmptySelectValue
|
||||
) => {
|
||||
if (permission === EmptySelectValue) {
|
||||
await groupMemberships.delete({
|
||||
collectionId: collection.id,
|
||||
groupId: membership.groupId,
|
||||
});
|
||||
} else {
|
||||
await groupMemberships.create({
|
||||
collectionId: collection.id,
|
||||
groupId: membership.groupId,
|
||||
permission,
|
||||
});
|
||||
try {
|
||||
if (permission === EmptySelectValue) {
|
||||
await groupMemberships.delete({
|
||||
collectionId: collection.id,
|
||||
groupId: membership.groupId,
|
||||
});
|
||||
} else {
|
||||
await groupMemberships.create({
|
||||
collectionId: collection.id,
|
||||
groupId: membership.groupId,
|
||||
permission,
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
toast.error(err.message);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}}
|
||||
disabled={!can.update}
|
||||
value={membership.permission}
|
||||
@@ -215,18 +222,24 @@ export const AccessControlList = observer(
|
||||
| CollectionPermission
|
||||
| typeof EmptySelectValue
|
||||
) => {
|
||||
if (permission === EmptySelectValue) {
|
||||
await memberships.delete({
|
||||
collectionId: collection.id,
|
||||
userId: membership.userId,
|
||||
});
|
||||
} else {
|
||||
await memberships.create({
|
||||
collectionId: collection.id,
|
||||
userId: membership.userId,
|
||||
permission,
|
||||
});
|
||||
try {
|
||||
if (permission === EmptySelectValue) {
|
||||
await memberships.delete({
|
||||
collectionId: collection.id,
|
||||
userId: membership.userId,
|
||||
});
|
||||
} else {
|
||||
await memberships.create({
|
||||
collectionId: collection.id,
|
||||
userId: membership.userId,
|
||||
permission,
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
toast.error(err.message);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}}
|
||||
disabled={!can.update}
|
||||
value={membership.permission}
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
import { observer } from "mobx-react";
|
||||
import { DraftsIcon, SearchIcon, HomeIcon, SidebarIcon } from "outline-icons";
|
||||
import { SearchIcon, HomeIcon, SidebarIcon } from "outline-icons";
|
||||
import * as React from "react";
|
||||
import { DndProvider } from "react-dnd";
|
||||
import { HTML5Backend } from "react-dnd-html5-backend";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import { metaDisplay } from "@shared/utils/keyboard";
|
||||
import Flex from "~/components/Flex";
|
||||
import Scrollable from "~/components/Scrollable";
|
||||
import Text from "~/components/Text";
|
||||
import { inviteUser } from "~/actions/definitions/users";
|
||||
import useCurrentTeam from "~/hooks/useCurrentTeam";
|
||||
import useCurrentUser from "~/hooks/useCurrentUser";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import OrganizationMenu from "~/menus/OrganizationMenu";
|
||||
import { homePath, draftsPath, searchPath } from "~/utils/routeHelpers";
|
||||
import { homePath, searchPath } from "~/utils/routeHelpers";
|
||||
import TeamLogo from "../TeamLogo";
|
||||
import Tooltip from "../Tooltip";
|
||||
import Sidebar from "./Sidebar";
|
||||
import ArchiveLink from "./components/ArchiveLink";
|
||||
import Collections from "./components/Collections";
|
||||
import { DraftsLink } from "./components/DraftsLink";
|
||||
import DragPlaceholder from "./components/DragPlaceholder";
|
||||
import HistoryNavigation from "./components/HistoryNavigation";
|
||||
import Section from "./components/Section";
|
||||
@@ -107,24 +106,7 @@ function AppSidebar() {
|
||||
label={t("Search")}
|
||||
exact={false}
|
||||
/>
|
||||
{can.createDocument && (
|
||||
<SidebarLink
|
||||
to={draftsPath()}
|
||||
icon={<DraftsIcon />}
|
||||
label={
|
||||
<Flex align="center" justify="space-between">
|
||||
{t("Drafts")}
|
||||
{documents.totalDrafts > 0 ? (
|
||||
<Drafts size="xsmall" type="tertiary">
|
||||
{documents.totalDrafts > 25
|
||||
? "25+"
|
||||
: documents.totalDrafts}
|
||||
</Drafts>
|
||||
) : null}
|
||||
</Flex>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{can.createDocument && <DraftsLink />}
|
||||
</Section>
|
||||
</Overflow>
|
||||
<Scrollable flex shadow>
|
||||
@@ -158,8 +140,4 @@ const Overflow = styled.div`
|
||||
flex-shrink: 0;
|
||||
`;
|
||||
|
||||
const Drafts = styled(Text)`
|
||||
margin: 0 4px;
|
||||
`;
|
||||
|
||||
export default observer(AppSidebar);
|
||||
@@ -14,6 +14,7 @@ import { ArchivedCollectionLink } from "./ArchivedCollectionLink";
|
||||
import { StyledError } from "./Collections";
|
||||
import PlaceholderCollections from "./PlaceholderCollections";
|
||||
import Relative from "./Relative";
|
||||
import SidebarContext from "./SidebarContext";
|
||||
import SidebarLink from "./SidebarLink";
|
||||
|
||||
function ArchiveLink() {
|
||||
@@ -64,38 +65,40 @@ function ArchiveLink() {
|
||||
useDropToArchive();
|
||||
|
||||
return (
|
||||
<Flex column>
|
||||
<div ref={dropToArchiveRef}>
|
||||
<SidebarLink
|
||||
to={archivePath()}
|
||||
icon={<ArchiveIcon open={isOverArchiveSection && isDragging} />}
|
||||
exact={false}
|
||||
label={t("Archive")}
|
||||
isActiveDrop={isOverArchiveSection && isDragging}
|
||||
depth={0}
|
||||
expanded={disclosure ? expanded : undefined}
|
||||
onDisclosureClick={handleDisclosureClick}
|
||||
onClick={handleClick}
|
||||
/>
|
||||
</div>
|
||||
{expanded === true ? (
|
||||
<Relative>
|
||||
<PaginatedList
|
||||
aria-label={t("Archived collections")}
|
||||
items={collections.archived}
|
||||
loading={<PlaceholderCollections />}
|
||||
renderError={(props) => <StyledError {...props} />}
|
||||
renderItem={(item: Collection) => (
|
||||
<ArchivedCollectionLink
|
||||
key={item.id}
|
||||
depth={1}
|
||||
collection={item}
|
||||
/>
|
||||
)}
|
||||
<SidebarContext.Provider value="archive">
|
||||
<Flex column>
|
||||
<div ref={dropToArchiveRef}>
|
||||
<SidebarLink
|
||||
to={archivePath()}
|
||||
icon={<ArchiveIcon open={isOverArchiveSection && isDragging} />}
|
||||
exact={false}
|
||||
label={t("Archive")}
|
||||
isActiveDrop={isOverArchiveSection && isDragging}
|
||||
depth={0}
|
||||
expanded={disclosure ? expanded : undefined}
|
||||
onDisclosureClick={handleDisclosureClick}
|
||||
onClick={handleClick}
|
||||
/>
|
||||
</Relative>
|
||||
) : null}
|
||||
</Flex>
|
||||
</div>
|
||||
{expanded === true ? (
|
||||
<Relative>
|
||||
<PaginatedList
|
||||
aria-label={t("Archived collections")}
|
||||
items={collections.archived}
|
||||
loading={<PlaceholderCollections />}
|
||||
renderError={(props) => <StyledError {...props} />}
|
||||
renderItem={(item: Collection) => (
|
||||
<ArchivedCollectionLink
|
||||
key={item.id}
|
||||
depth={1}
|
||||
collection={item}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</Relative>
|
||||
) : null}
|
||||
</Flex>
|
||||
</SidebarContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -147,16 +147,18 @@ const CollectionLink: React.FC<Props> = ({
|
||||
!isEditing &&
|
||||
!isDraggingAnyCollection && (
|
||||
<Fade>
|
||||
<NudeButton
|
||||
tooltip={{ content: t("New doc"), delay: 500 }}
|
||||
onClick={(ev) => {
|
||||
ev.preventDefault();
|
||||
setIsAddingNewChild();
|
||||
handleExpand();
|
||||
}}
|
||||
>
|
||||
<PlusIcon />
|
||||
</NudeButton>
|
||||
{can.createDocument && (
|
||||
<NudeButton
|
||||
tooltip={{ content: t("New doc"), delay: 500 }}
|
||||
onClick={(ev) => {
|
||||
ev.preventDefault();
|
||||
setIsAddingNewChild();
|
||||
handleExpand();
|
||||
}}
|
||||
>
|
||||
<PlusIcon />
|
||||
</NudeButton>
|
||||
)}
|
||||
<CollectionMenu
|
||||
collection={collection}
|
||||
onRename={handleRename}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { observer } from "mobx-react";
|
||||
import { DraftsIcon } from "outline-icons";
|
||||
import React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import Flex from "~/components/Flex";
|
||||
import Text from "~/components/Text";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { draftsPath } from "~/utils/routeHelpers";
|
||||
import { useDropToUnpublish } from "../hooks/useDragAndDrop";
|
||||
import SidebarLink from "./SidebarLink";
|
||||
|
||||
export const DraftsLink = observer(() => {
|
||||
const { t } = useTranslation();
|
||||
const { documents } = useStores();
|
||||
const [{ isOver, canDrop }, dropRef] = useDropToUnpublish();
|
||||
|
||||
return (
|
||||
<div ref={dropRef}>
|
||||
<SidebarLink
|
||||
to={draftsPath()}
|
||||
icon={<DraftsIcon />}
|
||||
label={
|
||||
<Flex align="center" justify="space-between">
|
||||
{t("Drafts")}
|
||||
{documents.totalDrafts > 0 ? (
|
||||
<Drafts size="xsmall" type="tertiary">
|
||||
{documents.totalDrafts > 25 ? "25+" : documents.totalDrafts}
|
||||
</Drafts>
|
||||
) : null}
|
||||
</Flex>
|
||||
}
|
||||
isActiveDrop={isOver && canDrop}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
const Drafts = styled(Text)`
|
||||
margin: 0 4px;
|
||||
`;
|
||||
@@ -5,6 +5,7 @@ import User from "~/models/User";
|
||||
export type SidebarContextType =
|
||||
| "collections"
|
||||
| "shared"
|
||||
| "archive"
|
||||
| `group-${string}`
|
||||
| `starred-${string}`
|
||||
| undefined;
|
||||
@@ -41,7 +42,7 @@ export const determineSidebarContext = ({
|
||||
}
|
||||
|
||||
if (document.collection) {
|
||||
return "collections";
|
||||
return document.collection.isArchived ? "archive" : "collections";
|
||||
} else if (
|
||||
user.documentMemberships.find((m) => m.documentId === document.id)
|
||||
) {
|
||||
|
||||
@@ -586,3 +586,45 @@ export function useDropToArchive() {
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDropToUnpublish() {
|
||||
const { t } = useTranslation();
|
||||
const { policies, documents } = useStores();
|
||||
|
||||
return useDrop<
|
||||
DragObject,
|
||||
Promise<void>,
|
||||
{ isOver: boolean; canDrop: boolean }
|
||||
>({
|
||||
accept: "document",
|
||||
drop: async (item) => {
|
||||
const document = documents.get(item.id);
|
||||
if (!document) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await document.unpublish({ detach: true });
|
||||
toast.success(
|
||||
t("Unpublished {{ documentName }}", {
|
||||
documentName: document.noun,
|
||||
})
|
||||
);
|
||||
} catch (err) {
|
||||
toast.error(err.message);
|
||||
}
|
||||
},
|
||||
canDrop: (item) => {
|
||||
const policy = policies.abilities(item.id);
|
||||
if (!policy) {
|
||||
return true; // optimistic, let the server check for the necessary permission.
|
||||
}
|
||||
|
||||
return policy.unpublish;
|
||||
},
|
||||
collect: (monitor) => ({
|
||||
isOver: monitor.isOver(),
|
||||
canDrop: monitor.canDrop(),
|
||||
}),
|
||||
});
|
||||
}
|
||||
@@ -225,6 +225,32 @@ class WebsocketProvider extends React.Component<Props> {
|
||||
})
|
||||
);
|
||||
|
||||
this.socket.on(
|
||||
"documents.unpublish",
|
||||
action(
|
||||
(event: {
|
||||
document: PartialExcept<Document, "id">;
|
||||
collectionId: string;
|
||||
}) => {
|
||||
const document = event.document;
|
||||
|
||||
// When document is detached as part of unpublishing, only the owner should be able to view it.
|
||||
if (
|
||||
!document.collectionId &&
|
||||
document.createdBy?.id !== currentUserId
|
||||
) {
|
||||
documents.remove(document.id);
|
||||
} else {
|
||||
documents.add(document);
|
||||
}
|
||||
policies.remove(document.id);
|
||||
|
||||
const collection = collections.get(event.collectionId);
|
||||
collection?.removeDocument(document.id);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
this.socket.on(
|
||||
"documents.archive",
|
||||
action((event: PartialExcept<Document, "id">) => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import React from "react";
|
||||
import useDictionary from "~/hooks/useDictionary";
|
||||
import getMenuItems from "../menus/block";
|
||||
import { useEditor } from "./EditorContext";
|
||||
import SuggestionsMenu, {
|
||||
Props as SuggestionsMenuProps,
|
||||
} from "./SuggestionsMenu";
|
||||
@@ -11,6 +12,7 @@ type Props = Omit<SuggestionsMenuProps, "renderMenuItem" | "items"> &
|
||||
|
||||
function BlockMenu(props: Props) {
|
||||
const dictionary = useDictionary();
|
||||
const { elementRef } = useEditor();
|
||||
|
||||
return (
|
||||
<SuggestionsMenu
|
||||
@@ -26,7 +28,7 @@ function BlockMenu(props: Props) {
|
||||
shortcut={item.shortcut}
|
||||
/>
|
||||
)}
|
||||
items={getMenuItems(dictionary)}
|
||||
items={getMenuItems(dictionary, elementRef)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,52 +25,6 @@ import { isDocumentUrl, isUrl } from "@shared/utils/urls";
|
||||
import stores from "~/stores";
|
||||
import PasteMenu from "../components/PasteMenu";
|
||||
|
||||
/**
|
||||
* Checks if the HTML string is likely coming from Dropbox Paper.
|
||||
*
|
||||
* @param html The HTML string to check.
|
||||
* @returns True if the HTML string is likely coming from Dropbox Paper.
|
||||
*/
|
||||
function isDropboxPaper(html: string): boolean {
|
||||
return html?.includes("usually-unique-id");
|
||||
}
|
||||
|
||||
function sliceSingleNode(slice: Slice) {
|
||||
return slice.openStart === 0 &&
|
||||
slice.openEnd === 0 &&
|
||||
slice.content.childCount === 1
|
||||
? slice.content.firstChild
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the text contents of an HTML string and returns the src of the first
|
||||
* iframe if it exists.
|
||||
*
|
||||
* @param text The HTML string to parse.
|
||||
* @returns The src of the first iframe if it exists, or undefined.
|
||||
*/
|
||||
function parseSingleIframeSrc(html: string) {
|
||||
try {
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(html, "text/html");
|
||||
|
||||
if (
|
||||
doc.body.children.length === 1 &&
|
||||
doc.body.firstElementChild?.tagName === "IFRAME"
|
||||
) {
|
||||
const iframe = doc.body.firstElementChild;
|
||||
const src = iframe.getAttribute("src");
|
||||
if (src) {
|
||||
return src;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore the million ways parsing could fail.
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export default class PasteHandler extends Extension {
|
||||
state: {
|
||||
open: boolean;
|
||||
@@ -261,9 +215,12 @@ export default class PasteHandler extends Extension {
|
||||
// If the text on the clipboard looks like Markdown OR there is no
|
||||
// html on the clipboard then try to parse content as Markdown
|
||||
if (
|
||||
(isMarkdown(text) && !isDropboxPaper(html)) ||
|
||||
(isMarkdown(text) &&
|
||||
!isDropboxPaper(html) &&
|
||||
!isContainingImage(html)) ||
|
||||
pasteCodeLanguage === "markdown" ||
|
||||
this.shiftKey
|
||||
this.shiftKey ||
|
||||
!html
|
||||
) {
|
||||
event.preventDefault();
|
||||
|
||||
@@ -475,3 +432,59 @@ export default class PasteHandler extends Extension {
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the HTML string is likely coming from Dropbox Paper.
|
||||
*
|
||||
* @param html The HTML string to check.
|
||||
* @returns True if the HTML string is likely coming from Dropbox Paper.
|
||||
*/
|
||||
function isDropboxPaper(html: string): boolean {
|
||||
return html?.includes("usually-unique-id");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the HTML string contains an image.
|
||||
*
|
||||
* @param html The HTML string to check.
|
||||
* @returns True if the HTML string contains an image.
|
||||
*/
|
||||
function isContainingImage(html: string): boolean {
|
||||
return html?.includes("<img");
|
||||
}
|
||||
|
||||
function sliceSingleNode(slice: Slice) {
|
||||
return slice.openStart === 0 &&
|
||||
slice.openEnd === 0 &&
|
||||
slice.content.childCount === 1
|
||||
? slice.content.firstChild
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the text contents of an HTML string and returns the src of the first
|
||||
* iframe if it exists.
|
||||
*
|
||||
* @param text The HTML string to parse.
|
||||
* @returns The src of the first iframe if it exists, or undefined.
|
||||
*/
|
||||
function parseSingleIframeSrc(html: string) {
|
||||
try {
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(html, "text/html");
|
||||
|
||||
if (
|
||||
doc.body.children.length === 1 &&
|
||||
doc.body.firstElementChild?.tagName === "IFRAME"
|
||||
) {
|
||||
const iframe = doc.body.firstElementChild;
|
||||
const src = iframe.getAttribute("src");
|
||||
if (src) {
|
||||
return src;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore the million ways parsing could fail.
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -19,7 +19,9 @@ export default class Suggestion extends Extension {
|
||||
super(options);
|
||||
|
||||
this.openRegex = new RegExp(
|
||||
`(?:^|\\s|\\()${escapeRegExp(this.options.trigger)}(${`[\\p{L}\\p{M}\\d${
|
||||
`(?:^|\\s|\\()${escapeRegExp(
|
||||
this.options.trigger
|
||||
)}(${`[\\p{L}\/\\p{M}\\d${
|
||||
this.options.allowSpaces ? "\\s{1}" : ""
|
||||
}\\.]+`})${this.options.requireSearchTerm ? "" : "?"}$`,
|
||||
"u"
|
||||
|
||||
@@ -38,7 +38,12 @@ const Img = styled(Image)`
|
||||
height: 18px;
|
||||
`;
|
||||
|
||||
export default function blockMenuItems(dictionary: Dictionary): MenuItem[] {
|
||||
export default function blockMenuItems(
|
||||
dictionary: Dictionary,
|
||||
documentRef: React.RefObject<HTMLDivElement>
|
||||
): MenuItem[] {
|
||||
const documentWidth = documentRef.current?.clientWidth ?? 0;
|
||||
|
||||
return [
|
||||
{
|
||||
name: "heading",
|
||||
@@ -119,7 +124,11 @@ export default function blockMenuItems(dictionary: Dictionary): MenuItem[] {
|
||||
name: "table",
|
||||
title: dictionary.table,
|
||||
icon: <TableIcon />,
|
||||
attrs: { rowsCount: 3, colsCount: 3 },
|
||||
attrs: {
|
||||
rowsCount: 3,
|
||||
colsCount: 3,
|
||||
colWidth: documentWidth / 3,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "blockquote",
|
||||
|
||||
@@ -2,13 +2,14 @@ import * as React from "react";
|
||||
import usePersistedState from "~/hooks/usePersistedState";
|
||||
import useStores from "./useStores";
|
||||
|
||||
export function usePinnedDocuments(
|
||||
urlId: "home" | string,
|
||||
collectionId?: string
|
||||
) {
|
||||
type UrlId = "home" | string;
|
||||
|
||||
export const pinsCacheKey = (urlId: UrlId) => `pins-${urlId}`;
|
||||
|
||||
export function usePinnedDocuments(urlId: UrlId, collectionId?: string) {
|
||||
const { pins } = useStores();
|
||||
const [pinsCacheCount, setPinsCacheCount] = usePersistedState<number>(
|
||||
`pins-${urlId}`,
|
||||
pinsCacheKey(urlId),
|
||||
0
|
||||
);
|
||||
|
||||
|
||||
@@ -92,13 +92,13 @@ type MenuTriggerProps = {
|
||||
const MenuTrigger: React.FC<MenuTriggerProps> = ({ label, onTrigger }) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { subscriptions } = useStores();
|
||||
const { subscriptions, pins } = useStores();
|
||||
const { model: document, menuState } = useMenuContext<Document>();
|
||||
|
||||
const {
|
||||
loading: subscriptionsLoading,
|
||||
loaded: subscriptionsLoaded,
|
||||
request: loadSubscriptions,
|
||||
loading: auxDataLoading,
|
||||
loaded: auxDataLoaded,
|
||||
request: auxDataRequest,
|
||||
} = useRequest(() =>
|
||||
Promise.all([
|
||||
subscriptions.fetchOne({
|
||||
@@ -111,15 +111,19 @@ const MenuTrigger: React.FC<MenuTriggerProps> = ({ label, onTrigger }) => {
|
||||
event: SubscriptionType.Document,
|
||||
})
|
||||
: noop,
|
||||
pins.fetchOne({
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId ?? null,
|
||||
}),
|
||||
])
|
||||
);
|
||||
|
||||
const handlePointerEnter = React.useCallback(() => {
|
||||
if (!subscriptionsLoading && !subscriptionsLoaded) {
|
||||
void loadSubscriptions();
|
||||
if (!auxDataLoading && !auxDataLoaded) {
|
||||
void auxDataRequest();
|
||||
void document.loadRelations();
|
||||
}
|
||||
}, [subscriptionsLoading, subscriptionsLoaded, loadSubscriptions, document]);
|
||||
}, [auxDataLoading, auxDataLoaded, auxDataRequest, document]);
|
||||
|
||||
return label ? (
|
||||
<MenuButton
|
||||
|
||||
+13
-3
@@ -27,6 +27,7 @@ import { client } from "~/utils/ApiClient";
|
||||
import { settingsPath } from "~/utils/routeHelpers";
|
||||
import Collection from "./Collection";
|
||||
import Notification from "./Notification";
|
||||
import Pin from "./Pin";
|
||||
import View from "./View";
|
||||
import ArchivableModel from "./base/ArchivableModel";
|
||||
import Field from "./decorators/Field";
|
||||
@@ -448,7 +449,11 @@ export default class Document extends ArchivableModel implements Searchable {
|
||||
restore = (options?: { revisionId?: string; collectionId?: string }) =>
|
||||
this.store.restore(this, options);
|
||||
|
||||
unpublish = () => this.store.unpublish(this);
|
||||
unpublish = (
|
||||
options: { detach?: boolean } = {
|
||||
detach: false,
|
||||
}
|
||||
) => this.store.unpublish(this, options);
|
||||
|
||||
@action
|
||||
enableEmbeds = () => {
|
||||
@@ -461,12 +466,17 @@ export default class Document extends ArchivableModel implements Searchable {
|
||||
};
|
||||
|
||||
@action
|
||||
pin = (collectionId?: string | null) =>
|
||||
this.store.rootStore.pins.create({
|
||||
pin = async (collectionId?: string | null) => {
|
||||
const pin = new Pin({}, this.store.rootStore.pins);
|
||||
|
||||
await pin.save({
|
||||
documentId: this.id,
|
||||
...(collectionId ? { collectionId } : {}),
|
||||
});
|
||||
|
||||
return pin;
|
||||
};
|
||||
|
||||
@action
|
||||
unpin = (collectionId?: string) => {
|
||||
const pin = this.store.rootStore.pins.orderedData.find(
|
||||
|
||||
+29
-1
@@ -1,15 +1,19 @@
|
||||
import { observable } from "mobx";
|
||||
import PinsStore from "~/stores/PinsStore";
|
||||
import { setPersistedState } from "~/hooks/usePersistedState";
|
||||
import { pinsCacheKey } from "~/hooks/usePinnedDocuments";
|
||||
import Collection from "./Collection";
|
||||
import Document from "./Document";
|
||||
import Model from "./base/Model";
|
||||
import Field from "./decorators/Field";
|
||||
import { AfterCreate, AfterDelete, AfterRemove } from "./decorators/Lifecycle";
|
||||
import Relation from "./decorators/Relation";
|
||||
|
||||
class Pin extends Model {
|
||||
static modelName = "Pin";
|
||||
|
||||
/** The collection ID that the document is pinned to. If empty the document is pinned to home. */
|
||||
collectionId: string;
|
||||
collectionId: string | null;
|
||||
|
||||
/** The collection that the document is pinned to. If empty the document is pinned to home. */
|
||||
@Relation(() => Collection, { onDelete: "cascade" })
|
||||
@@ -26,6 +30,30 @@ class Pin extends Model {
|
||||
@observable
|
||||
@Field
|
||||
index: string;
|
||||
|
||||
@AfterCreate
|
||||
@AfterDelete
|
||||
@AfterRemove
|
||||
static updateCache(model: Pin) {
|
||||
const pins = model.store as PinsStore;
|
||||
|
||||
// Pinned to home
|
||||
if (!model.collectionId) {
|
||||
setPersistedState(pinsCacheKey("home"), pins.home.length);
|
||||
return;
|
||||
}
|
||||
|
||||
// Pinned to collection
|
||||
const collection = pins.rootStore.collections.get(model.collectionId);
|
||||
if (!collection) {
|
||||
return;
|
||||
}
|
||||
|
||||
setPersistedState(
|
||||
pinsCacheKey(collection.urlId),
|
||||
pins.inCollection(collection.id).length
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Pin;
|
||||
@@ -73,10 +73,13 @@ const CollectionScene = observer(function _CollectionScene() {
|
||||
const sidebarContext = useLocationSidebarContext();
|
||||
|
||||
const id = params.id || "";
|
||||
const urlId = id.split("-").pop() ?? "";
|
||||
|
||||
const collection: Collection | null | undefined =
|
||||
collections.getByUrl(id) || collections.get(id);
|
||||
const can = usePolicy(collection);
|
||||
const { pins, count } = usePinnedDocuments(id, collection?.id);
|
||||
|
||||
const { pins, count } = usePinnedDocuments(urlId, collection?.id);
|
||||
const [collectionTab, setCollectionTab] = usePersistedState<CollectionPath>(
|
||||
`collection-tab:${collection?.id}`,
|
||||
collection?.hasDescription
|
||||
|
||||
@@ -183,7 +183,7 @@ function DataLoader({ match, children }: Props) {
|
||||
|
||||
// Prevents unauthorized request to load share information for the document
|
||||
// when viewing a public share link
|
||||
if (can.read && !document.isDeleted) {
|
||||
if (can.read && !document.isDeleted && !revisionId) {
|
||||
if (team.getPreference(TeamPreference.Commenting)) {
|
||||
void comments.fetchAll({
|
||||
documentId: document.id,
|
||||
@@ -199,7 +199,17 @@ function DataLoader({ match, children }: Props) {
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [can.read, can.update, document, isEditRoute, comments, team, shares, ui]);
|
||||
}, [
|
||||
can.read,
|
||||
can.update,
|
||||
document,
|
||||
isEditRoute,
|
||||
comments,
|
||||
team,
|
||||
shares,
|
||||
ui,
|
||||
revisionId,
|
||||
]);
|
||||
|
||||
if (error) {
|
||||
return error instanceof OfflineError ? (
|
||||
|
||||
@@ -542,14 +542,6 @@ class DocumentScene extends React.Component<Props> {
|
||||
</RevisionContainer>
|
||||
) : (
|
||||
<>
|
||||
{showContents && (
|
||||
<ContentsContainer
|
||||
docFullWidth={document.fullWidth}
|
||||
position={tocPos}
|
||||
>
|
||||
<Contents />
|
||||
</ContentsContainer>
|
||||
)}
|
||||
<MeasuredContainer
|
||||
name="document"
|
||||
as={EditorContainer}
|
||||
@@ -600,6 +592,14 @@ class DocumentScene extends React.Component<Props> {
|
||||
) : null}
|
||||
</Editor>
|
||||
</MeasuredContainer>
|
||||
{showContents && (
|
||||
<ContentsContainer
|
||||
docFullWidth={document.fullWidth}
|
||||
position={tocPos}
|
||||
>
|
||||
<Contents />
|
||||
</ContentsContainer>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</React.Suspense>
|
||||
|
||||
@@ -281,15 +281,18 @@ function DocumentHeader({
|
||||
limit={isCompact ? 3 : undefined}
|
||||
/>
|
||||
)}
|
||||
{(isEditing || !user?.separateEditMode) && !isTemplate && isNew && (
|
||||
<Action>
|
||||
<TemplatesMenu
|
||||
isCompact={isCompact}
|
||||
document={document}
|
||||
onSelectTemplate={onSelectTemplate}
|
||||
/>
|
||||
</Action>
|
||||
)}
|
||||
{(isEditing || !user?.separateEditMode) &&
|
||||
!isTemplate &&
|
||||
isNew &&
|
||||
can.update && (
|
||||
<Action>
|
||||
<TemplatesMenu
|
||||
isCompact={isCompact}
|
||||
document={document}
|
||||
onSelectTemplate={onSelectTemplate}
|
||||
/>
|
||||
</Action>
|
||||
)}
|
||||
{!isEditing && !isRevision && !isTemplate && can.update && (
|
||||
<Action>
|
||||
<ShareButton document={document} />
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import orderBy from "lodash/orderBy";
|
||||
import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useHistory, useRouteMatch } from "react-router-dom";
|
||||
import styled from "styled-components";
|
||||
import { Pagination } from "@shared/constants";
|
||||
import { RevisionHelper } from "@shared/utils/RevisionHelper";
|
||||
import Document from "~/models/Document";
|
||||
import Event from "~/models/Event";
|
||||
import EventModel from "~/models/Event";
|
||||
import Revision from "~/models/Revision";
|
||||
import Empty from "~/components/Empty";
|
||||
import { DocumentEvent, type Event } from "~/components/EventListItem";
|
||||
import PaginatedEventList from "~/components/PaginatedEventList";
|
||||
import useKeyDown from "~/hooks/useKeyDown";
|
||||
import { useLocationSidebarContext } from "~/hooks/useLocationSidebarContext";
|
||||
@@ -14,21 +18,148 @@ import useStores from "~/hooks/useStores";
|
||||
import { documentPath } from "~/utils/routeHelpers";
|
||||
import Sidebar from "./SidebarLayout";
|
||||
|
||||
const EMPTY_ARRAY: Event<Document>[] = [];
|
||||
const DocumentEvents = [
|
||||
"documents.publish",
|
||||
"documents.unpublish",
|
||||
"documents.archive",
|
||||
"documents.unarchive",
|
||||
"documents.delete",
|
||||
"documents.restore",
|
||||
"documents.add_user",
|
||||
"documents.remove_user",
|
||||
"documents.move",
|
||||
];
|
||||
|
||||
function History() {
|
||||
const { events, documents } = useStores();
|
||||
const { events, documents, revisions } = useStores();
|
||||
const { t } = useTranslation();
|
||||
const match = useRouteMatch<{ documentSlug: string }>();
|
||||
const history = useHistory();
|
||||
const sidebarContext = useLocationSidebarContext();
|
||||
const document = documents.getByUrl(match.params.documentSlug);
|
||||
|
||||
const eventsInDocument = document
|
||||
? events.filter({ documentId: document.id })
|
||||
: EMPTY_ARRAY;
|
||||
const [, setForceRender] = React.useState(0);
|
||||
const offset = React.useMemo(() => ({ revisions: 0, events: 0 }), []);
|
||||
|
||||
const onCloseHistory = () => {
|
||||
const toEvent = React.useCallback(
|
||||
(data: Revision | EventModel<Document>): Event => {
|
||||
if (data instanceof Revision) {
|
||||
return {
|
||||
id: data.id,
|
||||
name: "revisions.create",
|
||||
actorId: data.createdBy.id,
|
||||
createdAt: data.createdAt,
|
||||
latest: false,
|
||||
} satisfies Event;
|
||||
}
|
||||
|
||||
return {
|
||||
id: data.id,
|
||||
name: data.name as DocumentEvent["name"],
|
||||
actorId: data.actorId,
|
||||
userId: data.userId,
|
||||
createdAt: data.createdAt,
|
||||
} satisfies Event;
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const fetchHistory = React.useCallback(async () => {
|
||||
if (!document) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const [revisionsArr, eventsArr] = await Promise.all([
|
||||
revisions.fetchPage({
|
||||
documentId: document.id,
|
||||
offset: offset.revisions,
|
||||
limit: Pagination.defaultLimit,
|
||||
}),
|
||||
events.fetchPage({
|
||||
events: DocumentEvents,
|
||||
documentId: document.id,
|
||||
offset: offset.events,
|
||||
limit: Pagination.defaultLimit,
|
||||
}),
|
||||
]);
|
||||
|
||||
const pageEvents = orderBy(
|
||||
[...revisionsArr, ...eventsArr].map(toEvent),
|
||||
"createdAt",
|
||||
"desc"
|
||||
).slice(0, Pagination.defaultLimit);
|
||||
|
||||
const revisionsCount = pageEvents.filter(
|
||||
(event) => event.name === "revisions.create"
|
||||
).length;
|
||||
|
||||
offset.revisions += revisionsCount;
|
||||
offset.events += pageEvents.length - revisionsCount;
|
||||
|
||||
// needed to re-render after mobx store and offset is updated
|
||||
setForceRender((s) => ++s);
|
||||
|
||||
return pageEvents;
|
||||
}, [document, revisions, events, toEvent, offset]);
|
||||
|
||||
const revisionEvents = React.useMemo(() => {
|
||||
if (!document) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const latestRevisionId = RevisionHelper.latestId(document.id);
|
||||
return revisions
|
||||
.filter(
|
||||
(revision: Revision) =>
|
||||
revision.id !== latestRevisionId &&
|
||||
revision.documentId === document.id
|
||||
)
|
||||
.slice(0, offset.revisions)
|
||||
.map(toEvent);
|
||||
}, [document, revisions, offset.revisions, toEvent]);
|
||||
|
||||
const nonRevisionEvents = React.useMemo(
|
||||
() =>
|
||||
document
|
||||
? events
|
||||
.filter({ documentId: document.id })
|
||||
.slice(0, offset.events)
|
||||
.map(toEvent)
|
||||
: [],
|
||||
[document, events, offset.events, toEvent]
|
||||
);
|
||||
|
||||
const mergedEvents = React.useMemo(() => {
|
||||
const merged = orderBy(
|
||||
[...revisionEvents, ...nonRevisionEvents],
|
||||
"createdAt",
|
||||
"desc"
|
||||
);
|
||||
|
||||
const latestEvent = merged[0];
|
||||
|
||||
if (latestEvent && document) {
|
||||
const latestRevisionEvent = merged.find(
|
||||
(event) => event.name === "revisions.create"
|
||||
);
|
||||
|
||||
if (latestEvent.createdAt !== document.updatedAt) {
|
||||
merged.unshift({
|
||||
id: RevisionHelper.latestId(document.id),
|
||||
name: "revisions.create",
|
||||
createdAt: document.updatedAt,
|
||||
actorId: document.updatedBy?.id ?? "",
|
||||
latest: true,
|
||||
});
|
||||
} else if (latestRevisionEvent) {
|
||||
latestRevisionEvent.latest = true;
|
||||
}
|
||||
}
|
||||
|
||||
return merged;
|
||||
}, [document, revisionEvents, nonRevisionEvents]);
|
||||
|
||||
const onCloseHistory = React.useCallback(() => {
|
||||
if (document) {
|
||||
history.push({
|
||||
pathname: documentPath(document),
|
||||
@@ -37,30 +168,7 @@ function History() {
|
||||
} else {
|
||||
history.goBack();
|
||||
}
|
||||
};
|
||||
|
||||
const items = React.useMemo(() => {
|
||||
if (
|
||||
eventsInDocument[0] &&
|
||||
document &&
|
||||
eventsInDocument[0].createdAt !== document.updatedAt
|
||||
) {
|
||||
eventsInDocument.unshift(
|
||||
new Event(
|
||||
{
|
||||
id: RevisionHelper.latestId(document.id),
|
||||
name: "revisions.create",
|
||||
documentId: document.id,
|
||||
createdAt: document.updatedAt,
|
||||
actor: document.updatedBy,
|
||||
},
|
||||
events
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return eventsInDocument;
|
||||
}, [eventsInDocument, events, document]);
|
||||
}, [history, document, sidebarContext]);
|
||||
|
||||
useKeyDown("Escape", onCloseHistory);
|
||||
|
||||
@@ -69,11 +177,8 @@ function History() {
|
||||
{document ? (
|
||||
<PaginatedEventList
|
||||
aria-label={t("History")}
|
||||
fetch={events.fetchPage}
|
||||
events={items}
|
||||
options={{
|
||||
documentId: document.id,
|
||||
}}
|
||||
fetch={fetchHistory}
|
||||
events={mergedEvents}
|
||||
document={document}
|
||||
empty={<EmptyHistory>{t("No history yet")}</EmptyHistory>}
|
||||
/>
|
||||
|
||||
@@ -35,7 +35,7 @@ function Export() {
|
||||
<Heading>{t("Export")}</Heading>
|
||||
<Text as="p" type="secondary">
|
||||
<Trans
|
||||
defaults="A full export might take some time, consider exporting a single document or collection. The exported data is a zip of your documents in Markdown format. You may leave this page once the export has started – if you have notifications enabled, we will email a link to <em>{{ userEmail }}</em> when it’s complete."
|
||||
defaults="A full export might take some time, consider exporting a single document or collection. You may leave this page once the export has started – if you have notifications enabled, we will email a link to <em>{{ userEmail }}</em> when it’s complete."
|
||||
values={{
|
||||
userEmail: user.email,
|
||||
}}
|
||||
|
||||
@@ -64,6 +64,7 @@ export default class DocumentsStore extends Store<Document> {
|
||||
".md",
|
||||
".doc",
|
||||
".docx",
|
||||
".tsv",
|
||||
"text/csv",
|
||||
"text/markdown",
|
||||
"text/plain",
|
||||
@@ -343,18 +344,8 @@ export default class DocumentsStore extends Store<Document> {
|
||||
};
|
||||
|
||||
@action
|
||||
fetchArchived = async (options?: PaginationParams): Promise<Document[]> => {
|
||||
const archivedInResponse = await this.fetchNamedPage("archived", options);
|
||||
const archivedInMemory = this.archived;
|
||||
|
||||
archivedInMemory.forEach((docInMemory) => {
|
||||
!archivedInResponse.find(
|
||||
(docInResponse) => docInResponse.id === docInMemory.id
|
||||
) && this.remove(docInMemory.id);
|
||||
});
|
||||
|
||||
return archivedInResponse;
|
||||
};
|
||||
fetchArchived = async (options?: PaginationParams): Promise<Document[]> =>
|
||||
this.fetchNamedPage("archived", options);
|
||||
|
||||
@action
|
||||
fetchDeleted = async (options?: PaginationParams): Promise<Document[]> =>
|
||||
@@ -776,17 +767,30 @@ export default class DocumentsStore extends Store<Document> {
|
||||
};
|
||||
|
||||
@action
|
||||
unpublish = async (document: Document) => {
|
||||
unpublish = async (
|
||||
document: Document,
|
||||
options: { detach?: boolean } = {
|
||||
detach: false,
|
||||
}
|
||||
) => {
|
||||
const res = await client.post("/documents.unpublish", {
|
||||
id: document.id,
|
||||
...options,
|
||||
});
|
||||
|
||||
runInAction("Document#unpublish", () => {
|
||||
invariant(res?.data, "Data should be available");
|
||||
// unpublishing could sometimes detach the document from the collection.
|
||||
// so, get the collection id before data is updated.
|
||||
const collectionId = document.collectionId;
|
||||
|
||||
document.updateData(res.data);
|
||||
this.addPolicies(res.policies);
|
||||
const collection = this.getCollectionForDocument(document);
|
||||
void collection?.fetchDocuments({ force: true });
|
||||
|
||||
if (collectionId) {
|
||||
const collection = this.rootStore.collections.get(collectionId);
|
||||
collection?.removeDocument(document.id);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { action, runInAction, computed } from "mobx";
|
||||
import Pin from "~/models/Pin";
|
||||
import { PaginationParams } from "~/types";
|
||||
import { client } from "~/utils/ApiClient";
|
||||
import { AuthorizationError, NotFoundError } from "~/utils/errors";
|
||||
import RootStore from "./RootStore";
|
||||
import Store from "./base/Store";
|
||||
|
||||
@@ -13,6 +14,41 @@ export default class PinsStore extends Store<Pin> {
|
||||
super(rootStore, Pin);
|
||||
}
|
||||
|
||||
@action
|
||||
async fetchOne({
|
||||
documentId,
|
||||
collectionId,
|
||||
}: {
|
||||
documentId: string;
|
||||
collectionId: string | null;
|
||||
}) {
|
||||
const pin = this.orderedData.find(
|
||||
(p) => p.documentId === documentId && p.collectionId === collectionId
|
||||
);
|
||||
|
||||
if (pin) {
|
||||
return pin;
|
||||
}
|
||||
|
||||
this.isFetching = true;
|
||||
|
||||
try {
|
||||
const res = await client.post(`/${this.apiEndpoint}.info`, {
|
||||
documentId,
|
||||
collectionId,
|
||||
});
|
||||
invariant(res?.data, "Data should be available");
|
||||
return this.add(res.data);
|
||||
} catch (err) {
|
||||
if (err instanceof AuthorizationError || err instanceof NotFoundError) {
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
} finally {
|
||||
this.isFetching = false;
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
fetchPage = async (params?: FetchParams | undefined): Promise<Pin[]> => {
|
||||
this.isFetching = true;
|
||||
|
||||
@@ -58,7 +58,7 @@ export default class RevisionsStore extends Store<Revision> {
|
||||
|
||||
@action
|
||||
fetchPage = async (
|
||||
options: PaginationParams | undefined
|
||||
options: { documentId: string } & (PaginationParams | undefined)
|
||||
): Promise<Revision[]> => {
|
||||
this.isFetching = true;
|
||||
|
||||
|
||||
+15
-14
@@ -48,17 +48,17 @@
|
||||
"> 0.25%, not dead"
|
||||
],
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "3.740.0",
|
||||
"@aws-sdk/lib-storage": "3.740.0",
|
||||
"@aws-sdk/s3-presigned-post": "3.740.0",
|
||||
"@aws-sdk/s3-request-presigner": "3.740.0",
|
||||
"@aws-sdk/signature-v4-crt": "^3.740.0",
|
||||
"@babel/core": "^7.26.7",
|
||||
"@aws-sdk/client-s3": "3.749.0",
|
||||
"@aws-sdk/lib-storage": "3.749.0",
|
||||
"@aws-sdk/s3-presigned-post": "3.749.0",
|
||||
"@aws-sdk/s3-request-presigner": "3.749.0",
|
||||
"@aws-sdk/signature-v4-crt": "^3.749.0",
|
||||
"@babel/core": "^7.26.9",
|
||||
"@babel/plugin-proposal-decorators": "^7.25.9",
|
||||
"@babel/plugin-transform-class-properties": "^7.25.9",
|
||||
"@babel/plugin-transform-destructuring": "^7.25.9",
|
||||
"@babel/plugin-transform-regenerator": "^7.25.9",
|
||||
"@babel/preset-env": "^7.26.7",
|
||||
"@babel/preset-env": "^7.26.9",
|
||||
"@babel/preset-react": "^7.26.3",
|
||||
"@benrbray/prosemirror-math": "^0.2.2",
|
||||
"@bull-board/api": "^4.2.2",
|
||||
@@ -118,7 +118,7 @@
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"fetch-retry": "^5.0.6",
|
||||
"fetch-with-proxy": "^3.0.1",
|
||||
"form-data": "^4.0.1",
|
||||
"form-data": "^4.0.2",
|
||||
"fractional-index": "^1.0.0",
|
||||
"framer-motion": "^4.1.17",
|
||||
"fs-extra": "^11.2.0",
|
||||
@@ -136,7 +136,7 @@
|
||||
"jszip": "^3.10.1",
|
||||
"katex": "^0.16.21",
|
||||
"kbar": "0.1.0-beta.41",
|
||||
"koa": "^2.15.3",
|
||||
"koa": "^2.15.4",
|
||||
"koa-body": "^6.0.1",
|
||||
"koa-compress": "^5.1.1",
|
||||
"koa-helmet": "^6.1.0",
|
||||
@@ -201,7 +201,7 @@
|
||||
"react-helmet-async": "^2.0.5",
|
||||
"react-hook-form": "^7.54.2",
|
||||
"react-i18next": "^12.3.1",
|
||||
"react-medium-image-zoom": "5.2.10",
|
||||
"react-medium-image-zoom": "5.2.13",
|
||||
"react-merge-refs": "^2.1.1",
|
||||
"react-portal": "^4.2.2",
|
||||
"react-router-dom": "^5.3.4",
|
||||
@@ -237,11 +237,12 @@
|
||||
"tiny-cookie": "^2.5.1",
|
||||
"tmp": "^0.2.3",
|
||||
"turndown": "^7.2.0",
|
||||
"ukkonen": "^2.1.0",
|
||||
"umzug": "^3.8.2",
|
||||
"utility-types": "^3.11.0",
|
||||
"uuid": "^8.3.2",
|
||||
"validator": "13.12.0",
|
||||
"vite": "^5.4.12",
|
||||
"vite": "^5.4.14",
|
||||
"vite-plugin-pwa": "^0.20.3",
|
||||
"winston": "^3.17.0",
|
||||
"ws": "^7.5.10",
|
||||
@@ -263,7 +264,7 @@
|
||||
"@types/crypto-js": "^4.2.2",
|
||||
"@types/diff": "^5.0.9",
|
||||
"@types/dotenv": "^8.2.3",
|
||||
"@types/emoji-regex": "^9.2.0",
|
||||
"@types/emoji-regex": "^9.2.2",
|
||||
"@types/escape-html": "^1.0.4",
|
||||
"@types/express-useragent": "^1.0.5",
|
||||
"@types/formidable": "^2.0.6",
|
||||
@@ -333,7 +334,7 @@
|
||||
"discord-api-types": "^0.37.102",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-prettier": "^8.10.0",
|
||||
"eslint-import-resolver-typescript": "^3.7.0",
|
||||
"eslint-import-resolver-typescript": "^3.8.0",
|
||||
"eslint-plugin-es": "^4.1.0",
|
||||
"eslint-plugin-import": "^2.31.0",
|
||||
"eslint-plugin-jsx-a11y": "^6.10.2",
|
||||
@@ -369,5 +370,5 @@
|
||||
"qs": "6.9.7",
|
||||
"rollup": "^4.5.1"
|
||||
},
|
||||
"version": "0.81.0"
|
||||
"version": "0.82.0"
|
||||
}
|
||||
@@ -236,7 +236,16 @@ describe("#files.get", () => {
|
||||
it("should succeed with status 200 ok when file is requested using signature", async () => {
|
||||
const user = await buildUser();
|
||||
const fileName = "images.docx";
|
||||
const key = path.join("uploads", user.id, uuidV4(), fileName);
|
||||
const { key } = await buildAttachment(
|
||||
{
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
contentType:
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
acl: "private",
|
||||
},
|
||||
fileName
|
||||
);
|
||||
const signedUrl = await FileStorage.getSignedUrl(key);
|
||||
|
||||
ensureDirSync(
|
||||
@@ -262,6 +271,13 @@ describe("#files.get", () => {
|
||||
it("should succeed with status 200 ok when avatar is requested using key", async () => {
|
||||
const user = await buildUser();
|
||||
const key = path.join("avatars", user.id, uuidV4());
|
||||
await buildAttachment({
|
||||
key,
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
contentType: "image/jpg",
|
||||
acl: "public-read",
|
||||
});
|
||||
|
||||
ensureDirSync(
|
||||
path.dirname(path.join(env.FILE_STORAGE_LOCAL_ROOT_DIR, key))
|
||||
@@ -274,7 +290,7 @@ describe("#files.get", () => {
|
||||
|
||||
const res = await server.get(`/api/files.get?key=${key}`);
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.headers.get("Content-Type")).toEqual("application/octet-stream");
|
||||
expect(res.headers.get("Content-Type")).toEqual("image/jpg");
|
||||
expect(res.headers.get("Content-Disposition")).toEqual("attachment");
|
||||
});
|
||||
});
|
||||
@@ -77,19 +77,20 @@ router.get(
|
||||
const { isPublicBucket, fileName } = AttachmentHelper.parseKey(key);
|
||||
const skipAuthorize = isPublicBucket || isSignedRequest;
|
||||
const cacheHeader = "max-age=604800, immutable";
|
||||
let contentType =
|
||||
|
||||
const attachment = await Attachment.findOne({
|
||||
where: { key },
|
||||
rejectOnEmpty: true,
|
||||
});
|
||||
if (!skipAuthorize) {
|
||||
authorize(actor, "read", attachment);
|
||||
}
|
||||
|
||||
const contentType =
|
||||
attachment.contentType ||
|
||||
(fileName ? mime.lookup(fileName) : undefined) ||
|
||||
"application/octet-stream";
|
||||
|
||||
if (!skipAuthorize) {
|
||||
const attachment = await Attachment.findOne({
|
||||
where: { key },
|
||||
rejectOnEmpty: true,
|
||||
});
|
||||
authorize(actor, "read", attachment);
|
||||
contentType = attachment.contentType;
|
||||
}
|
||||
|
||||
ctx.set("Accept-Ranges", "bytes");
|
||||
ctx.set("Cache-Control", cacheHeader);
|
||||
ctx.set("Content-Type", contentType);
|
||||
|
||||
@@ -10,7 +10,7 @@ import BaseTask, {
|
||||
type Props = Record<string, never>;
|
||||
|
||||
export default class CleanupWebhookDeliveriesTask extends BaseTask<Props> {
|
||||
static cron = TaskSchedule.Daily;
|
||||
static cron = TaskSchedule.Day;
|
||||
|
||||
public async perform() {
|
||||
Logger.info("task", `Deleting WebhookDeliveries older than one week…`);
|
||||
|
||||
@@ -62,12 +62,13 @@ export default async function pinCreator({
|
||||
index = fractionalIndex(pins.length ? pins[0].index : null, null);
|
||||
}
|
||||
|
||||
const pin = await Pin.createWithCtx(ctx, {
|
||||
createdById: user.id,
|
||||
teamId: user.teamId,
|
||||
collectionId,
|
||||
documentId,
|
||||
index,
|
||||
const [pin] = await Pin.findOrCreateWithCtx(ctx, {
|
||||
where: {
|
||||
collectionId: collectionId ?? null,
|
||||
documentId,
|
||||
teamId: user.teamId,
|
||||
},
|
||||
defaults: { index, createdById: user.id },
|
||||
});
|
||||
|
||||
return pin;
|
||||
|
||||
@@ -11,6 +11,8 @@ import Heading from "./components/Heading";
|
||||
|
||||
type Props = EmailProps & {
|
||||
deleteConfirmationCode: string;
|
||||
teamName: string;
|
||||
teamUrl: string;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -29,15 +31,15 @@ export default class ConfirmUserDeleteEmail extends BaseEmail<Props> {
|
||||
return `Your requested account deletion code`;
|
||||
}
|
||||
|
||||
protected renderAsText({ deleteConfirmationCode }: Props): string {
|
||||
protected renderAsText({ teamName, deleteConfirmationCode }: Props): string {
|
||||
return `
|
||||
You requested to permanently delete your ${env.APP_NAME} account. Please enter the code below to confirm your account deletion.
|
||||
You requested to permanently delete your ${env.APP_NAME} user account in the ${teamName} workspace. Please enter the code below to confirm your account deletion.
|
||||
|
||||
Code: ${deleteConfirmationCode}
|
||||
`;
|
||||
}
|
||||
|
||||
protected render({ deleteConfirmationCode }: Props) {
|
||||
protected render({ teamUrl, teamName, deleteConfirmationCode }: Props) {
|
||||
return (
|
||||
<EmailTemplate previewText={this.preview()}>
|
||||
<Header />
|
||||
@@ -45,8 +47,9 @@ Code: ${deleteConfirmationCode}
|
||||
<Body>
|
||||
<Heading>Your account deletion request</Heading>
|
||||
<p>
|
||||
You requested to permanently delete your {env.APP_NAME} account.
|
||||
Please enter the code below to confirm your account deletion.
|
||||
You requested to permanently delete your {env.APP_NAME} user account
|
||||
in the <a href={teamUrl}>{teamName}</a> workspace. Please enter the
|
||||
code below to confirm your account deletion.
|
||||
</p>
|
||||
<EmptySpace height={5} />
|
||||
<p>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
/** @type {import('sequelize-cli').Migration} */
|
||||
module.exports = {
|
||||
async up (queryInterface) {
|
||||
await queryInterface.sequelize.query(
|
||||
`CREATE EXTENSION IF NOT EXISTS "pg_trgm";`,
|
||||
);
|
||||
await queryInterface.sequelize.query(
|
||||
`CREATE INDEX CONCURRENTLY documents_title_idx ON documents USING GIN (title gin_trgm_ops);`,
|
||||
);
|
||||
},
|
||||
|
||||
async down (queryInterface) {
|
||||
await queryInterface.sequelize.query(
|
||||
`DROP INDEX CONCURRENTLY documents_title_idx;`,
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
|
||||
/** @type {import('sequelize-cli').Migration} */
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
await queryInterface.sequelize.transaction(async transaction => {
|
||||
await queryInterface.addColumn("teams", "previousSubdomains", {
|
||||
type: Sequelize.ARRAY(Sequelize.STRING),
|
||||
allowNull: true,
|
||||
}, { transaction });
|
||||
await queryInterface.sequelize.query(
|
||||
`CREATE INDEX teams_previous_subdomains ON teams USING GIN ("previousSubdomains");`,
|
||||
{ transaction }
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
async down(queryInterface) {
|
||||
await queryInterface.sequelize.transaction(async transaction => {
|
||||
await queryInterface.sequelize.query(
|
||||
`DROP INDEX teams_previous_subdomains;`,
|
||||
{ transaction }
|
||||
);
|
||||
await queryInterface.removeColumn("teams", "previousSubdomains", { transaction });
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -46,6 +46,15 @@ describe("#ApiKey", () => {
|
||||
});
|
||||
|
||||
describe("canAccess", () => {
|
||||
it("should account for query string", async () => {
|
||||
const apiKey = await buildApiKey({
|
||||
name: "Dev",
|
||||
scope: ["/api/documents.info"],
|
||||
});
|
||||
|
||||
expect(apiKey.canAccess("/api/documents.info?foo=bar")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true for all resources if no scope", async () => {
|
||||
const apiKey = await buildApiKey({
|
||||
name: "Dev",
|
||||
|
||||
@@ -174,6 +174,9 @@ class ApiKey extends ParanoidModel<
|
||||
return true;
|
||||
}
|
||||
|
||||
// strip any query string from the path
|
||||
path = path.split("?")[0];
|
||||
|
||||
const resource = path.split("/").pop() ?? "";
|
||||
const [namespace, method] = resource.split(".");
|
||||
|
||||
|
||||
@@ -981,7 +981,13 @@ class Document extends ArchivableModel<
|
||||
return false;
|
||||
};
|
||||
|
||||
unpublish = async (user: User) => {
|
||||
/**
|
||||
*
|
||||
* @param user User who is performing the action
|
||||
* @param options.detach Whether to detach the document from the containing collection
|
||||
* @returns Updated document
|
||||
*/
|
||||
unpublish = async (user: User, options: { detach: boolean }) => {
|
||||
// If the document is already a draft then calling unpublish should act like save
|
||||
if (!this.publishedAt) {
|
||||
return this.save();
|
||||
@@ -1010,6 +1016,11 @@ class Document extends ArchivableModel<
|
||||
this.createdBy = user;
|
||||
this.updatedBy = user;
|
||||
this.publishedAt = null;
|
||||
|
||||
if (options.detach) {
|
||||
this.collectionId = null;
|
||||
}
|
||||
|
||||
return this.save();
|
||||
};
|
||||
|
||||
|
||||
@@ -19,13 +19,17 @@ import {
|
||||
AfterCreate,
|
||||
AfterUpdate,
|
||||
AfterDestroy,
|
||||
BeforeDestroy,
|
||||
BeforeUpdate,
|
||||
} from "sequelize-typescript";
|
||||
import { CollectionPermission, DocumentPermission } from "@shared/types";
|
||||
import { ValidationError } from "@server/errors";
|
||||
import { APIContext } from "@server/types";
|
||||
import Collection from "./Collection";
|
||||
import Document from "./Document";
|
||||
import Group from "./Group";
|
||||
import User from "./User";
|
||||
import UserMembership from "./UserMembership";
|
||||
import { type HookContext } from "./base/Model";
|
||||
import ParanoidModel from "./base/ParanoidModel";
|
||||
import Fix from "./decorators/Fix";
|
||||
@@ -247,6 +251,36 @@ class GroupMembership extends ParanoidModel<
|
||||
}
|
||||
}
|
||||
|
||||
@BeforeUpdate
|
||||
static async checkLastAdminBeforeUpdate(
|
||||
model: GroupMembership,
|
||||
ctx: APIContext["context"]
|
||||
) {
|
||||
if (
|
||||
model.permission === CollectionPermission.Admin ||
|
||||
model.previous("permission") !== CollectionPermission.Admin ||
|
||||
!model.collectionId
|
||||
) {
|
||||
return;
|
||||
}
|
||||
await this.validateLastAdminPermission(model, ctx);
|
||||
}
|
||||
|
||||
@BeforeDestroy
|
||||
static async checkLastAdminBeforeDestroy(
|
||||
model: GroupMembership,
|
||||
ctx: APIContext["context"]
|
||||
) {
|
||||
// Only check for last admin permission if this permission is admin
|
||||
if (
|
||||
model.permission !== CollectionPermission.Admin ||
|
||||
!model.collectionId
|
||||
) {
|
||||
return;
|
||||
}
|
||||
await this.validateLastAdminPermission(model, ctx);
|
||||
}
|
||||
|
||||
@AfterUpdate
|
||||
static async publishAddGroupEventAfterUpdate(
|
||||
model: GroupMembership,
|
||||
@@ -366,6 +400,34 @@ class GroupMembership extends ParanoidModel<
|
||||
await Document.insertEvent(name, this, hookContext);
|
||||
}
|
||||
}
|
||||
|
||||
private static async validateLastAdminPermission(
|
||||
model: GroupMembership,
|
||||
{ transaction }: APIContext["context"]
|
||||
) {
|
||||
const [userMemberships, groupMemberships] = await Promise.all([
|
||||
UserMembership.count({
|
||||
where: {
|
||||
collectionId: model.collectionId,
|
||||
permission: CollectionPermission.Admin,
|
||||
},
|
||||
transaction,
|
||||
}),
|
||||
this.count({
|
||||
where: {
|
||||
collectionId: model.collectionId,
|
||||
permission: CollectionPermission.Admin,
|
||||
},
|
||||
transaction,
|
||||
}),
|
||||
]);
|
||||
|
||||
if (userMemberships === 0 && groupMemberships === 1) {
|
||||
throw ValidationError(
|
||||
"At least one user or group must have manage permissions"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default GroupMembership;
|
||||
+37
-14
@@ -1,20 +1,43 @@
|
||||
import { buildTeam, buildCollection } from "@server/test/factories";
|
||||
|
||||
describe("collectionIds", () => {
|
||||
it("should return non-private collection ids", async () => {
|
||||
const team = await buildTeam();
|
||||
const collection = await buildCollection({
|
||||
teamId: team.id,
|
||||
describe("Team", () => {
|
||||
describe("collectionIds", () => {
|
||||
it("should return non-private collection ids", async () => {
|
||||
const team = await buildTeam();
|
||||
const collection = await buildCollection({
|
||||
teamId: team.id,
|
||||
});
|
||||
// build a collection in another team
|
||||
await buildCollection();
|
||||
// build a private collection
|
||||
await buildCollection({
|
||||
teamId: team.id,
|
||||
permission: null,
|
||||
});
|
||||
const response = await team.collectionIds();
|
||||
expect(response.length).toEqual(1);
|
||||
expect(response[0]).toEqual(collection.id);
|
||||
});
|
||||
// build a collection in another team
|
||||
await buildCollection();
|
||||
// build a private collection
|
||||
await buildCollection({
|
||||
teamId: team.id,
|
||||
permission: null,
|
||||
});
|
||||
|
||||
describe("previousSubdomains", () => {
|
||||
it("should list the previous subdomains", async () => {
|
||||
const team = await buildTeam({
|
||||
subdomain: "example",
|
||||
});
|
||||
const subdomain = "updated";
|
||||
|
||||
await team.update({ subdomain });
|
||||
expect(team.subdomain).toEqual(subdomain);
|
||||
expect(team.previousSubdomains?.length).toEqual(1);
|
||||
expect(team.previousSubdomains?.[0]).toEqual("example");
|
||||
|
||||
const subdomain2 = "another";
|
||||
await team.update({ subdomain: subdomain2 });
|
||||
expect(team.subdomain).toEqual(subdomain2);
|
||||
expect(team.previousSubdomains?.length).toEqual(2);
|
||||
expect(team.previousSubdomains?.[0]).toEqual("example");
|
||||
expect(team.previousSubdomains?.[1]).toEqual(subdomain);
|
||||
});
|
||||
const response = await team.collectionIds();
|
||||
expect(response.length).toEqual(1);
|
||||
expect(response[0]).toEqual(collection.id);
|
||||
});
|
||||
});
|
||||
@@ -171,6 +171,9 @@ class Team extends ParanoidModel<
|
||||
@Column
|
||||
lastActiveAt: Date | null;
|
||||
|
||||
@Column(DataType.ARRAY(DataType.STRING))
|
||||
previousSubdomains: string[] | null;
|
||||
|
||||
// getters
|
||||
|
||||
/**
|
||||
@@ -369,6 +372,25 @@ class Team extends ParanoidModel<
|
||||
return model;
|
||||
}
|
||||
|
||||
@BeforeUpdate
|
||||
static async savePreviousSubdomain(model: Team) {
|
||||
const previousSubdomain = model.previous("subdomain");
|
||||
if (previousSubdomain && previousSubdomain !== model.subdomain) {
|
||||
model.previousSubdomains = model.previousSubdomains || [];
|
||||
|
||||
if (!model.previousSubdomains.includes(previousSubdomain)) {
|
||||
// Add the previous subdomain to the list of previous subdomains
|
||||
// upto a maximum of 3 previous subdomains
|
||||
model.previousSubdomains.push(previousSubdomain);
|
||||
if (model.previousSubdomains.length > 3) {
|
||||
model.previousSubdomains.shift();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@AfterUpdate
|
||||
static deletePreviousAvatar = async (model: Team) => {
|
||||
const previousAvatarUrl = model.previous("avatarUrl");
|
||||
@@ -393,6 +415,41 @@ class Team extends ParanoidModel<
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Find a team by its current or previous subdomain.
|
||||
*
|
||||
* @param subdomain - The subdomain to search for.
|
||||
* @returns The team with the given or previous subdomain, or null if not found.
|
||||
*/
|
||||
static async findBySubdomain(subdomain: string) {
|
||||
// Preference is always given to the team with the subdomain currently
|
||||
// otherwise we can try and find a team that previously used the subdomain.
|
||||
return (
|
||||
(await this.findOne({
|
||||
where: {
|
||||
subdomain,
|
||||
},
|
||||
})) || (await this.findByPreviousSubdomain(subdomain))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a team by its previous subdomain.
|
||||
*
|
||||
* @param previousSubdomain - The previous subdomain to search for.
|
||||
* @returns The team with the given previous subdomain, or null if not found.
|
||||
*/
|
||||
static async findByPreviousSubdomain(previousSubdomain: string) {
|
||||
return this.findOne({
|
||||
where: {
|
||||
previousSubdomains: {
|
||||
[Op.contains]: [previousSubdomain],
|
||||
},
|
||||
},
|
||||
order: [["updatedAt", "DESC"]],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default Team;
|
||||
@@ -1,7 +1,7 @@
|
||||
import { buildAdmin, buildTeam } from "@server/test/factories";
|
||||
import TeamDomain from "./TeamDomain";
|
||||
|
||||
describe("team domain model", () => {
|
||||
describe("TeamDomain", () => {
|
||||
describe("create", () => {
|
||||
it("should allow creation of domains", async () => {
|
||||
const team = await buildTeam();
|
||||
|
||||
@@ -19,11 +19,15 @@ import {
|
||||
AfterUpdate,
|
||||
Length,
|
||||
AfterDestroy,
|
||||
BeforeDestroy,
|
||||
BeforeUpdate,
|
||||
} from "sequelize-typescript";
|
||||
import { CollectionPermission, DocumentPermission } from "@shared/types";
|
||||
import { ValidationError } from "@server/errors";
|
||||
import { APIContext } from "@server/types";
|
||||
import Collection from "./Collection";
|
||||
import Document from "./Document";
|
||||
import GroupMembership from "./GroupMembership";
|
||||
import User from "./User";
|
||||
import IdModel from "./base/IdModel";
|
||||
import { HookContext } from "./base/Model";
|
||||
@@ -249,6 +253,36 @@ class UserMembership extends IdModel<
|
||||
}
|
||||
}
|
||||
|
||||
@BeforeUpdate
|
||||
static async checkLastAdminBeforeUpdate(
|
||||
model: UserMembership,
|
||||
ctx: APIContext["context"]
|
||||
) {
|
||||
if (
|
||||
model.permission === CollectionPermission.Admin ||
|
||||
model.previous("permission") !== CollectionPermission.Admin ||
|
||||
!model.collectionId
|
||||
) {
|
||||
return;
|
||||
}
|
||||
await this.validateLastAdminPermission(model, ctx);
|
||||
}
|
||||
|
||||
@BeforeDestroy
|
||||
static async checkLastAdminBeforeDestroy(
|
||||
model: UserMembership,
|
||||
ctx: APIContext["context"]
|
||||
) {
|
||||
// Only check for last admin permission if this permission is admin
|
||||
if (
|
||||
model.permission !== CollectionPermission.Admin ||
|
||||
!model.collectionId
|
||||
) {
|
||||
return;
|
||||
}
|
||||
await this.validateLastAdminPermission(model, ctx);
|
||||
}
|
||||
|
||||
@AfterUpdate
|
||||
static async publishAddUserEventAfterUpdate(
|
||||
model: UserMembership,
|
||||
@@ -346,6 +380,34 @@ class UserMembership extends IdModel<
|
||||
await Document.insertEvent(name, this, hookContext);
|
||||
}
|
||||
}
|
||||
|
||||
private static async validateLastAdminPermission(
|
||||
model: UserMembership,
|
||||
{ transaction }: APIContext["context"]
|
||||
) {
|
||||
const [userMemberships, groupMemberships] = await Promise.all([
|
||||
this.count({
|
||||
where: {
|
||||
collectionId: model.collectionId,
|
||||
permission: CollectionPermission.Admin,
|
||||
},
|
||||
transaction,
|
||||
}),
|
||||
GroupMembership.count({
|
||||
where: {
|
||||
collectionId: model.collectionId,
|
||||
permission: CollectionPermission.Admin,
|
||||
},
|
||||
transaction,
|
||||
}),
|
||||
]);
|
||||
|
||||
if (userMemberships === 1 && groupMemberships === 0) {
|
||||
throw ValidationError(
|
||||
"At least one user or group must have manage permissions"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default UserMembership;
|
||||
@@ -74,5 +74,27 @@ describe("Model", () => {
|
||||
expect(usersBatch[0].length).toEqual(100);
|
||||
expect(usersBatch[1].length).toEqual(5);
|
||||
});
|
||||
|
||||
it("should return data in batches with total limit", async () => {
|
||||
const team = await buildTeam();
|
||||
await User.bulkCreate(
|
||||
[...Array(10)].map(() => ({
|
||||
email: faker.internet.email().toLowerCase(),
|
||||
name: faker.person.fullName(),
|
||||
teamId: team.id,
|
||||
}))
|
||||
);
|
||||
|
||||
const usersBatch: User[][] = [];
|
||||
|
||||
await User.findAllInBatches<User>(
|
||||
{ where: { teamId: team.id }, batchLimit: 2, totalLimit: 4 },
|
||||
async (foundUsers) => void usersBatch.push(foundUsers)
|
||||
);
|
||||
|
||||
expect(usersBatch.length).toEqual(2);
|
||||
expect(usersBatch[0].length).toEqual(2);
|
||||
expect(usersBatch[1].length).toEqual(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -282,7 +282,10 @@ class Model<
|
||||
* @param callback The function to call for each batch of results
|
||||
*/
|
||||
static async findAllInBatches<T extends Model>(
|
||||
query: Replace<FindOptions<T>, "limit", "batchLimit">,
|
||||
query: Replace<FindOptions<T>, "limit", "batchLimit"> & {
|
||||
/** The maximum number of results to return, after which the query will stop. */
|
||||
totalLimit?: number;
|
||||
},
|
||||
callback: (results: Array<T>, query: FindOptions<T>) => Promise<void>
|
||||
) {
|
||||
const mappedQuery = {
|
||||
@@ -298,7 +301,10 @@ class Model<
|
||||
results = await this.findAll<T>(mappedQuery);
|
||||
await callback(results, mappedQuery);
|
||||
mappedQuery.offset += mappedQuery.limit;
|
||||
} while (results.length >= mappedQuery.limit);
|
||||
} while (
|
||||
results.length >= mappedQuery.limit &&
|
||||
(mappedQuery.totalLimit ?? Infinity) > mappedQuery.offset
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { JSDOM } from "jsdom";
|
||||
import { Node } from "prosemirror-model";
|
||||
import ukkonen from "ukkonen";
|
||||
import { updateYFragment, yDocToProsemirrorJSON } from "y-prosemirror";
|
||||
import * as Y from "yjs";
|
||||
import textBetween from "@shared/editor/lib/textBetween";
|
||||
@@ -478,25 +479,26 @@ export class DocumentHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two documents and returns true if the text content is equal. This does not take into account
|
||||
* changes to other properties such as table column widths, other visual settings.
|
||||
* Compares two documents or revisions and returns whether the text differs by more than the threshold.
|
||||
*
|
||||
* @param document The document to compare
|
||||
* @param other The other document to compare
|
||||
* @returns True if the text content is equal
|
||||
* @param threshold The threshold for the change in characters
|
||||
* @returns True if the text differs by more than the threshold
|
||||
*/
|
||||
public static isTextContentEqual(
|
||||
public static isChangeOverThreshold(
|
||||
before: Document | Revision | null,
|
||||
after: Document | Revision | null
|
||||
after: Document | Revision | null,
|
||||
threshold: number
|
||||
) {
|
||||
if (!before || !after) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
before.title === after.title &&
|
||||
this.toMarkdown(before) === this.toMarkdown(after)
|
||||
);
|
||||
const first = before.title + this.toPlainText(before);
|
||||
const second = after.title + this.toPlainText(after);
|
||||
const distance = ukkonen(first, second, threshold + 1);
|
||||
return distance > threshold;
|
||||
}
|
||||
|
||||
private static textSerializers = getTextSerializers(schema);
|
||||
|
||||
@@ -877,7 +877,7 @@ describe("SearchHelper", () => {
|
||||
"this&is&a&test:*"
|
||||
);
|
||||
});
|
||||
test("should now wildcard quoted queries", () => {
|
||||
test("should not wildcard quoted queries", () => {
|
||||
expect(SearchHelper.webSearchQuery(`"this is a test"`)).toBe(
|
||||
`"this<->is<->a<->test"`
|
||||
);
|
||||
|
||||
@@ -470,7 +470,7 @@ export default class SearchHelper {
|
||||
const likelyUrls = getUrls(options.query);
|
||||
|
||||
// remove likely urls, and escape the rest of the query.
|
||||
const limitedQuery = this.escapeQuery(
|
||||
let limitedQuery = this.escapeQuery(
|
||||
likelyUrls
|
||||
.reduce((q, url) => q.replace(url, ""), options.query)
|
||||
.slice(0, this.maxQueryLength)
|
||||
@@ -482,6 +482,9 @@ export default class SearchHelper {
|
||||
(match) => match[1]
|
||||
);
|
||||
|
||||
// remove quoted queries from the limited query
|
||||
limitedQuery = limitedQuery.replace(/"([^"]*)"/g, "");
|
||||
|
||||
const iLikeQueries = [...quotedQueries, ...likelyUrls].slice(0, 3);
|
||||
|
||||
for (const match of iLikeQueries) {
|
||||
|
||||
@@ -42,7 +42,6 @@ export default class WebsocketsProcessor {
|
||||
switch (event.name) {
|
||||
case "documents.create":
|
||||
case "documents.publish":
|
||||
case "documents.unpublish":
|
||||
case "documents.restore": {
|
||||
const document = await Document.findByPk(event.documentId, {
|
||||
paranoid: false,
|
||||
@@ -73,6 +72,28 @@ export default class WebsocketsProcessor {
|
||||
});
|
||||
}
|
||||
|
||||
case "documents.unpublish": {
|
||||
const document = await Document.findByPk(event.documentId, {
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
if (!document) {
|
||||
return;
|
||||
}
|
||||
|
||||
const documentToPresent = await presentDocument(undefined, document);
|
||||
|
||||
const channels = await this.getDocumentEventChannels(event, document);
|
||||
|
||||
// We need to add the collection channel to let the members update the doc structure.
|
||||
channels.push(`collection-${event.collectionId}`);
|
||||
|
||||
return socketio.to(channels).emit(event.name, {
|
||||
document: documentToPresent,
|
||||
collectionId: event.collectionId,
|
||||
});
|
||||
}
|
||||
|
||||
case "documents.unarchive": {
|
||||
const [document, srcCollection] = await Promise.all([
|
||||
Document.findByPk(event.documentId, { paranoid: false }),
|
||||
|
||||
@@ -9,8 +9,9 @@ export enum TaskPriority {
|
||||
}
|
||||
|
||||
export enum TaskSchedule {
|
||||
Daily = "daily",
|
||||
Hourly = "hourly",
|
||||
Day = "daily",
|
||||
Hour = "hourly",
|
||||
Minute = "minute",
|
||||
}
|
||||
|
||||
export default abstract class BaseTask<T extends Record<string, any>> {
|
||||
|
||||
@@ -10,7 +10,7 @@ type Props = {
|
||||
};
|
||||
|
||||
export default class CleanupDeletedDocumentsTask extends BaseTask<Props> {
|
||||
static cron = TaskSchedule.Daily;
|
||||
static cron = TaskSchedule.Hour;
|
||||
|
||||
public async perform({ limit }: Props) {
|
||||
Logger.info(
|
||||
|
||||
@@ -10,7 +10,7 @@ type Props = {
|
||||
};
|
||||
|
||||
export default class CleanupDeletedTeamsTask extends BaseTask<Props> {
|
||||
static cron = TaskSchedule.Daily;
|
||||
static cron = TaskSchedule.Hour;
|
||||
|
||||
public async perform({ limit }: Props) {
|
||||
Logger.info(
|
||||
|
||||
@@ -8,7 +8,7 @@ type Props = {
|
||||
};
|
||||
|
||||
export default class CleanupExpiredAttachmentsTask extends BaseTask<Props> {
|
||||
static cron = TaskSchedule.Daily;
|
||||
static cron = TaskSchedule.Hour;
|
||||
|
||||
public async perform({ limit }: Props) {
|
||||
Logger.info("task", `Deleting expired attachments…`);
|
||||
|
||||
@@ -10,7 +10,7 @@ type Props = {
|
||||
};
|
||||
|
||||
export default class CleanupExpiredFileOperationsTask extends BaseTask<Props> {
|
||||
static cron = TaskSchedule.Daily;
|
||||
static cron = TaskSchedule.Hour;
|
||||
|
||||
public async perform({ limit }: Props) {
|
||||
Logger.info("task", `Expiring file operations older than 15 days…`);
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { subDays } from "date-fns";
|
||||
import { Op } from "sequelize";
|
||||
import Logger from "@server/logging/Logger";
|
||||
import { Event } from "@server/models";
|
||||
import BaseTask, {
|
||||
TaskPriority,
|
||||
TaskSchedule,
|
||||
} from "@server/queues/tasks/BaseTask";
|
||||
|
||||
type Props = Record<string, never>;
|
||||
|
||||
export default class CleanupOldEventsTask extends BaseTask<Props> {
|
||||
static cron = TaskSchedule.Hour;
|
||||
|
||||
public async perform() {
|
||||
// TODO: Hardcoded right now, configurable later
|
||||
const retentionDays = 365;
|
||||
const cutoffDate = subDays(new Date(), retentionDays);
|
||||
const maxEventsPerTask = 100000;
|
||||
let totalEventsDeleted = 0;
|
||||
|
||||
try {
|
||||
await Event.findAllInBatches(
|
||||
{
|
||||
attributes: ["id"],
|
||||
where: {
|
||||
createdAt: {
|
||||
[Op.lt]: cutoffDate,
|
||||
},
|
||||
},
|
||||
batchLimit: 1000,
|
||||
totalLimit: maxEventsPerTask,
|
||||
order: [["createdAt", "ASC"]],
|
||||
},
|
||||
async (events) => {
|
||||
totalEventsDeleted += await Event.destroy({
|
||||
where: {
|
||||
id: {
|
||||
[Op.in]: events.map((event) => event.id),
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
} finally {
|
||||
if (totalEventsDeleted > 0) {
|
||||
Logger.info("task", `Deleted old events`, {
|
||||
totalEventsDeleted,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public get options() {
|
||||
return {
|
||||
attempts: 1,
|
||||
priority: TaskPriority.Background,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import BaseTask, { TaskPriority, TaskSchedule } from "./BaseTask";
|
||||
type Props = Record<string, never>;
|
||||
|
||||
export default class CleanupOldNotificationsTask extends BaseTask<Props> {
|
||||
static cron = TaskSchedule.Daily;
|
||||
static cron = TaskSchedule.Hour;
|
||||
|
||||
public async perform() {
|
||||
Logger.info("task", `Permanently destroying old notifications…`);
|
||||
|
||||
@@ -10,7 +10,7 @@ type Props = {
|
||||
};
|
||||
|
||||
export default class ErrorTimedOutFileOperationsTask extends BaseTask<Props> {
|
||||
static cron = TaskSchedule.Daily;
|
||||
static cron = TaskSchedule.Hour;
|
||||
|
||||
public async perform({ limit }: Props) {
|
||||
Logger.info("task", `Error file operations running longer than 12 hours…`);
|
||||
|
||||
@@ -176,7 +176,7 @@ export default class ImportMarkdownZipTask extends ImportTask {
|
||||
document.text = document.text
|
||||
.replace(new RegExp(escapeRegExp(encodedPath), "g"), reference)
|
||||
.replace(
|
||||
new RegExp(`\.?/?${escapeRegExp(normalizedAttachmentPath)}`, "g"),
|
||||
new RegExp(`\\\.?/?${escapeRegExp(normalizedAttachmentPath)}`, "g"),
|
||||
reference
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import BaseTask, { TaskPriority, TaskSchedule } from "./BaseTask";
|
||||
type Props = Record<string, never>;
|
||||
|
||||
export default class InviteReminderTask extends BaseTask<Props> {
|
||||
static cron = TaskSchedule.Daily;
|
||||
static cron = TaskSchedule.Day;
|
||||
|
||||
public async perform() {
|
||||
const users = await User.scope("invited").findAll({
|
||||
|
||||
@@ -28,10 +28,10 @@ export default class RevisionCreatedNotificationsTask extends BaseTask<RevisionE
|
||||
const before = await revision.before();
|
||||
|
||||
// If the content looks the same, don't send notifications
|
||||
if (DocumentHelper.isTextContentEqual(before, revision)) {
|
||||
if (!DocumentHelper.isChangeOverThreshold(before, revision, 5)) {
|
||||
Logger.info(
|
||||
"processor",
|
||||
`suppressing notifications as update has no visual changes`
|
||||
`suppressing notifications as update has insignificant changes`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ type Props = {
|
||||
};
|
||||
|
||||
export default class UpdateTeamsAttachmentsSizeTask extends BaseTask<Props> {
|
||||
static cron = TaskSchedule.Daily;
|
||||
static cron = TaskSchedule.Day;
|
||||
|
||||
public async perform({ limit }: Props) {
|
||||
Logger.info(
|
||||
|
||||
@@ -176,6 +176,8 @@ router.post(
|
||||
throw InvalidRequestError(response.error);
|
||||
}
|
||||
|
||||
await attachment.reload();
|
||||
|
||||
ctx.body = {
|
||||
data: presentAttachment(attachment),
|
||||
};
|
||||
|
||||
@@ -6,13 +6,13 @@ import {
|
||||
FileOperationFormat,
|
||||
} from "@shared/types";
|
||||
import { Collection } from "@server/models";
|
||||
import { zodIconType } from "@server/utils/zod";
|
||||
import { zodIconType, zodIdType } from "@server/utils/zod";
|
||||
import { ValidateColor, ValidateIndex } from "@server/validation";
|
||||
import { BaseSchema, ProsemirrorSchema } from "../schema";
|
||||
|
||||
const BaseIdSchema = z.object({
|
||||
/** Id of the collection to be updated */
|
||||
id: z.string(),
|
||||
id: zodIdType(),
|
||||
});
|
||||
|
||||
export const CollectionsCreateSchema = BaseSchema.extend({
|
||||
|
||||
@@ -28,7 +28,7 @@ export const CommentsCreateSchema = BaseSchema.extend({
|
||||
id: z.string().uuid().optional(),
|
||||
|
||||
/** Create comment for this document */
|
||||
documentId: z.string(),
|
||||
documentId: z.string().uuid(),
|
||||
|
||||
/** Create comment under this parent */
|
||||
parentCommentId: z.string().uuid().optional(),
|
||||
|
||||
@@ -3,13 +3,20 @@ import env from "@server/env";
|
||||
import { AuthenticationError } from "@server/errors";
|
||||
import validate from "@server/middlewares/validate";
|
||||
import tasks from "@server/queues/tasks";
|
||||
import { TaskSchedule } from "@server/queues/tasks/BaseTask";
|
||||
import { APIContext } from "@server/types";
|
||||
import { safeEqual } from "@server/utils/crypto";
|
||||
import * as T from "./schema";
|
||||
|
||||
const router = new Router();
|
||||
|
||||
/** Whether the minutely cron job has been received */
|
||||
const receivedPeriods = new Set<TaskSchedule>();
|
||||
|
||||
const cronHandler = async (ctx: APIContext<T.CronSchemaReq>) => {
|
||||
const period = Object.keys(TaskSchedule).includes(ctx.params.period)
|
||||
? (ctx.params.period as TaskSchedule)
|
||||
: TaskSchedule.Day;
|
||||
const token = (ctx.input.body.token ?? ctx.input.query.token) as string;
|
||||
const limit = ctx.input.body.limit ?? ctx.input.query.limit;
|
||||
|
||||
@@ -17,9 +24,26 @@ const cronHandler = async (ctx: APIContext<T.CronSchemaReq>) => {
|
||||
throw AuthenticationError("Invalid secret token");
|
||||
}
|
||||
|
||||
receivedPeriods.add(period);
|
||||
|
||||
for (const name in tasks) {
|
||||
const TaskClass = tasks[name];
|
||||
if (TaskClass.cron) {
|
||||
if (TaskClass.cron === period) {
|
||||
await TaskClass.schedule({ limit });
|
||||
|
||||
// Backwards compatibility for installations that have not set up
|
||||
// cron jobs periods other than daily.
|
||||
} else if (
|
||||
TaskClass.cron === TaskSchedule.Minute &&
|
||||
!receivedPeriods.has(TaskSchedule.Minute) &&
|
||||
(period === TaskSchedule.Hour || period === TaskSchedule.Day)
|
||||
) {
|
||||
await TaskClass.schedule({ limit });
|
||||
} else if (
|
||||
TaskClass.cron === TaskSchedule.Hour &&
|
||||
!receivedPeriods.has(TaskSchedule.Hour) &&
|
||||
period === TaskSchedule.Day
|
||||
) {
|
||||
await TaskClass.schedule({ limit });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1997,14 +1997,18 @@ describe("#documents.templatize", () => {
|
||||
});
|
||||
const body = await res.json();
|
||||
expect(res.status).toBe(400);
|
||||
expect(body.message).toBe("id: Required");
|
||||
expect(body.message).toBe("id: Must be a valid UUID or slug");
|
||||
});
|
||||
it("should require publish", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const res = await server.post("/api/documents.templatize", {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
id: "random-id",
|
||||
id: document.id,
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
@@ -2581,7 +2585,7 @@ describe("#documents.move", () => {
|
||||
});
|
||||
const body = await res.json();
|
||||
expect(res.status).toEqual(400);
|
||||
expect(body.message).toEqual("id: Required");
|
||||
expect(body.message).toEqual("id: Must be a valid UUID or slug");
|
||||
});
|
||||
|
||||
it("should fail for invalid index", async () => {
|
||||
@@ -2887,7 +2891,7 @@ describe("#documents.restore", () => {
|
||||
});
|
||||
const body = await res.json();
|
||||
expect(res.status).toEqual(400);
|
||||
expect(body.message).toEqual("id: Required");
|
||||
expect(body.message).toEqual("id: Must be a valid UUID or slug");
|
||||
});
|
||||
|
||||
it("should fail for invalid collectionId", async () => {
|
||||
@@ -4331,7 +4335,7 @@ describe("#documents.update", () => {
|
||||
});
|
||||
const body = await res.json();
|
||||
expect(res.status).toBe(400);
|
||||
expect(body.message).toBe("id: Required");
|
||||
expect(body.message).toBe("id: Must be a valid UUID or slug");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4345,7 +4349,7 @@ describe("#documents.archive", () => {
|
||||
});
|
||||
const body = await res.json();
|
||||
expect(res.status).toEqual(400);
|
||||
expect(body.message).toEqual("id: Required");
|
||||
expect(body.message).toEqual("id: Must be a valid UUID or slug");
|
||||
});
|
||||
|
||||
it("should allow archiving document", async () => {
|
||||
@@ -4388,7 +4392,7 @@ describe("#documents.delete", () => {
|
||||
});
|
||||
const body = await res.json();
|
||||
expect(res.status).toEqual(400);
|
||||
expect(body.message).toEqual("id: Required");
|
||||
expect(body.message).toEqual("id: Must be a valid UUID or slug");
|
||||
});
|
||||
|
||||
it("should allow deleting document", async () => {
|
||||
@@ -4537,7 +4541,7 @@ describe("#documents.unpublish", () => {
|
||||
});
|
||||
const body = await res.json();
|
||||
expect(res.status).toEqual(400);
|
||||
expect(body.message).toEqual("id: Required");
|
||||
expect(body.message).toEqual("id: Must be a valid UUID or slug");
|
||||
});
|
||||
|
||||
it("should unpublish a document", async () => {
|
||||
@@ -5083,7 +5087,7 @@ describe("#documents.add_user", () => {
|
||||
});
|
||||
const body = await res.json();
|
||||
expect(res.status).toEqual(400);
|
||||
expect(body.message).toEqual("id: Required");
|
||||
expect(body.message).toEqual("id: Must be a valid UUID or slug");
|
||||
});
|
||||
|
||||
it("should require authentication", async () => {
|
||||
@@ -5169,7 +5173,7 @@ describe("#documents.remove_user", () => {
|
||||
});
|
||||
const body = await res.json();
|
||||
expect(res.status).toEqual(400);
|
||||
expect(body.message).toEqual("id: Required");
|
||||
expect(body.message).toEqual("id: Must be a valid UUID or slug");
|
||||
});
|
||||
|
||||
it("should require authentication", async () => {
|
||||
|
||||
@@ -1454,7 +1454,7 @@ router.post(
|
||||
auth(),
|
||||
validate(T.DocumentsUnpublishSchema),
|
||||
async (ctx: APIContext<T.DocumentsUnpublishReq>) => {
|
||||
const { id } = ctx.input.body;
|
||||
const { id, detach } = ctx.input.body;
|
||||
const { user } = ctx.state.auth;
|
||||
|
||||
const document = await Document.findByPk(id, {
|
||||
@@ -1473,14 +1473,14 @@ router.post(
|
||||
);
|
||||
}
|
||||
|
||||
await document.unpublish(user);
|
||||
// detaching would unset collectionId from document, so save a ref to the affected collectionId.
|
||||
const collectionId = document.collectionId;
|
||||
|
||||
await document.unpublish(user, { detach });
|
||||
await Event.createFromContext(ctx, {
|
||||
name: "documents.unpublish",
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
data: {
|
||||
title: document.title,
|
||||
},
|
||||
collectionId,
|
||||
});
|
||||
|
||||
ctx.body = {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { z } from "zod";
|
||||
import { DocumentPermission, StatusFilter } from "@shared/types";
|
||||
import { UrlHelper } from "@shared/utils/UrlHelper";
|
||||
import { BaseSchema } from "@server/routes/api/schema";
|
||||
import { zodIconType } from "@server/utils/zod";
|
||||
import { zodIconType, zodIdType } from "@server/utils/zod";
|
||||
import { ValidateColor } from "@server/validation";
|
||||
|
||||
const DocumentsSortParamsSchema = z.object({
|
||||
@@ -64,7 +64,7 @@ const BaseSearchSchema = DateFilterSchema.extend({
|
||||
|
||||
const BaseIdSchema = z.object({
|
||||
/** Id of the document to be updated */
|
||||
id: z.string(),
|
||||
id: zodIdType(),
|
||||
});
|
||||
|
||||
export const DocumentsListSchema = BaseSchema.extend({
|
||||
@@ -137,9 +137,7 @@ export type DocumentsDraftsReq = z.infer<typeof DocumentsDraftsSchema>;
|
||||
|
||||
export const DocumentsInfoSchema = BaseSchema.extend({
|
||||
body: z.object({
|
||||
/** Id of the document to be retrieved */
|
||||
id: z.string().optional(),
|
||||
|
||||
id: zodIdType().optional(),
|
||||
/** Share Id, if available */
|
||||
shareId: z
|
||||
.string()
|
||||
@@ -302,6 +300,9 @@ export type DocumentsDeleteReq = z.infer<typeof DocumentsDeleteSchema>;
|
||||
|
||||
export const DocumentsUnpublishSchema = BaseSchema.extend({
|
||||
body: BaseIdSchema.extend({
|
||||
/** Whether to detach the document from the collection */
|
||||
detach: z.boolean().default(false),
|
||||
|
||||
/** @deprecated Version of the API to be used, remove in a few releases */
|
||||
apiVersion: z.number().optional(),
|
||||
}),
|
||||
@@ -328,7 +329,7 @@ export type DocumentsImportReq = z.infer<typeof DocumentsImportSchema>;
|
||||
export const DocumentsCreateSchema = BaseSchema.extend({
|
||||
body: z.object({
|
||||
/** Id of the document to be created */
|
||||
id: z.string().uuid().optional(),
|
||||
id: zodIdType().optional(),
|
||||
|
||||
/** Document title */
|
||||
title: z.string().optional(),
|
||||
@@ -393,9 +394,7 @@ export const DocumentsUsersSchema = BaseSchema.extend({
|
||||
export type DocumentsUsersReq = z.infer<typeof DocumentsUsersSchema>;
|
||||
|
||||
export const DocumentsAddUserSchema = BaseSchema.extend({
|
||||
body: z.object({
|
||||
/** Id of the document to which the user is supposed to be added */
|
||||
id: z.string().uuid(),
|
||||
body: BaseIdSchema.extend({
|
||||
/** Id of the user who is to be added */
|
||||
userId: z.string().uuid(),
|
||||
/** Permission to be granted to the added user */
|
||||
@@ -406,9 +405,7 @@ export const DocumentsAddUserSchema = BaseSchema.extend({
|
||||
export type DocumentsAddUserReq = z.infer<typeof DocumentsAddUserSchema>;
|
||||
|
||||
export const DocumentsRemoveUserSchema = BaseSchema.extend({
|
||||
body: z.object({
|
||||
/** Id of the document from which to remove the user */
|
||||
id: z.string().uuid(),
|
||||
body: BaseIdSchema.extend({
|
||||
/** Id of the user who is to be removed */
|
||||
userId: z.string().uuid(),
|
||||
}),
|
||||
|
||||
@@ -228,6 +228,45 @@ describe("#events.list", () => {
|
||||
expect(body.data[0].id).toEqual(event.id);
|
||||
});
|
||||
|
||||
it("should allow filtering by events param", async () => {
|
||||
const user = await buildUser();
|
||||
const admin = await buildAdmin({ teamId: user.teamId });
|
||||
const collection = await buildCollection({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
collectionId: collection.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
// audit event
|
||||
await buildEvent({
|
||||
name: "users.promote",
|
||||
teamId: user.teamId,
|
||||
actorId: admin.id,
|
||||
userId: user.id,
|
||||
});
|
||||
// event viewable in activity stream
|
||||
const event = await buildEvent({
|
||||
name: "documents.publish",
|
||||
collectionId: collection.id,
|
||||
documentId: document.id,
|
||||
teamId: user.teamId,
|
||||
actorId: user.id,
|
||||
});
|
||||
const res = await server.post("/api/events.list", {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
events: ["documents.publish"],
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.data.length).toEqual(1);
|
||||
expect(body.data[0].id).toEqual(event.id);
|
||||
});
|
||||
|
||||
it("should return events with deleted actors", async () => {
|
||||
const user = await buildUser();
|
||||
const admin = await buildAdmin({ teamId: user.teamId });
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Router from "koa-router";
|
||||
import intersection from "lodash/intersection";
|
||||
import { Op, WhereOptions } from "sequelize";
|
||||
import { EventHelper } from "@shared/utils/EventHelper";
|
||||
import auth from "@server/middlewares/authentication";
|
||||
@@ -20,20 +21,35 @@ router.post(
|
||||
async (ctx: APIContext<T.EventsListReq>) => {
|
||||
const { user } = ctx.state.auth;
|
||||
const {
|
||||
sort,
|
||||
direction,
|
||||
name,
|
||||
events,
|
||||
auditLog,
|
||||
actorId,
|
||||
documentId,
|
||||
collectionId,
|
||||
name,
|
||||
auditLog,
|
||||
sort,
|
||||
direction,
|
||||
} = ctx.input.body;
|
||||
|
||||
let where: WhereOptions<Event> = {
|
||||
name: EventHelper.ACTIVITY_EVENTS,
|
||||
teamId: user.teamId,
|
||||
};
|
||||
|
||||
if (auditLog) {
|
||||
authorize(user, "audit", user.team);
|
||||
where.name = events
|
||||
? intersection(EventHelper.AUDIT_EVENTS, events)
|
||||
: EventHelper.AUDIT_EVENTS;
|
||||
} else {
|
||||
where.name = events
|
||||
? intersection(EventHelper.ACTIVITY_EVENTS, events)
|
||||
: EventHelper.ACTIVITY_EVENTS;
|
||||
}
|
||||
|
||||
if (name && (where.name as string[]).includes(name)) {
|
||||
where.name = name;
|
||||
}
|
||||
|
||||
if (actorId) {
|
||||
where = { ...where, actorId };
|
||||
}
|
||||
@@ -42,15 +58,6 @@ router.post(
|
||||
where = { ...where, documentId };
|
||||
}
|
||||
|
||||
if (auditLog) {
|
||||
authorize(user, "audit", user.team);
|
||||
where.name = EventHelper.AUDIT_EVENTS;
|
||||
}
|
||||
|
||||
if (name && (where.name as string[]).includes(name)) {
|
||||
where.name = name;
|
||||
}
|
||||
|
||||
if (collectionId) {
|
||||
where = { ...where, collectionId };
|
||||
|
||||
@@ -77,7 +84,7 @@ router.post(
|
||||
};
|
||||
}
|
||||
|
||||
const events = await Event.findAll({
|
||||
const loadedEvents = await Event.findAll({
|
||||
where,
|
||||
order: [[sort, direction]],
|
||||
include: [
|
||||
@@ -94,7 +101,7 @@ router.post(
|
||||
ctx.body = {
|
||||
pagination: ctx.state.pagination,
|
||||
data: await Promise.all(
|
||||
events.map((event) => presentEvent(event, auditLog))
|
||||
loadedEvents.map((event) => presentEvent(event, auditLog))
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
import { z } from "zod";
|
||||
import { EventHelper } from "@shared/utils/EventHelper";
|
||||
import { BaseSchema } from "@server/routes/api/schema";
|
||||
|
||||
export const EventsListSchema = BaseSchema.extend({
|
||||
body: z.object({
|
||||
/** Events to retrieve */
|
||||
events: z
|
||||
.array(
|
||||
z.union([
|
||||
z.enum(EventHelper.ACTIVITY_EVENTS),
|
||||
z.enum(EventHelper.AUDIT_EVENTS),
|
||||
])
|
||||
)
|
||||
.optional(),
|
||||
|
||||
/** Id of the user who performed the action */
|
||||
actorId: z.string().uuid().optional(),
|
||||
|
||||
@@ -15,7 +26,9 @@ export const EventsListSchema = BaseSchema.extend({
|
||||
/** Whether to include audit events */
|
||||
auditLog: z.boolean().default(false),
|
||||
|
||||
/** Name of the event to retrieve */
|
||||
/** @deprecated, use 'events' parameter instead
|
||||
* Name of the event to retrieve
|
||||
*/
|
||||
name: z.string().optional(),
|
||||
|
||||
/** The attribute to sort the events by */
|
||||
|
||||
@@ -74,7 +74,7 @@ export type NotificationsUpdateAllReq = z.infer<
|
||||
|
||||
export const NotificationsPixelSchema = BaseSchema.extend({
|
||||
query: z.object({
|
||||
id: z.string(),
|
||||
id: z.string().uuid(),
|
||||
token: z.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -168,6 +168,84 @@ describe("#pins.create", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#pins.info", () => {
|
||||
it("should provide info about a home pin", async () => {
|
||||
const admin = await buildAdmin();
|
||||
const document = await buildDocument({
|
||||
userId: admin.id,
|
||||
teamId: admin.teamId,
|
||||
});
|
||||
|
||||
await server.post("/api/pins.create", {
|
||||
body: {
|
||||
token: admin.getJwtToken(),
|
||||
documentId: document.id,
|
||||
},
|
||||
});
|
||||
|
||||
const res = await server.post("/api/pins.info", {
|
||||
body: {
|
||||
token: admin.getJwtToken(),
|
||||
documentId: document.id,
|
||||
},
|
||||
});
|
||||
const pin = await res.json();
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(pin.data.id).toBeDefined();
|
||||
expect(pin.data.documentId).toEqual(document.id);
|
||||
expect(pin.data.collectionId).toBeFalsy();
|
||||
});
|
||||
|
||||
it("should provide info about a collection pin", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
|
||||
await server.post("/api/pins.create", {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
},
|
||||
});
|
||||
|
||||
const res = await server.post("/api/pins.info", {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
},
|
||||
});
|
||||
const pin = await res.json();
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(pin.data.id).toBeDefined();
|
||||
expect(pin.data.documentId).toEqual(document.id);
|
||||
expect(pin.data.collectionId).toEqual(document.collectionId);
|
||||
});
|
||||
|
||||
it("should throw 404 if no pin found", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
|
||||
const res = await server.post("/api/pins.info", {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
documentId: document.id,
|
||||
collectionId: null,
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.status).toEqual(404);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#pins.list", () => {
|
||||
let user: User;
|
||||
let pins: Pin[];
|
||||
|
||||
@@ -57,12 +57,41 @@ router.post(
|
||||
}
|
||||
);
|
||||
|
||||
router.post(
|
||||
"pins.info",
|
||||
auth(),
|
||||
validate(T.PinsInfoSchema),
|
||||
async (ctx: APIContext<T.PinsInfoReq>) => {
|
||||
const { user } = ctx.state.auth;
|
||||
const { documentId, collectionId } = ctx.input.body;
|
||||
|
||||
const document = await Document.findByPk(documentId, { userId: user.id });
|
||||
authorize(user, "read", document);
|
||||
|
||||
// There can be only one pin with these props.
|
||||
const pin = await Pin.findOne({
|
||||
where: {
|
||||
documentId,
|
||||
collectionId: collectionId ?? null,
|
||||
createdById: user.id,
|
||||
teamId: user.teamId,
|
||||
},
|
||||
rejectOnEmpty: true,
|
||||
});
|
||||
|
||||
ctx.body = {
|
||||
data: presentPin(pin),
|
||||
policies: presentPolicies(user, [pin]),
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
router.post(
|
||||
"pins.list",
|
||||
auth(),
|
||||
validate(T.PinsListSchema),
|
||||
pagination(),
|
||||
async (ctx: APIContext<T.PinsCreateReq>) => {
|
||||
async (ctx: APIContext<T.PinsListReq>) => {
|
||||
const { collectionId } = ctx.input.body;
|
||||
const { user } = ctx.state.auth;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import isUUID from "validator/lib/isUUID";
|
||||
import { z } from "zod";
|
||||
import { UrlHelper } from "@shared/utils/UrlHelper";
|
||||
import { zodIdType } from "@server/utils/zod";
|
||||
import { BaseSchema } from "../schema";
|
||||
|
||||
export const PinsCreateSchema = BaseSchema.extend({
|
||||
@@ -24,13 +25,24 @@ export const PinsCreateSchema = BaseSchema.extend({
|
||||
|
||||
export type PinsCreateReq = z.infer<typeof PinsCreateSchema>;
|
||||
|
||||
export const PinsInfoSchema = BaseSchema.extend({
|
||||
body: z.object({
|
||||
/** Document to get the pin info for. */
|
||||
documentId: zodIdType(),
|
||||
/** Collection to which the pin belongs to. If not set, it's considered as "Home" pin. */
|
||||
collectionId: z.string().uuid().nullish(),
|
||||
}),
|
||||
});
|
||||
|
||||
export type PinsInfoReq = z.infer<typeof PinsInfoSchema>;
|
||||
|
||||
export const PinsListSchema = BaseSchema.extend({
|
||||
body: z.object({
|
||||
collectionId: z.string().uuid().nullish(),
|
||||
}),
|
||||
});
|
||||
|
||||
export type PinsListReq = z.infer<typeof PinsCreateSchema>;
|
||||
export type PinsListReq = z.infer<typeof PinsListSchema>;
|
||||
|
||||
export const PinsUpdateSchema = BaseSchema.extend({
|
||||
body: z.object({
|
||||
|
||||
@@ -125,6 +125,7 @@ router.post(
|
||||
|
||||
const document = await Document.findByPk(documentId, {
|
||||
userId: user.id,
|
||||
paranoid: false,
|
||||
});
|
||||
authorize(user, "listRevisions", document);
|
||||
|
||||
|
||||
@@ -636,6 +636,8 @@ router.post(
|
||||
await new ConfirmUserDeleteEmail({
|
||||
to: user.email,
|
||||
deleteConfirmationCode: user.deleteConfirmationCode,
|
||||
teamName: user.team.name,
|
||||
teamUrl: user.team.url,
|
||||
}).schedule();
|
||||
|
||||
ctx.body = {
|
||||
|
||||
@@ -76,7 +76,7 @@ export const renderApp = async (
|
||||
const csp = ctx.response.get("Content-Security-Policy");
|
||||
ctx.set(
|
||||
"Content-Security-Policy",
|
||||
csp.replace("script-src", `script-src ${parsed.hostname}`)
|
||||
csp.replace("script-src", `script-src ${parsed.host}`)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
+23
-4
@@ -7,6 +7,7 @@ import send from "koa-send";
|
||||
import userAgent, { UserAgentContext } from "koa-useragent";
|
||||
import { languages } from "@shared/i18n";
|
||||
import { IntegrationType, TeamPreference } from "@shared/types";
|
||||
import { parseDomain } from "@shared/utils/domains";
|
||||
import { Day } from "@shared/utils/time";
|
||||
import env from "@server/env";
|
||||
import { NotFoundError } from "@server/errors";
|
||||
@@ -138,11 +139,29 @@ router.get("*", shareDomains(), async (ctx, next) => {
|
||||
}
|
||||
|
||||
const team = await getTeamFromContext(ctx);
|
||||
let redirectUrl;
|
||||
|
||||
// Redirect all requests to custom domain if one is set
|
||||
if (team?.domain && team.domain !== ctx.hostname) {
|
||||
ctx.redirect(ctx.href.replace(ctx.hostname, team.domain));
|
||||
return;
|
||||
if (env.isCloudHosted) {
|
||||
// Redirect all requests to custom domain if one is set
|
||||
if (team?.domain && team.domain !== ctx.hostname) {
|
||||
redirectUrl = ctx.href.replace(ctx.hostname, team.domain);
|
||||
}
|
||||
|
||||
// Redirect if subdomain is not the current team's subdomain
|
||||
else if (team?.subdomain) {
|
||||
const { teamSubdomain } = parseDomain(ctx.href);
|
||||
if (team?.subdomain !== teamSubdomain) {
|
||||
redirectUrl = ctx.href.replace(
|
||||
`//${teamSubdomain}.`,
|
||||
`//${team.subdomain}.`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (redirectUrl) {
|
||||
ctx.redirect(redirectUrl);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const analytics = team
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Day, Hour, Second } from "@shared/utils/time";
|
||||
import { Day, Hour, Minute, Second } from "@shared/utils/time";
|
||||
import tasks from "@server/queues/tasks";
|
||||
import { TaskSchedule } from "@server/queues/tasks/BaseTask";
|
||||
|
||||
@@ -12,13 +12,15 @@ export default function init() {
|
||||
}
|
||||
}
|
||||
|
||||
setInterval(() => void run(TaskSchedule.Daily), Day.ms);
|
||||
setInterval(() => void run(TaskSchedule.Hourly), Hour.ms);
|
||||
setInterval(() => void run(TaskSchedule.Day), Day.ms);
|
||||
setInterval(() => void run(TaskSchedule.Hour), Hour.ms);
|
||||
setInterval(() => void run(TaskSchedule.Minute), Minute.ms);
|
||||
|
||||
// Just give everything time to startup before running the first time. Not
|
||||
// _technically_ required to function.
|
||||
setTimeout(() => {
|
||||
void run(TaskSchedule.Daily);
|
||||
void run(TaskSchedule.Hourly);
|
||||
}, 30 * Second.ms);
|
||||
void run(TaskSchedule.Day);
|
||||
void run(TaskSchedule.Hour);
|
||||
void run(TaskSchedule.Minute);
|
||||
}, 5 * Second.ms);
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Blob } from "buffer";
|
||||
import { Readable } from "stream";
|
||||
import { PresignedPost } from "@aws-sdk/s3-presigned-post";
|
||||
import { isBase64Url } from "@shared/utils/urls";
|
||||
import { isBase64Url, isInternalUrl } from "@shared/utils/urls";
|
||||
import env from "@server/env";
|
||||
import Logger from "@server/logging/Logger";
|
||||
import fetch, { RequestInit } from "@server/utils/fetch";
|
||||
import fetch, { chromeUserAgent, RequestInit } from "@server/utils/fetch";
|
||||
|
||||
export default abstract class BaseStorage {
|
||||
/** The default number of seconds until a signed URL expires. */
|
||||
@@ -149,7 +149,7 @@ export default abstract class BaseStorage {
|
||||
const endpoint = this.getUploadUrl(true);
|
||||
|
||||
// Early return if url is already uploaded to the storage provider
|
||||
if (url.startsWith("/api") || url.startsWith(endpoint)) {
|
||||
if (url.startsWith(endpoint) || isInternalUrl(url)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -168,6 +168,9 @@ export default abstract class BaseStorage {
|
||||
options?.maxUploadSize ?? Infinity,
|
||||
env.FILE_STORAGE_UPLOAD_MAX_SIZE
|
||||
),
|
||||
headers: {
|
||||
"User-Agent": chromeUserAgent,
|
||||
},
|
||||
timeout: 10000,
|
||||
...init,
|
||||
});
|
||||
|
||||
+5
-1
@@ -182,7 +182,6 @@ export type DocumentEvent = BaseEvent<Document> &
|
||||
name:
|
||||
| "documents.create"
|
||||
| "documents.publish"
|
||||
| "documents.unpublish"
|
||||
| "documents.delete"
|
||||
| "documents.permanent_delete"
|
||||
| "documents.archive"
|
||||
@@ -194,6 +193,11 @@ export type DocumentEvent = BaseEvent<Document> &
|
||||
source?: "import";
|
||||
};
|
||||
}
|
||||
| {
|
||||
name: "documents.unpublish";
|
||||
documentId: string;
|
||||
collectionId: string;
|
||||
}
|
||||
| {
|
||||
name: "documents.unarchive";
|
||||
documentId: string;
|
||||
|
||||
Vendored
+8
@@ -19,3 +19,11 @@ declare module "@joplin/turndown-plugin-gfm" {
|
||||
export const taskListItems: Plugin;
|
||||
export const gfm: Plugin;
|
||||
}
|
||||
|
||||
declare module "ukkonen" {
|
||||
export default function ukkonen(
|
||||
first: string,
|
||||
second: string,
|
||||
limit?: number
|
||||
): number;
|
||||
}
|
||||
@@ -7,6 +7,13 @@ import Logger from "@server/logging/Logger";
|
||||
|
||||
export type { RequestInit } from "node-fetch";
|
||||
|
||||
/**
|
||||
* Fake Chrome user agent string for use in fetch requests to
|
||||
* improve reliability.
|
||||
*/
|
||||
export const chromeUserAgent =
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36";
|
||||
|
||||
/**
|
||||
* Wrapper around fetch that uses the request-filtering-agent in cloud hosted
|
||||
* environments to filter malicious requests, and the fetch-with-proxy library
|
||||
|
||||
@@ -127,9 +127,7 @@ export async function getTeamFromContext(ctx: Context) {
|
||||
} else if (domain.custom) {
|
||||
team = await Team.findOne({ where: { domain: domain.host } });
|
||||
} else if (domain.teamSubdomain) {
|
||||
team = await Team.findOne({
|
||||
where: { subdomain: domain.teamSubdomain },
|
||||
});
|
||||
team = await Team.findBySubdomain(domain.teamSubdomain);
|
||||
}
|
||||
|
||||
return team;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import emojiRegex from "emoji-regex";
|
||||
import { z } from "zod";
|
||||
import { IconLibrary } from "@shared/utils/IconLibrary";
|
||||
import { UrlHelper } from "@shared/utils/UrlHelper";
|
||||
|
||||
export function zodEnumFromObjectKeys<
|
||||
TI extends Record<string, any>,
|
||||
@@ -10,6 +11,11 @@ export function zodEnumFromObjectKeys<
|
||||
return z.enum([firstKey, ...otherKeys]);
|
||||
}
|
||||
|
||||
export const zodIdType = () =>
|
||||
z.union([z.string().regex(UrlHelper.SLUG_URL_REGEX), z.string().uuid()], {
|
||||
message: "Must be a valid UUID or slug",
|
||||
});
|
||||
|
||||
export const zodIconType = () =>
|
||||
z.union([
|
||||
z.string().regex(emojiRegex()),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Fragment, Node, NodeType } from "prosemirror-model";
|
||||
import { Node, NodeType } from "prosemirror-model";
|
||||
import { Command, EditorState, TextSelection } from "prosemirror-state";
|
||||
import {
|
||||
CellSelection,
|
||||
@@ -20,14 +20,19 @@ import { collapseSelection } from "./collapseSelection";
|
||||
export function createTable({
|
||||
rowsCount,
|
||||
colsCount,
|
||||
colWidth,
|
||||
}: {
|
||||
/** The number of rows in the table. */
|
||||
rowsCount: number;
|
||||
/** The number of columns in the table. */
|
||||
colsCount: number;
|
||||
/** The widths of each column in the table. */
|
||||
colWidth: number;
|
||||
}): Command {
|
||||
return (state, dispatch) => {
|
||||
if (dispatch) {
|
||||
const offset = state.tr.selection.anchor + 1;
|
||||
const nodes = createTableInner(state, rowsCount, colsCount);
|
||||
const nodes = createTableInner(state, rowsCount, colsCount, colWidth);
|
||||
const tr = state.tr.replaceSelectionWith(nodes).scrollIntoView();
|
||||
const resolvedPos = tr.doc.resolve(offset);
|
||||
tr.setSelection(TextSelection.near(resolvedPos));
|
||||
@@ -41,6 +46,7 @@ function createTableInner(
|
||||
state: EditorState,
|
||||
rowsCount: number,
|
||||
colsCount: number,
|
||||
colWidth: number,
|
||||
withHeaderRow = true,
|
||||
cellContent?: Node
|
||||
) {
|
||||
@@ -49,23 +55,27 @@ function createTableInner(
|
||||
const cells: Node[] = [];
|
||||
const rows: Node[] = [];
|
||||
|
||||
const createCell = (
|
||||
cellType: NodeType,
|
||||
cellContent: Fragment | Node | readonly Node[] | null | undefined
|
||||
) =>
|
||||
const createCell = (cellType: NodeType, attrs: Record<string, any> | null) =>
|
||||
cellContent
|
||||
? cellType.createChecked(null, cellContent)
|
||||
: cellType.createAndFill();
|
||||
? cellType.createChecked(attrs, cellContent)
|
||||
: cellType.createAndFill(attrs);
|
||||
|
||||
for (let index = 0; index < colsCount; index += 1) {
|
||||
const cell = createCell(types.cell, cellContent);
|
||||
const attrs = colWidth
|
||||
? {
|
||||
colwidth: [colWidth],
|
||||
colspan: 1,
|
||||
rowspan: 1,
|
||||
}
|
||||
: null;
|
||||
const cell = createCell(types.cell, attrs);
|
||||
|
||||
if (cell) {
|
||||
cells.push(cell);
|
||||
}
|
||||
|
||||
if (withHeaderRow) {
|
||||
const headerCell = createCell(types.header_cell, cellContent);
|
||||
const headerCell = createCell(types.header_cell, attrs);
|
||||
|
||||
if (headerCell) {
|
||||
headerCells.push(headerCell);
|
||||
|
||||
@@ -71,6 +71,7 @@ const Content = styled.p<{ $width: number; $isSelected: boolean }>`
|
||||
cursor: text;
|
||||
width: ${(props) => props.$width}px;
|
||||
min-width: 200px;
|
||||
max-width: 100%;
|
||||
|
||||
${breakpoint("tablet")`
|
||||
font-size: 13px;
|
||||
|
||||
@@ -55,6 +55,7 @@ const mathStyle = (props: Props) => css`
|
||||
cursor: auto;
|
||||
white-space: pre-wrap;
|
||||
overflow-x: auto;
|
||||
overflow-y: none;
|
||||
}
|
||||
|
||||
.math-node.empty-math .math-render::before {
|
||||
@@ -251,10 +252,13 @@ const codeBlockStyle = (props: Props) => css`
|
||||
`;
|
||||
|
||||
const findAndReplaceStyle = () => css`
|
||||
.find-result {
|
||||
.find-result:not(:has(.mention)),
|
||||
.find-result .mention {
|
||||
background: rgba(255, 213, 0, 0.25);
|
||||
}
|
||||
|
||||
&.current-result {
|
||||
.find-result.current-result:not(:has(.mention)),
|
||||
.find-result.current-result .mention {
|
||||
background: rgba(255, 213, 0, 0.75);
|
||||
animation: ${pulse} 150ms 1;
|
||||
}
|
||||
@@ -615,7 +619,6 @@ iframe.embed {
|
||||
}
|
||||
|
||||
.column-resize-handle {
|
||||
animation: ${fadeIn} 150ms ease-in-out;
|
||||
${props.readOnly ? "display: none;" : ""}
|
||||
position: absolute;
|
||||
right: -1px;
|
||||
@@ -1093,6 +1096,7 @@ ol {
|
||||
direction: rtl;
|
||||
}
|
||||
|
||||
&:has(p:dir(rtl)),
|
||||
&:dir(rtl) {
|
||||
margin: 0 ${props.staticHTML ? "0" : "-26px"} 0 0.1em;
|
||||
padding: 0 48px 0 0;
|
||||
|
||||
@@ -35,8 +35,8 @@ export type MenuItem = {
|
||||
children?: MenuItem[];
|
||||
defaultHidden?: boolean;
|
||||
attrs?:
|
||||
| Record<string, Primitive>
|
||||
| ((state: EditorState) => Record<string, Primitive>);
|
||||
| Record<string, Primitive | null>
|
||||
| ((state: EditorState) => Record<string, Primitive | null>);
|
||||
visible?: boolean;
|
||||
active?: (state: EditorState) => boolean;
|
||||
appendSpace?: boolean;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
const EDITOR_VERSION = "13.0.0";
|
||||
const EDITOR_VERSION = "14.0.0";
|
||||
|
||||
export default EDITOR_VERSION;
|
||||
@@ -195,6 +195,7 @@
|
||||
"Default collection": "Výchozí sbírka",
|
||||
"Install now": "Nainstalovat",
|
||||
"Deleted Collection": "Odstraněná sbírka",
|
||||
"Untitled": "Bez názvu",
|
||||
"Unpin": "Zrušit připnutí",
|
||||
"{{ minutes }}m read": "{{ minutes }}m read",
|
||||
"Select a location to copy": "Select a location to copy",
|
||||
@@ -204,7 +205,6 @@
|
||||
"Copy to <em>{{ location }}</em>": "Copy to <em>{{ location }}</em>",
|
||||
"Search collections & documents": "Prohledat sbírky a dokumenty",
|
||||
"No results found": "Nebyly nalezeny žádné výsledky",
|
||||
"Untitled": "Bez názvu",
|
||||
"New": "Nový",
|
||||
"Only visible to you": "Viditelné pouze pro vás",
|
||||
"Draft": "Návrh",
|
||||
@@ -932,7 +932,7 @@
|
||||
"Danger": "Nebezpečí",
|
||||
"You can delete this entire workspace including collections, documents, and users.": "Můžete odstranit celý tento pracovní prostor včetně kolekcí, dokumentů a uživatelů.",
|
||||
"Export data": "Exportovat data",
|
||||
"A full export might take some time, consider exporting a single document or collection. The exported data is a zip of your documents in Markdown format. You may leave this page once the export has started – if you have notifications enabled, we will email a link to <em>{{ userEmail }}</em> when it’s complete.": "Úplný export může nějakou dobu trvat, zvažte export jednoho dokumentu nebo sbírky. Exportovaná data jsou zipem vašich dokumentů ve formátu Markdown. Po zahájení exportu můžete tuto stránku opustit – pokud máte povolená upozornění, pošleme vám e-mail s odkazem na <em>{{ userEmail }}</em> , až bude dokončen.",
|
||||
"A full export might take some time, consider exporting a single document or collection. You may leave this page once the export has started – if you have notifications enabled, we will email a link to <em>{{ userEmail }}</em> when it’s complete.": "A full export might take some time, consider exporting a single document or collection. You may leave this page once the export has started – if you have notifications enabled, we will email a link to <em>{{ userEmail }}</em> when it’s complete.",
|
||||
"Recent exports": "Nedávné exporty",
|
||||
"Manage optional and beta features. Changing these settings will affect the experience for all members of the workspace.": "Spravujte volitelné funkce a funkce beta. Změna těchto nastavení ovlivní prostředí všech členů pracovního prostoru.",
|
||||
"Separate editing": "Oddělený režim úprav",
|
||||
|
||||
@@ -195,6 +195,7 @@
|
||||
"Default collection": "Default collection",
|
||||
"Install now": "Install now",
|
||||
"Deleted Collection": "Deleted Collection",
|
||||
"Untitled": "Unavngivet",
|
||||
"Unpin": "Unpin",
|
||||
"{{ minutes }}m read": "{{ minutes }}m read",
|
||||
"Select a location to copy": "Select a location to copy",
|
||||
@@ -204,7 +205,6 @@
|
||||
"Copy to <em>{{ location }}</em>": "Copy to <em>{{ location }}</em>",
|
||||
"Search collections & documents": "Search collections & documents",
|
||||
"No results found": "Ingen resultater fundet",
|
||||
"Untitled": "Unavngivet",
|
||||
"New": "Ny",
|
||||
"Only visible to you": "Kun synlig for dig",
|
||||
"Draft": "Udkast",
|
||||
@@ -932,7 +932,7 @@
|
||||
"Danger": "Danger",
|
||||
"You can delete this entire workspace including collections, documents, and users.": "You can delete this entire workspace including collections, documents, and users.",
|
||||
"Export data": "Export data",
|
||||
"A full export might take some time, consider exporting a single document or collection. The exported data is a zip of your documents in Markdown format. You may leave this page once the export has started – if you have notifications enabled, we will email a link to <em>{{ userEmail }}</em> when it’s complete.": "A full export might take some time, consider exporting a single document or collection. The exported data is a zip of your documents in Markdown format. You may leave this page once the export has started – if you have notifications enabled, we will email a link to <em>{{ userEmail }}</em> when it’s complete.",
|
||||
"A full export might take some time, consider exporting a single document or collection. You may leave this page once the export has started – if you have notifications enabled, we will email a link to <em>{{ userEmail }}</em> when it’s complete.": "A full export might take some time, consider exporting a single document or collection. You may leave this page once the export has started – if you have notifications enabled, we will email a link to <em>{{ userEmail }}</em> when it’s complete.",
|
||||
"Recent exports": "Recent exports",
|
||||
"Manage optional and beta features. Changing these settings will affect the experience for all members of the workspace.": "Manage optional and beta features. Changing these settings will affect the experience for all members of the workspace.",
|
||||
"Separate editing": "Separate editing",
|
||||
|
||||
Loaded 100 of 126 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user