Compare commits
	
		
			2 Commits
		
	
	
		
			ea46dd664c
			...
			76f5a39a8f
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 76f5a39a8f | |||
| 37f8a3ac4e | 
@ -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);
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
}
 | 
			
		||||
@ -114,6 +114,10 @@ public class UserService {
 | 
			
		||||
        return userRepo.findAll();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Iterable<User> getAllExceptAdmins(){
 | 
			
		||||
        return userRepo.findAllExceptAdmins();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public Iterable<User> getAllTeachers (){return userRepo.findAllTeachers();}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user