Internal: Rename ROLE_RRHH to ROLE_HR and update user.roles migration - refs #5660

pull/5662/head
christianbeeznst 4 months ago
parent 1899d81eef
commit c55122bd08
  1. 2
      assets/vue/store/securityStore.js
  2. 2
      config/packages/security.yaml
  3. 2
      public/main/inc/lib/TicketManager.php
  4. 4
      public/main/inc/lib/api.lib.php
  5. 2
      src/CoreBundle/DataFixtures/PermissionFixtures.php
  6. 4
      src/CoreBundle/Entity/User.php
  7. 66
      src/CoreBundle/Migrations/Schema/V200/Version20240713125400.php
  8. 2
      src/CoreBundle/Repository/GroupRepository.php
  9. 2
      src/CoreBundle/Repository/SessionRepository.php
  10. 2
      src/CoreBundle/ServiceHelper/TicketProjectHelper.php
  11. 2
      src/CoreBundle/State/CategorizedExerciseResultStateProvider.php
  12. 2
      src/LtiBundle/Controller/CourseController.php
  13. 2
      src/LtiBundle/Util/Utils.php
  14. 4
      tests/CoreBundle/Repository/Node/UserRepositoryTest.php
  15. 2
      tests/CoreBundle/Repository/SessionRepositoryTest.php

