apres correction et finalisatio de la synchronisation
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package io.gmss.fiscad.controllers.user;
|
||||
|
||||
|
||||
import io.gmss.fiscad.entities.user.Role;
|
||||
import io.gmss.fiscad.entities.user.User;
|
||||
import io.gmss.fiscad.enums.UserRole;
|
||||
import io.gmss.fiscad.exceptions.*;
|
||||
@@ -20,6 +21,8 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "api/user", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@@ -114,7 +117,7 @@ public class UserController {
|
||||
try {
|
||||
User user = userService.validateUserAccount(login.getUsername(), login.getUserRole());
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, user, "Cet utilisateur à été activé avec succès."),
|
||||
new ApiResponse<>(true, user, "Cet compte à été activé avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
||||
@@ -138,7 +141,7 @@ public class UserController {
|
||||
public ResponseEntity<?> updateUser(@PathVariable Long id, @RequestBody User user) {
|
||||
try {
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, userService.updateUser(id, user), "User updated successully."),
|
||||
new ApiResponse<>(true, userService.updateUser(id, user), "Utilisateur modifié avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
||||
@@ -157,11 +160,24 @@ public class UserController {
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/activate-or-not")
|
||||
public ResponseEntity<?> acitvateOrNotUser(@RequestParam Long id) {
|
||||
@GetMapping("/activate-or-not/{id}")
|
||||
public ResponseEntity<?> acitvateOrNotUser(@PathVariable Long id) {
|
||||
try {
|
||||
|
||||
User user = userService.activateOrNotUser(id);
|
||||
User user = userService.getUserById(id);
|
||||
if(containsRoleAnonyme(user.getRoles())){
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(false, user , "Ce compte n'est pas encore validé."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
}
|
||||
if(user.isResetPassword()){
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(false, user , "Ce compte n'est pas encore validé."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
}
|
||||
user = userService.activateOrNotUser(id);
|
||||
String message = "Utilisateur activé avec succès";
|
||||
if (!user.isActive()) {
|
||||
message = "Utilisateur désactivé avec succès";
|
||||
@@ -214,7 +230,12 @@ public class UserController {
|
||||
@GetMapping("/all")
|
||||
public ResponseEntity<?> getAll(@CurrentUser UserPrincipal userPrincipal) {
|
||||
try {
|
||||
|
||||
if(userPrincipal==null){
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(false, null, "Vous n'êtes pas authorisés à accéder à la liste des utilisateurs"),
|
||||
HttpStatus.OK
|
||||
);
|
||||
}
|
||||
User user = userPrincipal.getUser();
|
||||
|
||||
if (user.getRoles().stream().anyMatch(r -> r.getNom().equals(UserRole.ROLE_ADMIN))) {
|
||||
@@ -353,5 +374,12 @@ public class UserController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean containsRoleAnonyme(Set<Role> roles){
|
||||
for(Role r: roles ){
|
||||
if(r.getNom().equals(UserRole.ROLE_ANONYMOUS)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user