@extrahorizon/exh-cli 1.8.2-feat-80-7fb183f → 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.
- package/build/commands/tasks/util.js +12 -12
- package/package.json +1 -1
|
@@ -74,34 +74,34 @@ async function syncFunctionUser(sdk, data) {
|
|
|
74
74
|
}
|
|
75
75
|
exports.syncFunctionUser = syncFunctionUser;
|
|
76
76
|
async function syncRoleWithPermissions(sdk, taskName, roleName, targetPermissions) {
|
|
77
|
-
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
|
+
}
|
|
78
81
|
let role = await userRepository.findGlobalRoleByName(sdk, roleName);
|
|
79
82
|
if (!role) {
|
|
80
|
-
console.log(chalk.white('⚙️
|
|
83
|
+
console.log(chalk.white('⚙️ Creating the new role...'));
|
|
81
84
|
const roleDescription = `A role created by the CLI for the execution of the task ${taskName}`;
|
|
82
85
|
role = await userRepository.createGlobalRole(sdk, roleName, roleDescription);
|
|
83
|
-
console.log(chalk.white('
|
|
84
|
-
if (targetPermissions.length === 0) {
|
|
85
|
-
console.log(chalk.yellow('⚠️ No permissions defined for the role'));
|
|
86
|
-
return role;
|
|
87
|
-
}
|
|
86
|
+
console.log(chalk.white('✅ Successfully created the role'));
|
|
88
87
|
await userRepository.addPermissionsToGlobalRole(sdk, roleName, targetPermissions);
|
|
89
|
-
console.log(chalk.
|
|
88
|
+
console.log(chalk.white(`🔐 Permissions added: [${targetPermissions.join(',')}]`));
|
|
89
|
+
console.groupEnd();
|
|
90
90
|
return role;
|
|
91
91
|
}
|
|
92
92
|
const currentPermissions = role.permissions?.flatMap(permission => permission.name) || [];
|
|
93
93
|
const permissionsToAdd = targetPermissions.filter(targetPermission => !currentPermissions.includes(targetPermission));
|
|
94
94
|
const permissionsToRemove = currentPermissions.filter(currentPermission => !targetPermissions.includes(currentPermission));
|
|
95
95
|
if (permissionsToAdd.length > 0) {
|
|
96
|
-
console.log(chalk.white('⚙️ Adding missing permissions to the role'));
|
|
97
96
|
await userRepository.addPermissionsToGlobalRole(sdk, roleName, permissionsToAdd);
|
|
98
|
-
console.log(chalk.green(
|
|
97
|
+
console.log(chalk.green(`+ Added permissions to the role: [${permissionsToAdd.join(',')}]`));
|
|
99
98
|
}
|
|
100
99
|
if (permissionsToRemove.length > 0) {
|
|
101
|
-
console.log(chalk.white('⚙️ Removing excess permissions from the role'));
|
|
102
100
|
await userRepository.removePermissionsFromGlobalRole(sdk, roleName, permissionsToRemove);
|
|
103
|
-
console.log(chalk.
|
|
101
|
+
console.log(chalk.white(`🔐 Permissions removed: [${permissionsToRemove.join(',')}]`));
|
|
104
102
|
}
|
|
103
|
+
console.groupEnd();
|
|
104
|
+
console.log(chalk.green('✅ Successfully synced role'));
|
|
105
105
|
return role;
|
|
106
106
|
}
|
|
107
107
|
async function assignRoleToUser(sdk, userId, roleId) {
|