added SITE_USER Entity
renamed USERS_SITES to USER_SITE
/!\ need to handle unassign
MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -253,7 +253,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
},
},
{
- resource: Entity.USERS_SITES, action: [Action.ASSIGN, Action.READ, Action.UPDATE, Action.LIST],
+ resource: Entity.USER_SITE, action: [Action.ASSIGN, Action.READ, Action.UPDATE, Action.LIST],
condition: {
Fn: 'custom:dynamicAuthorizations',
args: {
@@ -262,12 +262,35 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
}
},
attributes: [
- 'user.id', 'user.name', 'user.firstName', 'user.email', 'user.role', 'siteID',
'site.id', 'site.name', 'site.address.city', 'site.address.country', 'siteAdmin', 'siteOwner', 'userID'
]
},
{
- resource: Entity.USERS_SITES,
+ resource: Entity.USER_SITE,
+ action: Action.UNASSIGN,
+ condition: {
+ Fn: 'custom:dynamicAuthorizations',
+ args: {
+ asserts: [],
+ filters: ['-OwnUser', 'LocalIssuer']
+ }
+ }
+ },
+ {
+ resource: Entity.SITE_USER, action: [Action.ASSIGN, Action.READ, Action.UPDATE, Action.LIST],
+ condition: {
+ Fn: 'custom:dynamicAuthorizations',
+ args: {
+ asserts: [],
+ filters: ['LocalIssuer']
+ }
+ },
+ attributes: [
+ 'user.id', 'user.name', 'user.firstName', 'user.email', 'user.role', 'siteID', 'siteAdmin', 'siteOwner',
+ ]
+ },
+ {
+ resource: Entity.SITE_USER,
action: Action.UNASSIGN,
// condition: {
// Fn: 'custom:dynamicAuthorizations',
@@ -1150,7 +1173,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
}
},
{
- resource: Entity.USERS_SITES, action: [Action.ASSIGN, Action.READ, Action.UPDATE, Action.LIST],
+ resource: Entity.USER_SITE, action: [Action.ASSIGN, Action.READ, Action.UPDATE, Action.LIST],
condition: {
Fn: 'custom:dynamicAuthorizations',
args: {
@@ -1159,12 +1182,35 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
}
},
attributes: [
- 'user.id', 'user.name', 'user.firstName', 'user.email', 'user.role', 'siteID',
'site.id', 'site.name', 'site.address.city', 'site.address.country', 'siteAdmin', 'siteOwner', 'userID'
]
},
{
- resource: Entity.USERS_SITES,
+ resource: Entity.USER_SITE,
+ action: Action.UNASSIGN,
+ condition: {
+ Fn: 'custom:dynamicAuthorizations',
+ args: {
+ asserts: [],
+ filters: ['-OwnUser', 'LocalIssuer']
+ }
+ },
+ },
+ {
+ resource: Entity.SITE_USER, action: [Action.ASSIGN, Action.READ, Action.UPDATE, Action.LIST],
+ condition: {
+ Fn: 'custom:dynamicAuthorizations',
+ args: {
+ asserts: [],
+ filters: ['SitesAdminOrOwner', 'LocalIssuer']
+ }
+ },
+ attributes: [
+ 'user.id', 'user.name', 'user.firstName', 'user.email', 'user.role', 'siteID', 'siteAdmin', 'siteOwner',
+ ]
+ },
+ {
+ resource: Entity.SITE_USER,
action: Action.UNASSIGN,
condition: {
Fn: 'custom:dynamicAuthorizations',
@@ -1602,7 +1648,7 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
],
},
{
- resource: Entity.USERS_SITES, action: [Action.READ, Action.LIST],
+ resource: Entity.USER_SITE, action: [Action.READ, Action.LIST],
condition: {
Fn: 'custom:dynamicAuthorizations',
args: {
@@ -1611,10 +1657,22 @@ export const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
}
},
attributes: [
- 'user.id', 'user.name', 'user.firstName', 'user.email', 'user.role', 'siteID',
'site.id', 'site.name', 'site.address.city', 'site.address.country', 'siteAdmin', 'siteOwner', 'userID'
]
},
+ {
+ resource: Entity.SITE_USER, action: [Action.READ, Action.LIST],
+ condition: {
+ Fn: 'custom:dynamicAuthorizations',
+ args: {
+ asserts: [],
+ filters: ['SitesAdminOrOwner', 'LocalIssuer']
+ }
+ },
+ attributes: [
+ 'user.id', 'user.name', 'user.firstName', 'user.email', 'user.role', 'siteID', 'siteAdmin', 'siteOwner',
+ ]
+ },
{
resource: Entity.TRANSACTION, action: [Action.READ, Action.REFUND_TRANSACTION],
condition: {

MODIFY
src/scheduler/tasks/CheckPreparingSessionNotStartedTask.ts
src/scheduler/tasks/CheckPreparingSessionNotStartedTask.ts
@@ -29,7 +29,7 @@ export default class CheckPreparingSessionNotStartedTask extends TenantScheduler
// Get site owner and then send notification
if (chargingStation.siteArea && chargingStation.siteArea.siteID) {
// Get Site Owners
- const siteOwners = await SiteStorage.getUserSites(tenant,
+ const siteOwners = await SiteStorage.getSiteUsers(tenant,
{ siteIDs: [ chargingStation.siteArea.siteID ], siteOwnerOnly: true }, Constants.DB_PARAMS_MAX_LIMIT);
if (siteOwners && siteOwners.count > 0) {
// Send notification

MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -60,14 +60,14 @@ export default class AuthorizationService {
// Add Meta Data
userSites.metadata = authorizationFilter.metadata;
// Add Authorizations
- userSites.canUpdateUserSites = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.USERS_SITES, Action.UPDATE, authorizationFilter);
+ userSites.canUpdateUserSites = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.USER_SITE, Action.UPDATE, authorizationFilter);
}
public static async addSiteUsersAuthorizations(tenant: Tenant, userToken: UserToken, siteUsers: SiteUserDataResult, authorizationFilter: AuthorizationFilter): Promise<void> {
// Add Meta Data
siteUsers.metadata = authorizationFilter.metadata;
// Add Authorizations
- siteUsers.canUpdateSiteUsers = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.USERS_SITES, Action.UPDATE, authorizationFilter);
+ siteUsers.canUpdateSiteUsers = await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.SITE_USER, Action.UPDATE, authorizationFilter);
}
public static async addSitesAuthorizations(tenant: Tenant, userToken: UserToken, sites: SiteDataResult, authorizationFilter: AuthorizationFilter): Promise<void> {
@@ -96,11 +96,11 @@ export default class AuthorizationService {
site.canGenerateQrCode = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.SITE_AREA, Action.GENERATE_QR, authorizationFilter, { SiteID: site.id }, site);
site.canAssignUsers = await AuthorizationService.canPerformAuthorizationAction(
- tenant, userToken, Entity.USERS_SITES, Action.ASSIGN, authorizationFilter, { SiteID: site.id }, site);
+ tenant, userToken, Entity.SITE_USER, Action.ASSIGN, authorizationFilter, { SiteID: site.id }, site);
site.canUnassignUsers = await AuthorizationService.canPerformAuthorizationAction(
- tenant, userToken, Entity.USERS_SITES, Action.UNASSIGN, authorizationFilter, { SiteID: site.id }, site);
- site.canReadUsers = await AuthorizationService.canPerformAuthorizationAction(
- tenant, userToken, Entity.USERS_SITES, Action.READ, authorizationFilter, { SiteID: site.id }, site);
+ tenant, userToken, Entity.SITE_USER, Action.UNASSIGN, authorizationFilter, { SiteID: site.id }, site);
+ site.canListSiteUsers = await AuthorizationService.canPerformAuthorizationAction(
+ tenant, userToken, Entity.SITE_USER, Action.LIST, authorizationFilter, { SiteID: site.id }, site);
// Optimize data over the net
Utils.removeCanPropertiesWithFalseValue(site);
}
@@ -157,7 +157,7 @@ export default class AuthorizationService {
authorized: false,
};
// Check static & dynamic authorization
- await this.canPerformAuthorizationAction(tenant, userToken, Entity.USERS_SITES, Action.LIST,
+ await this.canPerformAuthorizationAction(tenant, userToken, Entity.SITE_USER, Action.LIST,
authorizations, filteredRequest, null, failsWithException);
return authorizations;
}
@@ -173,7 +173,7 @@ export default class AuthorizationService {
// Filter projected fields
authorizations.projectFields = AuthorizationService.filterProjectFields(authorizations.projectFields, filteredRequest.ProjectFields);
// Handle Sites
- await this.canPerformAuthorizationAction(tenant, userToken, Entity.USERS_SITES, Action.LIST,
+ await this.canPerformAuthorizationAction(tenant, userToken, Entity.USER_SITE, Action.LIST,
authorizations, filteredRequest, null, true);
return authorizations;
}
@@ -188,7 +188,7 @@ export default class AuthorizationService {
};
// Check static & dynamic authorization
const authAction = action === ServerAction.ADD_USERS_TO_SITE ? Action.ASSIGN : Action.UNASSIGN;
- await this.canPerformAuthorizationAction(tenant, userToken, Entity.USERS_SITES, authAction,
+ await this.canPerformAuthorizationAction(tenant, userToken, Entity.SITE_USER, authAction,
authorizations, filteredRequest, null, true);
return authorizations;
}
@@ -204,7 +204,7 @@ export default class AuthorizationService {
};
// Check static & dynamic authorization
const authAction = action === ServerAction.ADD_USERS_TO_SITE ? Action.ASSIGN : Action.UNASSIGN;
- await this.canPerformAuthorizationAction(tenant, userToken, Entity.USERS_SITES, authAction,
+ await this.canPerformAuthorizationAction(tenant, userToken, Entity.USER_SITE, authAction,
authorizations, filteredRequest, null, true);
return authorizations;
}
@@ -245,13 +245,17 @@ export default class AuthorizationService {
user.canDelete = await AuthorizationService.canPerformAuthorizationAction(
tenant, userToken, Entity.USER, Action.DELETE, authorizationFilter, { UserID: user.id }, user);
user.canAssignSites = await AuthorizationService.canPerformAuthorizationAction(
- tenant, userToken, Entity.USERS_SITES, Action.ASSIGN, authorizationFilter, { UserID: user.id }, user);
+ tenant, userToken, Entity.USER_SITE, Action.ASSIGN, authorizationFilter, { UserID: user.id }, user);
user.canUnassignSites = await AuthorizationService.canPerformAuthorizationAction(
- tenant, userToken, Entity.USERS_SITES, Action.UNASSIGN, authorizationFilter, { UserID: user.id }, user);
- user.canListSites = await AuthorizationService.canPerformAuthorizationAction(
- tenant, userToken, Entity.SITE, Action.LIST, authorizationFilter, { UserID: user.id }, user);
- user.canListTokens = await AuthorizationService.canPerformAuthorizationAction(
- tenant, userToken, Entity.REGISTRATION_TOKEN, Action.LIST, authorizationFilter, { UserID: user.id }, user);
+ tenant, userToken, Entity.USER_SITE, Action.UNASSIGN, authorizationFilter, { UserID: user.id }, user);
+ user.canListUserSites = await AuthorizationService.canPerformAuthorizationAction(
+ tenant, userToken, Entity.USER_SITE, Action.LIST, authorizationFilter, { UserID: user.id }, user);
+ user.canListTags = await AuthorizationService.canPerformAuthorizationAction(
+ tenant, userToken, Entity.TAG, Action.LIST, authorizationFilter, { UserID: user.id }, user);
+ user.canListTransactions = await AuthorizationService.canPerformAuthorizationAction(
+ tenant, userToken, Entity.TRANSACTION, Action.LIST, authorizationFilter, { UserID: user.id }, user);
+ user.canSynchronizeBillingUser = await AuthorizationService.canPerformAuthorizationAction(
+ tenant, userToken, Entity.USER, Action.SYNCHRONIZE_BILLING_USER, authorizationFilter, { UserID: user.id }, user);
Utils.removeCanPropertiesWithFalseValue(user);
}