@ -20,7 +20,7 @@ export const useSecurityStore = defineStore("security", () => {
const isStudentBoss = computed(() => hasRole.value("ROLE_STUDENT_BOSS")) 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"))) const isTeacher = computed(() => (isAdmin.value ? true : hasRole.value("ROLE_TEACHER")))

@ -45,7 +45,7 @@ security:
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] # Admin that can log in as another user. 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_GLOBAL_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] # The user that installed the platform.
ROLE_TEACHER: [ROLE_STUDENT] 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_QUESTION_MANAGER: [ROLE_STUDENT]
ROLE_SESSION_MANAGER: [ROLE_STUDENT, ROLE_ALLOWED_TO_SWITCH] ROLE_SESSION_MANAGER: [ROLE_STUDENT, ROLE_ALLOWED_TO_SWITCH]
ROLE_STUDENT_BOSS: [ROLE_STUDENT] ROLE_STUDENT_BOSS: [ROLE_STUDENT]

@ -2468,7 +2468,7 @@ class TicketManager
$roleMap = [ $roleMap = [
1 => 'ROLE_TEACHER', 1 => 'ROLE_TEACHER',
17 => 'ROLE_STUDENT_BOSS', 17 => 'ROLE_STUDENT_BOSS',
4 => 'ROLE_RRHH', 4 => 'ROLE_HR',
3 => 'ROLE_SESSION_MANAGER', 3 => 'ROLE_SESSION_MANAGER',
// ... other mappings can be added as needed // ... other mappings can be added as needed
]; ];

@ -2886,7 +2886,7 @@ function api_is_platform_admin($allowSessionAdmins = false, $allowDrh = false)
return true; return true;
} }
if ($allowDrh && $currentUser->hasRole('ROLE_RRHH')) { if ($allowDrh && $currentUser->hasRole('ROLE_HR')) {
return true; return true;
} }
@ -3155,7 +3155,7 @@ function api_is_session_admin(?User $user = null)
*/ */
function api_is_drh() function api_is_drh()
{ {
return api_user_has_role('ROLE_RRHH'); return api_user_has_role('ROLE_HR');
} }
/** /**

@ -157,7 +157,7 @@ class PermissionFixtures extends Fixture implements FixtureGroupInterface
'ROLE_ADMIN' => 'ADM', 'ROLE_ADMIN' => 'ADM',
'ROLE_SUPER_ADMIN' => 'SUA', 'ROLE_SUPER_ADMIN' => 'SUA',
'ROLE_GLOBAL_ADMIN' => 'GLO', 'ROLE_GLOBAL_ADMIN' => 'GLO',
'ROLE_RRHH' => 'HRM', 'ROLE_HR' => 'HRM',
'ROLE_QUESTION_MANAGER' => 'QBM', 'ROLE_QUESTION_MANAGER' => 'QBM',
'ROLE_SESSION_MANAGER' => 'SSM', 'ROLE_SESSION_MANAGER' => 'SSM',
'ROLE_STUDENT_BOSS' => 'STB', 'ROLE_STUDENT_BOSS' => 'STB',

@ -1743,7 +1743,7 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
return match ($status) { return match ($status) {
COURSEMANAGER => 'ROLE_TEACHER', COURSEMANAGER => 'ROLE_TEACHER',
STUDENT => 'ROLE_STUDENT', STUDENT => 'ROLE_STUDENT',
DRH => 'ROLE_RRHH', DRH => 'ROLE_HR',
SESSIONADMIN => 'ROLE_SESSION_MANAGER', SESSIONADMIN => 'ROLE_SESSION_MANAGER',
STUDENT_BOSS => 'ROLE_STUDENT_BOSS', STUDENT_BOSS => 'ROLE_STUDENT_BOSS',
INVITEE => 'ROLE_INVITEE', INVITEE => 'ROLE_INVITEE',
@ -1949,7 +1949,7 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
public function isHRM(): bool public function isHRM(): bool
{ {
return $this->hasRole('ROLE_RRHH'); return $this->hasRole('ROLE_HR');
} }
public function getStatus(): int public function getStatus(): int

@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;
final class Version20240713125400 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return 'Replace ROLE_RRHH with ROLE_HR in user.roles';
}
public function up(Schema $schema): void
{
$conn = $this->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']]
);
}
}
}
}

@ -66,7 +66,7 @@ class GroupRepository extends ServiceEntityRepository
[ [
'code' => 'RRHH', 'code' => 'RRHH',
'title' => 'Human resources manager', 'title' => 'Human resources manager',
'roles' => ['ROLE_RRHH'], 'roles' => ['ROLE_HR'],
], ],
[ [
'code' => 'SESSION_MANAGER', 'code' => 'SESSION_MANAGER',

@ -221,7 +221,7 @@ class SessionRepository extends ServiceEntityRepository
switch ($relationType) { switch ($relationType) {
case Session::DRH: case Session::DRH:
if ($user->hasRole('ROLE_RRHH')) { if ($user->hasRole('ROLE_HR')) {
$session->addUserInSession(Session::DRH, $user); $session->addUserInSession(Session::DRH, $user);
} }

@ -51,7 +51,7 @@ class TicketProjectHelper
$roleMap = [ $roleMap = [
1 => 'ROLE_TEACHER', 1 => 'ROLE_TEACHER',
17 => 'ROLE_STUDENT_BOSS', 17 => 'ROLE_STUDENT_BOSS',
4 => 'ROLE_RRHH', 4 => 'ROLE_HR',
3 => 'ROLE_SESSION_MANAGER', 3 => 'ROLE_SESSION_MANAGER',
// ... other mappings can be added as needed // ... other mappings can be added as needed
]; ];

@ -436,7 +436,7 @@ class CategorizedExerciseResultStateProvider implements ProviderInterface
private function isAllowedToSeeResults(): bool private function isAllowedToSeeResults(): bool
{ {
$isStudentBoss = $this->security->isGranted('ROLE_STUDENT_BOSS'); $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'); $isSessionAdmin = $this->security->isGranted('ROLE_SESSION_MANAGER');
$isCourseTutor = $this->security->isGranted('ROLE_CURRENT_COURSE_SESSION_TEACHER'); $isCourseTutor = $this->security->isGranted('ROLE_CURRENT_COURSE_SESSION_TEACHER');
$isAllowedToEdit = api_is_allowed_to_edit(null, true); $isAllowedToEdit = api_is_allowed_to_edit(null, true);

@ -211,7 +211,7 @@ class CourseController extends ToolBaseController
$params['lis_person_contact_email_primary'] = $user->getEmail(); $params['lis_person_contact_email_primary'] = $user->getEmail();
} }
if ($user->hasRole('ROLE_RRHH')) { if ($user->hasRole('ROLE_HR')) {
$scopeMentor = $ltiUtil->generateRoleScopeMentor($user); $scopeMentor = $ltiUtil->generateRoleScopeMentor($user);
if (!empty($scopeMentor)) { if (!empty($scopeMentor)) {

@ -56,7 +56,7 @@ class Utils
*/ */
public static function generateUserRoles(User $user) public static function generateUserRoles(User $user)
{ {
if ($user->hasRole('ROLE_RRHH')) { if ($user->hasRole('ROLE_HR')) {
return 'urn:lti:role:ims/lis/Mentor'; return 'urn:lti:role:ims/lis/Mentor';
} }

@ -101,7 +101,7 @@ class UserRepositoryTest extends AbstractApiTest
$student = $this->createUser('student'); $student = $this->createUser('student');
$drh = $this->createUser('drh'); $drh = $this->createUser('drh');
$drh->setRoles(['ROLE_RRHH']); $drh->setRoles(['ROLE_HR']);
$userRepo->update($drh); $userRepo->update($drh);
$student->addUserRelUser($drh, UserRelUser::USER_RELATION_TYPE_RRHH); $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_TEACHER', User::getRoleFromStatus(1));
$this->assertSame('ROLE_STUDENT', User::getRoleFromStatus(5)); $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_SESSION_MANAGER', User::getRoleFromStatus(3));
$this->assertSame('ROLE_STUDENT_BOSS', User::getRoleFromStatus(17)); $this->assertSame('ROLE_STUDENT_BOSS', User::getRoleFromStatus(17));
$this->assertSame('ROLE_INVITEE', User::getRoleFromStatus(20)); $this->assertSame('ROLE_INVITEE', User::getRoleFromStatus(20));

@ -275,7 +275,7 @@ class SessionRepositoryTest extends AbstractApiTest
$student = $this->createUser('student'); $student = $this->createUser('student');
$sessionAdmin = $this->createUser('session_admin'); $sessionAdmin = $this->createUser('session_admin');
$generalCoach = $this->createUser('general_coach'); $generalCoach = $this->createUser('general_coach');
$drh = $this->createUser('drh', '', '', 'ROLE_RRHH'); $drh = $this->createUser('drh', '', '', 'ROLE_HR');
$courseCoach = $this->createUser('course_coach', '', '', 'ROLE_TEACHER'); $courseCoach = $this->createUser('course_coach', '', '', 'ROLE_TEACHER');
// Add session admin + add course to session. // Add session admin + add course to session.

Loading…
Cancel
Save