fix: Remove old policies from frontend when collection sharing permission changes
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { trim } from "lodash";
|
import { trim } from "lodash";
|
||||||
import { action, computed, observable, runInAction } from "mobx";
|
import { action, computed, observable, reaction, runInAction } from "mobx";
|
||||||
import {
|
import {
|
||||||
CollectionPermission,
|
CollectionPermission,
|
||||||
FileOperationFormat,
|
FileOperationFormat,
|
||||||
@@ -66,6 +66,21 @@ export default class Collection extends ParanoidModel {
|
|||||||
|
|
||||||
urlId: string;
|
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
|
@computed
|
||||||
get isEmpty(): boolean | undefined {
|
get isEmpty(): boolean | undefined {
|
||||||
if (!this.documents) {
|
if (!this.documents) {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ function SharePopover({
|
|||||||
}: Props) {
|
}: Props) {
|
||||||
const team = useCurrentTeam();
|
const team = useCurrentTeam();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { shares } = useStores();
|
const { shares, collections } = useStores();
|
||||||
const { showToast } = useToasts();
|
const { showToast } = useToasts();
|
||||||
const [expandedOptions, setExpandedOptions] = React.useState(false);
|
const [expandedOptions, setExpandedOptions] = React.useState(false);
|
||||||
const [isEditMode, setIsEditMode] = React.useState(false);
|
const [isEditMode, setIsEditMode] = React.useState(false);
|
||||||
@@ -53,10 +53,14 @@ function SharePopover({
|
|||||||
const buttonRef = React.useRef<HTMLButtonElement>(null);
|
const buttonRef = React.useRef<HTMLButtonElement>(null);
|
||||||
const can = usePolicy(share ? share.id : "");
|
const can = usePolicy(share ? share.id : "");
|
||||||
const documentAbilities = usePolicy(document);
|
const documentAbilities = usePolicy(document);
|
||||||
|
const collection = document.collectionId
|
||||||
|
? collections.get(document.collectionId)
|
||||||
|
: undefined;
|
||||||
const canPublish =
|
const canPublish =
|
||||||
can.update &&
|
can.update &&
|
||||||
!document.isTemplate &&
|
!document.isTemplate &&
|
||||||
team.sharing &&
|
team.sharing &&
|
||||||
|
collection?.sharing &&
|
||||||
documentAbilities.share;
|
documentAbilities.share;
|
||||||
const isPubliclyShared =
|
const isPubliclyShared =
|
||||||
team.sharing &&
|
team.sharing &&
|
||||||
|
|||||||
Reference in New Issue
Block a user