2020-05-14 10:37:32 +02:00
|
|
|
'use strict';
|
|
|
|
|
2020-07-08 16:35:39 +02:00
|
|
|
const { SUPER_ADMIN_CODE } = require('../services/constants');
|
|
|
|
|
2020-05-14 10:37:32 +02:00
|
|
|
/**
|
|
|
|
* Create a new user model by merging default and specified attributes
|
|
|
|
* @param attributes A partial user object
|
|
|
|
*/
|
|
|
|
function createUser(attributes) {
|
|
|
|
return {
|
|
|
|
roles: [],
|
|
|
|
isActive: false,
|
2020-06-04 10:25:02 +02:00
|
|
|
username: null,
|
2020-05-14 10:37:32 +02:00
|
|
|
...attributes,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-08-08 23:33:39 +02:00
|
|
|
const hasSuperAdminRole = (user) => {
|
|
|
|
return user.roles.filter((role) => role.code === SUPER_ADMIN_CODE).length > 0;
|
2020-07-08 16:35:39 +02:00
|
|
|
};
|
|
|
|
|
2023-02-09 11:35:50 +01:00
|
|
|
const ADMIN_USER_ALLOWED_FIELDS = ['id', 'firstname', 'lastname', 'username'];
|
|
|
|
|
2020-05-14 10:37:32 +02:00
|
|
|
module.exports = {
|
|
|
|
createUser,
|
2020-07-08 16:35:39 +02:00
|
|
|
hasSuperAdminRole,
|
2023-02-09 11:35:50 +01:00
|
|
|
ADMIN_USER_ALLOWED_FIELDS,
|
2020-05-14 10:37:32 +02:00
|
|
|
};
|