59e945562d
* Add page_hierarchy table * feat(ee): page-level permissions * pagination * rename migration fixes * fix * tabs * fix theme * cleanup * sync * page permissions notification * other fixes * sharing disbled * fix column nodes * toggle error handling
27 lines
912 B
TypeScript
27 lines
912 B
TypeScript
import { useSpaceAbility } from "@/features/space/permissions/use-space-ability";
|
|
import {
|
|
SpaceCaslAction,
|
|
SpaceCaslSubject,
|
|
} from "@/features/space/permissions/permissions.type";
|
|
import { usePageRestrictionInfoQuery } from "@/ee/page-permission/queries/page-permission-query";
|
|
|
|
export function usePagePermission(pageId: string, spaceRules: any) {
|
|
const spaceAbility = useSpaceAbility(spaceRules);
|
|
const { data: restrictionInfo, isLoading } =
|
|
usePageRestrictionInfoQuery(pageId);
|
|
|
|
if (isLoading || !restrictionInfo) {
|
|
return { canEdit: false, restrictionInfo: undefined };
|
|
}
|
|
|
|
const hasRestriction =
|
|
restrictionInfo.hasDirectRestriction ||
|
|
restrictionInfo.hasInheritedRestriction;
|
|
|
|
const canEdit = hasRestriction
|
|
? (restrictionInfo.userAccess?.canEdit ?? false)
|
|
: spaceAbility.can(SpaceCaslAction.Manage, SpaceCaslSubject.Page);
|
|
|
|
return { canEdit, restrictionInfo };
|
|
}
|