added authAction to usersInError
added canAssignSites to UserAuthorization
handle usersInError changes (Authorization in UserService)
> maybe some changes are needed, first try
MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -192,7 +192,7 @@ export default class AuthorizationService {
}
public static async checkAndGetUsersInErrorAuthorizations(tenant: Tenant, userToken: UserToken,
- filteredRequest: Partial<HttpUsersRequest>): Promise<AuthorizationFilter> {
+ authAction: Action, filteredRequest: Partial<HttpUsersRequest>): Promise<AuthorizationFilter> {
const authorizationFilters: AuthorizationFilter = {
filters: {},
dataSources: new Map(),
@@ -200,7 +200,7 @@ export default class AuthorizationService {
authorized: false
};
// Check static & dynamic authorization
- await this.canPerformAuthorizationAction(tenant, userToken, Entity.USER, Action.IN_ERROR,
+ await this.canPerformAuthorizationAction(tenant, userToken, Entity.USER, authAction,
authorizationFilters, filteredRequest, null, true);
return authorizationFilters;
}
@@ -223,12 +223,14 @@ export default class AuthorizationService {
tenant, userToken, Entity.USER, Action.UPDATE, authorizationFilter, { UserID: user.id }, user);
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);
// Optimize data over the net
Utils.removeCanPropertiesWithFalseValue(user);
}
public static async checkAndGetUsersAuthorizations(tenant: Tenant, userToken: UserToken,
- filteredRequest: Partial<HttpUsersRequest>): Promise<AuthorizationFilter> {
+ authAction: Action, filteredRequest: Partial<HttpUsersRequest>): Promise<AuthorizationFilter> {
const authorizationFilters: AuthorizationFilter = {
filters: {},
dataSources: new Map(),
@@ -236,7 +238,7 @@ export default class AuthorizationService {
authorized: false,
};
// Check static & dynamic authorization
- await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.USER, Action.LIST,
+ await AuthorizationService.canPerformAuthorizationAction(tenant, userToken, Entity.USER, authAction,
authorizationFilters, filteredRequest, null, true);
return authorizationFilters;
}

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
-import { Action, AuthorizationFilter, Entity } from '../../../../types/Authorization';
+import { Action, Entity } from '../../../../types/Authorization';
import { ActionsResponse, ImportStatus } from '../../../../types/GlobalType';
import { AsyncTaskType, AsyncTasks } from '../../../../types/AsyncTask';
import Busboy, { FileInfo } from 'busboy';
@@ -32,7 +32,6 @@ import { OCPITokenWhitelist } from '../../../../types/ocpi/OCPIToken';
import OCPIUtils from '../../../ocpi/OCPIUtils';
import { Readable } from 'stream';
import { ServerAction } from '../../../../types/Server';
-import SiteStorage from '../../../../storage/mongodb/SiteStorage';
import { StartTransactionErrorCode } from '../../../../types/Transaction';
import TagStorage from '../../../../storage/mongodb/TagStorage';
import { UserInErrorType } from '../../../../types/InError';
@@ -379,12 +378,15 @@ export default class UserService {
next();
}
- public static async handleGetUsersInError(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
+ public static async handleGetUsersInError(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<DataResult<User>> {
// Filter
const filteredRequest = UserValidator.getInstance().validateUsersInErrorGetReq(req.query);
// Get authorization filters
const authorizationUserInErrorFilters = await AuthorizationService.checkAndGetUsersInErrorAuthorizations(
- req.tenant, req.user, filteredRequest);
+ req.tenant, req.user, Action.IN_ERROR, filteredRequest);
+ if (!authorizationUserInErrorFilters.authorized) {
+ return Constants.DB_EMPTY_DATA_RESULT;
+ }
// Get users
const users = await UserStorage.getUsersInError(req.tenant,
{
@@ -742,16 +744,21 @@ export default class UserService {
private static async getUsers(req: Request, filteredRequest: HttpUsersRequest): Promise<DataResult<User>> {
// Get authorization filters
const authorizationUsersFilters = await AuthorizationService.checkAndGetUsersAuthorizations(
- req.tenant, req.user, filteredRequest);
+ req.tenant, req.user, Action.LIST, filteredRequest);
if (!authorizationUsersFilters.authorized) {
return Constants.DB_EMPTY_DATA_RESULT;
}
// Optimization: Get Tag IDs from Visual IDs
if (filteredRequest.VisualTagID) {
+ const authorizationTagsFilters = await AuthorizationService.checkAndGetTagsAuthorizations(
+ req.tenant, req.user, filteredRequest);
+ if (!authorizationTagsFilters.authorized) {
+ return Constants.DB_EMPTY_DATA_RESULT;
+ }
const tagIDs = await TagStorage.getTags(req.tenant, {
- visualIDs: filteredRequest.VisualTagID.split('|')
- },
- Constants.DB_PARAMS_MAX_LIMIT, ['userID']);
+ visualIDs: filteredRequest.VisualTagID.split('|'),
+ ...authorizationUsersFilters.filters
+ }, Constants.DB_PARAMS_MAX_LIMIT, ['userID']);
if (!Utils.isEmptyArray(tagIDs.result)) {
const userIDs = _.uniq(tagIDs.result.map((tag) => tag.userID));
filteredRequest.UserID = userIDs.join('|');

MODIFY
src/types/Authorization.ts
src/types/Authorization.ts
@@ -186,6 +186,10 @@ export interface AuthorizationActions {
metadata?: Record<string, unknown>;
}
+export interface UserAuthorizationActions extends AuthorizationActions {
+ canAssignSites?: boolean;
+}
+
export interface TagAuthorizationActions extends AuthorizationActions {
canUnassign?: boolean;
canAssign?: boolean;

MODIFY
src/types/User.ts
src/types/User.ts
import Address from './Address';
-import { AuthorizationActions } from './Authorization';
import { BillingUserData } from './Billing';
import CreatedUpdatedProps from './CreatedUpdatedProps';
import { ImportStatus } from './GlobalType';
+import { UserAuthorizationActions } from './Authorization';
import UserNotifications from './UserNotifications';
-export default interface User extends CreatedUpdatedProps, AuthorizationActions {
+export default interface User extends CreatedUpdatedProps, UserAuthorizationActions {
id: string;
issuer: boolean;
name: string;

added authAction to usersInError
added canAssignSites to UserAuthorization
handle usersInError changes (Authorization in UserService)
-> maybe some changes are needed, first try