@@ -79,6 +79,7 @@ public BasePage() {
79
79
80
80
// setup some data that can be shared across all pages
81
81
this .currentUserUuid = this .businessService .getCurrentUser ().getId ();
82
+ role = GbRole .NONE ;
82
83
try {
83
84
this .role = this .businessService .getUserRole ();
84
85
} catch (final GbAccessDeniedException e ) {
@@ -229,7 +230,7 @@ public void renderHead(final IHeaderResponse response) {
229
230
/**
230
231
* Helper to disable a link. Add the Sakai class 'current'.
231
232
*/
232
- protected void disableLink (final Link <Void > l ) {
233
+ protected final void disableLink (final Link <Void > l ) {
233
234
l .add (new AttributeAppender ("class" , new Model <String >("current" ), " " ));
234
235
l .replace (new Label ("screenreaderlabel" , getString ("link.screenreader.tabselected" )));
235
236
l .setEnabled (false );
@@ -280,7 +281,7 @@ public void setUserPreferredLocale() {
280
281
*
281
282
* @param message the message
282
283
*/
283
- public void sendToAccessDeniedPage (final String message ) {
284
+ public final void sendToAccessDeniedPage (final String message ) {
284
285
final PageParameters params = new PageParameters ();
285
286
params .add ("message" , message );
286
287
log .debug ("Redirecting to AccessDeniedPage: " + message );
@@ -290,4 +291,24 @@ public void sendToAccessDeniedPage(final String message) {
290
291
public GbRole getCurrentRole () {
291
292
return BasePage .this .role ;
292
293
}
294
+
295
+ /**
296
+ * Performs role checks for instructor-only pages and redirects users to appropriate pages based on their role.
297
+ * No role -> AccessDeniedPage. Student -> StudentPage. TA -> GradebookPage.
298
+ */
299
+ protected final void defaultRoleChecksForInstructorOnlyPage ()
300
+ {
301
+ switch (role )
302
+ {
303
+ case NONE :
304
+ sendToAccessDeniedPage (getString ("error.role" ));
305
+ break ;
306
+ case STUDENT :
307
+ throw new RestartResponseException (StudentPage .class );
308
+ case TA :
309
+ throw new RestartResponseException (GradebookPage .class );
310
+ default :
311
+ break ;
312
+ }
313
+ }
293
314
}
0 commit comments