@extrahorizon/exh-cli 1.8.2-feat-79-bdd67ef → 1.8.2-feat-81-a86c1ff
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -39,10 +39,6 @@ async function syncFunctionUser(sdk, data) {
|
|
|
39
39
|
let user = await userRepository.findUserByEmail(sdk, email);
|
|
40
40
|
if (!user) {
|
|
41
41
|
console.log(chalk.white('⚙️ Creating a user for the task'));
|
|
42
|
-
const isEmailAvailable = await userRepository.isEmailAvailable(sdk, email);
|
|
43
|
-
if (!isEmailAvailable) {
|
|
44
|
-
throw new Error('❌ The user could not be created as the email address is already in use');
|
|
45
|
-
}
|
|
46
42
|
const registerUserData = {
|
|
47
43
|
firstName: `${taskName}`,
|
|
48
44
|
lastName: 'exh.tasks',
|
|
@@ -78,34 +74,34 @@ async function syncFunctionUser(sdk, data) {
|
|
|
78
74
|
}
|
|
79
75
|
exports.syncFunctionUser = syncFunctionUser;
|
|
80
76
|
async function syncRoleWithPermissions(sdk, taskName, roleName, targetPermissions) {
|
|
81
|
-
console.
|
|
77
|
+
console.group(chalk.white(`🔄 Syncing role: ${roleName}`));
|
|
78
|
+
if (targetPermissions.length === 0) {
|
|
79
|
+
console.log(chalk.yellow('⚠️ No permissions have been defined for the role'));
|
|
80
|
+
}
|
|
82
81
|
let role = await userRepository.findGlobalRoleByName(sdk, roleName);
|
|
83
82
|
if (!role) {
|
|
84
|
-
console.log(chalk.white('⚙️
|
|
83
|
+
console.log(chalk.white('⚙️ Creating the new role...'));
|
|
85
84
|
const roleDescription = `A role created by the CLI for the execution of the task ${taskName}`;
|
|
86
85
|
role = await userRepository.createGlobalRole(sdk, roleName, roleDescription);
|
|
87
|
-
console.log(chalk.white('
|
|
88
|
-
if (targetPermissions.length === 0) {
|
|
89
|
-
console.log(chalk.yellow('⚠️ No permissions defined for the role'));
|
|
90
|
-
return role;
|
|
91
|
-
}
|
|
86
|
+
console.log(chalk.white('✅ Successfully created the role'));
|
|
92
87
|
await userRepository.addPermissionsToGlobalRole(sdk, roleName, targetPermissions);
|
|
93
|
-
console.log(chalk.
|
|
88
|
+
console.log(chalk.white(`🔐 Permissions added: [${targetPermissions.join(',')}]`));
|
|
89
|
+
console.groupEnd();
|
|
94
90
|
return role;
|
|
95
91
|
}
|
|
96
92
|
const currentPermissions = role.permissions?.flatMap(permission => permission.name) || [];
|
|
97
93
|
const permissionsToAdd = targetPermissions.filter(targetPermission => !currentPermissions.includes(targetPermission));
|
|
98
94
|
const permissionsToRemove = currentPermissions.filter(currentPermission => !targetPermissions.includes(currentPermission));
|
|
99
95
|
if (permissionsToAdd.length > 0) {
|
|
100
|
-
console.log(chalk.white('⚙️ Adding missing permissions to the role'));
|
|
101
96
|
await userRepository.addPermissionsToGlobalRole(sdk, roleName, permissionsToAdd);
|
|
102
|
-
console.log(chalk.green(
|
|
97
|
+
console.log(chalk.green(`+ Added permissions to the role: [${permissionsToAdd.join(',')}]`));
|
|
103
98
|
}
|
|
104
99
|
if (permissionsToRemove.length > 0) {
|
|
105
|
-
console.log(chalk.white('⚙️ Removing excess permissions from the role'));
|
|
106
100
|
await userRepository.removePermissionsFromGlobalRole(sdk, roleName, permissionsToRemove);
|
|
107
|
-
console.log(chalk.
|
|
101
|
+
console.log(chalk.white(`🔐 Permissions removed: [${permissionsToRemove.join(',')}]`));
|
|
108
102
|
}
|
|
103
|
+
console.groupEnd();
|
|
104
|
+
console.log(chalk.green('✅ Successfully synced role'));
|
|
109
105
|
return role;
|
|
110
106
|
}
|
|
111
107
|
async function assignRoleToUser(sdk, userId, roleId) {
|
|
@@ -7,7 +7,11 @@ async function find(sdk) {
|
|
|
7
7
|
}
|
|
8
8
|
exports.find = find;
|
|
9
9
|
async function findByName(sdk, name) {
|
|
10
|
-
const response = await sdk.raw.get(`/tasks/v1/functions/${name}`, { customResponseKeys: ['*'] })
|
|
10
|
+
const response = await sdk.raw.get(`/tasks/v1/functions/${name}`, { customResponseKeys: ['*'] })
|
|
11
|
+
.catch(e => e);
|
|
12
|
+
if (response.status === 404) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
11
15
|
return response.data;
|
|
12
16
|
}
|
|
13
17
|
exports.findByName = findByName;
|