Merge branch 'fix/home-new-note-visibility' into develop
fix(home): make the "New note" button visible (role-based writability)
This commit is contained in:
@@ -1,27 +1,22 @@
|
|||||||
import { Button, Menu, Text } from "@mantine/core";
|
import { Button, Menu, Text } from "@mantine/core";
|
||||||
import { IconPlus } from "@tabler/icons-react";
|
import { IconPlus } from "@tabler/icons-react";
|
||||||
import { createMongoAbility } from "@casl/ability";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useGetSpacesQuery } from "@/features/space/queries/space-query.ts";
|
import { useGetSpacesQuery } from "@/features/space/queries/space-query.ts";
|
||||||
import { useCreatePageMutation } from "@/features/page/queries/page-query.ts";
|
import { useCreatePageMutation } from "@/features/page/queries/page-query.ts";
|
||||||
import { buildPageUrl } from "@/features/page/page.utils.ts";
|
import { buildPageUrl } from "@/features/page/page.utils.ts";
|
||||||
import { ISpace } from "@/features/space/types/space.types.ts";
|
import { ISpace } from "@/features/space/types/space.types.ts";
|
||||||
import {
|
import { SpaceRole } from "@/lib/types.ts";
|
||||||
SpaceAbility,
|
|
||||||
SpaceCaslAction,
|
|
||||||
SpaceCaslSubject,
|
|
||||||
} from "@/features/space/permissions/permissions.type.ts";
|
|
||||||
import { CustomAvatar } from "@/components/ui/custom-avatar.tsx";
|
import { CustomAvatar } from "@/components/ui/custom-avatar.tsx";
|
||||||
import { AvatarIconType } from "@/features/attachments/types/attachment.types.ts";
|
import { AvatarIconType } from "@/features/attachments/types/attachment.types.ts";
|
||||||
|
|
||||||
// A space is writable when the member's CASL rules allow managing pages —
|
// The /spaces list endpoint returns membership.role but NOT membership.permissions
|
||||||
// mirrors the create-page gate used in the space sidebar.
|
// (only /spaces/info includes CASL rules). Mirror the server space-ability mapping:
|
||||||
|
// ADMIN and WRITER can manage pages, READER is read-only. So a space is writable
|
||||||
|
// for the current user when their role is ADMIN or WRITER.
|
||||||
function canCreatePage(space: ISpace): boolean {
|
function canCreatePage(space: ISpace): boolean {
|
||||||
const ability = createMongoAbility<SpaceAbility>(
|
const role = space.membership?.role;
|
||||||
(space.membership?.permissions ?? []) as any,
|
return role === SpaceRole.ADMIN || role === SpaceRole.WRITER;
|
||||||
);
|
|
||||||
return ability.can(SpaceCaslAction.Manage, SpaceCaslSubject.Page);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prominent home-screen action to create a new note (page). Because the home
|
// Prominent home-screen action to create a new note (page). Because the home
|
||||||
|
|||||||
Reference in New Issue
Block a user