Compare commits
No commits in common. "25009ba149938c74594d53088e7c52ea5ad0fd16" and "1f14890d435bc8bd3d0350616708dab09f777e4f" have entirely different histories.
25009ba149
...
1f14890d43
@ -44,17 +44,17 @@ public class ApplicationsController {
|
|||||||
Role posterRole = authServ.getUserFromToken(token).getRole();
|
Role posterRole = authServ.getUserFromToken(token).getRole();
|
||||||
ArrayList<Applications> authorizedApps = new ArrayList<>();
|
ArrayList<Applications> authorizedApps = new ArrayList<>();
|
||||||
|
|
||||||
authorizedApps.add(Applications.Login);
|
authorizedApps.add(Applications.LOGIN);
|
||||||
authorizedApps.add(Applications.Profile);
|
authorizedApps.add(Applications.PROFILE);
|
||||||
authorizedApps.add(Applications.Msg);
|
authorizedApps.add(Applications.MSG);
|
||||||
authorizedApps.add(Applications.Forum);
|
authorizedApps.add(Applications.FORUM);
|
||||||
authorizedApps.add(Applications.Rdv);
|
authorizedApps.add(Applications.RDV);
|
||||||
|
|
||||||
if (posterRole == Role.Student || posterRole == Role.Admin) return authorizedApps;
|
if (posterRole == Role.Student || posterRole == Role.Admin) return authorizedApps;
|
||||||
|
|
||||||
if (posterRole == Role.Teacher || posterRole == Role.Secretary || posterRole == Role.Admin) authorizedApps.add(Applications.ManageCourses);
|
if (posterRole == Role.Teacher || posterRole == Role.Secretary || posterRole == Role.Admin) authorizedApps.add(Applications.MANAGECOURSES);
|
||||||
|
|
||||||
if (posterRole == Role.InscriptionService || posterRole == Role.Admin) authorizedApps.add(Applications.Inscription);
|
if (posterRole == Role.InscriptionService || posterRole == Role.Admin) authorizedApps.add(Applications.INSCRIPTION);
|
||||||
|
|
||||||
return authorizedApps;
|
return authorizedApps;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ public class InscriptionController {
|
|||||||
@GetMapping("/inscriptionRequests")
|
@GetMapping("/inscriptionRequests")
|
||||||
public ResponseEntity<Iterable<Map<String,Object>>> getAllRequests(@RequestHeader("Authorization") String token){
|
public ResponseEntity<Iterable<Map<String,Object>>> getAllRequests(@RequestHeader("Authorization") String token){
|
||||||
|
|
||||||
if (authServ.isNotSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);}
|
if (!isSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);}
|
||||||
|
|
||||||
Iterable<InscriptionRequest> inscriptionRequests = inscriptionServ.getAll();
|
Iterable<InscriptionRequest> inscriptionRequests = inscriptionServ.getAll();
|
||||||
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
||||||
@ -70,4 +70,15 @@ public class InscriptionController {
|
|||||||
toReturn.put("state", inscriptionRequest.getState());
|
toReturn.put("state", inscriptionRequest.getState());
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean isSecretaryOrAdmin(String authorization){
|
||||||
|
if (authorization ==null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
User poster = authServ.getUserFromToken(authorization);
|
||||||
|
if (poster == null) return false;
|
||||||
|
|
||||||
|
return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin;
|
||||||
|
}
|
||||||
}
|
}
|
@ -43,7 +43,7 @@ public class UserController {
|
|||||||
@PostMapping("/user")
|
@PostMapping("/user")
|
||||||
public ResponseEntity<String> postUser(@RequestBody User user,@RequestHeader("Authorization") String authorization){
|
public ResponseEntity<String> postUser(@RequestBody User user,@RequestHeader("Authorization") String authorization){
|
||||||
|
|
||||||
if (authServ.isNotSecretaryOrAdmin(authorization))
|
if (!isSecretaryOrAdmin(authorization))
|
||||||
return new UnauthorizedResponse<>(null);
|
return new UnauthorizedResponse<>(null);
|
||||||
|
|
||||||
userService.save(user);
|
userService.save(user);
|
||||||
@ -53,7 +53,7 @@ public class UserController {
|
|||||||
@GetMapping("/users")
|
@GetMapping("/users")
|
||||||
public ResponseEntity<Iterable<HashMap<String,Object>>> getAllUsers(@RequestHeader("Authorization") String authorization){
|
public ResponseEntity<Iterable<HashMap<String,Object>>> getAllUsers(@RequestHeader("Authorization") String authorization){
|
||||||
|
|
||||||
if (authServ.isNotSecretaryOrAdmin(authorization))
|
if (!isSecretaryOrAdmin(authorization))
|
||||||
return new UnauthorizedResponse<>(null);
|
return new UnauthorizedResponse<>(null);
|
||||||
|
|
||||||
Iterable<User> users = userService.getAll();
|
Iterable<User> users = userService.getAll();
|
||||||
@ -85,6 +85,7 @@ public class UserController {
|
|||||||
*/
|
*/
|
||||||
private HashMap<String,Object> userWithoutPassword(User user){
|
private HashMap<String,Object> userWithoutPassword(User user){
|
||||||
HashMap<String,Object> toReturn = new HashMap<>();
|
HashMap<String,Object> toReturn = new HashMap<>();
|
||||||
|
|
||||||
toReturn.put("regNo",user.getRegNo());
|
toReturn.put("regNo",user.getRegNo());
|
||||||
toReturn.put("firstName",user.getFirstName());
|
toReturn.put("firstName",user.getFirstName());
|
||||||
toReturn.put("lastName",user.getLastName());
|
toReturn.put("lastName",user.getLastName());
|
||||||
@ -92,7 +93,18 @@ public class UserController {
|
|||||||
toReturn.put("country",user.getCountry());
|
toReturn.put("country",user.getCountry());
|
||||||
toReturn.put("address",user.getAddress());
|
toReturn.put("address",user.getAddress());
|
||||||
toReturn.put("role",user.getRole());
|
toReturn.put("role",user.getRole());
|
||||||
|
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isSecretaryOrAdmin(String authorization){
|
||||||
|
if (authorization ==null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
User poster = authServ.getUserFromToken(authorization);
|
||||||
|
if (poster == null) return false;
|
||||||
|
|
||||||
|
return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import org.springframework.stereotype.Service;
|
|||||||
import ovh.herisson.Clyde.EndPoints.LoginController;
|
import ovh.herisson.Clyde.EndPoints.LoginController;
|
||||||
import ovh.herisson.Clyde.Repositories.InscriptionRepository;
|
import ovh.herisson.Clyde.Repositories.InscriptionRepository;
|
||||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
||||||
import ovh.herisson.Clyde.Tables.Role;
|
|
||||||
import ovh.herisson.Clyde.Tables.Token;
|
import ovh.herisson.Clyde.Tables.Token;
|
||||||
import ovh.herisson.Clyde.Tables.User;
|
import ovh.herisson.Clyde.Tables.User;
|
||||||
|
|
||||||
@ -40,17 +39,4 @@ public class AuthenticatorService {
|
|||||||
public void register(InscriptionRequest inscriptionRequest) {
|
public void register(InscriptionRequest inscriptionRequest) {
|
||||||
inscriptionService.save(inscriptionRequest);
|
inscriptionService.save(inscriptionRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isNotSecretaryOrAdmin(String authorization){
|
|
||||||
if (authorization ==null)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
User poster = getUserFromToken(authorization);
|
|
||||||
if (poster == null) return true;
|
|
||||||
|
|
||||||
return poster.getRole() != Role.Secretary || poster.getRole() != Role.Admin;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,20 +2,23 @@ package ovh.herisson.Clyde.Tables;
|
|||||||
|
|
||||||
public enum Applications {
|
public enum Applications {
|
||||||
// without any token
|
// without any token
|
||||||
Login,
|
LOGIN,
|
||||||
|
|
||||||
// with any token
|
// with any token
|
||||||
Profile,
|
PROFILE,
|
||||||
|
|
||||||
|
|
||||||
// Students and higher authorization
|
// Students and higher authorization
|
||||||
Msg,
|
MSG,
|
||||||
Forum,
|
FORUM,
|
||||||
Rdv,
|
RDV,
|
||||||
|
|
||||||
// teachers and Secretary authorization
|
// teachers and Secretary authorization
|
||||||
ManageCourses,
|
MANAGECOURSES,
|
||||||
|
|
||||||
// InscriptionService authorization
|
// InscriptionService authorization
|
||||||
Inscription
|
INSCRIPTION;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package ovh.herisson.Clyde.Tables;
|
|||||||
|
|
||||||
public enum CursusType {
|
public enum CursusType {
|
||||||
|
|
||||||
InfoBab1,
|
infoBab1,
|
||||||
ChemistryBab1,
|
chemistryBab1,
|
||||||
PsychologyBab1
|
psychologyBab1;
|
||||||
}
|
}
|
||||||
|
@ -3,5 +3,5 @@ package ovh.herisson.Clyde.Tables;
|
|||||||
public enum RequestState {
|
public enum RequestState {
|
||||||
Accepted,
|
Accepted,
|
||||||
Refused,
|
Refused,
|
||||||
Pending
|
Pending;
|
||||||
}
|
}
|
||||||
|
@ -5,5 +5,5 @@ public enum Role {
|
|||||||
Student,
|
Student,
|
||||||
Admin,
|
Admin,
|
||||||
InscriptionService,
|
InscriptionService,
|
||||||
Secretary
|
Secretary;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user