55use Icinga \Authentication \Auth ;
66use Icinga \Module \Director \Db ;
77use Icinga \Module \Director \Objects \IcingaObject ;
8+ use Icinga \Module \Director \Restriction \FilterByNameRestriction ;
89use Icinga \Module \Director \Restriction \HostgroupRestriction ;
910use Icinga \Module \Director \Restriction \ObjectRestriction ;
1011
@@ -13,6 +14,9 @@ trait ObjectRestrictions
1314 /** @var ObjectRestriction[] */
1415 private $ objectRestrictions ;
1516
17+ /** @var IcingaObject */
18+ private $ dummyRestrictedObject ;
19+
1620 /**
1721 * @return ObjectRestriction[]
1822 */
@@ -30,13 +34,27 @@ public function getObjectRestrictions()
3034 */
3135 protected function loadObjectRestrictions (Db $ db , Auth $ auth )
3236 {
33- return [
34- new HostgroupRestriction ($ db , $ auth )
35- ];
37+ $ objectType = $ this ->dummyRestrictedObject ->getShortTableName ();
38+ if (
39+ ($ objectType === 'service ' && $ this ->dummyRestrictedObject ->isApplyRule ())
40+ || $ objectType === 'notification '
41+ || $ objectType === 'service_set '
42+ || $ objectType === 'scheduled_downtime '
43+ ) {
44+ if ($ objectType === 'scheduled_downtime ' ) {
45+ $ objectType = 'scheduled-downtime ' ;
46+ }
47+
48+ return [new FilterByNameRestriction ($ db , $ auth , $ objectType )];
49+ }
50+
51+ // If the object is host or host group load HostgroupRestriction
52+ return [new HostgroupRestriction ($ db , $ auth )];
3653 }
3754
3855 public function allowsObject (IcingaObject $ object )
3956 {
57+ $ this ->dummyRestrictedObject = $ object ;
4058 foreach ($ this ->getObjectRestrictions () as $ restriction ) {
4159 if (! $ restriction ->allows ($ object )) {
4260 return false ;
0 commit comments