BILLING PLATFORM - align authorization definition
MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -392,10 +392,10 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
},
{ resource: Entity.BILLING, action: [Action.CHECK_CONNECTION, Action.CLEAR_BILLING_TEST_DATA] },
{
- resource: Entity.BILLING_PLATFORM,
- action: [Action.BILLING_CREATE_SUB_ACCOUNT, Action.BILLING_ONBOARD_SUB_ACCOUNT, Action.LIST, Action.READ],
+ resource: Entity.BILLING_SUB_ACCOUNT,
+ action: [Action.CREATE, Action.READ, Action.UPDATE, Action.DELETE, Action.BILLING_ONBOARD_SUB_ACCOUNT],
attributes: [
- 'id', 'accountID', 'userID', 'user.id', 'user.firstName', 'user.lastName', 'user.email', 'status'
+ 'id', 'accountExternalID', 'businessOwnerID', 'user.id', 'user.firstName', 'user.lastName', 'user.email', 'status'
]
},
{ resource: Entity.TAX, action: [Action.LIST] },

MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -608,7 +608,7 @@ export default class AuthorizationService {
public static async checkAndGetBillingSubAccountAuthorizations(tenant: Tenant, userToken: UserToken,
filteredRequest: Partial<HttpBillingSubAccountGetRequest>, authAction: Action, entityData?: EntityData): Promise<AuthorizationFilter> {
return AuthorizationService.checkAndGetEntityAuthorizations(
- tenant, Entity.BILLING_PLATFORM, userToken, filteredRequest, filteredRequest.ID ? { id: filteredRequest.ID } : {}, authAction, entityData);
+ tenant, Entity.BILLING_SUB_ACCOUNT, userToken, filteredRequest, filteredRequest.ID ? { id: filteredRequest.ID } : {}, authAction, entityData);
}
public static async checkAndGetTaxesAuthorizations(tenant: Tenant, userToken: UserToken, failsWithException = true): Promise<AuthorizationFilter> {

MODIFY
src/server/rest/v1/service/BillingService.ts
src/server/rest/v1/service/BillingService.ts
@@ -474,10 +474,10 @@ export default class BillingService {
public static async handleCreateSubAccount(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check if component is active
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING_PLATFORM,
- Action.BILLING_CREATE_SUB_ACCOUNT, Entity.BILLING_PLATFORM, MODULE_NAME, 'handleCreateSubAccount');
+ Action.CREATE, Entity.BILLING_SUB_ACCOUNT, MODULE_NAME, 'handleCreateSubAccount');
const filteredRequest = BillingValidatorRest.getInstance().validateBillingCreateSubAccountReq(req.body);
// Check authorization
- await AuthorizationService.checkAndGetBillingPlatformAuthorizations(req.tenant, req.user, Action.BILLING_CREATE_SUB_ACCOUNT);
+ await AuthorizationService.checkAndGetBillingSubAccountAuthorizations(req.tenant, req.user, {}, Action.CREATE, filteredRequest);
// Get the billing impl
const billingImpl = await BillingFactory.getBillingImpl(req.tenant);
if (!billingImpl) {
@@ -537,7 +537,7 @@ export default class BillingService {
const filteredRequest = BillingValidatorRest.getInstance().validateBillingSubAccountsGetReq(req.query);
// Check if component is active
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING_PLATFORM,
- Action.LIST, Entity.BILLING_PLATFORM, MODULE_NAME, 'handleBillingGetSubAccounts');
+ Action.LIST, Entity.BILLING_SUB_ACCOUNT, MODULE_NAME, 'handleBillingGetSubAccounts');
const authorizations = await AuthorizationService.checkAndGetBillingPlatformAuthorizations(req.tenant, req.user, Action.LIST);
if (!authorizations.authorized) {
UtilsService.sendEmptyDataResult(res, next);
@@ -567,7 +567,7 @@ export default class BillingService {
const filteredRequest = BillingValidatorRest.getInstance().validateBillingSubAccountGetReq(req.params);
// Check if component is active
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING_PLATFORM,
- Action.READ, Entity.BILLING_PLATFORM, MODULE_NAME, 'handleBillingGetSubAccount');
+ Action.READ, Entity.BILLING_SUB_ACCOUNT, MODULE_NAME, 'handleBillingGetSubAccount');
// Get the billing sub accounts
const subAccount = await UtilsService.checkAndGetBillingSubAccountAuthorization(req.tenant, req.user, filteredRequest.ID, Action.READ, action, null, {}, true);
res.json(subAccount);
@@ -577,7 +577,7 @@ export default class BillingService {
public static async handleOnboardAccount(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check if component is active
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING_PLATFORM,
- Action.BILLING_ONBOARD_SUB_ACCOUNT, Entity.BILLING_PLATFORM, MODULE_NAME, 'handleOnboardAccount');
+ Action.BILLING_ONBOARD_SUB_ACCOUNT, Entity.BILLING_SUB_ACCOUNT, MODULE_NAME, 'handleOnboardAccount');
const filteredRequest = BillingValidatorRest.getInstance().validateBillingSubAccountGetReq(req.params);
// Check authorization
await AuthorizationService.checkAndGetBillingPlatformAuthorizations(req.tenant, req.user, Action.BILLING_ONBOARD_SUB_ACCOUNT);

MODIFY
src/types/Authorization.ts
src/types/Authorization.ts
@@ -77,6 +77,7 @@ export enum Entity {
PRICING_DEFINITION = 'PricingDefinition',
BILLING = 'Billing',
BILLING_PLATFORM = 'BillingPlatform',
+ BILLING_SUB_ACCOUNT = 'BillingSubAccount',
SETTING = 'Setting',
ASYNC_TASK = 'AsyncTask',
OCPI_ENDPOINT = 'OcpiEndpoint',
@@ -135,7 +136,6 @@ export enum Action {
BILLING_PAYMENT_METHODS = 'BillingPaymentMethods',
BILLING_DELETE_PAYMENT_METHOD = 'BillingDeletePaymentMethod',
BILLING_CHARGE_INVOICE = 'BillingChargeInvoice',
- BILLING_CREATE_SUB_ACCOUNT = 'BillingSubAccountCreate',
BILLING_ACTIVATE_SUB_ACCOUNT = 'BillingSubAccountActivate',
BILLING_ONBOARD_SUB_ACCOUNT = 'BillingSubAccountOnboard',
CHECK_CONNECTION = 'CheckConnection',

MODIFY
src/types/GlobalType.ts
src/types/GlobalType.ts
-import { BillingInvoice, BillingPaymentMethod } from './Billing';
+import { BillingAccount, BillingInvoice, BillingPaymentMethod } from './Billing';
import { Car, CarCatalog } from './Car';
import ChargingStation from './ChargingStation';
@@ -84,7 +84,7 @@ export enum ImportStatus {
ERROR = 'E',
}
-export type EntityData = Car|User|Company|Site|SiteArea|Tag|CarCatalog|ChargingStation|PricingDefinition|Log|RegistrationToken|BillingInvoice|BillingPaymentMethod|Setting;
+export type EntityData = Car|User|Company|Site|SiteArea|Tag|CarCatalog|ChargingStation|PricingDefinition|Log|RegistrationToken|BillingInvoice|BillingPaymentMethod|Setting|BillingAccount;
interface TSGlobal extends Global {
database: MongoDBStorage;

MODIFY
src/types/requests/HttpBillingRequest.ts
src/types/requests/HttpBillingRequest.ts
-import { BillingInvoiceStatus } from '../Billing';
+import { BillingAccount, BillingInvoiceStatus } from '../Billing';
+
import HttpByIDRequest from './HttpByIDRequest';
import HttpDatabaseRequest from './HttpDatabaseRequest';
@@ -29,8 +30,12 @@ export interface HttpDeletePaymentMethod {
paymentMethodId: string;
}
-export interface HttpBillingSubAccountCreateRequest {
- businessOwnerID: string;
+// eslint-disable-next-line @typescript-eslint/no-empty-interface
+export interface HttpBillingSubAccountCreateRequest extends BillingAccount {
+}
+
+// eslint-disable-next-line @typescript-eslint/no-empty-interface
+export interface HttpBillingSubAccountUpdateRequest extends BillingAccount {
}
export interface HttpBillingSubAccountActivateRequest {
@@ -47,6 +52,6 @@ export interface HttpBillingSubAccountsGetRequest extends HttpDatabaseRequest {
Search?: string;
}
-export interface HttpBillingSubAccountGetRequest {
+export interface HttpBillingSubAccountGetRequest extends HttpByIDRequest {
ID: string;
}

MODIFY
test/api/BillingTest.ts
test/api/BillingTest.ts
@@ -1133,12 +1133,13 @@ describeif(isBillingProperlyConfigured)('Billing', () => {
});
expect(subAccountCreateResponse.status).to.be.eq(StatusCodes.CREATED);
- // List sub-accounts
+ // Get the sub-account
const subAccountResponse = await billingTestHelper.userService.billingApi.readSubAccount(subAccountCreateResponse.data.id);
+ const subAccount = subAccountResponse.data as BillingAccount;
expect(subAccountResponse.status).to.be.eq(StatusCodes.OK);
- expect(subAccountResponse.data.id).to.be.eq(subAccountCreateResponse.data.id);
- expect(subAccountResponse.data.userID).to.be.eq(billingTestHelper.userContext.id);
- expect(subAccountResponse.data.status).to.be.eq(BillingAccountStatus.IDLE);
+ expect(subAccount.id).to.be.eq(subAccountCreateResponse.data.id);
+ expect(subAccount.businessOwnerID).to.be.eq(billingTestHelper.userContext.id);
+ expect(subAccount.status).to.be.eq(BillingAccountStatus.IDLE);
});
it('should send sub-account onboarding', async () => {

BILLING PLATFORM - align authorization definition