1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
<?php
/**
* Privacy.php - Privacy policy of Stud.IP
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* @author Timo Hartge <hartge@data-quest.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
*/
class Privacy
{
/**
* Names of classes containing user data.
*/
private static $privacy_classes = [
'core' => [
'User',
'DataField',
'DatafieldEntryModel',
'UserConfig',
'HelpTourUser',
'Grading\Instance',
'LogEvent',
],
'date' => [
'CalendarEvent',
'EventData',
'CourseDate',
'CourseExDate',
],
'message' => [
'BlubberThread',
'BlubberComment',
'StudipNews',
'StudipComment',
'Message',
'MessageUser',
],
'content' => [
'FileRef',
'ForumEntry',
'WikiPage',
'Courseware\Unit',
'Courseware\StructuralElement',
'Courserware\StructuralElementComment',
'Courserware\StructuralElementFeedback',
'Courseware\TaskGroup',
'Courseware\TaskFeedback',
'Courseware\Bookmark',
'Courseware\Container',
'Courseware\Block',
'Courserware\BlockComment',
'Courserware\BlockFeedback',
'Courseware\UserDataField',
'Courseware\UserProgress'
],
'quest' => [
'Evaluation',
'Questionnaire',
'QuestionnaireAnswer',
'QuestionnaireAnonymousAnswer',
'QuestionnaireAssignment',
'eTask\Attempt',
'eTask\Response',
'eTask\Task',
'eTask\Test',
],
'membership' => [
'Course',
'CourseMember',
'AdmissionApplication',
'ArchivedCourse',
'ArchivedCourseMember',
'Statusgruppen',
'StatusgruppeUser',
'InstituteMember',
'UserStudyCourse',
'Fach',
'Abschluss',
],
'plugins' => [
],
];
/**
* Returns the tables containing user data.
* the array consists of the tables containing user data
* the expected format for each table is:
* $array[ table display name ] = [ 'table_name' => name of the table, 'table_content' => array of db rows containing userdata]
*
* @param string $user_id
* @param string $section
* @return array
*/
public static function getUserdataInformation($user_id, $section = null)
{
$storage = new StoredUserData($user_id);
if ($section && !isset(self::$privacy_classes[$section])) {
throw new Exception("Invalid privacy section '{$section}'");
}
$privacy_classes = $section
? self::$privacy_classes[$section]
: array_flatten(array_values(self::$privacy_classes));
foreach ($privacy_classes as $privacy_class) {
if (is_a($privacy_class, 'PrivacyObject', true)) {
$privacy_class::exportUserData($storage);
}
}
if (!$section || $section === 'plugins') {
foreach (PluginEngine::getPlugins('PrivacyPlugin') as $plugin) {
$plugin->exportUserData($storage);
}
}
$user_data = [];
foreach ($storage->getTabularData() as $meta) {
$user_data[$meta['name']] = [
'table_name' => $meta['key'],
'table_content' => $meta['value'],
];
}
return $user_data;
}
/**
* Checks if current user is privileged to see the data of given user
*
* @param string $user_id
* @return boolean
*/
public static function isVisible($user_id)
{
$needed_perm = Config::get()->PRIVACY_PERM ?: 'root';
$allowed_person = true;
if (!in_array($needed_perm, ['root', 'admin']) && !$GLOBALS['perm']->have_perm('admin')) {
$allowed_person = $GLOBALS['user']->user_id === $user_id;
}
return $GLOBALS['perm']->have_perm($needed_perm)
&& $allowed_person;
}
}
|