Skip to content

Commit

Permalink
filter hidden blocks and properties if you do not have edit access to…
Browse files Browse the repository at this point in the history
… a proposal source board (#4876)

* update to subtree logic

* remove gray coloring
  • Loading branch information
mattcasey authored Oct 23, 2024
1 parent 13473f4 commit 46267ef
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions components/common/Icons/VisibilityIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export function VisibilityIcon({
}

const icon = visible ? (
<MuiVisibilityIcon color='gray' fontSize={size} onClick={handleClick} />
<MuiVisibilityIcon fontSize={size} onClick={handleClick} />
) : (
<VisibilityOffIcon color='gray' fontSize={size} onClick={handleClick} />
<VisibilityOffIcon fontSize={size} onClick={handleClick} />
);

const tooltip = visible ? visibleTooltip : hiddenTooltip;
Expand Down
6 changes: 2 additions & 4 deletions lib/databases/getSubtree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { permissionsApiClient } from 'lib/permissions/api/client';
import { DataNotFoundError } from 'lib/utils/errors';
import { isTruthy } from 'lib/utils/types';

export async function getSubtree({ pageId, userId }: { pageId: string; userId: string }) {
export async function getSubtree({ pageId, userId }: { pageId: string; userId?: string }) {
const page = await prisma.page.findFirstOrThrow({
where: {
id: pageId
Expand Down Expand Up @@ -44,13 +44,12 @@ export async function getSubtree({ pageId, userId }: { pageId: string; userId: s
if (block?.type === 'board') {
(block as any as Board).isLocked = !!page.isLocked;
}

// Hydrate and filter blocks based on proposal permissions
if (block && (block.fields as BoardFields).sourceType === 'proposals') {
let result = await getBlocksAndRefresh(block, blocks);

// Only edit
if (page.isLocked && block?.type === 'board' && !computed.edit_lock && block) {
if (((page.isLocked && !computed.edit_lock) || !computed.edit_content) && block?.type === 'board' && block) {
const views = result.filter((b) => b.type === 'view');
const cards = result.filter((b) => b.type === 'card');
const filteredCards = filterLockedDatabaseCards({
Expand Down Expand Up @@ -120,7 +119,6 @@ export async function getSubtree({ pageId, userId }: { pageId: string; userId: s
let filtered = blocks.filter(
(b) => !proposalBlocksMap[b.id] && (typeof b.pageId === 'undefined' || !!permissionsById[b.pageId]?.read)
);

const cardsWithProposalProps = [...filtered, ...refreshedBlocks];

// Only edit
Expand Down

0 comments on commit 46267ef

Please sign in to comment.