no dedicated methods
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -724,10 +724,6 @@ export default class Authorizations {
return user.role === UserRole.DEMO;
}
- public static isTechnical(user: UserToken | User): boolean {
- return user.technical === true;
- }
-
public static async can(loggedUser: UserToken, entity: Entity, action: Action, context?: AuthorizationContext): Promise<AuthorizationResult> {
// Check
const authDefinition = AuthorizationsDefinition.getInstance();

MODIFY
src/server/rest/v1/service/AuthService.ts
src/server/rest/v1/service/AuthService.ts
@@ -755,7 +755,7 @@ export default class AuthService {
token = jwt.sign(payload, jwtOptions.secretOrKey, {
expiresIn: _centralSystemRestConfig.userDemoTokenLifetimeDays * 24 * 3600
});
- } else if (Authorizations.isTechnical(user)) {
+ } else if (user.technical) {
token = jwt.sign(payload, jwtOptions.secretOrKey, {
expiresIn: _centralSystemRestConfig.userTechnicalTokenLifetimeDays * 24 * 3600
});

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -226,14 +226,17 @@ export default class UserService {
if (filteredRequest.role) {
await UserStorage.saveUserRole(req.tenant, user.id, filteredRequest.role);
}
- // Save Technical user flag
- await UserStorage.saveUserTechnicalFlag(req.tenant, user.id, user.technical);
// Save Admin Data
if (Utils.objectHasProperty(filteredRequest, 'plateID')) {
const adminData: { plateID?: string; } = {};
adminData.plateID = filteredRequest.plateID || null;
await UserStorage.saveUserAdminData(req.tenant, user.id, adminData);
}
+ if (Utils.objectHasProperty(filteredRequest, 'technical')) {
+ const adminData: { technical?: boolean; } = {};
+ adminData.technical = filteredRequest.technical || null;
+ await UserStorage.saveUserAdminData(req.tenant, user.id, adminData);
+ }
}
// Update Billing
await UserService.updateUserBilling(ServerAction.USER_UPDATE, req.tenant, req.user, user);
@@ -679,11 +682,9 @@ export default class UserService {
if (newUser.role) {
await UserStorage.saveUserRole(req.tenant, newUser.id, newUser.role);
}
- // Save Technical user flag
- await UserStorage.saveUserTechnicalFlag(req.tenant, newUser.id, newUser.technical);
// Save Admin Data
- if (newUser.plateID || Utils.objectHasProperty(newUser, 'notificationsActive')) {
- const adminData: { plateID?: string; notificationsActive?: boolean; notifications?: UserNotifications } = {};
+ if (newUser.plateID || Utils.objectHasProperty(newUser, 'notificationsActive') || Utils.objectHasProperty(newUser, 'technical')) {
+ const adminData: { plateID?: string; notificationsActive?: boolean; notifications?: UserNotifications, technical?: boolean } = {};
if (newUser.plateID) {
adminData.plateID = newUser.plateID;
}
@@ -693,6 +694,9 @@ export default class UserService {
adminData.notifications = newUser.notifications;
}
}
+ if (Utils.objectHasProperty(newUser, 'technical')) {
+ adminData.technical = newUser.technical;
+ }
// Save User Admin data
await UserStorage.saveUserAdminData(req.tenant, newUser.id, adminData);
}

MODIFY
src/storage/mongodb/UserStorage.ts
src/storage/mongodb/UserStorage.ts
@@ -454,19 +454,6 @@ export default class UserStorage {
await Logging.traceEnd(tenant.id, MODULE_NAME, 'saveUserRole', uniqueTimerID);
}
- public static async saveUserTechnicalFlag(tenant: Tenant, userID: string, flag: boolean): Promise<void> {
- // Debug
- const uniqueTimerID = Logging.traceStart(tenant.id, MODULE_NAME, 'saveUserTechnicalFlag');
- // Check Tenant
- DatabaseUtils.checkTenantObject(tenant);
- // Modify and return the modified document
- await global.database.getCollection<any>(tenant.id, 'users').findOneAndUpdate(
- { '_id': DatabaseUtils.convertToObjectID(userID) },
- { $set: { technical: flag === true } });
- // Debug
- await Logging.traceEnd(tenant.id, MODULE_NAME, 'saveUserTechnicalFlag', uniqueTimerID);
- }
-
public static async saveUserEULA(tenant: Tenant, userID: string,
params: { eulaAcceptedHash: string; eulaAcceptedOn: Date; eulaAcceptedVersion: number }): Promise<void> {
// Debug
@@ -496,7 +483,7 @@ export default class UserStorage {
}
public static async saveUserAdminData(tenant: Tenant, userID: string,
- params: { plateID?: string; notificationsActive?: boolean; notifications?: UserNotifications }): Promise<void> {
+ params: { plateID?: string; notificationsActive?: boolean; notifications?: UserNotifications, technical?: boolean }): Promise<void> {
// Debug
const uniqueTimerID = Logging.traceStart(tenant.id, MODULE_NAME, 'saveUserAdminData');
// Check Tenant
@@ -513,6 +500,9 @@ export default class UserStorage {
if (Utils.objectHasProperty(params, 'notifications')) {
updatedUserMDB.notifications = params.notifications;
}
+ if (Utils.objectHasProperty(params, 'technical')) {
+ updatedUserMDB.technical = params.technical;
+ }
// Modify and return the modified document
await global.database.getCollection<any>(tenant.id, 'users').findOneAndUpdate(
{ '_id': DatabaseUtils.convertToObjectID(userID) },

no dedicated methods