Compare commits

..

6 Commits

Author SHA1 Message Date
19b4950be4 Merge branch 'master' into wal/front/listingUsers
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 2m4s
Build and test backend / Test-backend (pull_request) Successful in 1m57s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 23s
2024-03-17 21:39:04 +01:00
7a23dcc96a Merge pull request 'Max/Backend/ReturnUserPasswordIssue' (#137) from Max/Backend/ReturnUserPasswordIssue into master
All checks were successful
Build and test backend / Test-backend (push) Successful in 1m20s
deploy to production / deploy-frontend (push) Successful in 23s
Build and test backend / Build-backend (push) Successful in 2m12s
deploy to production / deploy-backend (push) Successful in 2m18s
Build and test FrontEnd / Build-frontend (push) Successful in 23s
Reviewed-on: #137
Reviewed-by: Wal <karpinskiwal@gmail.com>
Reviewed-by: LeoMoulin <leomoulin125@gmail.com>
Reviewed-by: Debucquoy Anthony <d.tonitch@gmail.com>
2024-03-17 21:36:53 +01:00
ea4a0745e0 creation of the user when request accepted
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 2m42s
Build and test backend / Test-backend (pull_request) Successful in 2m30s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 33s
2024-03-17 17:15:33 +01:00
76f5a39a8f GET /users doesn't return Admins if the poster isn't an admin
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 2m1s
Build and test backend / Test-backend (pull_request) Successful in 2m0s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 24s
2024-03-17 16:26:30 +01:00
37f8a3ac4e removed an unused variable 2024-03-17 16:25:00 +01:00
ea46dd664c added a todo to send an email for every state changement of request
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 1m58s
Build and test backend / Test-backend (pull_request) Successful in 1m59s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 25s
2024-03-17 16:02:30 +01:00
10 changed files with 93 additions and 38 deletions

View File

@ -54,8 +54,6 @@ public class ApplicationsController {
// if authed
authorizedApps.add(Applications.Profile);
Role posterRole = user.getRole();
if (!authServ.isNotIn(new Role[]{Role.Teacher,Role.Student,Role.Admin},token)) {
authorizedApps.add(Applications.Msg);
authorizedApps.add(Applications.Forum);

View File

@ -58,22 +58,6 @@ public class InscriptionController {
return new ResponseEntity<>(requestWithoutPassword(foundInscriptionRequest), HttpStatus.OK);
}
/**
@GetMapping("request/user")
public ResponseEntity<InscriptionRequest> getUserInscriptionRequest(@RequestHeader("Authorization") String token){
//todo return l'inscriptionRequest ACTUELLE du user (check si le poster est bien le même que id target ou secretariat)
if (authServ.IsNotIn(new Role[]{Role.Student,Role.Admin},token))
return new UnauthorizedResponse<>(null);
User poster = authServ.getUserFromToken(token);
inscriptionServ.getById()
return null;
} **/
@PatchMapping("/request/register/{id}")
public ResponseEntity<InscriptionRequest> changeRequestState(@PathVariable long id,
@RequestHeader("Authorization") String token,
@ -99,7 +83,7 @@ public class InscriptionController {
toReturn.put("email",inscriptionRequest.getEmail());
toReturn.put("birthDate", inscriptionRequest.getBirthDate());
toReturn.put("country", inscriptionRequest.getCountry());
toReturn.put("curriculum", inscriptionRequest.getCurriculum());
toReturn.put("curriculum", inscriptionRequest.getCurriculumId());
toReturn.put("state", inscriptionRequest.getState());
toReturn.put("profilePictureUrl", inscriptionRequest.getProfilePicture());

View File

@ -44,7 +44,7 @@ public class LoginController {
return ResponseEntity.ok().headers(responseHeaders).build();
}
@PostMapping("/request/register")
@PostMapping("/register")
public ResponseEntity<InscriptionRequest> register(@RequestBody InscriptionRequest inscriptionRequest){
return new ResponseEntity<>(authServ.register(inscriptionRequest), HttpStatus.CREATED);
}

View File

@ -9,6 +9,8 @@ import ovh.herisson.Clyde.Services.ProtectionService;
import ovh.herisson.Clyde.Services.UserService;
import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.User;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@ -53,7 +55,15 @@ public class UserController {
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token))
return new UnauthorizedResponse<>(null);
Iterable<User> users = userService.getAll();
Role posterRole = authServ.getUserFromToken(token).getRole();
Iterable<User> users = new ArrayList<>();
if (posterRole == Role.Admin)
users = userService.getAll();
else if (posterRole == Role.Secretary)
users = userService.getAllExceptAdmins();
return new ResponseEntity<>(ProtectionService.usersWithoutPasswords(users), HttpStatus.OK);
}

View File

@ -0,0 +1,7 @@
package ovh.herisson.Clyde.Repositories;
import org.springframework.data.repository.CrudRepository;
import ovh.herisson.Clyde.Tables.UserCurriculum;
public interface UserCurriculumRepository extends CrudRepository<UserCurriculum, Long> {
}

View File

@ -10,9 +10,14 @@ public interface UserRepository extends CrudRepository<User, Long> {
User findByEmail(String email);
@Query("select u from User u where u.role = ovh.herisson.Clyde.Tables.Role.Teacher")
Iterable<User> findAllTeachers();
@Query("select u from User u where u.role = ovh.herisson.Clyde.Tables.Role.Student")
Iterable<User> findAllStudents();
@Query("select u from User u where u.role <> ovh.herisson.Clyde.Tables.Role.Admin")
Iterable<User> findAllExceptAdmins();
}

View File

@ -2,9 +2,7 @@ package ovh.herisson.Clyde.Services;
import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.Tables.*;
import java.util.Date;
import java.util.HashMap;
@Service
public class AuthenticatorService {

View File

@ -1,20 +1,39 @@
package ovh.herisson.Clyde.Services;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.Repositories.CurriculumRepository;
import ovh.herisson.Clyde.Repositories.InscriptionRepository;
import ovh.herisson.Clyde.Repositories.UserCurriculumRepository;
import ovh.herisson.Clyde.Repositories.UserRepository;
import ovh.herisson.Clyde.Tables.InscriptionRequest;
import ovh.herisson.Clyde.Tables.RequestState;
import ovh.herisson.Clyde.Tables.User;
import ovh.herisson.Clyde.Tables.UserCurriculum;
@Service
public class InscriptionService {
InscriptionRepository inscriptionRepo;
private final InscriptionRepository inscriptionRepo;
public InscriptionService(InscriptionRepository inscriptionRepo){
private final UserRepository userRepo;
private final UserCurriculumRepository userCurriculumRepo;
private final CurriculumRepository curriculumRepo;
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
public InscriptionService(InscriptionRepository inscriptionRepo, UserRepository userRepo, UserCurriculumRepository userCurriculumRepo, CurriculumRepository curriculumRepo){
this.inscriptionRepo = inscriptionRepo;
this.userRepo = userRepo;
this.userCurriculumRepo = userCurriculumRepo;
this.curriculumRepo = curriculumRepo;
}
public InscriptionRequest save(InscriptionRequest inscriptionRequest){
inscriptionRequest.setPassword(passwordEncoder.encode(inscriptionRequest.getPassword()));
return inscriptionRepo.save(inscriptionRequest);
}
@ -27,13 +46,45 @@ public class InscriptionService {
}
public boolean modifyState(long id, RequestState requestState) {
InscriptionRequest inscriptionRequest = getById(id);
InscriptionRequest inscrRequest = getById(id);
if (inscriptionRequest == null)
if (inscrRequest == null)
return false;
inscriptionRequest.setState(requestState);
save(inscriptionRequest);
// if th state is the same we don't send an email
if (requestState == inscrRequest.getState())
return false;
/** todo send an email to tell the poster of the inscrRequest (inscrRequest.getEmail())
* to notify them that the state of their request changed
* FooEmailFormat toSend = (String.format("Your request state changed from %s to %s"),
* inscrRequest.getState(), requestState)
* FooEmailSender.send(toSend, inscrRequest.getEmail())
*/
//saves the user from the request if accepted
if (requestState == RequestState.Accepted)
{
if (curriculumRepo.findById(inscrRequest.getCurriculumId()) == null)
return false;
User userFromRequest = new User(
inscrRequest.getLastName(),
inscrRequest.getFirstName(),
inscrRequest.getEmail(),
inscrRequest.getAddress(),
inscrRequest.getCountry(),
inscrRequest.getBirthDate(),
inscrRequest.getProfilePicture(),
inscrRequest.getPassword()
);
userRepo.save(userFromRequest);
userCurriculumRepo.save(new UserCurriculum(userFromRequest, curriculumRepo.findById(inscrRequest.getCurriculumId())));
}
inscrRequest.setState(requestState);
save(inscrRequest);
return true;
}
}

View File

@ -114,6 +114,10 @@ public class UserService {
return userRepo.findAll();
}
public Iterable<User> getAllExceptAdmins(){
return userRepo.findAllExceptAdmins();
}
public Iterable<User> getAllTeachers (){return userRepo.findAllTeachers();}

View File

@ -16,22 +16,20 @@ public class InscriptionRequest {
private String country;
private Date birthDate;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="Curriculum")
private Curriculum curriculum;
private Long curriculumId;
private RequestState state;
private String profilePicture;
private String password;
public InscriptionRequest(){}
public InscriptionRequest(String lastName, String firstName, String address, String email, String country, Date birthDate,Curriculum curriculum, RequestState state, String profilePicture, String password){
public InscriptionRequest(String lastName, String firstName, String address, String email, String country, Date birthDate,Long curriculumId, RequestState state, String profilePicture, String password){
this.lastName = lastName;
this.firstName = firstName;
this.address = address;
this.email = email;
this.country = country;
this.birthDate = birthDate;
this.curriculum = curriculum;
this.curriculumId = curriculumId;
this.state = state;
this.profilePicture = profilePicture;
this.password = password;
@ -89,12 +87,12 @@ public class InscriptionRequest {
this.birthDate = birthDate;
}
public Curriculum getCurriculum() {
return curriculum;
public long getCurriculumId() {
return curriculumId;
}
public void setCurriculum(Curriculum curriculum) {
this.curriculum = curriculum;
public void setCurriculumId(long curriculum) {
this.curriculumId = curriculum;
}
public RequestState getState() {