Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Permission check on parent Notes in Views #427

Merged
merged 1 commit into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/strong-falcons-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'mexit-webapp': patch
---

Permission checks on parent notes
20 changes: 17 additions & 3 deletions apps/webapp/src/Components/Views/ViewRenderer/KanbanView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ const KanbanView: React.FC<any> = (props) => {
return getBlocksBoard(props.results)
}, [props.results])

const checkIsNoteReadOnly = (noteId: string) => {
return isReadonly(accessWhenShared(noteId))
}

const handleBlockEvents = (block: SearchResult, field: string, move: { fromColumnId: any; toColumnId: any }) => {
if (!block || !field || move.toColumnId === 'Ungrouped') return

Expand Down Expand Up @@ -109,6 +113,13 @@ const KanbanView: React.FC<any> = (props) => {
break

case 'parent':
const hasPermission = !checkIsNoteReadOnly(move.toColumnId)

if (!hasPermission) {
toast('You do not have permission to move this block')
return
}

const updated = moveBlockFromNode(move.fromColumnId, move.toColumnId, blockContent)
if (updated) {
const moveBlockRequest: MoveBlocksType = {
Expand Down Expand Up @@ -153,7 +164,8 @@ const KanbanView: React.FC<any> = (props) => {
})
break
case 'parent':
if (todo.content) {
const hasPermission = !checkIsNoteReadOnly(move.toColumnId)
if (todo.content && hasPermission) {
const updatedBlock = todo.content?.at(0)
if (updatedBlock) {
const updated = moveBlockFromNode(move.fromColumnId, move.toColumnId, updatedBlock)
Expand All @@ -168,16 +180,18 @@ const KanbanView: React.FC<any> = (props) => {
moveBlocksInIndex(moveBlockRequest)
}
}
} else {
toast('You do not have permission to move this block')
}
}
}
}

const handleCardMove = (card, { fromColumnId }, { toColumnId }) => {
const hasOnlyReadPermission = isReadonly(accessWhenShared(card.parent))
const hasOnlyReadPermission = checkIsNoteReadOnly(card.parent)

if (hasOnlyReadPermission) {
toast('Cannot move task in a note with Read only permission')
toast('You do not have permission to move this block')
return
}

Expand Down