Fixed auth in Create user
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -346,12 +346,10 @@ export default class Authorizations {
public static async canImportTags(loggedUser: UserToken, authContext?: AuthorizationContext): Promise<AuthorizationResult> {
return Authorizations.can(loggedUser, Entity.TAGS, Action.IMPORT, authContext);
- // return Authorizations.canPerformAction(loggedUser, Entity.TAGS, Action.IMPORT);
}
public static async canExportTags(loggedUser: UserToken, authContext?: AuthorizationContext): Promise<AuthorizationResult> {
return Authorizations.can(loggedUser, Entity.TAGS, Action.EXPORT, authContext);
- // return Authorizations.canPerformAction(loggedUser, Entity.TAGS, Action.EXPORT);
}
public static async canReadUser(loggedUser: UserToken, authContext?: AuthorizationContext): Promise<AuthorizationResult> {
@@ -382,16 +380,16 @@ export default class Authorizations {
return Authorizations.can(loggedUser, Entity.SITE, Action.READ, authContext);
}
- public static async canCreateSite(loggedUser: UserToken): Promise<boolean> {
- return Authorizations.canPerformAction(loggedUser, Entity.SITE, Action.CREATE);
+ public static async canCreateSite(loggedUser: UserToken, authContext?: AuthorizationContext): Promise<AuthorizationResult> {
+ return Authorizations.can(loggedUser, Entity.SITE, Action.CREATE, authContext);
}
- public static async canUpdateSite(loggedUser: UserToken): Promise<boolean> {
- return Authorizations.canPerformAction(loggedUser, Entity.SITE, Action.UPDATE);
+ public static async canUpdateSite(loggedUser: UserToken, authContext?: AuthorizationContext): Promise<AuthorizationResult> {
+ return Authorizations.can(loggedUser, Entity.SITE, Action.UPDATE, authContext);
}
- public static async canDeleteSite(loggedUser: UserToken): Promise<boolean> {
- return Authorizations.canPerformAction(loggedUser, Entity.SITE, Action.DELETE);
+ public static async canDeleteSite(loggedUser: UserToken, authContext?: AuthorizationContext): Promise<AuthorizationResult> {
+ return Authorizations.can(loggedUser, Entity.SITE, Action.DELETE, authContext);
}
public static async canListSettings(loggedUser: UserToken): Promise<boolean> {

MODIFY
src/server/rest/v1/service/SiteService.ts
src/server/rest/v1/service/SiteService.ts
@@ -354,7 +354,7 @@ export default class SiteService {
await UtilsService.checkAndGetCompanyAuthorization(
req.tenant, req.user, filteredRequest.companyID, Action.READ, action);
// Check static auth
- if (!await Authorizations.canCreateSite(req.user)) {
+ if (!(await Authorizations.canCreateSite(req.user)).authorized) {
throw new AppAuthError({
errorCode: HTTPAuthError.FORBIDDEN,
user: req.user,

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -411,7 +411,7 @@ export default class UserService {
// eslint-disable-next-line @typescript-eslint/require-await
public static async handleImportUsers(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check auth
- if (!await Authorizations.canImportUsers(req.user)) {
+ if (!(await Authorizations.canImportUsers(req.user)).authorized) {
throw new AppAuthError({
errorCode: HTTPAuthError.FORBIDDEN,
user: req.user,
@@ -609,7 +609,7 @@ export default class UserService {
public static async handleCreateUser(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check auth
- if (!await Authorizations.canCreateUser(req.user)) {
+ if (!(await Authorizations.canCreateUser(req.user)).authorized) {
throw new AppAuthError({
errorCode: HTTPAuthError.FORBIDDEN,
user: req.user,

MODIFY
src/server/rest/v1/service/UtilsService.ts
src/server/rest/v1/service/UtilsService.ts
@@ -596,7 +596,7 @@ export default class UtilsService {
}
// Check User
let userProject: string[] = [];
- if (await Authorizations.canReadUser(userToken)) {
+ if ((await Authorizations.canReadUser(userToken)).authorized) {
userProject = [ 'createdBy.name', 'createdBy.firstName', 'lastChangedBy.name', 'lastChangedBy.firstName', 'carUsers.id',
'carUsers.user.id', 'carUsers.user.name', 'carUsers.user.firstName', 'carUsers.user.email', 'carUsers.default', 'carUsers.owner'
];

MODIFY
src/server/rest/v1/validator/UserValidator.ts
src/server/rest/v1/validator/UserValidator.ts
@@ -2,7 +2,6 @@ import User, { ImportedUser } from '../../../../types/User';
import Schema from '../../../../types/validator/Schema';
import SchemaValidator from './SchemaValidator';
-import UserToken from '../../../../types/UserToken';
import fs from 'fs';
import global from '../../../../types/GlobalType';

Fixed auth in Create user