From c55122bd08bc1a6e89ebdaf9689664a32e1fd790 Mon Sep 17 00:00:00 2001 From: christianbeeznst Date: Sat, 13 Jul 2024 13:33:46 -0500 Subject: [PATCH] Internal: Rename ROLE_RRHH to ROLE_HR and update user.roles migration - refs #5660 --- assets/vue/store/securityStore.js | 2 +- config/packages/security.yaml | 2 +- public/main/inc/lib/TicketManager.php | 2 +- public/main/inc/lib/api.lib.php | 4 +- .../DataFixtures/PermissionFixtures.php | 2 +- src/CoreBundle/Entity/User.php | 4 +- .../Schema/V200/Version20240713125400.php | 66 +++++++++++++++++++ src/CoreBundle/Repository/GroupRepository.php | 2 +- .../Repository/SessionRepository.php | 2 +- .../ServiceHelper/TicketProjectHelper.php | 2 +- ...CategorizedExerciseResultStateProvider.php | 2 +- src/LtiBundle/Controller/CourseController.php | 2 +- src/LtiBundle/Util/Utils.php | 2 +- .../Repository/Node/UserRepositoryTest.php | 4 +- .../Repository/SessionRepositoryTest.php | 2 +- 15 files changed, 83 insertions(+), 17 deletions(-) create mode 100644 src/CoreBundle/Migrations/Schema/V200/Version20240713125400.php diff --git a/assets/vue/store/securityStore.js b/assets/vue/store/securityStore.js index cc03441eb8..18530326ab 100644 --- a/assets/vue/store/securityStore.js +++ b/assets/vue/store/securityStore.js @@ -20,7 +20,7 @@ export const useSecurityStore = defineStore("security", () => { const isStudentBoss = computed(() => hasRole.value("ROLE_STUDENT_BOSS")) - const isHRM = computed(() => hasRole.value("ROLE_RRHH")) + const isHRM = computed(() => hasRole.value("ROLE_HR")) const isTeacher = computed(() => (isAdmin.value ? true : hasRole.value("ROLE_TEACHER"))) diff --git a/config/packages/security.yaml b/config/packages/security.yaml index fece317940..4adfcabd9d 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -45,7 +45,7 @@ security: ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] # Admin that can log in as another user. ROLE_GLOBAL_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] # The user that installed the platform. ROLE_TEACHER: [ROLE_STUDENT] - ROLE_RRHH: [ROLE_TEACHER, ROLE_ALLOWED_TO_SWITCH] + ROLE_HR: [ROLE_TEACHER, ROLE_ALLOWED_TO_SWITCH] ROLE_QUESTION_MANAGER: [ROLE_STUDENT] ROLE_SESSION_MANAGER: [ROLE_STUDENT, ROLE_ALLOWED_TO_SWITCH] ROLE_STUDENT_BOSS: [ROLE_STUDENT] diff --git a/public/main/inc/lib/TicketManager.php b/public/main/inc/lib/TicketManager.php index 31693e683a..16a8dc0efe 100644 --- a/public/main/inc/lib/TicketManager.php +++ b/public/main/inc/lib/TicketManager.php @@ -2468,7 +2468,7 @@ class TicketManager $roleMap = [ 1 => 'ROLE_TEACHER', 17 => 'ROLE_STUDENT_BOSS', - 4 => 'ROLE_RRHH', + 4 => 'ROLE_HR', 3 => 'ROLE_SESSION_MANAGER', // ... other mappings can be added as needed ]; diff --git a/public/main/inc/lib/api.lib.php b/public/main/inc/lib/api.lib.php index 8f6d6578ce..a763ef8a97 100644 --- a/public/main/inc/lib/api.lib.php +++ b/public/main/inc/lib/api.lib.php @@ -2886,7 +2886,7 @@ function api_is_platform_admin($allowSessionAdmins = false, $allowDrh = false) return true; } - if ($allowDrh && $currentUser->hasRole('ROLE_RRHH')) { + if ($allowDrh && $currentUser->hasRole('ROLE_HR')) { return true; } @@ -3155,7 +3155,7 @@ function api_is_session_admin(?User $user = null) */ function api_is_drh() { - return api_user_has_role('ROLE_RRHH'); + return api_user_has_role('ROLE_HR'); } /** diff --git a/src/CoreBundle/DataFixtures/PermissionFixtures.php b/src/CoreBundle/DataFixtures/PermissionFixtures.php index 1a2619cccb..7a15f715a6 100644 --- a/src/CoreBundle/DataFixtures/PermissionFixtures.php +++ b/src/CoreBundle/DataFixtures/PermissionFixtures.php @@ -157,7 +157,7 @@ class PermissionFixtures extends Fixture implements FixtureGroupInterface 'ROLE_ADMIN' => 'ADM', 'ROLE_SUPER_ADMIN' => 'SUA', 'ROLE_GLOBAL_ADMIN' => 'GLO', - 'ROLE_RRHH' => 'HRM', + 'ROLE_HR' => 'HRM', 'ROLE_QUESTION_MANAGER' => 'QBM', 'ROLE_SESSION_MANAGER' => 'SSM', 'ROLE_STUDENT_BOSS' => 'STB', diff --git a/src/CoreBundle/Entity/User.php b/src/CoreBundle/Entity/User.php index 1e699b5930..35d5064f85 100644 --- a/src/CoreBundle/Entity/User.php +++ b/src/CoreBundle/Entity/User.php @@ -1743,7 +1743,7 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso return match ($status) { COURSEMANAGER => 'ROLE_TEACHER', STUDENT => 'ROLE_STUDENT', - DRH => 'ROLE_RRHH', + DRH => 'ROLE_HR', SESSIONADMIN => 'ROLE_SESSION_MANAGER', STUDENT_BOSS => 'ROLE_STUDENT_BOSS', INVITEE => 'ROLE_INVITEE', @@ -1949,7 +1949,7 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso public function isHRM(): bool { - return $this->hasRole('ROLE_RRHH'); + return $this->hasRole('ROLE_HR'); } public function getStatus(): int diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20240713125400.php b/src/CoreBundle/Migrations/Schema/V200/Version20240713125400.php new file mode 100644 index 0000000000..11533daa04 --- /dev/null +++ b/src/CoreBundle/Migrations/Schema/V200/Version20240713125400.php @@ -0,0 +1,66 @@ +connection; + + $users = $conn->fetchAllAssociative("SELECT id, roles FROM user WHERE roles LIKE '%ROLE_RRHH%'"); + + foreach ($users as $user) { + $roles = unserialize($user['roles']); + + if ($roles !== false) { + $updatedRoles = array_map(function ($role) { + return $role === 'ROLE_RRHH' ? 'ROLE_HR' : $role; + }, $roles); + + $newRolesSerialized = serialize($updatedRoles); + $conn->executeUpdate( + 'UPDATE user SET roles = ? WHERE id = ?', + [$newRolesSerialized, $user['id']] + ); + + } + } + } + + public function down(Schema $schema): void + { + $conn = $this->connection; + + $users = $conn->fetchAllAssociative("SELECT id, roles FROM user WHERE roles LIKE '%ROLE_HR%'"); + + foreach ($users as $user) { + $roles = unserialize($user['roles']); + + if ($roles !== false) { + $updatedRoles = array_map(function ($role) { + return $role === 'ROLE_HR' ? 'ROLE_RRHH' : $role; + }, $roles); + + $newRolesSerialized = serialize($updatedRoles); + + $conn->executeUpdate( + 'UPDATE user SET roles = ? WHERE id = ?', + [$newRolesSerialized, $user['id']] + ); + } + } + } +} diff --git a/src/CoreBundle/Repository/GroupRepository.php b/src/CoreBundle/Repository/GroupRepository.php index 0012b7a0d1..aed34a2763 100644 --- a/src/CoreBundle/Repository/GroupRepository.php +++ b/src/CoreBundle/Repository/GroupRepository.php @@ -66,7 +66,7 @@ class GroupRepository extends ServiceEntityRepository [ 'code' => 'RRHH', 'title' => 'Human resources manager', - 'roles' => ['ROLE_RRHH'], + 'roles' => ['ROLE_HR'], ], [ 'code' => 'SESSION_MANAGER', diff --git a/src/CoreBundle/Repository/SessionRepository.php b/src/CoreBundle/Repository/SessionRepository.php index 3be808cb0f..4b99057cff 100644 --- a/src/CoreBundle/Repository/SessionRepository.php +++ b/src/CoreBundle/Repository/SessionRepository.php @@ -221,7 +221,7 @@ class SessionRepository extends ServiceEntityRepository switch ($relationType) { case Session::DRH: - if ($user->hasRole('ROLE_RRHH')) { + if ($user->hasRole('ROLE_HR')) { $session->addUserInSession(Session::DRH, $user); } diff --git a/src/CoreBundle/ServiceHelper/TicketProjectHelper.php b/src/CoreBundle/ServiceHelper/TicketProjectHelper.php index 98e46b844e..83e7ec083f 100644 --- a/src/CoreBundle/ServiceHelper/TicketProjectHelper.php +++ b/src/CoreBundle/ServiceHelper/TicketProjectHelper.php @@ -51,7 +51,7 @@ class TicketProjectHelper $roleMap = [ 1 => 'ROLE_TEACHER', 17 => 'ROLE_STUDENT_BOSS', - 4 => 'ROLE_RRHH', + 4 => 'ROLE_HR', 3 => 'ROLE_SESSION_MANAGER', // ... other mappings can be added as needed ]; diff --git a/src/CoreBundle/State/CategorizedExerciseResultStateProvider.php b/src/CoreBundle/State/CategorizedExerciseResultStateProvider.php index 659c5bb345..d3e1c75357 100644 --- a/src/CoreBundle/State/CategorizedExerciseResultStateProvider.php +++ b/src/CoreBundle/State/CategorizedExerciseResultStateProvider.php @@ -436,7 +436,7 @@ class CategorizedExerciseResultStateProvider implements ProviderInterface private function isAllowedToSeeResults(): bool { $isStudentBoss = $this->security->isGranted('ROLE_STUDENT_BOSS'); - $isHRM = $this->security->isGranted('ROLE_RRHH'); + $isHRM = $this->security->isGranted('ROLE_HR'); $isSessionAdmin = $this->security->isGranted('ROLE_SESSION_MANAGER'); $isCourseTutor = $this->security->isGranted('ROLE_CURRENT_COURSE_SESSION_TEACHER'); $isAllowedToEdit = api_is_allowed_to_edit(null, true); diff --git a/src/LtiBundle/Controller/CourseController.php b/src/LtiBundle/Controller/CourseController.php index e2ed25aca0..f165cba7fd 100644 --- a/src/LtiBundle/Controller/CourseController.php +++ b/src/LtiBundle/Controller/CourseController.php @@ -211,7 +211,7 @@ class CourseController extends ToolBaseController $params['lis_person_contact_email_primary'] = $user->getEmail(); } - if ($user->hasRole('ROLE_RRHH')) { + if ($user->hasRole('ROLE_HR')) { $scopeMentor = $ltiUtil->generateRoleScopeMentor($user); if (!empty($scopeMentor)) { diff --git a/src/LtiBundle/Util/Utils.php b/src/LtiBundle/Util/Utils.php index 155216f8cb..da9adcd7ea 100644 --- a/src/LtiBundle/Util/Utils.php +++ b/src/LtiBundle/Util/Utils.php @@ -56,7 +56,7 @@ class Utils */ public static function generateUserRoles(User $user) { - if ($user->hasRole('ROLE_RRHH')) { + if ($user->hasRole('ROLE_HR')) { return 'urn:lti:role:ims/lis/Mentor'; } diff --git a/tests/CoreBundle/Repository/Node/UserRepositoryTest.php b/tests/CoreBundle/Repository/Node/UserRepositoryTest.php index 13ede1792e..bcc26ec6df 100644 --- a/tests/CoreBundle/Repository/Node/UserRepositoryTest.php +++ b/tests/CoreBundle/Repository/Node/UserRepositoryTest.php @@ -101,7 +101,7 @@ class UserRepositoryTest extends AbstractApiTest $student = $this->createUser('student'); $drh = $this->createUser('drh'); - $drh->setRoles(['ROLE_RRHH']); + $drh->setRoles(['ROLE_HR']); $userRepo->update($drh); $student->addUserRelUser($drh, UserRelUser::USER_RELATION_TYPE_RRHH); @@ -126,7 +126,7 @@ class UserRepositoryTest extends AbstractApiTest $this->assertSame('ROLE_TEACHER', User::getRoleFromStatus(1)); $this->assertSame('ROLE_STUDENT', User::getRoleFromStatus(5)); - $this->assertSame('ROLE_RRHH', User::getRoleFromStatus(4)); + $this->assertSame('ROLE_HR', User::getRoleFromStatus(4)); $this->assertSame('ROLE_SESSION_MANAGER', User::getRoleFromStatus(3)); $this->assertSame('ROLE_STUDENT_BOSS', User::getRoleFromStatus(17)); $this->assertSame('ROLE_INVITEE', User::getRoleFromStatus(20)); diff --git a/tests/CoreBundle/Repository/SessionRepositoryTest.php b/tests/CoreBundle/Repository/SessionRepositoryTest.php index f99b91c226..2600275b8e 100644 --- a/tests/CoreBundle/Repository/SessionRepositoryTest.php +++ b/tests/CoreBundle/Repository/SessionRepositoryTest.php @@ -275,7 +275,7 @@ class SessionRepositoryTest extends AbstractApiTest $student = $this->createUser('student'); $sessionAdmin = $this->createUser('session_admin'); $generalCoach = $this->createUser('general_coach'); - $drh = $this->createUser('drh', '', '', 'ROLE_RRHH'); + $drh = $this->createUser('drh', '', '', 'ROLE_HR'); $courseCoach = $this->createUser('course_coach', '', '', 'ROLE_TEACHER'); // Add session admin + add course to session.