@@ -39,6 +39,16 @@ abstract class BaseController
39
39
/** @var bool */
40
40
protected $ is_popup = false ;
41
41
42
+ /**
43
+ * Minimum role required to access the page
44
+ *
45
+ * @var int
46
+ */
47
+ protected $ min_role ;
48
+
49
+ /** @var int */
50
+ protected $ role_id ;
51
+
42
52
/** @var array */
43
53
private $ helpers ;
44
54
@@ -59,8 +69,8 @@ public function __construct()
59
69
public function run ()
60
70
{
61
71
// NOTE: canAccess needs $issue_id for the template
62
- if (!$ this ->canAccess ()) {
63
- $ this ->displayTemplate ( ' permission_denied.tpl.html ' );
72
+ if (!$ this ->canRoleAccess () || ! $ this -> canAccess ()) {
73
+ $ this ->error ( ev_gettext ( ' Sorry, you are not allowed to access this page. ' ) );
64
74
exit ;
65
75
}
66
76
@@ -89,18 +99,48 @@ protected function getRequest()
89
99
90
100
/**
91
101
* display template
102
+ *
92
103
* @param string $tpl_name
93
104
*/
94
105
protected function displayTemplate ($ tpl_name = null )
95
106
{
96
- $ this ->tpl ->assign ('messages ' , $ this ->messages ->getMessages ());
107
+ $ this ->tpl ->assign (
108
+ [
109
+ 'messages ' => $ this ->messages ->getMessages (),
110
+ 'is_popup ' => $ this ->is_popup ,
111
+ ]
112
+ );
113
+
97
114
// set new template, if needed
98
115
if ($ tpl_name ) {
99
116
$ this ->tpl ->setTemplate ($ tpl_name );
100
117
}
101
118
$ this ->tpl ->displayTemplate ();
102
119
}
103
120
121
+ /**
122
+ * If page is restricted, check for minimum role.
123
+ *
124
+ * @return bool
125
+ */
126
+ final protected function canRoleAccess ()
127
+ {
128
+ if ($ this ->min_role === null ) {
129
+ // not restricted
130
+ return true ;
131
+ }
132
+
133
+ if ($ this ->is_popup ) {
134
+ Auth::checkAuthentication (null , true );
135
+ } else {
136
+ Auth::checkAuthentication ();
137
+ }
138
+
139
+ $ this ->role_id = Auth::getCurrentRole ();
140
+
141
+ return $ this ->role_id >= $ this ->min_role ;
142
+ }
143
+
104
144
/**
105
145
* Display error message $msg and exit
106
146
*
0 commit comments