MODIFY
src/server/rest/v1/service/UtilsService.ts
src/server/rest/v1/service/UtilsService.ts
@@ -476,7 +476,7 @@ export default class UtilsService {
errorCode: HTTPAuthError.FORBIDDEN,
user: userToken,
action: action === ServerAction.ADD_USERS_TO_SITE ? Action.ASSIGN : Action.UNASSIGN,
- entity: Entity.USERS_SITES,
+ entity: Entity.USER_SITE,
module: MODULE_NAME, method: 'checkUserSitesAuthorization',
});
}
@@ -515,7 +515,7 @@ export default class UtilsService {
errorCode: HTTPAuthError.FORBIDDEN,
user: userToken,
action: action === ServerAction.ADD_USERS_TO_SITE ? Action.ASSIGN : Action.UNASSIGN,
- entity: Entity.USERS_SITES,
+ entity: Entity.USER_SITE,
module: MODULE_NAME, method: 'checkSiteUsersAuthorization',
});
}

MODIFY
src/types/Authorization.ts
src/types/Authorization.ts
@@ -71,8 +71,8 @@ export enum Entity {
TRANSACTION = 'Transaction',
REPORT = 'Report',
USER = 'User',
- USERS_SITES = 'UsersSites',
- SITES_USERS = 'SiteUsers',
+ USER_SITE = 'UserSite',
+ SITE_USER = 'SiteUser',
LOGGING = 'Logging',
PRICING = 'Pricing',
PRICING_DEFINITION = 'PricingDefinition',
@@ -191,8 +191,10 @@ export interface AuthorizationActions {
export interface UserAuthorizationActions extends AuthorizationActions {
canAssignSites?: boolean;
canUnassignSites?: boolean;
- canListSites?: boolean;
- canListTokens?: boolean;
+ canListUserSites?: boolean;
+ canListTags?: boolean;
+ canListTransactions?: boolean;
+ canSynchronizeBillingUser?: boolean;
}
export interface TagAuthorizationActions extends AuthorizationActions {
@@ -226,7 +228,7 @@ export interface SiteAreaAuthorizationActions extends AuthorizationActions {
export interface SiteAuthorizationActions extends AuthorizationActions {
canAssignUsers?: boolean;
canUnassignUsers?: boolean;
- canReadUsers?: boolean;
+ canListSiteUsers?: boolean;
canExportOCPPParams?: boolean;
canGenerateQrCode?: boolean;
canMaintainPricingDefinitions?: boolean;

added SITE_USER Entity
renamed USERS_SITES to USER_SITE
/!\ need to handle unassign