Ticket : Refactor Ticket::userIsAllowInProject use entity + fix test

pull/4020/head^2
Julio 4 years ago
parent e7f2a1ac63
commit 4b65b7a58e
  1. 25
      public/main/inc/lib/TicketManager.php
  2. 2
      public/main/inc/lib/template.lib.php
  3. 2
      public/main/ticket/ticket_details.php
  4. 2
      public/main/ticket/tickets.php
  5. 2
      src/CoreBundle/EventListener/TwigListener.php
  6. 1
      tests/CoreBundle/Controller/Admin/PluginControllerTest.php

@ -8,6 +8,7 @@ use Chamilo\CoreBundle\Entity\TicketMessageAttachment;
use Chamilo\CoreBundle\Entity\TicketPriority;
use Chamilo\CoreBundle\Entity\TicketProject;
use Chamilo\CoreBundle\Entity\TicketStatus;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CLp;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@ -862,7 +863,7 @@ class TicketManager
";
$projectId = (int) $_GET['project_id'];
$userIsAllowInProject = self::userIsAllowInProject($userInfo, $projectId);
$userIsAllowInProject = self::userIsAllowInProject(api_get_user_entity($userId), $projectId);
// Check if a role was set to the project
if (false == $userIsAllowInProject) {
@ -1058,7 +1059,8 @@ class TicketManager
// Check if a role was set to the project
if (!empty($allowRoleList) && is_array($allowRoleList)) {
if (!in_array($userInfo['status'], $allowRoleList)) {
$allowed = self::userIsAllowInProject(api_get_user_entity(), $projectId);
if (!$allowed) {
$sql .= " AND (ticket.assigned_last_user = $userId OR ticket.sys_insert_user_id = $userId )";
}
} else {
@ -2421,25 +2423,28 @@ class TicketManager
}
/**
* @param array $userInfo
* @param int $projectId
*
* @return bool
*/
public static function userIsAllowInProject($userInfo, $projectId)
public static function userIsAllowInProject(User $user, $projectId): bool
{
if (api_is_platform_admin()) {
if ($user->hasRole('ROLE_ADMIN')) {
return true;
}
$allowRoleList = self::getAllowedRolesFromProject($projectId);
// Check if a role was set to the project
// Check if a role was set to the project.
// Project 1 is considered the default and is accessible to all users
if (!empty($allowRoleList) && is_array($allowRoleList)) {
if (in_array($userInfo['status'], $allowRoleList)) {
return true;
$result = false;
foreach ($allowRoleList as $role) {
if ($user->hasRole($role)) {
$result = true;
break;
}
}
return $result;
}
return false;

@ -993,7 +993,7 @@ class Template
}
$url = api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$defaultProjectId.'&'.$courseParams;
$allow = TicketManager::userIsAllowInProject(api_get_user_info(), $defaultProjectId);
$allow = TicketManager::userIsAllowInProject(api_get_user_entity(), $defaultProjectId);
if ($allow) {
$rightFloatMenu .= '<div class="help">

@ -131,7 +131,7 @@ if (empty($ticket)) {
api_not_allowed(true);
}
$projectId = (int) $ticket['ticket']['project_id'];
$userIsAllowInProject = TicketManager::userIsAllowInProject($userInfo, $projectId);
$userIsAllowInProject = TicketManager::userIsAllowInProject(api_get_user_entity(), $projectId);
$allowEdition = $ticket['ticket']['assigned_last_user'] == $user_id
|| $ticket['ticket']['sys_insert_user_id']
== $user_id

@ -131,7 +131,7 @@ if (empty($projectId)) {
}
$currentUrl = api_get_self().'?project_id='.$projectId;
$isAllow = TicketManager::userIsAllowInProject(api_get_user_info(), $projectId);
$isAllow = TicketManager::userIsAllowInProject(api_get_user_entity(), $projectId);
$actionRight = '';
Display::display_header(get_lang('My tickets'));

@ -55,7 +55,7 @@ class TwigListener
'groups' => ['user_json:read'],
]);
$isAuth = true;
$userIsAllowedInProject = TicketManager::userIsAllowInProject(['status' => $userClone->getStatus()], 1);
$userIsAllowedInProject = TicketManager::userIsAllowInProject($userClone, 1);
}
}

@ -20,7 +20,6 @@ class PluginControllerTest extends WebTestCase
$client->loginUser($admin);
$client->request('GET', '/plugins/');
$this->assertResponseIsSuccessful();
$content = (string) $client->getResponse()->getContent();

Loading…
Cancel
Save