Skip to content

Commit

Permalink
fix: page permission validation
Browse files Browse the repository at this point in the history
  • Loading branch information
anmolsinghbhatia committed Sep 12, 2024
1 parent fdcd9a3 commit 5ed6eb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import { PageEditInformationPopover } from "@/components/pages";
import { convertHexEmojiToDecimal } from "@/helpers/emoji.helper";
import { getPageName } from "@/helpers/page.helper";
// hooks
import { usePage, useProject } from "@/hooks/store";
import { usePage, useProject, useUser, useUserPermissions } from "@/hooks/store";
import { usePlatformOS } from "@/hooks/use-platform-os";
// plane web components
import { PageDetailsHeaderExtraActions } from "@/plane-web/components/pages";
import { EUserPermissions, EUserPermissionsLevel } from "ee/constants/user-permissions";

export interface IPagesHeaderProps {
showButton?: boolean;
Expand All @@ -32,10 +33,17 @@ export const PageDetailsHeader = observer(() => {
// store hooks
const { currentProjectDetails, loader } = useProject();
const page = usePage(pageId?.toString() ?? "");
const { name, logo_props, updatePageLogo } = page;
const { name, logo_props, updatePageLogo, owned_by } = page;
const { allowPermissions } = useUserPermissions();
const { data: currentUser } = useUser();
// use platform
const { isMobile } = usePlatformOS();

const isAdmin = allowPermissions([EUserPermissions.ADMIN], EUserPermissionsLevel.PROJECT);
const isOwner = owned_by === currentUser?.id;

const isEditable = isAdmin || isOwner;

const handlePageLogoUpdate = async (data: TLogoProps) => {
if (data) {
updatePageLogo(data)
Expand Down Expand Up @@ -144,6 +152,7 @@ export const PageDetailsHeader = observer(() => {
? EmojiIconPickerTypes.EMOJI
: EmojiIconPickerTypes.ICON
}
disabled={!isEditable}
/>
</div>
<Tooltip tooltipContent={pageTitle} position="bottom" isMobile={isMobile}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const PagesListHeader = observer(() => {
const { setTrackElement } = useEventTracker();

const canUserCreatePage = allowPermissions(
[EUserPermissions.ADMIN, EUserPermissions.MEMBER],
[EUserPermissions.ADMIN, EUserPermissions.MEMBER, EUserPermissions.GUEST],
EUserPermissionsLevel.PROJECT
);

Expand Down

0 comments on commit 5ed6eb4

Please sign in to comment.