Merge pull request 'Link back and front all get' (#115) from wal/front/listingUsers into master
Reviewed-on: PGL/Clyde#115 Reviewed-by: Debucquoy Anthony <d.tonitch@gmail.com> Reviewed-by: LeoMoulin <leomoulin125@gmail.com>
This commit is contained in:
		
							
								
								
									
										2
									
								
								backend/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								backend/.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -35,3 +35,5 @@ out/ | ||||
|  | ||||
| ### VS Code ### | ||||
| .vscode/ | ||||
|  | ||||
| /cdn | ||||
|  | ||||
| @ -64,9 +64,12 @@ public class ApplicationsController { | ||||
|         if (!authServ.isNotIn(new Role[]{Role.Teacher,Role.Secretary,Role.Admin},token)) | ||||
|             authorizedApps.add(Applications.ManageCourses); | ||||
|  | ||||
|         if (!authServ.isNotIn(new Role[]{Role.InscriptionService,Role.Admin},token)) | ||||
|         if (!authServ.isNotIn(new Role[]{Role.InscriptionService,Role.Admin},token)){ | ||||
|             authorizedApps.add(Applications.Inscription); | ||||
|             authorizedApps.add(Applications.StudentsList);} | ||||
|  | ||||
|         if (!authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)){  | ||||
|           authorizedApps.add(Applications.UsersList);} | ||||
|         return authorizedApps; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -74,7 +74,8 @@ public class CourseController { | ||||
|     public ResponseEntity<Map<String ,Object>> postCourse(@RequestHeader("Authorization") String token, | ||||
|                                              @RequestBody Course course) | ||||
|     { | ||||
|  | ||||
|         System.out.println(course); | ||||
|         System.out.println(token); | ||||
|         if (authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)) | ||||
|             return new UnauthorizedResponse<>(null); | ||||
|  | ||||
|  | ||||
| @ -57,7 +57,6 @@ public class InscriptionController { | ||||
|                                                                  @RequestHeader("Authorization") String token, | ||||
|                                                                  @RequestBody RequestState state) | ||||
|     { | ||||
|  | ||||
|         if (authServ.isNotIn(new Role[]{Role.InscriptionService,Role.Admin},token)) | ||||
|             return new UnauthorizedResponse<>(null); | ||||
|  | ||||
|  | ||||
| @ -53,8 +53,9 @@ public class MockController { | ||||
|         User joe = new User("Mama","Joe","student@student.com","roundabout","DaWarudo",new Date(0), null,Role.Student,passwordEncoder.encode("student")); | ||||
|         User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0), null,Role.Secretary,passwordEncoder.encode("secretary")); | ||||
|         User joke = new User("CthemBalls","Lemme","teacher@teacher.com","lab","faculty",new Date(0), null,Role.Teacher,passwordEncoder.encode("teacher")); | ||||
|         User jojo = new User("hhoo","yeay","teacher2@teacher2.com","lab","faculty",new Date(0), null,Role.Teacher,passwordEncoder.encode("teacher")); | ||||
|         User lena = new User("Louille","Lena","inscriptionService@InscriptionService.com","no","yes",new Date(0), null,Role.InscriptionService,passwordEncoder.encode("inscriptionService")); | ||||
|         mockUsers = new ArrayList<>(Arrays.asList(herobrine,joe,meh,joke,lena)); | ||||
|         mockUsers = new ArrayList<>(Arrays.asList(herobrine,joe,meh,joke,lena,jojo)); | ||||
|  | ||||
|         userRepo.saveAll(mockUsers); | ||||
|  | ||||
| @ -91,7 +92,7 @@ public class MockController { | ||||
|         CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,chemistry1)); | ||||
|  | ||||
|  | ||||
|         InscriptionRequest inscriptionRequest = new InscriptionRequest("helen","prenom","non","helen@gmail.com","america",new Date(),(long) 1,RequestState.Refused,"yes.png","password"); | ||||
|         InscriptionRequest inscriptionRequest = new InscriptionRequest("helen","prenom","non","helen@gmail.com","america",new Date(),(long) 1,RequestState.Pending,"yes.png","password"); | ||||
|  | ||||
|         inscriptionService.save(inscriptionRequest); | ||||
|          | ||||
|  | ||||
| @ -63,7 +63,7 @@ public class UserController { | ||||
|     public ResponseEntity<Iterable<HashMap<String,Object>>> getAllUsers(@RequestHeader("Authorization") String token){ | ||||
|  | ||||
|         if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token)) | ||||
|             return new UnauthorizedResponse<>(null); | ||||
|           return new UnauthorizedResponse<>(null); | ||||
|  | ||||
|         Role posterRole = authServ.getUserFromToken(token).getRole(); | ||||
|  | ||||
| @ -122,9 +122,10 @@ public class UserController { | ||||
|         return new ResponseEntity<>(ProtectionService.usersWithoutPasswords(students), HttpStatus.OK); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     @DeleteMapping("/user/{id}") | ||||
|     public ResponseEntity<String> deleteStudent(@RequestHeader("Authorization") String token, @PathVariable Long id){ | ||||
|         if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token) || id.equals(authServ.getUserFromToken(token).getRegNo())) | ||||
|         if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token) && !id.equals(authServ.getUserFromToken(token).getRegNo())) | ||||
|             return new UnauthorizedResponse<>(null); | ||||
|  | ||||
|         User toDelete = userService.getUserById(id); | ||||
| @ -135,4 +136,4 @@ public class UserController { | ||||
|         userService.delete(toDelete); | ||||
|         return new ResponseEntity<>(HttpStatus.OK); | ||||
|     } | ||||
| } | ||||
| } | ||||
|  | ||||
| @ -123,6 +123,7 @@ public class UserService { | ||||
|  | ||||
|     public Iterable<User> getAllStudents(){return userRepo.findAllStudents();} | ||||
|  | ||||
|  | ||||
|     public User getUserById(long id) { | ||||
|         return userRepo.findById(id); | ||||
|     } | ||||
|  | ||||
| @ -15,7 +15,9 @@ public enum Applications { | ||||
|  | ||||
|     // teachers and Secretary authorization | ||||
|     ManageCourses, | ||||
|     UsersList, | ||||
|  | ||||
|     // InscriptionService authorization | ||||
|     Inscription | ||||
|     Inscription, | ||||
|     StudentsList | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user