@@ -201,12 +201,56 @@ export class amqpwrapper {
201201 if ( this . channel == null || this . conn == null ) throw new Error ( "Cannot Add new Queue Consumer, not connected to rabbitmq" ) ;
202202 if ( queue == null ) queue = "" ;
203203 var q : amqpqueue = null ;
204- if ( Config . amqp_force_queue_prefix && ! Util . IsNullEmpty ( jwt ) ) {
205- var tuser = Crypt . verityToken ( jwt ) ;
206- var name = tuser . username . split ( "@" ) . join ( "" ) . split ( "." ) . join ( "" ) ;
207- name = name . toLowerCase ( ) ;
204+ if ( Config . amqp_force_queue_prefix && ! Util . IsNullEmpty ( jwt ) && ! Util . IsNullEmpty ( queue ) ) {
205+ if ( queue . length == 24 ) {
206+ var tuser = Crypt . verityToken ( jwt ) ;
207+ var name = tuser . username . split ( "@" ) . join ( "" ) . split ( "." ) . join ( "" ) ;
208+ name = name . toLowerCase ( ) ;
209+ var isrole = tuser . roles . filter ( x => x . _id == queue ) ;
210+ if ( isrole . length == 0 && tuser . _id != queue ) {
211+ var skip : boolean = false ;
212+ var arr = await Config . db . query ( { _id : queue } , { name : 1 } , 1 , 0 , null , "users" , jwt ) ;
213+ if ( arr . length == 0 ) skip = true ;
214+ if ( ! skip ) {
215+ var arr = await Config . db . query ( { _id : queue } , { name : 1 } , 1 , 0 , null , "openrpa" , jwt ) ;
216+ if ( arr . length == 0 ) skip = true ;
217+ }
218+ if ( ! skip ) {
219+ var arr = await Config . db . query ( { _id : queue } , { name : 1 } , 1 , 0 , null , "workflow" , jwt ) ;
220+ if ( arr . length == 0 ) skip = true ;
221+ }
222+ if ( ! skip ) {
223+ queue = name + queue ;
224+ } else {
225+ this . _logger . info ( "[SKIP] skipped force prefix for " + queue ) ;
226+ }
227+ } else {
228+ this . _logger . info ( "[SKIP] skipped force prefix for " + queue ) ;
229+ }
230+ } else {
231+ var tuser = Crypt . verityToken ( jwt ) ;
232+ var name = tuser . username . split ( "@" ) . join ( "" ) . split ( "." ) . join ( "" ) ;
233+ name = name . toLowerCase ( ) ;
234+ queue = name + queue ;
235+ }
236+ } else if ( queue . length == 24 ) {
208237 var isrole = tuser . roles . filter ( x => x . _id == queue ) ;
209- if ( isrole . length == 0 && tuser . _id != queue ) queue = name + queue ;
238+ if ( isrole . length == 0 && tuser . _id != queue ) {
239+ var skip : boolean = false ;
240+ var arr = await Config . db . query ( { _id : queue } , { name : 1 } , 1 , 0 , null , "users" , jwt ) ;
241+ if ( arr . length == 0 ) skip = true ;
242+ if ( ! skip ) {
243+ var arr = await Config . db . query ( { _id : queue } , { name : 1 } , 1 , 0 , null , "openrpa" , jwt ) ;
244+ if ( arr . length == 0 ) skip = true ;
245+ }
246+ if ( ! skip ) {
247+ var arr = await Config . db . query ( { _id : queue } , { name : 1 } , 1 , 0 , null , "workflow" , jwt ) ;
248+ if ( arr . length == 0 ) skip = true ;
249+ }
250+ if ( ! skip ) {
251+ throw new Error ( "Access denied creating consumer for " + queue ) ;
252+ }
253+ }
210254 }
211255 // if (!await amqpwrapper.TestInstance().checkQueue(queue)) {
212256 // if (amqpwrapper.TestInstance().conn == null || amqpwrapper.TestInstance().channel == null) {
@@ -340,9 +384,8 @@ export class amqpwrapper {
340384 options . replyTo = replyTo ;
341385 if ( Util . IsNullEmpty ( correlationId ) ) correlationId = this . generateUuid ( ) ;
342386 if ( ! Util . IsNullEmpty ( correlationId ) ) options . correlationId = correlationId ;
343- if ( ! Util . IsNullEmpty ( expiration ) ) {
344- if ( expiration > 0 ) options . expiration = expiration . toString ( ) ;
345- }
387+ if ( expiration < 1 ) expiration = Config . amqp_default_expiration ;
388+ options . expiration = expiration . toString ( ) ;
346389 if ( Util . IsNullEmpty ( exchange ) ) {
347390 if ( ! await this . checkQueue ( queue ) ) {
348391 throw new Error ( "No consumer listening at " + queue ) ;
@@ -364,9 +407,8 @@ export class amqpwrapper {
364407 this . _logger . info ( "send to queue: " + queue + " exchange: " + exchange ) ;
365408 var options : any = { mandatory : true } ;
366409 if ( ! Util . IsNullEmpty ( correlationId ) ) options . correlationId = correlationId ;
367- if ( ! Util . IsNullEmpty ( expiration ) ) {
368- if ( expiration > 0 ) options . expiration = expiration . toString ( ) ;
369- }
410+ if ( expiration < 1 ) expiration = Config . amqp_default_expiration ;
411+ options . expiration = expiration . toString ( ) ;
370412 if ( Util . IsNullEmpty ( exchange ) ) {
371413 if ( ! await this . checkQueue ( queue ) ) {
372414 throw new Error ( "No consumer listening at " + queue ) ;
0 commit comments