Migrate download billing invoice
MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -625,7 +625,8 @@ export default class AuthorizationService {
public static async addInvoiceAuthorizations(tenant: Tenant, userToken: UserToken, billingInvoice: BillingInvoice, authorizationFilter: AuthorizationFilter): Promise<void> {
billingInvoice.canRead = true; // Always true as it should be filtered upfront
- billingInvoice.canDownload = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.INVOICE, Action.DOWNLOAD, authorizationFilter);
+ billingInvoice.canDownload = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.INVOICE, Action.DOWNLOAD,
+ authorizationFilter, billingInvoice.userID ? { UserID : billingInvoice.userID } : {}, billingInvoice);
// Optimize data over the net
Utils.removeCanPropertiesWithFalseValue(billingInvoice);
}

MODIFY
src/server/rest/v1/service/BillingService.ts
src/server/rest/v1/service/BillingService.ts
@@ -367,15 +367,8 @@ export default class BillingService {
const billingInvoice = await BillingStorage.getInvoice(req.tenant, filteredRequest.ID);
UtilsService.assertObjectExists(action, billingInvoice, `Invoice ID '${filteredRequest.ID}' does not exist`,
MODULE_NAME, 'handleDownloadInvoice', req.user);
- // Check Auth
- if (!await Authorizations.canDownloadInvoiceBilling(req.user, billingInvoice.userID)) {
- throw new AppAuthError({
- errorCode: HTTPAuthError.FORBIDDEN,
- user: req.user,
- entity: Entity.INVOICE, action: Action.DOWNLOAD,
- module: MODULE_NAME, method: 'handleDownloadInvoice',
- });
- }
+ // Check and get authorizations
+ await UtilsService.checkAndGetInvoiceAuthorization(req.tenant, req.user, filteredRequest.ID, Action.DOWNLOAD, action, null, {}, [], true);
// Get the billing impl
const billingImpl = await BillingFactory.getBillingImpl(req.tenant);
if (!billingImpl) {

Migrate download billing invoice