1
|
|
|
<?php |
2
|
|
|
namespace SilverStripe\SecurityReport; |
3
|
|
|
|
4
|
|
|
use SilverStripe\Control\Director; |
5
|
|
|
use SilverStripe\Forms\FormField; |
6
|
|
|
use SilverStripe\Forms\GridField\GridField; |
7
|
|
|
use SilverStripe\Forms\GridField\GridFieldExportButton; |
8
|
|
|
use SilverStripe\Forms\GridField\GridFieldPrintButton; |
9
|
|
|
use SilverStripe\ORM\DataList; |
10
|
|
|
use SilverStripe\Reports\Report; |
11
|
|
|
use SilverStripe\Security\Member; |
12
|
|
|
use SilverStripe\Security\Permission; |
13
|
|
|
use SilverStripe\SecurityReport\Forms\GridFieldExportReportButton; |
14
|
|
|
use SilverStripe\SecurityReport\Forms\GridFieldPrintReportButton; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* User Security Report |
18
|
|
|
* |
19
|
|
|
* @author Michael Parkhill <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class UserSecurityReport extends Report |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Columns in the report |
26
|
|
|
* |
27
|
|
|
* @var array |
28
|
|
|
* @config |
29
|
|
|
*/ |
30
|
|
|
private static $columns = array( |
|
|
|
|
31
|
|
|
'ID' => 'User ID', |
32
|
|
|
'FirstName' => 'First Name', |
33
|
|
|
'Surname' => 'Surname', |
34
|
|
|
'Email' => 'Email', |
35
|
|
|
'Created' => 'Date Created', |
36
|
|
|
'GroupsDescription' => 'Groups', |
37
|
|
|
'PermissionsDescription' => 'Permissions', |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
protected $dataClass = Member::class; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Returns the report title |
44
|
|
|
* |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
public function title() |
48
|
|
|
{ |
49
|
|
|
return _t(__CLASS__ . '.REPORTTITLE', 'Users, Groups and Permissions'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Builds a report description which is the current hostname with the current date and time |
54
|
|
|
* |
55
|
|
|
* @return string e.g. localhost/sitename - 21/12/2112 |
56
|
|
|
*/ |
57
|
|
|
public function description() |
58
|
|
|
{ |
59
|
|
|
return str_replace( |
60
|
|
|
array('http', 'https', '://'), |
61
|
|
|
'', |
62
|
|
|
Director::protocolAndHost() . ' - ' . date('d/m/Y H:i:s') |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Returns the column names of the report |
68
|
|
|
* |
69
|
|
|
* @return array |
70
|
|
|
*/ |
71
|
|
|
public function columns() |
72
|
|
|
{ |
73
|
|
|
return self::config()->columns; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Alias of columns(), to support the export to csv action |
78
|
|
|
* in {@link GridFieldExportButton} generateExportFileData method. |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
|
public function getColumns() |
82
|
|
|
{ |
83
|
|
|
return $this->columns(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return array |
88
|
|
|
*/ |
89
|
|
|
public function summaryFields() |
90
|
|
|
{ |
91
|
|
|
return $this->columns(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Defines the sortable columns on the report gridfield |
96
|
|
|
* |
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
|
|
public function sortColumns() |
100
|
|
|
{ |
101
|
|
|
return array_keys($this->columns()); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Get the source records for the report gridfield |
106
|
|
|
* |
107
|
|
|
* @return DataList |
108
|
|
|
*/ |
109
|
|
|
public function sourceRecords() |
110
|
|
|
{ |
111
|
|
|
// Get members sorted by ID |
112
|
|
|
return Member::get()->sort('ID'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Restrict access to this report to users with security admin access |
117
|
|
|
* |
118
|
|
|
* @param Member $member |
119
|
|
|
* @return boolean |
120
|
|
|
*/ |
121
|
|
|
public function canView($member = null) |
122
|
|
|
{ |
123
|
|
|
return (bool)Permission::checkMember($member, "CMS_ACCESS_SecurityAdmin"); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Return a field, such as a {@link GridField} that is |
128
|
|
|
* used to show and manipulate data relating to this report. |
129
|
|
|
* |
130
|
|
|
* @return FormField subclass |
131
|
|
|
*/ |
132
|
|
|
public function getReportField() |
133
|
|
|
{ |
134
|
|
|
/** @var GridField $gridField */ |
135
|
|
|
$gridField = parent::getReportField(); |
136
|
|
|
$gridField->setModelClass(self::class); |
137
|
|
|
$gridConfig = $gridField->getConfig(); |
138
|
|
|
$gridConfig->removeComponentsByType([GridFieldPrintButton::class, GridFieldExportButton::class]); |
139
|
|
|
$gridConfig->addComponents( |
140
|
|
|
new GridFieldPrintReportButton('buttons-before-left'), |
141
|
|
|
new GridFieldExportReportButton('buttons-before-left') |
142
|
|
|
); |
143
|
|
|
return $gridField; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.