@@ -375,6 +375,12 @@ export class ApiKeysService {
375375 async getApiKeyScopesForGroup (
376376 groupId : number ,
377377 ) : Promise < Record < string , string > > {
378+ const group = await this . prisma . groups . findOne ( {
379+ where : { id : groupId } ,
380+ select : { attributes : true } ,
381+ } ) ;
382+ const attributes = group . attributes as { stripeCustomerId ?: string } ;
383+
378384 const scopes : Record < string , string > = { } ;
379385 scopes [ `read-info` ] = 'Read group details' ;
380386 scopes [ `write-info` ] = 'Update group details' ;
@@ -430,24 +436,30 @@ export class ApiKeysService {
430436 scopes [ `delete-billing` ] = 'Delete billing details' ;
431437
432438 scopes [ `read-invoice-*` ] = 'Read invoices' ;
433- for await ( const invoice of await this . stripeService . getInvoices (
434- groupId ,
435- { } ,
436- ) ) {
437- scopes [ `read-invoice-${ invoice . id } ` ] = `Read invoice: ${ invoice . number } ` ;
438- }
439+ if ( attributes ?. stripeCustomerId )
440+ for await ( const invoice of await this . stripeService . getInvoices (
441+ groupId ,
442+ { } ,
443+ ) ) {
444+ scopes [
445+ `read-invoice-${ invoice . id } `
446+ ] = `Read invoice: ${ invoice . number } ` ;
447+ }
439448
440449 scopes [ `write-source-*` ] = 'Write payment methods' ;
441450 scopes [ `read-source-*` ] = 'Read payment methods' ;
442- for await ( const source of await this . stripeService . getSources (
443- groupId ,
444- { } ,
445- ) ) {
446- scopes [ `read-source-${ source . id } ` ] = `Read payment method: ${ source . id } ` ;
447- scopes [
448- `delete-source-${ source . id } `
449- ] = `Delete payment method: ${ source . id } ` ;
450- }
451+ if ( attributes ?. stripeCustomerId )
452+ for await ( const source of await this . stripeService . getSources (
453+ groupId ,
454+ { } ,
455+ ) ) {
456+ scopes [
457+ `read-source-${ source . id } `
458+ ] = `Read payment method: ${ source . id } ` ;
459+ scopes [
460+ `delete-source-${ source . id } `
461+ ] = `Delete payment method: ${ source . id } ` ;
462+ }
451463
452464 scopes [ `read-audit-log-*` ] = 'Read audit logs' ;
453465 return scopes ;
0 commit comments