Add setting "ticket_project_user_roles" see BT#12632

Allow some user roles to have access to ticket projects.
pull/2487/head
jmontoyaa 8 years ago
parent ab69ef6b6a
commit 0e9b9d47c9
  1. 72
      main/inc/lib/TicketManager.php
  2. 6
      main/install/configuration.dist.php
  3. 286
      main/ticket/ticket_details.php
  4. 7
      main/ticket/tickets.php

@ -781,6 +781,7 @@ class TicketManager
$table_support_status = Database::get_main_table(TABLE_TICKET_STATUS);
$direction = !empty($direction) ? $direction : 'DESC';
$userId = !empty($userId) ? $userId : api_get_user_id();
$userInfo = api_get_user_info($userId);
$isAdmin = UserManager::is_admin($userId);
if (!isset($_GET['project_id'])) {
@ -841,7 +842,11 @@ class TicketManager
WHERE 1=1
";
if (!$isAdmin) {
$projectId = (int) $_GET['project_id'];
$userIsAllowInProject = self::userIsAllowInProject($userInfo, $projectId);
// Check if a role was set to the project
if ($userIsAllowInProject == false) {
$sql .= " AND (ticket.assigned_last_user = $userId OR ticket.sys_insert_user_id = $userId )";
}
@ -980,7 +985,7 @@ class TicketManager
/**
* @param int $userId
* @return mixed
* @return int
*/
public static function get_total_tickets_by_user_id($userId = 0)
{
@ -989,7 +994,11 @@ class TicketManager
$table_support_priority = Database::get_main_table(TABLE_TICKET_PRIORITY);
$table_support_status = Database::get_main_table(TABLE_TICKET_STATUS);
$userId = api_get_user_id();
$userInfo = api_get_user_info();
if (empty($userInfo)) {
return 0;
}
$userId = $userInfo['id'];
if (!isset($_GET['project_id'])) {
return 0;
@ -1005,9 +1014,19 @@ class TicketManager
ON (ticket.status_id = status.id)
WHERE 1 = 1";
$projectId = (int) $_GET['project_id'];
$allowRoleList = self::getAllowedRolesFromProject($projectId);
// Check if a role was set to the project
if (!empty($allowRoleList) && is_array($allowRoleList)) {
if (!in_array($userInfo['status'], $allowRoleList)) {
$sql .= " AND (ticket.assigned_last_user = $userId OR ticket.sys_insert_user_id = $userId )";
}
} else {
if (!api_is_platform_admin()) {
$sql .= " AND (ticket.assigned_last_user = $userId OR ticket.sys_insert_user_id = $userId )";
}
}
// Search simple
if (isset($_GET['submit_simple'])) {
@ -1066,7 +1085,7 @@ class TicketManager
$res = Database::query($sql);
$obj = Database::fetch_object($res);
return $obj->total;
return (int)$obj->total;
}
/**
@ -1140,10 +1159,8 @@ class TicketManager
$webPath = api_get_path(WEB_CODE_PATH);
while ($row = Database::fetch_assoc($result)) {
$message = $row;
$completeName = api_get_person_name($row['firstname'], $row['lastname']);
$href = $webPath.'main/admin/user_information.php?user_id='.$row['user_id'];
$message['admin'] = UserManager::is_admin($message['user_id']);
$message['user_created'] = "<a href='$href'> $completeName </a>";
$message['user_info'] = api_get_user_info($message['user_id']);
$sql = "SELECT *
FROM $table_support_message_attachments
WHERE
@ -2252,4 +2269,45 @@ class TicketManager
Database::query($sql);
}
}
/**
* @param array $userInfo
* @param int $projectId
*
* @return bool
*/
public static function userIsAllowInProject($userInfo, $projectId)
{
if (api_is_platform_admin()) {
return true;
}
$allowRoleList = self::getAllowedRolesFromProject($projectId);
// Check if a role was set to the project
if (!empty($allowRoleList) && is_array($allowRoleList)) {
if (in_array($userInfo['status'], $allowRoleList)) {
return true;
}
}
return false;
}
/**
* @param int $projectId
* @todo load from database instead of configuration.php setting
* @return array
*/
public static function getAllowedRolesFromProject($projectId)
{
$options = api_get_configuration_value('ticket_project_user_roles');
if ($options) {
if (isset($options['permissions'][$projectId])) {
return $options['permissions'][$projectId];
}
}
return [];
}
}

@ -500,3 +500,9 @@ $_configuration['send_all_emails_to'] = [
// Add option in exercise to show or hide the "previous" button.
// ALTER TABLE c_quiz ADD show_previous_button TINYINT(1) DEFAULT 1;
//$_configuration['allow_quiz_show_previous_button_setting'] = false;
// Allow ticket projects to be access by specific chamilo roles
/*$_configuration['ticket_project_user_roles'] = [
'permissions' => [
1 => [17] // project_id = 1, STUDENT_BOSS = 17
]
];*/

@ -123,14 +123,14 @@ $htmlHeadXtra[] = '<style>
$ticket_id = $_GET['ticket_id'];
$ticket = TicketManager::get_ticket_detail_by_id($ticket_id);
if (!isset($ticket['ticket'])) {
api_not_allowed();
api_not_allowed(true);
}
if (!isset($_GET['ticket_id'])) {
header('Location: '.api_get_path(WEB_CODE_PATH).'ticket/tickets.php');
exit;
}
if (isset($_POST['response'])) {
/*if (isset($_POST['response'])) {
if ($user_id == $ticket['ticket']['assigned_last_user'] || api_is_platform_admin()) {
$response = $_POST['response'] === '1' ? true : false;
$newStatus = TicketManager::STATUS_PENDING;
@ -145,113 +145,23 @@ if (isset($_POST['response'])) {
Display::addFlash(Display::return_message(get_lang('Updated')));
header("Location:".api_get_self()."?ticket_id=".$ticket_id);
exit;
}
}
}*/
$title = 'Ticket #'.$ticket['ticket']['code'];
if (!isset($_POST['compose'])) {
if (isset($_REQUEST['close'])) {
if (isset($_REQUEST['close'])) {
TicketManager::close_ticket($_REQUEST['ticket_id'], $user_id);
$ticket['ticket']['status_id'] = TicketManager::STATUS_CLOSE;
$ticket['ticket']['status'] = get_lang('Closed');
}
Display::display_header();
$projectId = $ticket['ticket']['project_id'];
echo '<div class="actions">';
echo Display::url(
Display::return_icon('back.png', get_lang('Tickets'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$projectId
);
echo '</div>';
$bold = '';
if ($ticket['ticket']['status_id'] == TicketManager::STATUS_CLOSE) {
$bold = 'style = "font-weight: bold;"';
echo "<style>
#confirmticket {
display: none;
}
</style>";
}
if ($isAdmin) {
$senderData = get_lang('AddedBy').' '.$ticket['ticket']['user_url'].' ('.$ticket['usuario']['username'].').';
} else {
$senderData = get_lang('AddedBy').' '.$ticket['usuario']['complete_name'].' ('.$ticket['usuario']['username'].').';
}
echo '<table width="100%" >
<tr>
<td colspan="3">
<h1>'.$title.'</h1>
<h2>'.$ticket['ticket']['subject'].'</h2>
<p>
'.$senderData.' '.
get_lang('Created').' '.
Display::url(
date_to_str_ago($ticket['ticket']['start_date_from_db']),
'#',
['title' => $ticket['ticket']['start_date'], 'class' => 'boot-tooltip']
).'. '.
get_lang('TicketUpdated').' '.
Display::url(
date_to_str_ago($ticket['ticket']['sys_lastedit_datetime_from_db']),
'#',
['title' => $ticket['ticket']['sys_lastedit_datetime'], 'class' => 'boot-tooltip']
).'
</p>
</td>
</tr>
<tr>
<td><p><b>' . get_lang('Category').': </b>'.$ticket['ticket']['name'].'</p></td>
</tr>
<tr>
<td><p ' . $bold.'><b>'.get_lang('Status').':</b> '.$ticket['ticket']['status'].'</p></td>
</tr>
<tr>
<td><p><b>' . get_lang('Priority').': </b>'.$ticket['ticket']['priority'].'<p></td>
</tr>';
if (!empty($ticket['ticket']['assigned_last_user'])) {
$assignedUser = api_get_user_info($ticket['ticket']['assigned_last_user']);
echo '<tr>
<td><p><b>' . get_lang('AssignedTo').': </b>'.$assignedUser['complete_name'].'<p></td>
</tr>';
} else {
echo '<tr>
<td><p><b>' . get_lang('AssignedTo').': </b>-<p></td>
</tr>';
}
if ($ticket['ticket']['course_url'] != null) {
if (!empty($ticket['ticket']['session_id'])) {
$sessionInfo = api_get_session_info($ticket['ticket']['session_id']);
echo '<tr>
<td><b>' . get_lang('Session').':</b> '.$sessionInfo['name'].' </td>
<td></td>
<td colspan="2"></td>
</tr>';
}
}
echo '<tr>
<td><b>' . get_lang('Course').':</b> '.$ticket['ticket']['course_url'].' </td>
<td></td>
<td colspan="2"></td>
</tr>';
}
echo '<tr>
<td>
<hr />
<b>' . get_lang('Description').':</b> <br />
'.$ticket['ticket']['message'].'
<hr />
</td>
</tr>
';
echo '</table>';
$messages = $ticket['messages'];
$counter = 1;
foreach ($messages as $message) {
$projectId = $ticket['ticket']['project_id'];
$messages = $ticket['messages'];
$counter = 1;
$messageToShow = '';
$formToShow = '';
foreach ($messages as $message) {
$date = Display::url(
date_to_str_ago($message['sys_insert_datetime']),
'#',
@ -279,45 +189,43 @@ if (!isset($_POST['compose'])) {
$entireMessage = $receivedMessage.$attachmentLinks;
$counterLink = Display::url('#'.$counter, api_get_self().'?ticket_id='.$ticket_id.'#note-'.$counter);
echo '<a id="note-'.$counter.'"> </a><h4>'.sprintf(get_lang('UpdatedByX'), $message['user_created']).' '.$date.
' <span class="pull-right">'.$counterLink.'</span></h4>';
echo '<hr />';
$messageToShow .= '<a id="note-'.$counter.'"> </a><h4>'.sprintf(
get_lang('UpdatedByX'),
$message['user_info']['complete_name_with_message_link']
);
$messageToShow .= ' '.$date.' <span class="pull-right">'.$counterLink.'</span></h4>';
$messageToShow .= '<hr />';
if (!empty($entireMessage)) {
echo Display::div(
$messageToShow .= Display::div(
$entireMessage,
['class' => 'well']
);
}
$counter++;
}
}
$subject = get_lang('ReplyShort').': '.$ticket['ticket']['subject'];
$subject = get_lang('ReplyShort').': '.$ticket['ticket']['subject'];
if ($ticket['ticket']['status_id'] != TicketManager::STATUS_FORWARDED &&
if ($ticket['ticket']['status_id'] != TicketManager::STATUS_FORWARDED &&
$ticket['ticket']['status_id'] != TicketManager::STATUS_CLOSE
) {
if (!$isAdmin && $ticket['ticket']['status_id'] != TicketManager::STATUS_UNCONFIRMED) {
show_form_send_message($ticket['ticket']);
} else {
) {
if ($ticket['ticket']['assigned_last_user'] == $user_id ||
$ticket['ticket']['sys_insert_user_id'] == $user_id ||
$isAdmin
) {
show_form_send_message($ticket['ticket']);
}
}
}
$form = getForm($ticket['ticket']);
$formToShow = $form->returnForm();
Display::display_footer();
} else {
if ($form->validate()) {
$ticket_id = $_POST['ticket_id'];
$content = $_POST['content'];
$messageToSend = '';
$subject = $_POST['subject'];
$message = isset($_POST['confirmation']) ? true : false;
$file_attachments = $_FILES;
$user_id = api_get_user_id();
if ($isAdmin) {
$oldUserId = $ticket['ticket']['assigned_last_user'];
@ -331,13 +239,15 @@ if (!isset($_POST['compose'])) {
$oldUserName = '-';
if (!empty($oldUserId)) {
$oldUserInfo = api_get_user_info($oldUserId);
$oldUserName = $oldUserInfo['complete_name'];
$oldUserName = $oldUserInfo['complete_name_with_message_link'];
}
$userCompleteName = '-';
if (!empty($_POST['assigned_last_user'])) {
$userInfo = api_get_user_info($_POST['assigned_last_user']);
$userCompleteName = $userInfo['complete_name'];
$userInfo = api_get_user_info(
$_POST['assigned_last_user']
);
$userCompleteName = $userInfo['complete_name_with_message_link'];
}
$messageToSend .= sprintf(
@ -357,12 +267,16 @@ if (!isset($_POST['compose'])) {
);
if ($_POST['priority_id'] != $ticket['ticket']['priority_id']) {
$newPriority = TicketManager::getPriority($_POST['priority_id']);
$newPriority = TicketManager::getPriority(
$_POST['priority_id']
);
$newPriorityTitle = '-';
if ($newPriority) {
$newPriorityTitle = $newPriority->getName();
}
$oldPriority = TicketManager::getPriority($ticket['ticket']['priority_id']);
$oldPriority = TicketManager::getPriority(
$ticket['ticket']['priority_id']
);
$oldPriorityTitle = '-';
if ($oldPriority) {
$oldPriorityTitle = $oldPriority->getName();
@ -375,12 +289,16 @@ if (!isset($_POST['compose'])) {
}
if ($_POST['status_id'] != $ticket['ticket']['status_id']) {
$newStatus = TicketManager::getStatus($_POST['status_id']);
$newStatus = TicketManager::getStatus(
$_POST['status_id']
);
$newTitle = '-';
if ($newStatus) {
$newTitle = $newStatus->getName();
}
$oldStatus = TicketManager::getStatus($ticket['ticket']['status_id']);
$oldStatus = TicketManager::getStatus(
$ticket['ticket']['status_id']
);
$oldStatusTitle = '-';
if ($oldStatus) {
$oldStatusTitle = $oldStatus->getName();
@ -415,14 +333,110 @@ if (!isset($_POST['compose'])) {
Display::addFlash(Display::return_message(get_lang('Saved')));
header("Location:".api_get_self()."?ticket_id=".$ticket_id);
exit;
}
}
}
Display::display_header();
echo '<div class="actions">';
echo Display::url(
Display::return_icon('back.png', get_lang('Tickets'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$projectId
);
echo '</div>';
$bold = '';
if ($ticket['ticket']['status_id'] == TicketManager::STATUS_CLOSE) {
$bold = 'style = "font-weight: bold;"';
}
if ($isAdmin) {
$senderData = get_lang('AddedBy').' '.$ticket['ticket']['user_url'].' ('.$ticket['usuario']['complete_name_with_message_link'].').';
} else {
$senderData = get_lang('AddedBy').' '.$ticket['usuario']['complete_name_with_message_link'].' ('.$ticket['usuario']['username'].').';
}
echo '<table width="100%" >
<tr>
<td colspan="3">
<h1>'.$title.'</h1>
<h2>'.$ticket['ticket']['subject'].'</h2>
<p>
'.$senderData.' '.
get_lang('Created').' '.
Display::url(
date_to_str_ago($ticket['ticket']['start_date_from_db']),
'#',
['title' => $ticket['ticket']['start_date'], 'class' => 'boot-tooltip']
).'. '.
get_lang('TicketUpdated').' '.
Display::url(
date_to_str_ago($ticket['ticket']['sys_lastedit_datetime_from_db']),
'#',
['title' => $ticket['ticket']['sys_lastedit_datetime'], 'class' => 'boot-tooltip']
).'
</p>
</td>
</tr>
<tr>
<td><p><b>' . get_lang('Category').': </b>'.$ticket['ticket']['name'].'</p></td>
</tr>
<tr>
<td><p ' . $bold.'><b>'.get_lang('Status').':</b> '.$ticket['ticket']['status'].'</p></td>
</tr>
<tr>
<td><p><b>' . get_lang('Priority').': </b>'.$ticket['ticket']['priority'].'<p></td>
</tr>';
if (!empty($ticket['ticket']['assigned_last_user'])) {
$assignedUser = api_get_user_info($ticket['ticket']['assigned_last_user']);
echo '<tr>
<td><p><b>' . get_lang('AssignedTo').': </b>'.$assignedUser['complete_name_with_message_link'].'<p></td>
</tr>';
} else {
echo '<tr>
<td><p><b>' . get_lang('AssignedTo').': </b>-<p></td>
</tr>';
}
if ($ticket['ticket']['course_url'] != null) {
if (!empty($ticket['ticket']['session_id'])) {
$sessionInfo = api_get_session_info($ticket['ticket']['session_id']);
echo '<tr>
<td><b>' . get_lang('Session').':</b> '.$sessionInfo['name'].' </td>
<td></td>
<td colspan="2"></td>
</tr>';
}
echo '<tr>
<td><b>' . get_lang('Course').':</b> '.$ticket['ticket']['course_url'].' </td>
<td></td>
<td colspan="2"></td>
</tr>';
}
echo '<tr>
<td>
<hr />
<b>' . get_lang('Description').':</b> <br />
'.$ticket['ticket']['message'].'
<hr />
</td>
</tr>
';
echo '</table>';
echo $messageToShow;
echo $formToShow;
Display::display_footer();
/**
* @param array $ticket
* @return FormValidator
*/
function show_form_send_message($ticket)
function getForm($ticket)
{
global $isAdmin;
$isAdmin = api_is_platform_admin();
global $subject;
$form = new FormValidator(
@ -517,19 +531,11 @@ function show_form_send_message($ticket)
'<span id="link-more-attach">
<span class="btn btn-success" onclick="return add_image_form()">' . get_lang('AddOneMoreFile').'</span>
</span>
('.sprintf(get_lang('MaximunFileSizeX'), format_file_size(api_get_setting('message_max_upload_filesize'))).')
');
('.sprintf(get_lang('MaximunFileSizeX'), format_file_size(api_get_setting('message_max_upload_filesize'))).')'
);
$form->addElement('html', '<br/>');
$form->addElement(
'button',
'compose',
get_lang('SendMessage'),
null,
null,
null,
'btn btn-primary'
);
$form->addButtonSend(get_lang('Send'));
$form->display();
return $form;
}

@ -127,6 +127,7 @@ if (empty($projectId)) {
$currentUrl = api_get_self().'?project_id='.$projectId;
$user_id = api_get_user_id();
$isAllow = TicketManager::userIsAllowInProject(api_get_user_info(), $projectId);
$isAdmin = api_is_platform_admin();
$actionRight = '';
@ -278,7 +279,7 @@ if (!empty($projectId)) {
}
$options = '';
if (api_is_platform_admin()) {
if ($isAdmin) {
$options .=Display::url(
get_lang('Projects'),
api_get_path(WEB_CODE_PATH).'ticket/projects.php'
@ -290,7 +291,7 @@ if (!empty($projectId)) {
$url
);
if (api_is_platform_admin()) {
if ($isAllow) {
echo Display::toolbarAction(
'options',
array(
@ -358,8 +359,10 @@ if ($isAdmin) {
$table->set_header(6, get_lang('AssignedTo'), true);
$table->set_header(7, get_lang('Message'), true);
} else {
if ($isAllow == false) {
echo Display::page_subheader(get_lang('MyTickets'));
echo Display::return_message(get_lang('TicketMsgWelcome'));
}
$table->set_header(0, '#', true);
$table->set_header(1, get_lang('Status'), false);
$table->set_header(2, get_lang('Date'), true);

Loading…
Cancel
Save