page-utils.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { isTopPage } from './page-path-utils/is-top-page';
  2. // const GRANT_PUBLIC = 1;
  3. const GRANT_RESTRICTED = 2;
  4. const GRANT_SPECIFIED = 3; // DEPRECATED
  5. // const GRANT_OWNER = 4;
  6. // const GRANT_USER_GROUP = 5;
  7. // const PAGE_GRANT_ERROR = 1;
  8. // const STATUS_PUBLISHED = 'published';
  9. const STATUS_DELETED = 'deleted';
  10. /**
  11. * Returns true if the page is on tree including the top page.
  12. * @param page Page
  13. * @returns boolean
  14. */
  15. // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
  16. export const isOnTree = (page): 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. // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
  36. export const isPageNormalized = (page): boolean => {
  37. const { grant, status } = page;
  38. if (grant === GRANT_RESTRICTED || grant === GRANT_SPECIFIED) {
  39. return true;
  40. }
  41. if (status === STATUS_DELETED) {
  42. return true;
  43. }
  44. if (isOnTree(page)) {
  45. return true;
  46. }
  47. return true;
  48. };