@@ -97,7 +97,7 @@ class QwDocumentsComponent extends MnLifeCycleHooksToStream {
9797 }
9898
9999 docViewer ( ) {
100- return this . rbac . init && this . rbac . cluster . collection [ '.:.:.' ] . data . docs . read ;
100+ return this . rbac . init && ( this . rbac . cluster . collection [ '.:.:.' ] . data . docs . read || this . rbac . cluster . collection [ '.:.:.' ] . data . docs . upsert ) ;
101101 }
102102
103103 constructor (
@@ -169,6 +169,7 @@ class QwDocumentsComponent extends MnLifeCycleHooksToStream {
169169 dec . how_to_query = how_to_query ;
170170 dec . can_use_n1ql = can_use_n1ql ;
171171 dec . has_indexes = has_indexes ;
172+ dec . get_n1ql_placeholder = get_n1ql_placeholder ;
172173
173174 // whenever the collection menu is changed, remove any 'where' clause and offset
174175 dec . collectionMenuCallback = function ( event ) {
@@ -184,8 +185,12 @@ class QwDocumentsComponent extends MnLifeCycleHooksToStream {
184185 dec . searchForm . get ( 'where_clause' ) . setValue ( '' ) ;
185186 dec . searchForm . get ( 'offset' ) . setValue ( 0 ) ;
186187
187- if ( event . bucket && event . scope && event . collection )
188- retrieveDocs_inner ( ) ;
188+ if ( event . bucket && event . scope && event . collection ) {
189+ // get permissions for new collection
190+ qwMetadataService . checkCollectionPerms ( dec . options . selected_bucket , dec . options . selected_scope , dec . options . selected_collection ) . then ( function ( ) {
191+ retrieveDocs_inner ( ) ;
192+ } ) ;
193+ }
189194 }
190195 } ;
191196
@@ -197,22 +202,25 @@ class QwDocumentsComponent extends MnLifeCycleHooksToStream {
197202 //
198203 // what are we allowed to access?
199204 //
205+
200206 dec . upsertAllowed = function ( ) {
201- if ( ! this . rbac . init || ! this . options . selected_collection || ! this . rbac . cluster . collection ) {
207+ if ( ! this . rbac . init || ! this . options . selected_bucket || ! this . options . selected_scope || ! this . options . selected_collection )
202208 return false ;
203- }
204209
205- // return the cached value
206- return this . rbac . cluster . collection [ `${ this . options . selected_bucket } :${ this . options . selected_scope } :${ this . options . selected_collection } ` ] ?. data . docs . upsert ;
210+ const fullName = `${ dec . options . selected_bucket } :${ dec . options . selected_scope } :${ dec . options . selected_collection } ` ;
211+
212+ return ( this . rbac . cluster . collection [ fullName ] ?. data ?. docs ?. upsert ||
213+ this . rbac . cluster . bucket [ this . options . selected_bucket ] . data . docs . upsert ) ;
207214 } ;
208215
209216 dec . deleteAllowed = function ( ) {
210- if ( ! this . rbac . init || ! this . options . selected_collection || ! this . rbac . cluster . collection ) {
217+ if ( ! this . rbac . init || ! this . options . selected_bucket || ! this . options . selected_scope || ! this . options . selected_collection )
211218 return false ;
212- }
213219
214- // return the cached value
215- return this . rbac . cluster . collection [ `${ this . options . selected_bucket } :${ this . options . selected_scope } :${ this . options . selected_collection } ` ] ?. data . docs . delete ;
220+ const fullName = `${ dec . options . selected_bucket } :${ dec . options . selected_scope } :${ dec . options . selected_collection } ` ;
221+
222+ return ( this . rbac . cluster . collection [ fullName ] ?. data ?. docs ?. delete ||
223+ this . rbac . cluster . bucket [ this . options . selected_bucket ] . data . docs . delete ) ;
216224 } ;
217225
218226 //
@@ -292,10 +300,20 @@ class QwDocumentsComponent extends MnLifeCycleHooksToStream {
292300 return ( false ) ;
293301 }
294302
303+ // corner case - can't query if we can't read documents
304+ if ( dec . rbac . cluster . collection [ `${ dec . options . selected_bucket } :${ dec . options . selected_scope } :${ dec . options . selected_collection } ` ] ?. data ?. docs ?. read !== true ) {
305+ dec . options . current_result = "No permission to read documents." ;
306+ return ( false ) ;
307+ }
308+
295309 // always use KV for single doc lookups by ID
296310 if ( dec . options . show_id && dec . options . doc_id )
297311 return KV ;
298312
313+ // N1QL is not available if the user lacks n1ql.select permissions on the current collection
314+ if ( dec . rbac . cluster . collection [ `${ dec . options . selected_bucket } :${ dec . options . selected_scope } :${ dec . options . selected_collection } ` ] ?. n1ql . select . execute !== true )
315+ return KV ;
316+
299317 // key range lookup or limit/offset with no WHERE clause
300318 // - use N1QL if primary index, otherwise KV (though fail if ephemeral)
301319 if ( ( ! dec . options . show_id && ( dec . options . doc_id_start || dec . options . doc_id_end ) ) || dec . options . where_clause . length == 0 ) {
@@ -333,7 +351,18 @@ class QwDocumentsComponent extends MnLifeCycleHooksToStream {
333351 //
334352
335353 function can_use_n1ql ( ) {
336- return ( has_prim ( ) || has_sec ( ) ) ;
354+ // N1QL is not available if the user lacks n1ql.select permissions on the current collection
355+ return ( dec . rbac . cluster . collection [ `${ dec . options . selected_bucket } :${ dec . options . selected_scope } :${ dec . options . selected_collection } ` ] ?. n1ql . select . execute === true
356+ && ( has_prim ( ) || has_sec ( ) ) ) ;
357+ }
358+
359+ function get_n1ql_placeholder ( ) {
360+ if ( dec . rbac . cluster . collection [ `${ dec . options . selected_bucket } :${ dec . options . selected_scope } :${ dec . options . selected_collection } ` ] ?. n1ql . select . execute !== true )
361+ return 'no query permissions' ;
362+ else if ( ! has_indexes ( ) )
363+ return 'no indexes available...' ;
364+ else
365+ return 'optional...' ;
337366 }
338367
339368 //
@@ -764,6 +793,7 @@ class QwDocumentsComponent extends MnLifeCycleHooksToStream {
764793 case false : // error status
765794 showErrorDialog ( "Document Error" , dec . options . current_result , true ) ;
766795 dec . options . current_query = dec . options . selected_bucket ;
796+ refreshResults ( ) ;
767797 break ;
768798 }
769799 }
@@ -1261,7 +1291,10 @@ class QwDocumentsComponent extends MnLifeCycleHooksToStream {
12611291 metadataUpdate ( meta ) ;
12621292 // MB-51579 - when collection unspecified, don't try to retrieve documents
12631293 if ( dec . options . selected_bucket && dec . options . selected_scope && dec . options . selected_collection && dec . docViewer ( ) )
1264- retrieveDocs ( ) ;
1294+ // get permissions for new collection
1295+ qwMetadataService . checkCollectionPerms ( dec . options . selected_bucket , dec . options . selected_scope , dec . options . selected_collection ) . then ( function ( ) {
1296+ retrieveDocs_inner ( ) ;
1297+ } ) ;
12651298 } ) ;
12661299 } ) ;
12671300 }
0 commit comments