4
4
5
5
namespace Icinga \Module \Reporting \Controllers ;
6
6
7
+ use Icinga \Authentication \Auth as IcingaAuth ;
7
8
use Icinga \Module \Icingadb \ProvidedHook \Reporting \HostSlaReport ;
8
9
use Icinga \Module \Icingadb \ProvidedHook \Reporting \ServiceSlaReport ;
9
10
use Icinga \Module \Reporting \Database ;
12
13
use Icinga \Module \Reporting \Web \Forms \ReportForm ;
13
14
use Icinga \Module \Reporting \Web \ReportsTimeframesAndTemplatesTabs ;
14
15
use ipl \Html \Html ;
16
+ use ipl \Stdlib \Filter ;
17
+ use ipl \Web \Filter \QueryString ;
15
18
use ipl \Web \Url ;
16
19
use ipl \Web \Widget \ButtonLink ;
17
20
use ipl \Web \Widget \Icon ;
@@ -27,22 +30,53 @@ public function indexAction()
27
30
$ this ->createTabs ()->activate ('reports ' );
28
31
29
32
if ($ this ->hasPermission ('reporting/reports ' )) {
30
- $ this ->addControl (new ButtonLink (
31
- $ this ->translate ('New Report ' ),
32
- Url::fromPath ('reporting/reports/new ' ),
33
- 'plus ' ,
34
- [
35
- 'data-icinga-modal ' => true ,
36
- 'data-no-icinga-ajax ' => true
37
- ]
38
- ));
33
+ $ canCreate = true ;
34
+ $ report = ['report.author ' => $ this ->auth ->getUser ()->getUsername ()];
35
+ $ restrictions = IcingaAuth::getInstance ()->getRestrictions ('reporting/reports ' );
36
+ foreach ($ restrictions as $ restriction ) {
37
+ $ this ->parseRestriction (
38
+ $ restriction ,
39
+ 'reporting/reports ' ,
40
+ function (Filter \Condition $ condition ) use (&$ canCreate , $ report ) {
41
+ if ($ condition ->getColumn () != 'report.author ' ) {
42
+ // Only filters like `report.author!=$user.local_name$` can fully prevent the current user
43
+ // from creating his own reports.
44
+ return ;
45
+ }
46
+
47
+ if (! $ canCreate || Filter::match ($ condition , $ report )) {
48
+ return ;
49
+ }
50
+
51
+ $ canCreate = false ;
52
+ }
53
+ );
54
+
55
+ if (! $ canCreate ) {
56
+ break ;
57
+ }
58
+ }
59
+
60
+ if ($ canCreate ) {
61
+ $ this ->addControl (new ButtonLink (
62
+ $ this ->translate ('New Report ' ),
63
+ Url::fromPath ('reporting/reports/new ' ),
64
+ 'plus ' ,
65
+ [
66
+ 'data-icinga-modal ' => true ,
67
+ 'data-no-icinga-ajax ' => true
68
+ ]
69
+ ));
70
+ }
39
71
}
40
72
41
73
$ tableRows = [];
42
74
43
75
$ reports = Report::on ($ this ->getDb ())
44
76
->withColumns (['report.timeframe.name ' ]);
45
77
78
+ $ this ->applyRestrictions ($ reports );
79
+
46
80
$ sortControl = $ this ->createSortControl (
47
81
$ reports ,
48
82
[
@@ -64,16 +98,16 @@ public function indexAction()
64
98
Html::tag ('td ' , null , $ report ->timeframe ->name ),
65
99
Html::tag ('td ' , null , $ report ->ctime ->format ('Y-m-d H:i ' )),
66
100
Html::tag ('td ' , null , $ report ->mtime ->format ('Y-m-d H:i ' )),
67
- Html::tag ('td ' , ['class ' => 'icon-col ' ], [
68
- new Link (
101
+ ! $ this ->hasPermission ('reporting/reports ' )
102
+ ? null
103
+ : Html::tag ('td ' , ['class ' => 'icon-col ' ], new Link (
69
104
new Icon ('edit ' ),
70
105
Url::fromPath ('reporting/report/edit ' , ['id ' => $ report ->id ]),
71
106
[
72
107
'data-icinga-modal ' => true ,
73
108
'data-no-icinga-ajax ' => true
74
109
]
75
- )
76
- ])
110
+ ))
77
111
]);
78
112
}
79
113
0 commit comments