4
4
getPublishedId ,
5
5
useAddonDataset ,
6
6
useCurrentUser ,
7
+ useDocumentValuePermissions ,
7
8
useEditState ,
8
9
useSchema ,
9
10
useUserListWithPermissions ,
@@ -73,9 +74,23 @@ export const CommentsProvider = memo(function CommentsProvider(props: CommentsPr
73
74
74
75
const { name : workspaceName , dataset, projectId} = useWorkspace ( )
75
76
77
+ const documentValue = useMemo ( ( ) => {
78
+ return editState . draft || editState . published
79
+ } , [ editState . draft , editState . published ] )
80
+
81
+ const documentRevisionId = useMemo ( ( ) => documentValue ?. _rev , [ documentValue ] )
82
+
76
83
// A map to keep track of the latest transaction ID for each comment document.
77
84
const transactionsIdMap = useMemo ( ( ) => new Map < DocumentId , TransactionId > ( ) , [ ] )
78
85
86
+ // We only need to check for read permission on the document since users with
87
+ // read permission on the document can both read and write comments.
88
+ // This is how permission work for the comments add-on dataset.
89
+ const [ readPermission ] = useDocumentValuePermissions ( {
90
+ document : documentValue || { _type : documentType , _id : publishedId } ,
91
+ permission : 'read' ,
92
+ } )
93
+
79
94
// When the latest transaction ID is received, we remove the transaction id from the map.
80
95
const handleOnLatestTransactionIdReceived = useCallback (
81
96
( commentDocumentId : string ) => {
@@ -109,12 +124,6 @@ export const CommentsProvider = memo(function CommentsProvider(props: CommentsPr
109
124
[ transactionsIdMap ] ,
110
125
)
111
126
112
- const documentValue = useMemo ( ( ) => {
113
- return editState . draft || editState . published
114
- } , [ editState . draft , editState . published ] )
115
-
116
- const documentRevisionId = useMemo ( ( ) => documentValue ?. _rev , [ documentValue ] )
117
-
118
127
const handleSetStatus = useCallback (
119
128
( newStatus : CommentStatus ) => {
120
129
// Avoids going to "resolved" when using links to comments
@@ -267,6 +276,8 @@ export const CommentsProvider = memo(function CommentsProvider(props: CommentsPr
267
276
isCommentsOpen,
268
277
onCommentsOpen,
269
278
279
+ hasPermission : Boolean ( readPermission ?. granted ) ,
280
+
270
281
comments : {
271
282
data : threadItemsByStatus ,
272
283
error,
@@ -282,20 +293,21 @@ export const CommentsProvider = memo(function CommentsProvider(props: CommentsPr
282
293
mentionOptions,
283
294
} ) ,
284
295
[
285
- error ,
296
+ isCreatingDataset ,
297
+ status ,
298
+ handleSetStatus ,
286
299
getComment ,
287
300
isCommentsOpen ,
288
- isCreatingDataset ,
289
- loading ,
290
- mentionOptions ,
291
301
onCommentsOpen ,
302
+ readPermission ?. granted ,
303
+ threadItemsByStatus ,
304
+ error ,
305
+ loading ,
292
306
operation . create ,
293
307
operation . react ,
294
308
operation . remove ,
295
309
operation . update ,
296
- status ,
297
- handleSetStatus ,
298
- threadItemsByStatus ,
310
+ mentionOptions ,
299
311
] ,
300
312
)
301
313
0 commit comments