Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access for ticket validator to form answer #3511

Open
wants to merge 1 commit into
base: support/2.13.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,23 @@ public function canViewItem() {
}
}

if ($this->userIsTicketActor()) {
return true;
}


if ($this->userIsTicketValidator()) {
return true;
}

return false;
}

public function userIsTicketActor(): bool {
global $DB;

$currentUser = Session::getLoginUserID();

// Check if the current user is a requester of a ticket linked to a form answer typed
// Matches search option 42, 43 and 44 of PluginFormcreatorIssue (requester, watcher, assigned)
$ticket_table = Ticket::getTable();
Expand Down Expand Up @@ -208,6 +225,52 @@ public function canViewItem() {
return false;
}

public function userIsTicketValidator(): bool {
global $DB;

$currentUser = Session::getLoginUserID();

// Check if the current user is a validator of a ticket linked to a form answer typed
$ticket_table = Ticket::getTable();
$ticketvalidation_table = TicketValidation::getTable();
$item_ticket_table = Item_Ticket::getTable();
$request = [
'SELECT' => [
TicketValidation::getTableField(User::getForeignKeyField() . '_validate'),
Ticket::getTableField('id'),
],
'FROM' => $ticketvalidation_table,
'INNER JOIN' => [
$ticket_table => [
'FKEY' => [
$ticket_table => 'id',
$ticketvalidation_table => 'tickets_id',
['AND' => [
TicketValidation::getTableField(User::getForeignKeyField() . '_validate') => $currentUser,
]],
],
],
$item_ticket_table => [
'FKEY' => [
$item_ticket_table => 'tickets_id',
$ticket_table => 'id',
['AND' => [
Item_Ticket::getTableField('itemtype') => self::getType(),
Item_Ticket::getTableField('items_id') => $this->getID(),
]],
],
],
]
];

if ($DB->request($request)->count() > 0) {
return true;
}

return false;

}

public static function canPurge() {
return true;
}
Expand Down Expand Up @@ -581,6 +644,12 @@ public function showForm($ID, $options = []) {
if (!isset($ID) || !$this->getFromDB($ID)) {
Html::displayNotFoundError();
}

if ($this->canViewItem() && !$this->userIsTicketActor()) {
echo '<div class="alert alert-danger">' . __('You are not allowed to view this answer.') . '</div>';
return false;
}

$options['canedit'] = false;

// Print css media
Expand Down
Loading