Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ protected boolean isStudentInRunAndPeriod(Authentication auth, Run run, Group pe
}

protected boolean isTeacherOfRun(Authentication auth, Run run) {
User user = userService.retrieveUser((TeacherUserDetails) auth.getPrincipal());
return user != null && run.isTeacherAssociatedToThisRun(user);
if (isTeacher(auth)) {
User user = userService.retrieveUser((TeacherUserDetails) auth.getPrincipal());
return user != null && run.isTeacherAssociatedToThisRun(user);
}
return false;
}

protected boolean isComponentType(Run run, String nodeId, String componentId,
Expand All @@ -75,8 +78,7 @@ protected ProjectComponent getProjectComponent(Run run, String nodeId, String co
return projectContent.getComponent(nodeId, componentId);
}

protected List<ProjectComponent> getProjectComponents(Run run)
throws IOException, JSONException {
protected List<ProjectComponent> getProjectComponents(Run run) throws IOException, JSONException {
String projectString = projectService.getProjectContent(run.getProject());
JSONObject projectJSON = new JSONObject(projectString);
ProjectContent projectContent = new ProjectContent(projectJSON);
Expand All @@ -92,8 +94,7 @@ protected List<StudentWork> getStudentWork(Run run, Group period, String nodeId,
return vleService.getStudentWork(run, period, nodeId, componentId);
}

protected List<StudentWork> getLatestStudentWork(Run run, String nodeId,
String componentId) {
protected List<StudentWork> getLatestStudentWork(Run run, String nodeId, String componentId) {
return vleService.getLatestStudentWork(run, nodeId, componentId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.wise.vle.domain.work.StudentWork;

@RestController
@Secured("ROLE_STUDENT")
@Secured({ "ROLE_STUDENT", "ROLE_TEACHER" })
@RequestMapping("/api/classmate/discussion")
public class ClassmateDiscussionDataController extends ClassmateDataController {

Expand All @@ -28,8 +28,7 @@ public class ClassmateDiscussionDataController extends ClassmateDataController {
@GetMapping("/student-work/{runId}/{periodId}/{nodeId}/{componentId}")
public List<StudentWork> getClassmateDiscussionWork(Authentication auth,
@PathVariable("runId") RunImpl run, @PathVariable Long periodId, @PathVariable String nodeId,
@PathVariable String componentId)
throws IOException, JSONException, ObjectNotFoundException {
@PathVariable String componentId) throws IOException, JSONException, ObjectNotFoundException {
Group period = groupService.retrieveById(periodId);
if (isAllowedToGetData(auth, run, period, nodeId, componentId)) {
return getStudentWork(run, period, nodeId, componentId);
Expand All @@ -52,7 +51,7 @@ public List<Annotation> getClassmateDiscussionAnnotations(Authentication auth,

private boolean isAllowedToGetData(Authentication auth, Run run, Group period, String nodeId,
String componentId) throws IOException, JSONException, ObjectNotFoundException {
return isStudentInRunAndPeriod(auth, run, period)
return (isTeacherOfRun(auth, run) || isStudentInRunAndPeriod(auth, run, period))
&& isDiscussionComponent(run, nodeId, componentId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public class ClassmateSummaryDataController extends ClassmateDataController {
@GetMapping("/student-work/{runId}/{nodeId}/{componentId}/period/{periodId}")
public List<StudentWork> getClassmateSummaryWorkInPeriod(Authentication auth,
@PathVariable("runId") RunImpl run, @PathVariable Long periodId, @PathVariable String nodeId,
@PathVariable String componentId)
throws IOException, JSONException, ObjectNotFoundException {
@PathVariable String componentId) throws IOException, JSONException, ObjectNotFoundException {
Group period = groupService.retrieveById(periodId);
if (isAllowedToGetData(auth, run, period, nodeId, componentId)) {
return getLatestStudentWork(run, period, nodeId, componentId);
Expand All @@ -45,8 +44,7 @@ public List<StudentWork> getClassmateSummaryWorkInPeriod(Authentication auth,
@GetMapping("/student-work/{runId}/{nodeId}/{componentId}/class")
public List<StudentWork> getClassmateSummaryWorkInClass(Authentication auth,
@PathVariable("runId") RunImpl run, @PathVariable String nodeId,
@PathVariable String componentId)
throws IOException, JSONException, ObjectNotFoundException {
@PathVariable String componentId) throws IOException, JSONException, ObjectNotFoundException {
if (isAllowedToGetData(auth, run, nodeId, componentId)) {
return getLatestStudentWork(run, nodeId, componentId);
}
Expand All @@ -56,8 +54,7 @@ public List<StudentWork> getClassmateSummaryWorkInClass(Authentication auth,
@GetMapping("/scores/{runId}/{nodeId}/{componentId}/period/{periodId}")
public List<Annotation> getClassmateSummaryScoresInPeriod(Authentication auth,
@PathVariable("runId") RunImpl run, @PathVariable Long periodId, @PathVariable String nodeId,
@PathVariable String componentId)
throws IOException, JSONException, ObjectNotFoundException {
@PathVariable String componentId) throws IOException, JSONException, ObjectNotFoundException {
Group period = groupService.retrieveById(periodId);
if (isAllowedToGetData(auth, run, period, nodeId, componentId)) {
return getLatestScoreAnnotations(getAnnotations(run, period, nodeId, componentId));
Expand All @@ -68,8 +65,7 @@ public List<Annotation> getClassmateSummaryScoresInPeriod(Authentication auth,
@GetMapping("/scores/{runId}/{nodeId}/{componentId}/class")
public List<Annotation> getClassmateSummaryScoresInClass(Authentication auth,
@PathVariable("runId") RunImpl run, @PathVariable String nodeId,
@PathVariable String componentId)
throws IOException, JSONException, ObjectNotFoundException {
@PathVariable String componentId) throws IOException, JSONException, ObjectNotFoundException {
if (isAllowedToGetData(auth, run, nodeId, componentId)) {
return getLatestScoreAnnotations(getAnnotations(run, nodeId, componentId));
}
Expand All @@ -78,25 +74,23 @@ public List<Annotation> getClassmateSummaryScoresInClass(Authentication auth,

private boolean isAllowedToGetData(Authentication auth, Run run, Group period, String nodeId,
String componentId) throws IOException, JSONException, ObjectNotFoundException {
return (isStudent(auth) && isStudentInRunAndPeriod(auth, run, period) &&
isValidSummaryComponent(run, nodeId, componentId)) ||
(isTeacher(auth) && isTeacherOfRun(auth, run));
return (isStudent(auth) && isStudentInRunAndPeriod(auth, run, period)
&& isValidSummaryComponent(run, nodeId, componentId)) || isTeacherOfRun(auth, run);
}

private boolean isAllowedToGetData(Authentication auth, Run run, String nodeId,
String componentId) throws IOException, JSONException, ObjectNotFoundException {
return (isStudent(auth) && isStudentInRun(auth, run) &&
isValidSummaryComponent(run, nodeId, componentId)) ||
(isTeacher(auth) && isTeacherOfRun(auth, run));
return (isStudent(auth) && isStudentInRun(auth, run)
&& isValidSummaryComponent(run, nodeId, componentId)) || isTeacherOfRun(auth, run);
}

private boolean isValidSummaryComponent(Run run, String nodeId, String componentId)
throws IOException, JSONException, ObjectNotFoundException {
List<ProjectComponent> projectComponents = getProjectComponents(run);
for (ProjectComponent projectComponent : projectComponents) {
if (projectComponent.getString("type").equals(SUMMARY_TYPE) &&
projectComponent.getString("summaryNodeId").equals(nodeId) &&
projectComponent.getString("summaryComponentId").equals(componentId)) {
if (projectComponent.getString("type").equals(SUMMARY_TYPE)
&& projectComponent.getString("summaryNodeId").equals(nodeId)
&& projectComponent.getString("summaryComponentId").equals(componentId)) {
return true;
}
}
Expand Down
Loading