Skip to content

Commit

Permalink
feat(glpiselectfield): restrict tickets in simplified interface
Browse files Browse the repository at this point in the history
list obeys view my tickets and vie my groups tickets in current user's profile

Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Nov 3, 2021
1 parent 0327d52 commit 8a901f4
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions inc/field/dropdownfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,23 @@
use Session;
use DBUtils;
use Dropdown;
use CommonITILActor;
use CommonITILObject;
use CommonTreeDropdown;
use ITILCategory;
use Entity;
use User;
use Group;
use Group_Ticket;
use Group_User;
use Ticket;
use Ticket_User;
use Search;
use SLA;
use SLM;
use OLA;
use QuerySubQuery;
use QueryUnion;
use GlpiPlugin\Formcreator\Exception\ComparisonException;

class DropdownField extends PluginFormcreatorAbstractField
Expand Down Expand Up @@ -278,6 +283,47 @@ public function buildParams($rand = null) {
}
break;

case Ticket::class:
// Shall match logic in \Search::getDefaultWhere()
if (!Session::haveRight("ticket", Ticket::READALL)) {
$currentUser = Session::getLoginUserID();
if (Session::haveRight(Ticket::$rightname, Ticket::READMY)) {
$requestersObserversQuery = new QuerySubQuery([
'SELECT' => 'tickets_id',
'FROM' => Ticket_User::getTable(),
'WHERE' => [
'users_id' => $currentUser,
'type' => [CommonITILActor::REQUESTER, CommonITILActor::OBSERVER]
],
]);
$dparams_cond_crit['OR'] = [
'id' => $requestersObserversQuery,
'users_id_recipient' => $currentUser,
];
}
if (Session::haveRight(Ticket::$rightname, Ticket::READGROUP)) {
$requestersObserversGroupsQuery = new QuerySubQuery([
'SELECT' => 'tickets_id',
'FROM' => Group_Ticket::getTable(),
'WHERE' => [
'groups_id' => $_SESSION['glpigroups'],
'type' => [CommonITILActor::REQUESTER, CommonITILActor::OBSERVER]
],
]);
if (!isset($dparams_cond_crit['OR']['id'])) {
$dparams_cond_crit['OR'] = [
'id' => $requestersObserversGroupsQuery,
];
} else {
$dparams_cond_crit['OR']['id'] = new QueryUnion([
$dparams_cond_crit['OR']['id'],
$requestersObserversGroupsQuery,
]);
}
}
}
break;

default:
$assignableToTicket = in_array($itemtype, $CFG_GLPI['ticket_types']);
if (Session::getLoginUserID()) {
Expand Down

0 comments on commit 8a901f4

Please sign in to comment.