Skip to content

Commit

Permalink
fix(comments): drop permission check (#6110)
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanwikner committed Mar 21, 2024
1 parent eca9c30 commit d6a3891
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 35 deletions.
Expand Up @@ -92,7 +92,6 @@ function CommentFieldInner(

const {
comments,
hasPermission,
isCommentsOpen,
isCreatingDataset,
mentionOptions,
Expand Down Expand Up @@ -317,11 +316,6 @@ function CommentFieldInner(
],
)

// Render the default field component if the user doesn't have permission
if (!hasPermission) {
return props.renderDefault(props)
}

return (
<FieldStack {...applyCommentsFieldAttr(PathUtils.toString(props.path))} ref={rootRef}>
{props.renderDefault({
Expand Down
Expand Up @@ -63,16 +63,8 @@ export const CommentsPortableTextInputInner = React.memo(function CommentsPortab
const currentUser = useCurrentUser()
const portal = usePortal()

const {
comments,
getComment,
hasPermission,
mentionOptions,
onCommentsOpen,
operation,
setStatus,
status,
} = useComments()
const {comments, getComment, mentionOptions, onCommentsOpen, operation, setStatus, status} =
useComments()
const {setSelectedPath, selectedPath} = useCommentsSelectedPath()
const {scrollToComment, scrollToGroup} = useCommentsScroll()
const {handleOpenDialog} = useCommentsUpsell()
Expand Down Expand Up @@ -510,11 +502,6 @@ export const CommentsPortableTextInputInner = React.memo(function CommentsPortab
)
const showFloatingInput = Boolean(nextCommentSelection && popoverAuthoringReferenceElement)

// Render the default input if the user doesn't have permission
if (!hasPermission) {
return props.renderDefault(props)
}

return (
<>
<BoundaryElementProvider element={boundaryElement}>
Expand Down
Expand Up @@ -4,7 +4,6 @@ import {
getPublishedId,
useAddonDataset,
useCurrentUser,
useDocumentValuePermissions,
useEditState,
useSchema,
useUserListWithPermissions,
Expand Down Expand Up @@ -83,14 +82,6 @@ export const CommentsProvider = memo(function CommentsProvider(props: CommentsPr
// A map to keep track of the latest transaction ID for each comment document.
const transactionsIdMap = useMemo(() => new Map<DocumentId, TransactionId>(), [])

// We only need to check for read permission on the document since users with
// read permission on the document can both read and write comments.
// This is how permission work for the comments add-on dataset.
const [readPermission] = useDocumentValuePermissions({
document: documentValue || {_type: documentType, _id: publishedId},
permission: 'read',
})

// When the latest transaction ID is received, we remove the transaction id from the map.
const handleOnLatestTransactionIdReceived = useCallback(
(commentDocumentId: string) => {
Expand Down Expand Up @@ -276,8 +267,6 @@ export const CommentsProvider = memo(function CommentsProvider(props: CommentsPr
isCommentsOpen,
onCommentsOpen,

hasPermission: Boolean(readPermission?.granted),

comments: {
data: threadItemsByStatus,
error,
Expand All @@ -299,7 +288,6 @@ export const CommentsProvider = memo(function CommentsProvider(props: CommentsPr
getComment,
isCommentsOpen,
onCommentsOpen,
readPermission?.granted,
threadItemsByStatus,
error,
loading,
Expand Down
Expand Up @@ -19,8 +19,6 @@ export interface CommentsContextValue {
isCommentsOpen?: boolean
onCommentsOpen?: () => void

hasPermission: boolean

comments: {
data: {
open: CommentThreadItem[]
Expand Down

0 comments on commit d6a3891

Please sign in to comment.