2
2
3
3
import org .dcsc .admin .constants .AttributeNames ;
4
4
import org .dcsc .admin .constants .ViewNames ;
5
- import org .dcsc .admin .profile .ProfileCreateForm ;
6
5
import org .dcsc .admin .profile .ProfileForm ;
7
6
import org .dcsc .core .activity .Activity ;
8
7
import org .dcsc .core .activity .ActivityService ;
22
21
import org .springframework .web .bind .annotation .RequestMethod ;
23
22
24
23
import java .util .List ;
24
+ import java .util .Optional ;
25
25
26
26
@ Controller
27
27
public class AdminProfileController {
28
28
@ Autowired
29
29
private ActivityService activityService ;
30
30
@ Autowired
31
- private DcscUserService dcscUserService ;
31
+ private DcscUserService userService ;
32
32
@ Autowired
33
33
private RolePermissionService rolePermissionService ;
34
34
35
- @ RequestMapping (value = "/admin/profile " , method = RequestMethod .GET )
35
+ @ RequestMapping (value = "/admin/user " , method = RequestMethod .GET )
36
36
public String profile (Authentication authentication , Model model ) {
37
37
DcscUserDetails userDetails = ((DcscUserDetails ) authentication .getPrincipal ());
38
38
DcscUser user = userDetails .getUser ();
@@ -46,17 +46,16 @@ public String profile(Authentication authentication, Model model) {
46
46
return ViewNames .ADMIN_PROFILE ;
47
47
}
48
48
49
- @ RequestMapping (value = "/admin/profile/edit" , method = RequestMethod .GET )
50
- public String profileEdit (Model model ) {
51
- model .addAttribute ("profileForm" , new ProfileForm ());
52
-
53
- return ViewNames .ADMIN_PROFILE_EDIT ;
54
- }
55
-
56
49
@ RequestMapping (value = "/admin/user/{user_id}" , method = RequestMethod .GET )
57
50
@ PreAuthorize ("hasPermission('user','read')" )
58
51
public String profileView (@ PathVariable ("user_id" ) long id , Model model ) {
59
- DcscUser user = dcscUserService .getUserById (id ).get ();
52
+ Optional <DcscUser > dcscUser = userService .getUserById (id );
53
+
54
+ if (!dcscUser .isPresent ()) {
55
+ return "redirect:/admin/user" ;
56
+ }
57
+
58
+ DcscUser user = dcscUser .get ();
60
59
61
60
List <Activity > list = activityService .getAllActivities (user .getId ());
62
61
@@ -67,18 +66,13 @@ public String profileView(@PathVariable("user_id") long id, Model model) {
67
66
return ViewNames .ADMIN_PROFILE ;
68
67
}
69
68
70
- @ RequestMapping (value = "/admin/user/create" , method = RequestMethod .GET )
71
- @ PreAuthorize ("hasPermission('user','create')" )
72
- public String userCreatePage (Model model ) {
73
- model .addAttribute ("profileForm" , new ProfileCreateForm ());
74
-
75
- return ViewNames .ADMIN_PROFILE_CREATE ;
76
- }
77
69
78
- @ RequestMapping (value = "/admin/user/{user_id}/edit" , method = RequestMethod .GET )
79
- public String userEditPage (@ PathVariable ("user_id" ) long id , Model model ) {
70
+ @ RequestMapping (value = "/admin/user/edit" , method = RequestMethod .GET )
71
+ @ PreAuthorize ("hasPermission('user','update')" )
72
+ public String profileEdit (Model model ) {
73
+ model .addAttribute ("profileForm" , new ProfileForm ());
80
74
81
- return ViewNames .ADMIN_PROFILE_CREATE ;
75
+ return ViewNames .ADMIN_PROFILE_EDIT ;
82
76
}
83
77
84
78
@ ExceptionHandler (TypeMismatchException .class )
0 commit comments