File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -11,14 +11,20 @@ public static function module()
1111
1212 public static function getLegalTemplates ()
1313 {
14-
1514 $ legalTemplates = self ::module ()->legalTemplates ;
1615 $ templates = \ProcessWire \wire ('templates ' )->find ("name= " . implode ('| ' , $ legalTemplates ));
17-
1816 $ user = \ProcessWire \wire ('user ' );
17+
18+ // Wierd behavior with ProcessWire. $user->hasPermission() does not
19+ // work if you do not load the required roles beforehand.
20+ \ProcessWire \wire ('roles ' )->find ("" );
1921
2022 foreach ($ templates as $ template ) {
21- if (!$ user ->hasPermission ('page-view ' , $ template )) {
23+ // we serve templates with access control disabled
24+ if (!$ template ->useRoles ) continue ;
25+
26+ // if enabled we serve only those that user has permission to view
27+ if (!$ user ->hasTemplatePermission ('page-view ' , $ template )) {
2228 $ templates ->remove ($ template );
2329 }
2430 }
You can’t perform that action at this time.
0 commit comments