page-utils.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import type { IPage } from '..';
  2. import { isTopPage } from './page-path-utils/is-top-page';
  3. // const GRANT_PUBLIC = 1;
  4. const GRANT_RESTRICTED = 2;
  5. const GRANT_SPECIFIED = 3; // DEPRECATED
  6. // const GRANT_OWNER = 4;
  7. // const GRANT_USER_GROUP = 5;
  8. // const PAGE_GRANT_ERROR = 1;
  9. // const STATUS_PUBLISHED = 'published';
  10. const STATUS_DELETED = 'deleted';
  11. /**
  12. * Returns true if the page is on tree including the top page.
  13. * @param page Page
  14. * @returns boolean
  15. */
  16. export const isOnTree = (page: IPage): boolean => {
  17. const { path, parent } = page;
  18. if (isTopPage(path)) {
  19. return true;
  20. }
  21. if (parent != null) {
  22. return true;
  23. }
  24. return false;
  25. };
  26. /**
  27. * Returns true if the page meet the condition below.
  28. * - The page is on tree (has parent or the top page)
  29. * - The page's grant is GRANT_RESTRICTED or GRANT_SPECIFIED
  30. * - The page's status is STATUS_DELETED
  31. * This does not check grantedUser or grantedGroup.
  32. * @param page PageDocument
  33. * @returns boolean
  34. */
  35. export const isPageNormalized = (page: IPage): boolean => {
  36. const { grant, status } = page;
  37. if (grant === GRANT_RESTRICTED || grant === GRANT_SPECIFIED) {
  38. return true;
  39. }
  40. if (status === STATUS_DELETED) {
  41. return true;
  42. }
  43. if (isOnTree(page)) {
  44. return true;
  45. }
  46. return true;
  47. };