Skip to content

Commit

Permalink
Merge pull request #266 from SELab-2/feature/studentnummer_en_project…
Browse files Browse the repository at this point in the history
…visibletime

Studentennummer + tijdstip waarop project zichtbaar wordt
  • Loading branch information
usserwoutV2 authored May 18, 2024
2 parents d9ce256 + 746a319 commit e8e2d3b
Show file tree
Hide file tree
Showing 45 changed files with 591 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void doFilterInternal(HttpServletRequest request, HttpServletResponse res
String lastName;
String email;
String oid;
String studentnumber;

String version = jwt.getClaim("ver").asString();

Expand All @@ -92,21 +93,21 @@ public void doFilterInternal(HttpServletRequest request, HttpServletResponse res
lastName = jwt.getClaim("family_name").asString();
email = jwt.getClaim("unique_name").asString();
oid = jwt.getClaim("oid").asString();
studentnumber = jwt.getClaim("ugentStudentID").asString();
} else if (version.startsWith("2.0")) {
displayName = jwt.getClaim("name").asString();
lastName = jwt.getClaim("surname").asString();
firstName = displayName.replace(lastName, "").strip();
email = jwt.getClaim("mail").asString();
oid = jwt.getClaim("oid").asString();
studentnumber = jwt.getClaim("ugentStudentID").asString();
} else {
throw new JwkException("Invalid OAuth version");
}
// print full object
// logger.info(jwt.getClaims());
logger.info(jwt.getClaims());



User user = new User(displayName, firstName,lastName, email, oid);
User user = new User(displayName, firstName,lastName, email, oid, studentnumber);

Auth authUser = new Auth(user, new ArrayList<>());
SecurityContextHolder.getContext().setAuthentication(authUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons

if(userEntity == null) {
System.out.println("User does not exist, creating new one. user_id: " + auth.getOid());
userEntity = new UserEntity(auth.getUser().firstName,auth.getUser().lastName, auth.getEmail(), UserRole.student, auth.getOid());
userEntity = new UserEntity(auth.getUser().firstName,auth.getUser().lastName, auth.getEmail(), UserRole.student, auth.getOid(), auth.getStudentNumber());
OffsetDateTime now = OffsetDateTime.now();
userEntity.setCreatedAt(now);
userEntity = userRepository.save(userEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@ public ResponseEntity<?> getClustersForCourse(@PathVariable("courseid") Long cou
if (checkResult.getStatus() != HttpStatus.OK) {
return ResponseEntity.status(checkResult.getStatus()).body(checkResult.getMessage());
}

CourseRelation courseRelation = checkResult.getData().getSecond();
boolean hideStudentNumber = courseRelation.equals(CourseRelation.enrolled);

// Get the clusters for the course
List<GroupClusterEntity> clusters = groupClusterRepository.findClustersWithoutInvidualByCourseId(courseid);
List<GroupClusterJson> clusterJsons = clusters.stream().map(
entityToJsonConverter::clusterEntityToClusterJson).toList();
g -> entityToJsonConverter.clusterEntityToClusterJson(g, hideStudentNumber)
).toList();
// Return the clusters
return ResponseEntity.ok(clusterJsons);
}
Expand Down Expand Up @@ -107,13 +112,14 @@ public ResponseEntity<?> createClusterForCourse(@PathVariable("courseid") Long c
clusterJson.groupCount()
);
cluster.setCreatedAt(OffsetDateTime.now());
cluster.setLockGroupsAfter(clusterJson.lockGroupsAfter());
GroupClusterEntity clusterEntity = groupClusterRepository.save(cluster);

for (int i = 0; i < clusterJson.groupCount(); i++) {
groupRepository.save(new GroupEntity("Group " + (i + 1), cluster.getId()));
}

GroupClusterJson clusterJsonResponse = entityToJsonConverter.clusterEntityToClusterJson(clusterEntity);
GroupClusterJson clusterJsonResponse = entityToJsonConverter.clusterEntityToClusterJson(clusterEntity, false);

// Return the cluster
return ResponseEntity.status(HttpStatus.CREATED).body(clusterJsonResponse);
Expand All @@ -138,8 +144,11 @@ public ResponseEntity<?> getCluster(@PathVariable("clusterid") Long clusterid, A
return ResponseEntity.status(checkResult.getStatus()).body(checkResult.getMessage());
}
GroupClusterEntity cluster = checkResult.getData();

CheckResult<CourseEntity> courseAdmin = courseUtil.getCourseIfAdmin(cluster.getCourseId(), auth.getUserEntity());
boolean hideStudentNumber = !courseAdmin.getStatus().equals(HttpStatus.OK);
// Return the cluster
return ResponseEntity.ok(entityToJsonConverter.clusterEntityToClusterJson(cluster));
return ResponseEntity.ok(entityToJsonConverter.clusterEntityToClusterJson(cluster, hideStudentNumber));
}


Expand Down Expand Up @@ -174,8 +183,9 @@ public ResponseEntity<?> doGroupClusterUpdate(GroupClusterEntity clusterEntity,
}
clusterEntity.setMaxSize(clusterJson.getCapacity());
clusterEntity.setName(clusterJson.getName());
clusterEntity.setLockGroupsAfter(clusterJson.getLockGroupsAfter());
clusterEntity = groupClusterRepository.save(clusterEntity);
return ResponseEntity.ok(entityToJsonConverter.clusterEntityToClusterJson(clusterEntity));
return ResponseEntity.ok(entityToJsonConverter.clusterEntityToClusterJson(clusterEntity, false));
}

/**
Expand Down Expand Up @@ -226,7 +236,7 @@ public ResponseEntity<?> fillCluster(@PathVariable("clusterid") Long clusterid,

groupCluster.setGroupAmount(clusterFillJson.getClusterGroupMembers().size());
groupClusterRepository.save(groupCluster);
return ResponseEntity.status(HttpStatus.OK).body(entityToJsonConverter.clusterEntityToClusterJson(groupCluster));
return ResponseEntity.status(HttpStatus.OK).body(entityToJsonConverter.clusterEntityToClusterJson(groupCluster, false));
} catch (Exception e) {
Logger.getGlobal().severe(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Something went wrong");
Expand All @@ -253,6 +263,10 @@ public ResponseEntity<?> patchCluster(@PathVariable("clusterid") Long clusterid,
clusterJson.setName(cluster.getName());
}

if (clusterJson.getLockGroupsAfter() == null) {
clusterJson.setLockGroupsAfter(cluster.getLockGroupsAfter());
}

return doGroupClusterUpdate(cluster, clusterJson);
}

Expand Down Expand Up @@ -317,6 +331,6 @@ public ResponseEntity<?> createGroupForCluster(@PathVariable("clusterid") Long c

cluster.setGroupAmount(cluster.getGroupAmount() + 1);
groupClusterRepository.save(cluster);
return ResponseEntity.status(HttpStatus.CREATED).body(entityToJsonConverter.groupEntityToJson(group));
return ResponseEntity.status(HttpStatus.CREATED).body(entityToJsonConverter.groupEntityToJson(group, false));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -591,14 +591,16 @@ public ResponseEntity<?> getCourseMembers(Auth auth, @PathVariable Long courseId
return ResponseEntity.status(checkResult.getStatus()).body(checkResult.getMessage());
}

boolean hideStudentNumber = checkResult.getData().getSecond().equals(CourseRelation.enrolled);

List<CourseUserEntity> members = courseUserRepository.findAllMembers(courseId);
List<UserReferenceWithRelation> memberJson = members.stream().
map(cue -> {
UserEntity user = userUtil.getUserIfExists(cue.getUserId());
if (user == null) {
return null;
}
return entityToJsonConverter.userEntityToUserReferenceWithRelation(user, cue.getRelation());
return entityToJsonConverter.userEntityToUserReferenceWithRelation(user, cue.getRelation(), hideStudentNumber);
}).
filter(Objects::nonNull).toList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import com.ugent.pidgeon.postgre.models.types.UserRole;
import com.ugent.pidgeon.postgre.repository.GroupRepository;
import com.ugent.pidgeon.util.CheckResult;
import com.ugent.pidgeon.util.ClusterUtil;
import com.ugent.pidgeon.util.CommonDatabaseActions;
import com.ugent.pidgeon.util.CourseUtil;
import com.ugent.pidgeon.util.EntityToJsonConverter;
import com.ugent.pidgeon.util.GroupUtil;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -28,6 +30,10 @@ public class GroupController {
private EntityToJsonConverter entityToJsonConverter;
@Autowired
private CommonDatabaseActions commonDatabaseActions;
@Autowired
private ClusterUtil clusterUtil;
@Autowired
private CourseUtil courseUtil;


/**
Expand All @@ -50,8 +56,14 @@ public ResponseEntity<?> getGroupById(@PathVariable("groupid") Long groupid, Aut
return ResponseEntity.status(checkResult1.getStatus()).body(checkResult1.getMessage());
}

boolean hideStudentNumber = true;
CheckResult<Void> adminCheck = groupUtil.isAdminOfGroup(groupid, auth.getUserEntity());
if (adminCheck.getStatus().equals(HttpStatus.OK)) {
hideStudentNumber = false;
}

// Return the group
GroupJson groupJson = entityToJsonConverter.groupEntityToJson(group);
GroupJson groupJson = entityToJsonConverter.groupEntityToJson(group, hideStudentNumber);
return ResponseEntity.ok(groupJson);
}

Expand Down Expand Up @@ -113,7 +125,7 @@ private ResponseEntity<?> doGroupNameUpdate(Long groupid, NameRequest nameReques
groupRepository.save(group);

// Return the updated group
GroupJson groupJson = entityToJsonConverter.groupEntityToJson(group);
GroupJson groupJson = entityToJsonConverter.groupEntityToJson(group, false);
return ResponseEntity.ok(groupJson);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ public ResponseEntity<Object> addMemberToGroup(@PathVariable("groupid") long gro
try {
groupMemberRepository.addMemberToGroup(groupId, memberid);
List<UserEntity> members = groupMemberRepository.findAllMembersByGroupId(groupId);
List<UserReferenceJson> response = members.stream().map(entityToJsonConverter::userEntityToUserReference).toList();
List<UserReferenceJson> response = members.stream().map(
u -> entityToJsonConverter.userEntityToUserReference(u, false)
).toList();
return ResponseEntity.ok(response);
} catch (Exception e) {
Logger.getGlobal().severe(e.getMessage());
Expand Down Expand Up @@ -143,7 +145,9 @@ public ResponseEntity<Object> addMemberToGroupInferred(@PathVariable("groupid")
try {
groupMemberRepository.addMemberToGroup(groupId,user.getId());
List<UserEntity> members = groupMemberRepository.findAllMembersByGroupId(groupId);
List<UserReferenceJson> response = members.stream().map(entityToJsonConverter::userEntityToUserReference).toList();
List<UserReferenceJson> response = members.stream().map(
u -> entityToJsonConverter.userEntityToUserReference(u, true)
).toList();
return ResponseEntity.ok(response);
} catch (Exception e) {
Logger.getGlobal().severe(e.getMessage());
Expand Down Expand Up @@ -171,8 +175,12 @@ public ResponseEntity<Object> findAllMembersByGroupId(@PathVariable("groupid") l
return ResponseEntity.status(checkResult.getStatus()).body(checkResult.getMessage());
}

boolean hideStudentnumber = !groupUtil.isAdminOfGroup(groupId, user).getStatus().equals(HttpStatus.OK);

List<UserEntity> members = groupMemberRepository.findAllMembersByGroupId(groupId);
List<UserReferenceJson> response = members.stream().map((UserEntity e) -> entityToJsonConverter.userEntityToUserReference(e)).toList();
List<UserReferenceJson> response = members.stream().map(
(UserEntity e) -> entityToJsonConverter.userEntityToUserReference(e, hideStudentnumber))
.toList();
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.ugent.pidgeon.postgre.models.types.UserRole;
import com.ugent.pidgeon.postgre.repository.*;
import com.ugent.pidgeon.util.*;
import java.time.OffsetDateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -74,6 +75,10 @@ public ResponseEntity<?> getProjects(Auth auth) {
CourseRelation relation = courseCheck.getData().getSecond();

if (relation.equals(CourseRelation.enrolled)) {
if (project.getVisibleAfter() != null && project.getVisibleAfter().isBefore(OffsetDateTime.now())) {
project.setVisible(true);
projectRepository.save(project);
}
if (project.isVisible()) {
enrolledProjects.add(entityToJsonConverter.projectEntityToProjectResponseJsonWithStatus(project, course, user));
}
Expand Down Expand Up @@ -113,6 +118,11 @@ public ResponseEntity<?> getProjectById(@PathVariable Long projectId, Auth auth)
}
CourseEntity course = courseCheck.getData().getFirst();
CourseRelation relation = courseCheck.getData().getSecond();

if (project.getVisibleAfter() != null && project.getVisibleAfter().isBefore(OffsetDateTime.now())) {
project.setVisible(true);
projectRepository.save(project);
}
if (!project.isVisible() && relation.equals(CourseRelation.enrolled)) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Project not found");
}
Expand Down Expand Up @@ -161,6 +171,8 @@ public ResponseEntity<Object> createProject(
projectJson.getGroupClusterId(), null, projectJson.isVisible(),
projectJson.getMaxScore(), projectJson.getDeadline());

project.setVisibleAfter(projectJson.getVisibleAfter());

// Save the project entity
ProjectEntity savedProject = projectRepository.save(project);
CourseEntity courseEntity = checkAcces.getData();
Expand All @@ -180,6 +192,10 @@ private ResponseEntity<?> doProjectUpdate(ProjectEntity project, ProjectJson pro
project.setDeadline(projectJson.getDeadline());
project.setMaxScore(projectJson.getMaxScore());
project.setVisible(projectJson.isVisible());
project.setVisibleAfter(projectJson.getVisibleAfter());
if (project.getVisibleAfter() != null && project.getVisibleAfter().isBefore(OffsetDateTime.now())) {
project.setVisible(true);
}
projectRepository.save(project);
return ResponseEntity.ok(entityToJsonConverter.projectEntityToProjectResponseJson(project, courseRepository.findById(project.getCourseId()).get(), user));
}
Expand Down Expand Up @@ -261,6 +277,10 @@ public ResponseEntity<?> patchProjectById(@PathVariable Long projectId, @Request
projectJson.setVisible(project.isVisible());
}

if (projectJson.getVisibleAfter() == null) {
projectJson.setVisibleAfter(project.getVisibleAfter());
}

CheckResult<Void> checkProject = projectUtil.checkProjectJson(projectJson, project.getCourseId());
if (checkProject.getStatus() != HttpStatus.OK) {
return ResponseEntity.status(checkProject.getStatus()).body(checkProject.getMessage());
Expand Down Expand Up @@ -292,11 +312,15 @@ public ResponseEntity<?> getGroupsOfProject(@PathVariable Long projectId, Auth a
"No groups for this project: use " + memberUrl + " to get the members of the course");
}

boolean hideStudentNumber;
CheckResult<Void> adminCheck = projectUtil.isProjectAdmin(projectId, auth.getUserEntity());
hideStudentNumber = !adminCheck.getStatus().equals(HttpStatus.OK);

List<Long> groups = projectRepository.findGroupIdsByProjectId(projectId);
List<GroupJson> groupjsons = groups.stream()
.map((Long id) -> {
return groupRepository.findById(id).orElse(null);
}).filter(Objects::nonNull).map(entityToJsonConverter::groupEntityToJson).toList();
.map((Long id) -> groupRepository.findById(id).orElse(null)).filter(Objects::nonNull).map(
g -> entityToJsonConverter.groupEntityToJson(g, hideStudentNumber))
.toList();
return ResponseEntity.ok(groupjsons);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public ResponseEntity<?> getSubmissions(@PathVariable("projectid") long projecti
if (group == null) {
throw new RuntimeException("Group not found");
}
GroupJson groupjson = entityToJsonConverter.groupEntityToJson(group);
GroupJson groupjson = entityToJsonConverter.groupEntityToJson(group, false);
GroupFeedbackEntity groupFeedbackEntity = groupFeedbackRepository.getGroupFeedback(groupId, projectid);
GroupFeedbackJson groupFeedbackJson;
if (groupFeedbackEntity == null) {
Expand Down Expand Up @@ -201,6 +201,8 @@ public ResponseEntity<?> submitFile(@RequestParam("file") MultipartFile file, @P
Logger.getLogger("SubmissionController").info("no tests");
submission.setStructureFeedback("No specific structure requested for this project.");
submission.setStructureAccepted(true);
submission.setDockerAccepted(true);
submissionRepository.save(submission);
} else {

// Check file structure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public String getName(){
public String getEmail(){
return user.email;
}
public String getStudentNumber() { return user.studentnumber; }

public String getOid(){
return user.oid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ public record ProjectResponseJson(
boolean visible,
ProjectProgressJson progress,
Long groupId,
Long clusterId
Long clusterId,
OffsetDateTime visibleAfter
) {}
4 changes: 3 additions & 1 deletion backend/app/src/main/java/com/ugent/pidgeon/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ public class User {
public String lastName;
public String email;
public String oid;
public String studentnumber;

public User (String name, String firstName, String lastName, String email, String oid) {
public User (String name, String firstName, String lastName, String email, String oid, String studentnumber) {
this.name = name;
this.email = email;
this.oid = oid;
this.firstName = firstName;
this.lastName = lastName;
this.studentnumber = studentnumber;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.ugent.pidgeon.model.json;

import java.time.OffsetDateTime;

public record GroupClusterCreateJson(
String name,
Integer capacity,
Integer groupCount
Integer groupCount,
OffsetDateTime lockGroupsAfter
) {
public GroupClusterCreateJson {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public record GroupClusterJson(
int groupCount,
OffsetDateTime createdAt,
List<GroupJson> groups,
OffsetDateTime lockGroupsAfter,

String courseUrl
) {
Expand Down
Loading

0 comments on commit e8e2d3b

Please sign in to comment.