33import org .entityc .tutorial .dto .TutorialDto ;
44import org .entityc .tutorial .exception .ServiceException ;
55import org .entityc .tutorial .model .Module ;
6+ import org .entityc .tutorial .model .Role ;
67import org .entityc .tutorial .model .Session ;
78import org .entityc .tutorial .model .User ;
89import org .entityc .tutorial .security .PersistentUserDetailsService ;
2021import org .springframework .web .bind .annotation .GetMapping ;
2122import org .springframework .web .bind .annotation .PathVariable ;
2223
24+ import java .util .Set ;
2325import java .util .UUID ;
2426import java .util .Vector ;
2527
@@ -47,6 +49,7 @@ public String homePage(Model model) throws ServiceException {
4749 model .addAttribute ("TutorialList" , tutorialService .getTutorialDtoList (0 , 100 , true ));
4850 User user = userDetailsService .findByEmail (securityService .findLoggedInUsername ());
4951 model .addAttribute ("loggedInUser" , user );
52+ addCanGoToAdminSide (model );
5053 return "UserHome" ;
5154 }
5255
@@ -57,6 +60,7 @@ public String tutorialPage(Model model, @PathVariable("id") UUID tutorialId) thr
5760 model .addAttribute ("ModulesList" , moduleService .getModuleDtoListByTutorial (tutorialId , 0 , 100 , true ));
5861 User user = userDetailsService .findByEmail (securityService .findLoggedInUsername ());
5962 model .addAttribute ("loggedInUser" , user );
63+ addCanGoToAdminSide (model );
6064 return "UserTutorial" ;
6165 }
6266
@@ -70,6 +74,7 @@ public String modulePage(Model model, @PathVariable("id") UUID moduleId) throws
7074 model .addAttribute ("SessionsList" , sessionService .getSessionDtoListByModule (moduleId , 0 , 100 , true ));
7175 User user = userDetailsService .findByEmail (securityService .findLoggedInUsername ());
7276 model .addAttribute ("loggedInUser" , user );
77+ addCanGoToAdminSide (model );
7378 return "UserModule" ;
7479 }
7580
@@ -98,6 +103,14 @@ public String sessionPage(Model model, @PathVariable("id") UUID sessionId) throw
98103 model .addAttribute ("SessionMarkdown" , sessionService .buildMarkdownDocSection (1 , sessionDto , 1 ));
99104 User user = userDetailsService .findByEmail (securityService .findLoggedInUsername ());
100105 model .addAttribute ("loggedInUser" , user );
106+ addCanGoToAdminSide (model );
101107 return "UserSession" ;
102108 }
109+ private void addCanGoToAdminSide (Model model ) {
110+ User user = userDetailsService .findByEmail (securityService .findLoggedInUsername ());
111+ Set <Role > roles = user .getRoles ();
112+
113+ boolean canGoToAdminSide = roles .contains (Role .INSTRUCTOR ) || roles .contains (Role .ADMINISTRATOR );
114+ model .addAttribute ("canGoToAdminSide" , canGoToAdminSide );
115+ }
103116}
0 commit comments