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