fix: Remove old policies from frontend when collection sharing permission changes

This commit is contained in:
Tom Moor
2023-05-22 22:30:53 -04:00
parent fbd16d4b9a
commit bb0cd891bd
2 changed files with 21 additions and 2 deletions

View File

@@ -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<Collection>, 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) {

View File

@@ -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<HTMLButtonElement>(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 &&