Ticket: Refactoring userIsAllowInProject to use current user

pull/4690/head
Angel Fernando Quiroz Campos 2 years ago
parent 4ff20f8866
commit beeb8d47d9
  1. 17
      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/Controller/PlatformConfigurationController.php
  6. 2
      src/CoreBundle/EventListener/TwigListener.php

@ -863,7 +863,7 @@ class TicketManager
";
$projectId = (int) $_GET['project_id'];
$userIsAllowInProject = self::userIsAllowInProject(api_get_user_entity($userId), $projectId);
$userIsAllowInProject = self::userIsAllowInProject($projectId);
// Check if a role was set to the project
if (false == $userIsAllowInProject) {
@ -1059,7 +1059,7 @@ class TicketManager
// Check if a role was set to the project
if (!empty($allowRoleList) && is_array($allowRoleList)) {
$allowed = self::userIsAllowInProject(api_get_user_entity(), $projectId);
$allowed = self::userIsAllowInProject($projectId);
if (!$allowed) {
$sql .= " AND (ticket.assigned_last_user = $userId OR ticket.sys_insert_user_id = $userId )";
}
@ -2422,12 +2422,11 @@ class TicketManager
}
}
/**
* @param int $projectId
*/
public static function userIsAllowInProject(User $user, $projectId): bool
public static function userIsAllowInProject(int $projectId): bool
{
if ($user->hasRole('ROLE_ADMIN')) {
$authorizationChecked = Container::getAuthorizationChecker();
if ($authorizationChecked->isGranted('ROLE_ADMIN')) {
return true;
}
@ -2435,10 +2434,10 @@ class TicketManager
// 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 (!empty($allowRoleList)) {
$result = false;
foreach ($allowRoleList as $role) {
if ($user->hasRole($role)) {
if ($authorizationChecked->isGranted($role)) {
$result = true;
break;
}

@ -992,7 +992,7 @@ class Template
}
$url = api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$defaultProjectId.'&'.$courseParams;
$allow = TicketManager::userIsAllowInProject(api_get_user_entity(), $defaultProjectId);
$allow = TicketManager::userIsAllowInProject($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(api_get_user_entity(), $projectId);
$userIsAllowInProject = TicketManager::userIsAllowInProject($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_entity(), $projectId);
$isAllow = TicketManager::userIsAllowInProject($projectId);
$actionRight = '';
Display::display_header(get_lang('My tickets'));

@ -62,7 +62,7 @@ class PlatformConfigurationController extends AbstractController
$configuration['settings']['display.show_link_ticket_notification'] = 'false';
if (!empty($user)) {
$userIsAllowedInProject = TicketManager::userIsAllowInProject($user, 1);
$userIsAllowedInProject = TicketManager::userIsAllowInProject(1);
if ($userIsAllowedInProject
&& 'true' === $settingsManager->getSetting('display.show_link_ticket_notification')

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

Loading…
Cancel
Save