diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000000..276d9a7dbb --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,70 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ main ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ main ] + schedule: + - cron: '28 15 * * 2' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'javascript' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://git.io/codeql-language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # â„šī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/app/components/Editor.js b/app/components/Editor.js index b349938a7e..8a7ede7c76 100644 --- a/app/components/Editor.js +++ b/app/components/Editor.js @@ -40,6 +40,7 @@ export type Props = {| maxLength?: number, scrollTo?: string, theme?: Theme, + className?: string, handleDOMEvents?: Object, readOnlyWriteCheckboxes?: boolean, onBlur?: (event: SyntheticEvent<>) => any, @@ -276,6 +277,7 @@ const StyledEditor = styled(RichMarkdownEditor)` } > div { opacity: 0; + transition: opacity 100ms ease-in-out; position: absolute; top: -1.8em; font-size: 13px; @@ -295,11 +297,14 @@ const StyledEditor = styled(RichMarkdownEditor)` &:hover { > div { opacity: 1; - transition: opacity 100ms ease-in-out; } } } } + + &.show-cursor-names .ProseMirror-yjs-cursor > div { + opacity: 1; + } `; const EditorTooltip = ({ children, ...props }) => ( diff --git a/app/components/EventListItem.js b/app/components/EventListItem.js index 47f2d29663..8da20ba944 100644 --- a/app/components/EventListItem.js +++ b/app/components/EventListItem.js @@ -137,7 +137,8 @@ const ListItem = styled(Item)` &:nth-child(2)::before { height: 50%; - top: 50%; + top: auto; + bottom: -4px; } &:last-child::before { diff --git a/app/hooks/useIsMounted.js b/app/hooks/useIsMounted.js new file mode 100644 index 0000000000..c2b7040247 --- /dev/null +++ b/app/hooks/useIsMounted.js @@ -0,0 +1,21 @@ +// @flow +import * as React from "react"; + +/** + * Hook to check if component is still mounted + * + * @returns {boolean} true if the component is mounted, false otherwise + */ +export default function useIsMounted() { + const isMounted = React.useRef(false); + + React.useEffect(() => { + isMounted.current = true; + + return () => { + isMounted.current = false; + }; + }, []); + + return React.useCallback(() => isMounted.current, []); +} diff --git a/app/hooks/useKeyDown.js b/app/hooks/useKeyDown.js index ed95858351..449b8806c5 100644 --- a/app/hooks/useKeyDown.js +++ b/app/hooks/useKeyDown.js @@ -17,7 +17,9 @@ const createKeyPredicate = (keyFilter: KeyFilter) => typeof keyFilter === "function" ? keyFilter : typeof keyFilter === "string" - ? (event: KeyboardEvent) => event.key === keyFilter + ? (event: KeyboardEvent) => + event.key === keyFilter || + event.code === `Key${keyFilter.toUpperCase()}` : keyFilter ? (_event) => true : (_event) => false; diff --git a/app/menus/RevisionMenu.js b/app/menus/RevisionMenu.js index ea4c47f449..f48b763806 100644 --- a/app/menus/RevisionMenu.js +++ b/app/menus/RevisionMenu.js @@ -32,11 +32,19 @@ function RevisionMenu({ document, revisionId, className }: Props) { const handleRestore = React.useCallback( async (ev: SyntheticEvent<>) => { ev.preventDefault(); - await document.restore({ revisionId }); - showToast(t("Document restored"), { type: "success" }); - history.push(document.url); + + if (team.collaborativeEditing) { + history.push(document.url, { + restore: true, + revisionId, + }); + } else { + await document.restore({ revisionId }); + showToast(t("Document restored"), { type: "success" }); + history.push(document.url); + } }, - [history, showToast, t, document, revisionId] + [history, showToast, t, team.collaborativeEditing, document, revisionId] ); const handleCopy = React.useCallback(() => { @@ -57,11 +65,7 @@ function RevisionMenu({ document, revisionId, className }: Props) { {...menu} /> - + diff --git a/app/scenes/Document/components/DataLoader.js b/app/scenes/Document/components/DataLoader.js index 95e550b34d..4fd8a3716b 100644 --- a/app/scenes/Document/components/DataLoader.js +++ b/app/scenes/Document/components/DataLoader.js @@ -24,6 +24,7 @@ import { type LocationWithState, type NavigationNode } from "types"; import { NotFoundError, OfflineError } from "utils/errors"; import { matchDocumentEdit, updateDocumentUrl } from "utils/routeHelpers"; import { isInternalUrl } from "utils/urls"; + type Props = {| match: Match, auth: AuthStore, @@ -45,6 +46,7 @@ class DataLoader extends React.Component { sharedTree: ?NavigationNode; @observable document: ?Document; @observable revision: ?Revision; + @observable shapshot: ?Blob; @observable error: ?Error; componentDidMount() { @@ -226,7 +228,8 @@ class DataLoader extends React.Component { }; render() { - const { location, policies, auth, ui } = this.props; + const { location, policies, auth, match, ui } = this.props; + const { revisionId } = match.params; if (this.error) { return this.error instanceof OfflineError ? ( @@ -240,7 +243,7 @@ class DataLoader extends React.Component { const document = this.document; const revision = this.revision; - if (!document || !team) { + if (!document || !team || (revisionId && !revision)) { return ( <> diff --git a/app/scenes/Document/components/Document.js b/app/scenes/Document/components/Document.js index 549e884cf7..2c5bf69b86 100644 --- a/app/scenes/Document/components/Document.js +++ b/app/scenes/Document/components/Document.js @@ -37,6 +37,7 @@ import MarkAsViewed from "./MarkAsViewed"; import PublicReferences from "./PublicReferences"; import References from "./References"; import { type LocationWithState, type NavigationNode, type Theme } from "types"; +import { client } from "utils/ApiClient"; import { isCustomDomain } from "utils/domains"; import { emojiToUrl } from "utils/emoji"; import { isModKey } from "utils/keyboard"; @@ -125,7 +126,7 @@ class DocumentScene extends React.Component { } } - onSelectTemplate = (template: Document) => { + replaceDocument = (template: Document | Revision) => { this.title = template.title; this.isDirty = true; @@ -141,13 +142,36 @@ class DocumentScene extends React.Component { .replaceSelectionWith(parser.parse(template.text)) ); - this.props.document.templateId = template.id; + if (template instanceof Document) { + this.props.document.templateId = template.id; + } this.props.document.title = template.title; this.props.document.text = template.text; this.updateIsDirty(); }; + onSynced = async () => { + const { toasts, history, location, t } = this.props; + const restore = location.state?.restore; + const revisionId = location.state?.revisionId; + + const editorRef = this.editor.current; + if (!editorRef || !restore) { + return; + } + + const response = await client.post("/revisions.info", { + id: revisionId, + }); + + if (response) { + this.replaceDocument(response.data); + toasts.showToast(t("Document restored")); + history.replace(this.props.document.url); + } + }; + goToMove = (ev) => { if (!this.props.readOnly) return; @@ -179,11 +203,12 @@ class DocumentScene extends React.Component { goToHistory = (ev) => { if (!this.props.readOnly) return; + if (ev.ctrlKey) return; ev.preventDefault(); - const { document, revision } = this.props; + const { document, location } = this.props; - if (revision) { + if (location.pathname.endsWith("history")) { this.props.history.push(document.url); } else { this.props.history.push(documentHistoryUrl(document)); @@ -458,7 +483,7 @@ class DocumentScene extends React.Component { savingIsDisabled={document.isSaving || this.isEmpty} sharedTree={this.props.sharedTree} goBack={this.goBack} - onSelectTemplate={this.onSelectTemplate} + onSelectTemplate={this.replaceDocument} onSave={this.onSave} headings={headings} /> @@ -531,6 +556,7 @@ class DocumentScene extends React.Component { value={readOnly ? value : undefined} defaultValue={value} disableEmbeds={disableEmbeds} + onSynced={this.onSynced} onImageUploadStart={this.onImageUploadStart} onImageUploadStop={this.onImageUploadStop} onSearchLink={this.props.onSearchLink} diff --git a/app/scenes/Document/components/MultiplayerEditor.js b/app/scenes/Document/components/MultiplayerEditor.js index f1e2a688b9..6ddead0234 100644 --- a/app/scenes/Document/components/MultiplayerEditor.js +++ b/app/scenes/Document/components/MultiplayerEditor.js @@ -10,6 +10,7 @@ import env from "env"; import useCurrentToken from "hooks/useCurrentToken"; import useCurrentUser from "hooks/useCurrentUser"; import useIdle from "hooks/useIdle"; +import useIsMounted from "hooks/useIsMounted"; import usePageVisibility from "hooks/usePageVisibility"; import useStores from "hooks/useStores"; import useToasts from "hooks/useToasts"; @@ -19,15 +20,17 @@ import { homePath } from "utils/routeHelpers"; type Props = {| ...EditorProps, id: string, + onSynced?: () => void, |}; -function MultiplayerEditor({ ...props }: Props, ref: any) { +function MultiplayerEditor({ onSynced, ...props }: Props, ref: any) { const documentId = props.id; const history = useHistory(); const { t } = useTranslation(); const currentUser = useCurrentUser(); const { presence, ui } = useStores(); const token = useCurrentToken(); + const [showCursorNames, setShowCursorNames] = React.useState(false); const [remoteProvider, setRemoteProvider] = React.useState(); const [isLocalSynced, setLocalSynced] = React.useState(false); const [isRemoteSynced, setRemoteSynced] = React.useState(false); @@ -35,6 +38,7 @@ function MultiplayerEditor({ ...props }: Props, ref: any) { const { showToast } = useToasts(); const isIdle = useIdle(); const isVisible = usePageVisibility(); + const isMounted = useIsMounted(); // Provider initialization must be within useLayoutEffect rather than useState // or useMemo as both of these are ran twice in React StrictMode resulting in @@ -75,6 +79,18 @@ function MultiplayerEditor({ ...props }: Props, ref: any) { }); }); + const showCursorNames = () => { + setShowCursorNames(true); + setTimeout(() => { + if (isMounted()) { + setShowCursorNames(false); + } + }, 2000); + provider.off("awarenessChange", showCursorNames); + }; + + provider.on("awarenessChange", showCursorNames); + localProvider.on("synced", () => // only set local storage to "synced" if it's loaded a non-empty doc setLocalSynced(!!ydoc.get("default")._start) @@ -139,6 +155,12 @@ function MultiplayerEditor({ ...props }: Props, ref: any) { ]; }, [remoteProvider, user, ydoc]); + React.useEffect(() => { + if (isLocalSynced && isRemoteSynced) { + onSynced?.(); + } + }, [onSynced, isLocalSynced, isRemoteSynced]); + // Disconnect the realtime connection while idle. `isIdle` also checks for // page visibility and will immediately disconnect when a tab is hidden. React.useEffect(() => { @@ -180,6 +202,7 @@ function MultiplayerEditor({ ...props }: Props, ref: any) { extensions={extensions} ref={showCache ? undefined : ref} style={showCache ? { display: "none" } : undefined} + className={showCursorNames ? "show-cursor-names" : undefined} /> ); diff --git a/app/scenes/Document/components/ShareButton.js b/app/scenes/Document/components/ShareButton.js index af7d1606e3..c61556679b 100644 --- a/app/scenes/Document/components/ShareButton.js +++ b/app/scenes/Document/components/ShareButton.js @@ -60,7 +60,7 @@ function ShareButton({ document }: Props) { document={document} share={share} sharedParent={sharedParent} - onSubmit={popover.hide} + onRequestClose={popover.hide} visible={popover.visible} /> diff --git a/app/scenes/Document/components/SharePopover.js b/app/scenes/Document/components/SharePopover.js index 10c9d544a5..c6070b8fc0 100644 --- a/app/scenes/Document/components/SharePopover.js +++ b/app/scenes/Document/components/SharePopover.js @@ -15,6 +15,7 @@ import HelpText from "components/HelpText"; import Input from "components/Input"; import Notice from "components/Notice"; import Switch from "components/Switch"; +import useKeyDown from "hooks/useKeyDown"; import useStores from "hooks/useStores"; import useToasts from "hooks/useToasts"; @@ -22,7 +23,7 @@ type Props = {| document: Document, share: Share, sharedParent: ?Share, - onSubmit: () => void, + onRequestClose: () => void, visible: boolean, |}; @@ -30,7 +31,7 @@ function SharePopover({ document, share, sharedParent, - onSubmit, + onRequestClose, visible, }: Props) { const { t } = useTranslation(); @@ -38,6 +39,7 @@ function SharePopover({ const { showToast } = useToasts(); const [isCopied, setIsCopied] = React.useState(false); const timeout = React.useRef(); + const buttonRef = React.useRef(); const can = policies.abilities(share ? share.id : ""); const documentAbilities = policies.abilities(document.id); const canPublish = @@ -47,8 +49,13 @@ function SharePopover({ documentAbilities.share; const isPubliclyShared = (share && share.published) || sharedParent; + useKeyDown("Escape", onRequestClose); + React.useEffect(() => { - if (visible) document.share(); + if (visible) { + document.share(); + buttonRef.current?.focus(); + } return () => clearTimeout(timeout.current); }, [document, visible]); @@ -87,11 +94,11 @@ function SharePopover({ timeout.current = setTimeout(() => { setIsCopied(false); - onSubmit(); + onRequestClose(); showToast(t("Share link copied"), { type: "info" }); }, 250); - }, [t, onSubmit, showToast]); + }, [t, onRequestClose, showToast]); return ( <> @@ -176,7 +183,12 @@ function SharePopover({ readOnly /> - diff --git a/app/scenes/KeyboardShortcuts.js b/app/scenes/KeyboardShortcuts.js index 5fa1c58983..ded6ee724e 100644 --- a/app/scenes/KeyboardShortcuts.js +++ b/app/scenes/KeyboardShortcuts.js @@ -21,6 +21,7 @@ function KeyboardShortcuts() { }, { shortcut: e, label: t("Edit current document") }, { shortcut: m, label: t("Move current document") }, + { shortcut: h, label: t("Open document history") }, { shortcut: ( <> diff --git a/package.json b/package.json index 49de4bdc7c..2f473c32b5 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "build:webpack": "webpack --config webpack.config.prod.js", "build": "yarn clean && yarn build:webpack && yarn build:i18n && yarn build:server", "start": "node ./build/server/index.js", - "dev": "yarn concurrently -n api,collaboration -c \"blue,magenta\" \"node --inspect=0.0.0.0 build/server/index.js --services=collaboration,websockets,admin,web,worker\"", + "dev": "NODE_ENV=development yarn concurrently -n api,collaboration -c \"blue,magenta\" \"node --inspect=0.0.0.0 build/server/index.js --services=collaboration,websockets,admin,web,worker\"", "dev:watch": "nodemon --exec \"yarn build:server && yarn build:i18n && yarn dev\" -e js --ignore build/ --ignore app/ --ignore flow-typed/", "lint": "eslint app server shared", "deploy": "git push heroku master", @@ -48,8 +48,8 @@ "@babel/preset-react": "^7.10.4", "@bull-board/api": "^3.5.0", "@bull-board/koa": "^3.5.0", - "@hocuspocus/provider": "^1.0.0-alpha.20", - "@hocuspocus/server": "^1.0.0-alpha.74", + "@hocuspocus/provider": "^1.0.0-alpha.21", + "@hocuspocus/server": "^1.0.0-alpha.77", "@outlinewiki/koa-passport": "^4.1.4", "@outlinewiki/passport-azure-ad-oauth2": "^0.1.0", "@renderlesskit/react": "^0.6.0", @@ -97,7 +97,7 @@ "js-search": "^1.4.2", "json-loader": "0.5.4", "jsonwebtoken": "^8.5.0", - "jszip": "^3.5.0", + "jszip": "^3.7.0", "kbar": "^0.1.0-beta.16", "koa": "^2.10.0", "koa-body": "^4.2.0", @@ -122,7 +122,7 @@ "oy-vey": "^0.10.0", "passport": "^0.4.1", "passport-google-oauth2": "^0.2.0", - "passport-oauth2": "^1.6.0", + "passport-oauth2": "^1.6.1", "passport-slack-oauth2": "^1.1.0", "pg": "^8.5.1", "pg-hstore": "^2.3.3", @@ -150,7 +150,7 @@ "react-window": "^1.8.6", "reakit": "^1.3.10", "regenerator-runtime": "^0.13.7", - "rich-markdown-editor": "^11.19.0", + "rich-markdown-editor": "^11.19.2", "semver": "^7.3.2", "sequelize": "^6.3.4", "sequelize-cli": "^6.2.0", diff --git a/server/collaboration/logger.js b/server/collaboration/logger.js index b5a96d22c6..bad3ec7685 100644 --- a/server/collaboration/logger.js +++ b/server/collaboration/logger.js @@ -3,11 +3,11 @@ import Logger from "../logging/logger"; import { User } from "../models"; export default class CollaborationLogger { - async onCreateDocument(data: { + async onLoadDocument(data: { documentName: string, context: { user: User }, }) { - Logger.info("hocuspocus", `Created document "${data.documentName}"`, { + Logger.info("hocuspocus", `Loaded document "${data.documentName}"`, { userId: data.context.user.id, }); } diff --git a/server/collaboration/persistence.js b/server/collaboration/persistence.js index fab8cb25cb..016f0db67f 100644 --- a/server/collaboration/persistence.js +++ b/server/collaboration/persistence.js @@ -9,7 +9,7 @@ import markdownToYDoc from "./utils/markdownToYDoc"; const DELAY = 3000; export default class Persistence { - async onCreateDocument({ + async onLoadDocument({ documentName, ...data }: { @@ -52,7 +52,7 @@ export default class Persistence { documentName, }: { document: Y.Doc, - context: { user: User }, + context: { user: ?User }, documentName: string, }) => { const [, documentId] = documentName.split("."); @@ -63,7 +63,7 @@ export default class Persistence { await documentUpdater({ documentId, ydoc: document, - userId: context.user.id, + userId: context.user?.id, }); } catch (err) { Logger.error("Unable to persist document", err, { diff --git a/server/collaboration/tracing.js b/server/collaboration/tracing.js index f6ce2eb235..fc856f0df4 100644 --- a/server/collaboration/tracing.js +++ b/server/collaboration/tracing.js @@ -2,14 +2,14 @@ import Metrics from "../logging/metrics"; export default class Tracing { - onCreateDocument({ + onLoadDocument({ documentName, instance, }: { documentName: string, instance: any, }) { - Metrics.increment("collaboration.create_document", { documentName }); + Metrics.increment("collaboration.load_document", { documentName }); Metrics.gaugePerInstance( "collaboration.documents_count", diff --git a/server/commands/documentUpdater.js b/server/commands/documentUpdater.js index 72de0acc1c..d9a845b26c 100644 --- a/server/commands/documentUpdater.js +++ b/server/commands/documentUpdater.js @@ -13,7 +13,7 @@ export default async function documentUpdater({ }: { documentId: string, ydoc: Y.Doc, - userId: string, + userId?: string, }) { const document = await Document.findByPk(documentId); const state = Y.encodeStateAsUpdate(ydoc); @@ -38,7 +38,8 @@ export default async function documentUpdater({ text, state: Buffer.from(state), updatedAt: isUnchanged ? document.updatedAt : new Date(), - lastModifiedById: isUnchanged ? document.lastModifiedById : userId, + lastModifiedById: + isUnchanged || !userId ? document.lastModifiedById : userId, collaboratorIds, }, { diff --git a/server/commands/teamPermanentDeleter.js b/server/commands/teamPermanentDeleter.js index 24d8d95449..998390882c 100644 --- a/server/commands/teamPermanentDeleter.js +++ b/server/commands/teamPermanentDeleter.js @@ -14,6 +14,7 @@ import { User, UserAuthentication, Integration, + IntegrationAuthentication, SearchQuery, Share, } from "../models"; @@ -130,6 +131,12 @@ export default async function teamPermanentDeleter(team: Team) { transaction, }); + await IntegrationAuthentication.destroy({ + where: { teamId }, + force: true, + transaction, + }); + await NotificationSetting.destroy({ where: { teamId }, force: true, diff --git a/server/index.js b/server/index.js index 8e7e0ce257..6ad638f430 100644 --- a/server/index.js +++ b/server/index.js @@ -26,7 +26,11 @@ const normalizedServiceFlag = getArg("services"); // The default is to run all services to make development and OSS installations // easier to deal with. Separate services are only needed at scale. const serviceNames = uniq( - (normalizedServiceFlag || env.SERVICES || "websockets,worker,web") + ( + normalizedServiceFlag || + env.SERVICES || + "collaboration,websockets,worker,web" + ) .split(",") .map((service) => service.trim()) ); diff --git a/server/migrations/20211107021900-missing-cascades.js b/server/migrations/20211107021900-missing-cascades.js new file mode 100644 index 0000000000..bdfe9d7b84 --- /dev/null +++ b/server/migrations/20211107021900-missing-cascades.js @@ -0,0 +1,51 @@ +module.exports = { + up: async (queryInterface, Sequelize) => { + let tableName, constraintName; + + tableName = "collection_groups"; + constraintName = "collection_groups_collectionId_fkey"; + await queryInterface.sequelize.query( + `alter table "${tableName}" drop constraint "${constraintName}"` + ); + await queryInterface.sequelize.query( + `alter table "${tableName}" + add constraint "${constraintName}" foreign key("collectionId") references "collections" ("id") + on delete cascade` + ); + + constraintName = "collection_groups_groupId_fkey"; + await queryInterface.sequelize.query( + `alter table "${tableName}" drop constraint "${constraintName}"` + ); + await queryInterface.sequelize.query( + `alter table "${tableName}" + add constraint "${constraintName}" foreign key("groupId") references "groups" ("id") + on delete cascade` + ); + }, + + down: async (queryInterface, Sequelize) => { + let tableName, constraintName; + + tableName = "collection_groups"; + constraintName = "collection_groups_collectionId_fkey"; + await queryInterface.sequelize.query( + `alter table "${tableName}" drop constraint "${constraintName}"` + ); + await queryInterface.sequelize.query( + `alter table "${tableName}" + add constraint "${constraintName}" foreign key("collectionId") references "collections" ("id") + on delete no action` + ); + + constraintName = "collection_groups_groupId_fkey"; + await queryInterface.sequelize.query( + `alter table "${tableName}" drop constraint "${constraintName}"` + ); + await queryInterface.sequelize.query( + `alter table "${tableName}" + add constraint "${constraintName}" foreign key("groupId") references "groups" ("id") + on delete no action` + ); + }, +}; diff --git a/server/policies/share.js b/server/policies/share.js index b5db8b459b..944d497242 100644 --- a/server/policies/share.js +++ b/server/policies/share.js @@ -12,7 +12,7 @@ allow(User, "read", Share, (user, share) => { allow(User, "update", Share, (user, share) => { if (user.isViewer) return false; - // only the user who can share the document publicaly can update the share. + // only the user who can share the document publicly can update the share. if (cannot(user, "share", share.document)) return false; return user.teamId === share.teamId; }); diff --git a/server/routes/api/shares.js b/server/routes/api/shares.js index 2ec30771d9..3600e31988 100644 --- a/server/routes/api/shares.js +++ b/server/routes/api/shares.js @@ -62,7 +62,9 @@ router.post("shares.info", auth(), async (ctx) => { const parentIds = document?.collection?.getDocumentParents(documentId); const parentShare = parentIds - ? await Share.findOne({ + ? await Share.scope({ + method: ["withCollection", user.id], + }).findOne({ where: { documentId: parentIds, teamId: user.teamId, diff --git a/server/routes/api/shares.test.js b/server/routes/api/shares.test.js index aedfc3fdb8..3e23f2f313 100644 --- a/server/routes/api/shares.test.js +++ b/server/routes/api/shares.test.js @@ -424,6 +424,8 @@ describe("#shares.info", () => { expect(body.data.shares[0].documentId).toBe(document.id); expect(body.data.shares[0].published).toBe(true); expect(body.data.shares[0].includeChildDocuments).toBe(true); + expect(body.policies.length).toBe(1); + expect(body.policies[0].abilities.update).toBe(true); }); it("should not return share for parent document with includeChildDocuments=false", async () => { diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index 06a14f0c68..5994b7e574 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -449,6 +449,7 @@ "Send Invites": "Send Invites", "Edit current document": "Edit current document", "Move current document": "Move current document", + "Open document history": "Open document history", "Jump to search": "Jump to search", "Jump to home": "Jump to home", "Toggle navigation": "Toggle navigation", diff --git a/yarn.lock b/yarn.lock index 4db023c829..dc0c7222fe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1229,28 +1229,28 @@ dependencies: "@hapi/hoek" "^8.3.0" -"@hocuspocus/provider@^1.0.0-alpha.20": - version "1.0.0-alpha.20" - resolved "https://registry.yarnpkg.com/@hocuspocus/provider/-/provider-1.0.0-alpha.20.tgz#2be84b2279c5087bc1f17e94bbc648a5c6ba4b16" - integrity sha512-eaq3MrTrS6dpzBX7PX2qlts2zxR3tPM6ji3goga9frkOSAroMQ91ADap1RUpfFFKQYt1Q03F0WdVA5FV/BUuOA== +"@hocuspocus/provider@^1.0.0-alpha.21": + version "1.0.0-alpha.21" + resolved "https://registry.yarnpkg.com/@hocuspocus/provider/-/provider-1.0.0-alpha.21.tgz#369869e33a7c138041a03bbb80acd61dd77e3632" + integrity sha512-24brZ0OIeUInbMBTN2weL06Xmt4KUn3Sj7BbNkxgt7QwHjIqpcqlZrHE8IYg46HTbp8k0KKnc1CCMxb1ui0fRA== dependencies: "@lifeomic/attempt" "^3.0.0" lib0 "^0.2.42" y-protocols "^1.0.5" - yjs "^13.5.8" + yjs "^13.5.0" -"@hocuspocus/server@^1.0.0-alpha.74": - version "1.0.0-alpha.74" - resolved "https://registry.yarnpkg.com/@hocuspocus/server/-/server-1.0.0-alpha.74.tgz#d02693659f88a17b2a8c5ce3643e50b8a8213bb2" - integrity sha512-EvvyA4+WyYHZ3+HSNeeCugKC6mbX4Q7LHRBzYziricF3Hpbk/tWRUc+zrU2aXbpSQ9xwpVgUB+LP2r/muhvGag== +"@hocuspocus/server@^1.0.0-alpha.77": + version "1.0.0-alpha.77" + resolved "https://registry.yarnpkg.com/@hocuspocus/server/-/server-1.0.0-alpha.77.tgz#0f50b901d15eca6089189c22fdba0f5defc74c25" + integrity sha512-b0TThM3vsjQakV3fdEXD3TgNt8LAodbCnjzg3kln6NMHarbQX49ZBuhlD7Q1h7AjoMaSf3HpVp0GyYscZw63cA== dependencies: "@types/async-lock" "^1.1.2" "@types/uuid" "^8.3.0" - "@types/ws" "^7.4.0" + "@types/ws" "^8.2.0" async-lock "^1.2.8" lib0 "^0.2.41" uuid "^8.3.2" - ws "^7.4.3" + ws "^8.2.3" yjs "^13.5.0" "@icons/material@^0.2.4": @@ -2919,10 +2919,10 @@ resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.1.tgz#1a32969cf8f0364b3d8c8af9cc3555b7805df14f" integrity sha512-Y2mHTRAbqfFkpjldbkHGY8JIzRN6XqYRliG8/24FcHm2D2PwW24fl5xMRTVGdrb7iMrwCaIEbLWerGIkXuFWVg== -"@types/ws@^7.4.0": - version "7.4.7" - resolved "https://registry.yarnpkg.com/@types/ws/-/ws-7.4.7.tgz#f7c390a36f7a0679aa69de2d501319f4f8d9b702" - integrity sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww== +"@types/ws@^8.2.0": + version "8.2.0" + resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.2.0.tgz#75faefbe2328f3b833cb8dc640658328990d04f3" + integrity sha512-cyeefcUCgJlEk+hk2h3N+MqKKsPViQgF5boi9TTHSK+PoR9KWBb/C5ccPcDyAqgsbAYHTwulch725DV84+pSpg== dependencies: "@types/node" "*" @@ -9166,10 +9166,10 @@ jsprim@^1.2.2: array-includes "^3.1.1" object.assign "^4.1.1" -jszip@^3.5.0: - version "3.5.0" - resolved "https://registry.yarnpkg.com/jszip/-/jszip-3.5.0.tgz#b4fd1f368245346658e781fec9675802489e15f6" - integrity sha512-WRtu7TPCmYePR1nazfrtuF216cIVon/3GWOvHS9QR5bIwSbnxtdpma6un3jyGGNhHsKCSzn5Ypk+EkDRvTGiFA== +jszip@^3.7.0: + version "3.7.0" + resolved "https://registry.yarnpkg.com/jszip/-/jszip-3.7.0.tgz#9b8b995a4e7c9024653ce743e902076a82fdf4e6" + integrity sha512-Y2OlFIzrDOPWUnpU0LORIcDn2xN7rC9yKffFM/7pGhQuhO+SUhfm2trkJ/S5amjFvem0Y+1EALz/MEPkvHXVNw== dependencies: lie "~3.3.0" pako "~1.0.2" @@ -10325,9 +10325,9 @@ minipass-pipeline@^1.2.2: minipass "^3.0.0" minipass@^3.0.0, minipass@^3.1.1: - version "3.1.3" - resolved "https://registry.yarnpkg.com/minipass/-/minipass-3.1.3.tgz#7d42ff1f39635482e15f9cdb53184deebd5815fd" - integrity sha512-Mgd2GdMVzY+x3IJ+oHnVM+KG3lA5c8tnabyJKmHSaG2kAGpudxuOf8ToDkhumF7UzME7DecbQE9uOZhNm7PuJg== + version "3.1.5" + resolved "https://registry.yarnpkg.com/minipass/-/minipass-3.1.5.tgz#71f6251b0a33a49c01b3cf97ff77eda030dff732" + integrity sha512-+8NzxD82XQoNKNrl1d/FSi+X8wAEWR+sbYAfIvub4Nz0d22plFG72CEVVaufV8PNf4qSslFTD8VMOxNVhHCjTw== dependencies: yallist "^4.0.0" @@ -10679,9 +10679,9 @@ normalize-path@^3.0.0, normalize-path@~3.0.0: integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA== normalize-url@^4.1.0: - version "4.5.0" - resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-4.5.0.tgz#453354087e6ca96957bd8f5baf753f5982142129" - integrity sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ== + version "4.5.1" + resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-4.5.1.tgz#0dd90cf1288ee1d1313b87081c9a5932ee48518a" + integrity sha512-9UZCFRHQdNrfTpGg8+1INIg93B6zE0aXMVFkw1WFwvO4SlZywU6aLg5Of0Ap/PgcbSw4LNxvMWXMeugwMCX0AA== notepack.io@~2.2.0: version "2.2.0" @@ -11222,10 +11222,10 @@ passport-oauth1@1.x.x: passport-strategy "1.x.x" utils-merge "1.x.x" -passport-oauth2@1.x.x, passport-oauth2@^1.1.2, passport-oauth2@^1.5.0, passport-oauth2@^1.6.0: - version "1.6.0" - resolved "https://registry.yarnpkg.com/passport-oauth2/-/passport-oauth2-1.6.0.tgz#5f599735e0ea40ea3027643785f81a3a9b4feb50" - integrity sha512-emXPLqLcVEcLFR/QvQXZcwLmfK8e9CqvMgmOFJxcNT3okSFMtUbRRKpY20x5euD+01uHsjjCa07DYboEeLXYiw== +passport-oauth2@1.x.x, passport-oauth2@^1.1.2, passport-oauth2@^1.5.0, passport-oauth2@^1.6.1: + version "1.6.1" + resolved "https://registry.yarnpkg.com/passport-oauth2/-/passport-oauth2-1.6.1.tgz#c5aee8f849ce8bd436c7f81d904a3cd1666f181b" + integrity sha512-ZbV43Hq9d/SBSYQ22GOiglFsjsD1YY/qdiptA+8ej+9C1dL1TVB+mBE5kDH/D4AJo50+2i8f4bx0vg4/yDDZCQ== dependencies: base64url "3.x.x" oauth "0.9.x" @@ -12755,10 +12755,10 @@ retry-as-promised@^3.2.0: dependencies: any-promise "^1.3.0" -rich-markdown-editor@^11.19.0: - version "11.19.0" - resolved "https://registry.yarnpkg.com/rich-markdown-editor/-/rich-markdown-editor-11.19.0.tgz#ef8b87db8f8adb5a36878e99cc770c815cb84525" - integrity sha512-F7vIv8nOWJBuZWMZWYEsgvG3jlRk6sFmoROOAY8Gmd6vXIosLCxpgRp3AeSBrVKb/9zNatkTyYbdDeKcTivALg== +rich-markdown-editor@^11.19.2: + version "11.19.2" + resolved "https://registry.yarnpkg.com/rich-markdown-editor/-/rich-markdown-editor-11.19.2.tgz#b1931822a4c102064174cacd7ecdc1d8041503d3" + integrity sha512-bV1oAjfIeJh2mlajsRcQV4479Hd7yN/covs6HKY3KDyM8+06+UI8B5XSC7mmlXalFPz7fApT0sEapEHA380ooA== dependencies: copy-to-clipboard "^3.0.8" fuzzy-search "^3.2.1" @@ -13977,9 +13977,9 @@ tapable@^2.0.0: integrity sha512-FBk4IesMV1rBxX2tfiK8RAmogtWn53puLOQlvO8XuwlgxcYbP4mVPS9Ph4aeamSyyVjOl24aYWAuc8U5kCVwMw== tar@^6.0.2: - version "6.0.5" - resolved "https://registry.yarnpkg.com/tar/-/tar-6.0.5.tgz#bde815086e10b39f1dcd298e89d596e1535e200f" - integrity sha512-0b4HOimQHj9nXNEAA7zWwMM91Zhhba3pspja6sQbgTpynOJf+bkjBnfybNYzbpLbnwXnbyB4LOREvlyXLkCHSg== + version "6.1.11" + resolved "https://registry.yarnpkg.com/tar/-/tar-6.1.11.tgz#6760a38f003afa1b2ffd0ffe9e9abbd0eab3d621" + integrity sha512-an/KZQzQUkZCkuoAA64hM92X0Urb6VpRhAFllDzz44U2mcD5scmT3zBc4VgVpkugF580+DQn8eAFSyoQt0tznA== dependencies: chownr "^2.0.0" fs-minipass "^2.0.0" @@ -14751,9 +14751,9 @@ url-parse-lax@^1.0.0: prepend-http "^1.0.1" url-parse@^1.4.3: - version "1.4.7" - resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.4.7.tgz#a8a83535e8c00a316e403a5db4ac1b9b853ae278" - integrity sha512-d3uaVyzDB9tQoSXFvuSUNFibTd9zxd2bkVrDRvF5TmvWWQwqE4lgYJ5m+x1DbecWkw+LK4RNl2CU1hHuOKPVlg== + version "1.5.3" + resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.3.tgz#71c1303d38fb6639ade183c2992c8cc0686df862" + integrity sha512-IIORyIQD9rvj0A4CLWsHkBBJuNqWpFQe224b6j9t/ABmquIS0qDU2pY6kl6AuOrL5OkCXHMCFNe1jBcuAggjvQ== dependencies: querystringify "^2.1.1" requires-port "^1.0.0" @@ -15516,11 +15516,16 @@ write@1.0.3: dependencies: mkdirp "^0.5.1" -ws@^7.2.3, ws@^7.4.3, ws@^7.5.3: +ws@^7.2.3, ws@^7.5.3: version "7.5.5" resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.5.tgz#8b4bc4af518cfabd0473ae4f99144287b33eb881" integrity sha512-BAkMFcAzl8as1G/hArkxOxq3G7pjUqQ3gzYbLL0/5zNkph70e+lCoxBGnm6AW1+/aiNeV4fnKqZ8m4GZewmH2w== +ws@^8.2.3: + version "8.2.3" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.2.3.tgz#63a56456db1b04367d0b721a0b80cae6d8becbba" + integrity sha512-wBuoj1BDpC6ZQ1B7DWQBYVLphPWkm8i9Y0/3YdHjHKHiohOJ1ws+3OccDWtH+PoC9DZD5WOTrJvNbWvjS6JWaA== + ws@~7.4.2: version "7.4.6" resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.6.tgz#5654ca8ecdeee47c33a9a4bf6d28e2be2980377c" @@ -15734,7 +15739,7 @@ yeast@0.1.2: resolved "https://registry.yarnpkg.com/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419" integrity sha1-AI4G2AlDIMNy28L47XagymyKxBk= -yjs@^13.5.0, yjs@^13.5.12, yjs@^13.5.8: +yjs@^13.5.0, yjs@^13.5.12: version "13.5.12" resolved "https://registry.yarnpkg.com/yjs/-/yjs-13.5.12.tgz#7a0cf3119fb368c07243825e989a55de164b3f9c" integrity sha512-/buy1kh8Ls+t733Lgov9hiNxCsjHSCymTuZNahj2hsPNoGbvnSdDmCz9Z4F19Yr1eUAAXQLJF3q7fiBcvPC6Qg==