diff --git a/app/models/Collection.ts b/app/models/Collection.ts index f100a54e2..79b05631e 100644 --- a/app/models/Collection.ts +++ b/app/models/Collection.ts @@ -1,5 +1,5 @@ import { trim } from "lodash"; -import { action, computed, observable, runInAction } from "mobx"; +import { action, computed, observable, reaction, runInAction } from "mobx"; import { CollectionPermission, FileOperationFormat, @@ -66,6 +66,21 @@ export default class Collection extends ParanoidModel { urlId: string; + constructor(fields: Partial, store: CollectionsStore) { + super(fields, store); + + const resetDocumentPolicies = () => { + this.store.rootStore.documents + .inCollection(this.id) + .forEach((document) => { + this.store.rootStore.policies.remove(document.id); + }); + }; + + reaction(() => this.permission, resetDocumentPolicies); + reaction(() => this.sharing, resetDocumentPolicies); + } + @computed get isEmpty(): boolean | undefined { if (!this.documents) { diff --git a/app/scenes/Document/components/SharePopover.tsx b/app/scenes/Document/components/SharePopover.tsx index 480f12a9a..6d87dd893 100644 --- a/app/scenes/Document/components/SharePopover.tsx +++ b/app/scenes/Document/components/SharePopover.tsx @@ -43,7 +43,7 @@ function SharePopover({ }: Props) { const team = useCurrentTeam(); const { t } = useTranslation(); - const { shares } = useStores(); + const { shares, collections } = useStores(); const { showToast } = useToasts(); const [expandedOptions, setExpandedOptions] = React.useState(false); const [isEditMode, setIsEditMode] = React.useState(false); @@ -53,10 +53,14 @@ function SharePopover({ const buttonRef = React.useRef(null); const can = usePolicy(share ? share.id : ""); const documentAbilities = usePolicy(document); + const collection = document.collectionId + ? collections.get(document.collectionId) + : undefined; const canPublish = can.update && !document.isTemplate && team.sharing && + collection?.sharing && documentAbilities.share; const isPubliclyShared = team.sharing &&