added security to assistant posting and Get courses/owned for owners
This commit is contained in:
@@ -31,6 +31,13 @@ public class CourseService {
|
||||
return courseRepo.findAll();
|
||||
}
|
||||
|
||||
|
||||
public Iterable<Course> findOwnedCourses(User userFromToken) {
|
||||
return courseRepo.findAllOwnedCoures(userFromToken);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean modifyData(long id, Map<String, Object> updates, Role role) {
|
||||
Course target = courseRepo.findById(id);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package ovh.herisson.Clyde.Services;
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ProtectionService {
|
||||
@@ -13,6 +14,7 @@ public class ProtectionService {
|
||||
*/
|
||||
public static HashMap<String,Object> userWithoutPassword(User user){
|
||||
HashMap<String,Object> toReturn = new HashMap<>();
|
||||
|
||||
toReturn.put("regNo",user.getRegNo());
|
||||
toReturn.put("lastName",user.getLastName());
|
||||
toReturn.put("firstName",user.getFirstName());
|
||||
@@ -24,6 +26,19 @@ public class ProtectionService {
|
||||
toReturn.put("role",user.getRole());
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static Iterable<HashMap<String ,Object>>usersWithoutPasswords(Iterable<User> users){
|
||||
ArrayList<HashMap<String,Object>> toReturn = new ArrayList<>();
|
||||
|
||||
for (User u : users){
|
||||
toReturn.add(userWithoutPassword(u));
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static HashMap<String,Object> courseWithoutPassword(Course course){
|
||||
HashMap<String ,Object> toReturn = new HashMap<>();
|
||||
|
||||
@@ -34,5 +49,17 @@ public class ProtectionService {
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static Iterable<HashMap<String ,Object>> coursesWithoutPasswords(Iterable<Course> courses){
|
||||
ArrayList<HashMap<String,Object>> toReturn = new ArrayList<>();
|
||||
|
||||
for (Course course: courses){
|
||||
toReturn.add(ProtectionService.courseWithoutPassword(course));
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.springframework.stereotype.Controller;
|
||||
import ovh.herisson.Clyde.Repositories.TeacherCourseRepository;
|
||||
import ovh.herisson.Clyde.Repositories.UserRepository;
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.TeacherCourse;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
@@ -20,6 +21,13 @@ public class TeacherCourseService {
|
||||
this.userRepo = userRepo;
|
||||
}
|
||||
|
||||
public Iterable<User> findCourseAssistants(Course course) {
|
||||
if (course == null)
|
||||
return null;
|
||||
return teacherCourseRepo.findAllAssistantOfCourse(course);
|
||||
}
|
||||
|
||||
|
||||
public boolean saveAll(Iterable<Long> teacherIds, Course course){
|
||||
|
||||
if (course == null || teacherIds == null)
|
||||
@@ -31,7 +39,7 @@ public class TeacherCourseService {
|
||||
if ( teacher== null){
|
||||
return false;
|
||||
}
|
||||
if (!toAdd.contains(teacher))
|
||||
if (!toAdd.contains(teacher) && teacher.getRole() == Role.Teacher)
|
||||
{
|
||||
toAdd.add(teacher);
|
||||
}
|
||||
@@ -41,4 +49,5 @@ public class TeacherCourseService {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user