Skip to content

Commit 8909e4e

Browse files
committed
fix(form_answer): restrict display of form answers to requesters and valdators
fix #869
1 parent 891e40c commit 8909e4e

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

inc/form_answer.class.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,55 @@ public static function canView() {
3232
return true;
3333
}
3434

35+
public function canViewItem() {
36+
global $DB;
37+
38+
if (!isset($_SESSION['glpiID'])) {
39+
return false;
40+
}
41+
42+
if ($_SESSION['glpiID'] == $this->getField('requester_id')) {
43+
return true;
44+
}
45+
46+
$request = [
47+
'SELECT' => PluginFormcreatorForm_Validator::getTable() . '.*',
48+
'FROM' => $this::getTable(),
49+
'INNER JOIN' => [
50+
PluginFormcreatorForm::getTable() => [
51+
'FKEY' => [
52+
PluginFormcreatorForm::getTable() => PluginFormcreatorForm::getIndexName(),
53+
$this::getTable() => PluginFormcreatorForm::getForeignKeyField(),
54+
],
55+
],
56+
PluginFormcreatorForm_Validator::getTable() => [
57+
'FKEY' => [
58+
PluginFormcreatorForm::getTable() => PluginFormcreatorForm::getIndexName(),
59+
PluginFormcreatorForm_Validator::getTable() => PluginFormcreatorForm::getForeignKeyField()
60+
]
61+
]
62+
],
63+
'WHERE' => [$this::getTable() . '.id' => $this->getID()],
64+
];
65+
foreach ($DB->request($request) as $row) {
66+
if ($row['itemtype'] == User::class) {
67+
if ($_SESSION['glpiID'] == $row['items_id']) {
68+
return true;
69+
}
70+
} else {
71+
$groupUser = new Group_User();
72+
$groups = $groupUser->getUserGroups($_SESSION['glpiID']);
73+
foreach ($groups as $group) {
74+
if ($row['items_id'] == $group['id']) {
75+
return true;
76+
}
77+
}
78+
}
79+
}
80+
81+
return false;
82+
}
83+
3584
/**
3685
* Returns the type name with consideration of plural
3786
*

0 commit comments

Comments
 (0)