added email to Logging messages
construction: WIP : authorizations
need to handle canList and canCreate paymentMethod(s)
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -685,6 +685,21 @@ export default class Authorizations {
return Authorizations.canPerformAction(loggedUser, Entity.NOTIFICATION, Action.CREATE);
}
+ public static canListPaymentMethod(loggedUser: UserToken): boolean {
+ return Authorizations.canPerformAction(loggedUser, Entity.NOTIFICATION, Action.CREATE);
+ }
+
+ // or canPerformAction(loggedUser, Entity.BILLING, Action.CREATE_PAYMENT_METHOD)
+ public static canCreatePaymentMethod(loggedUser: UserToken, userID: string): boolean {
+ return Authorizations.canPerformAction(loggedUser, Entity.PAYMENT_METHOD, Action.CREATE,
+ { user: userID, owner: loggedUser.id }
+ );
+ }
+
+ public static canDeletePaymentMethod(loggedUser: UserToken): boolean {
+ return Authorizations.canPerformAction(loggedUser, Entity.PAYMENT_METHOD, Action.CREATE);
+ }
+
public static isSuperAdmin(user: UserToken | User): boolean {
return user.role === UserRole.SUPER_ADMIN;
}

MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -93,6 +93,11 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
{ resource: Entity.NOTIFICATION, action: Action.CREATE, attributes: ['*'] },
{ resource: Entity.USERS_SITES, action: Action.LIST, attributes: ['*'] },
{ resource: Entity.USERS_SITES, action: [Action.ASSIGN, Action.UNASSIGN], attributes: ['*'] },
+ { resource: Entity.PAYMENT_METHODS, action: Action.LIST, attributes: ['*'] },
+ {
+ resource: Entity.PAYMENT_METHOD, action: [Action.READ, Action.CREATE], attributes: ['*'],
+ condition: { Fn: 'EQUALS', args: { 'user': '$.owner' } }
+ },
]
},
basic: {
@@ -200,6 +205,10 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
condition: { Fn: 'EQUALS', args: { 'user': '$.owner' } }
},
{ resource: Entity.NOTIFICATION, action: Action.CREATE, attributes: ['*'] },
+ {
+ resource: Entity.PAYMENT_METHOD, action: [Action.READ, Action.CREATE], attributes: ['*'],
+ condition: { Fn: 'EQUALS', args: { 'user': '$.owner' } }
+ },
]
},
demo: {

MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -549,7 +549,7 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
source: Constants.CENTRAL_SERVER,
action: ServerAction.BILLING_SETUP_PAYMENT_METHOD,
module: MODULE_NAME, method: '_createSetupIntent',
- message: `Setup intent has been created - customer '${customerID}'`
+ message: `Setup intent has been created - customer '${customerID}' - (${user.email})`
});
// Send some feedback
return {
@@ -573,7 +573,7 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
source: Constants.CENTRAL_SERVER,
action: ServerAction.BILLING_SETUP_PAYMENT_METHOD,
module: MODULE_NAME, method: '_attachPaymentMethod',
- message: `Payment method ${paymentMethodId} has been attached - customer '${customerID}'`
+ message: `Payment method ${paymentMethodId} has been attached - customer '${customerID}' - (${user.email})`
});
// Set this payment method as the default
await this.stripe.customers.update(customerID, {
@@ -584,7 +584,7 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
source: Constants.CENTRAL_SERVER,
action: ServerAction.BILLING_SETUP_PAYMENT_METHOD,
module: MODULE_NAME, method: '_attachPaymentMethod',
- message: `Default payment method has been set ${paymentMethodId} - customer '${customerID}'`
+ message: `Default payment method has been set ${paymentMethodId} - customer '${customerID}' - (${user.email})`
});
// Send some feedback
return {

MODIFY
src/server/rest/v1/service/BillingService.ts
src/server/rest/v1/service/BillingService.ts
@@ -496,6 +496,14 @@ export default class BillingService {
// Check if component is active
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.BILLING,
Action.BILLING_SETUP_PAYMENT_METHOD, Entity.BILLING, MODULE_NAME, 'handleSetupSetupPaymentMethod');
+ if (!Authorizations.canCreatePaymentMethod(req.user, 'oo')) {
+ throw new AppAuthError({
+ errorCode: HTTPAuthError.FORBIDDEN,
+ user: req.user,
+ action: Action.CREATE, entity: Entity.PAYMENT_METHOD,
+ module: MODULE_NAME, method: 'handleBillingSetupPaymentMethod'
+ });
+ }
// Filter
// TODO - const filteredRequest = BillingSecurity.filterSynchronizeUserRequest(req.body);
// Get the billing impl

MODIFY
src/types/Authorization.ts
src/types/Authorization.ts
@@ -86,6 +86,8 @@ export enum Entity {
NOTIFICATION = 'Notification',
TAGS = 'Tags',
TAG = 'Tag',
+ PAYMENT_METHOD = 'PaymentMethod',
+ PAYMENT_METHODS = 'PaymentMethods',
}
export enum Action {

added email to Logging messages
:construction: WIP : authorizations
need to handle canList and canCreate paymentMethod(s)