Skip to content

Commit c5cade4

Browse files
feat(DiscussionSummary): Allow teachers to retrieve student data (#316)
1 parent 32eac49 commit c5cade4

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

src/main/java/org/wise/portal/presentation/web/controllers/student/ClassmateDataController.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ protected boolean isStudentInRunAndPeriod(Authentication auth, Run run, Group pe
5757
}
5858

5959
protected boolean isTeacherOfRun(Authentication auth, Run run) {
60-
User user = userService.retrieveUser((TeacherUserDetails) auth.getPrincipal());
61-
return user != null && run.isTeacherAssociatedToThisRun(user);
60+
if (isTeacher(auth)) {
61+
User user = userService.retrieveUser((TeacherUserDetails) auth.getPrincipal());
62+
return user != null && run.isTeacherAssociatedToThisRun(user);
63+
}
64+
return false;
6265
}
6366

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

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

95-
protected List<StudentWork> getLatestStudentWork(Run run, String nodeId,
96-
String componentId) {
97+
protected List<StudentWork> getLatestStudentWork(Run run, String nodeId, String componentId) {
9798
return vleService.getLatestStudentWork(run, nodeId, componentId);
9899
}
99100

src/main/java/org/wise/portal/presentation/web/controllers/student/ClassmateDiscussionDataController.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.wise.vle.domain.work.StudentWork;
2020

2121
@RestController
22-
@Secured("ROLE_STUDENT")
22+
@Secured({ "ROLE_STUDENT", "ROLE_TEACHER" })
2323
@RequestMapping("/api/classmate/discussion")
2424
public class ClassmateDiscussionDataController extends ClassmateDataController {
2525

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

5352
private boolean isAllowedToGetData(Authentication auth, Run run, Group period, String nodeId,
5453
String componentId) throws IOException, JSONException, ObjectNotFoundException {
55-
return isStudentInRunAndPeriod(auth, run, period)
54+
return (isTeacherOfRun(auth, run) || isStudentInRunAndPeriod(auth, run, period))
5655
&& isDiscussionComponent(run, nodeId, componentId);
5756
}
5857

src/main/java/org/wise/portal/presentation/web/controllers/student/ClassmateSummaryDataController.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ public class ClassmateSummaryDataController extends ClassmateDataController {
3333
@GetMapping("/student-work/{runId}/{nodeId}/{componentId}/period/{periodId}")
3434
public List<StudentWork> getClassmateSummaryWorkInPeriod(Authentication auth,
3535
@PathVariable("runId") RunImpl run, @PathVariable Long periodId, @PathVariable String nodeId,
36-
@PathVariable String componentId)
37-
throws IOException, JSONException, ObjectNotFoundException {
36+
@PathVariable String componentId) throws IOException, JSONException, ObjectNotFoundException {
3837
Group period = groupService.retrieveById(periodId);
3938
if (isAllowedToGetData(auth, run, period, nodeId, componentId)) {
4039
return getLatestStudentWork(run, period, nodeId, componentId);
@@ -45,8 +44,7 @@ public List<StudentWork> getClassmateSummaryWorkInPeriod(Authentication auth,
4544
@GetMapping("/student-work/{runId}/{nodeId}/{componentId}/class")
4645
public List<StudentWork> getClassmateSummaryWorkInClass(Authentication auth,
4746
@PathVariable("runId") RunImpl run, @PathVariable String nodeId,
48-
@PathVariable String componentId)
49-
throws IOException, JSONException, ObjectNotFoundException {
47+
@PathVariable String componentId) throws IOException, JSONException, ObjectNotFoundException {
5048
if (isAllowedToGetData(auth, run, nodeId, componentId)) {
5149
return getLatestStudentWork(run, nodeId, componentId);
5250
}
@@ -56,8 +54,7 @@ public List<StudentWork> getClassmateSummaryWorkInClass(Authentication auth,
5654
@GetMapping("/scores/{runId}/{nodeId}/{componentId}/period/{periodId}")
5755
public List<Annotation> getClassmateSummaryScoresInPeriod(Authentication auth,
5856
@PathVariable("runId") RunImpl run, @PathVariable Long periodId, @PathVariable String nodeId,
59-
@PathVariable String componentId)
60-
throws IOException, JSONException, ObjectNotFoundException {
57+
@PathVariable String componentId) throws IOException, JSONException, ObjectNotFoundException {
6158
Group period = groupService.retrieveById(periodId);
6259
if (isAllowedToGetData(auth, run, period, nodeId, componentId)) {
6360
return getLatestScoreAnnotations(getAnnotations(run, period, nodeId, componentId));
@@ -68,8 +65,7 @@ public List<Annotation> getClassmateSummaryScoresInPeriod(Authentication auth,
6865
@GetMapping("/scores/{runId}/{nodeId}/{componentId}/class")
6966
public List<Annotation> getClassmateSummaryScoresInClass(Authentication auth,
7067
@PathVariable("runId") RunImpl run, @PathVariable String nodeId,
71-
@PathVariable String componentId)
72-
throws IOException, JSONException, ObjectNotFoundException {
68+
@PathVariable String componentId) throws IOException, JSONException, ObjectNotFoundException {
7369
if (isAllowedToGetData(auth, run, nodeId, componentId)) {
7470
return getLatestScoreAnnotations(getAnnotations(run, nodeId, componentId));
7571
}
@@ -78,25 +74,23 @@ public List<Annotation> getClassmateSummaryScoresInClass(Authentication auth,
7874

7975
private boolean isAllowedToGetData(Authentication auth, Run run, Group period, String nodeId,
8076
String componentId) throws IOException, JSONException, ObjectNotFoundException {
81-
return (isStudent(auth) && isStudentInRunAndPeriod(auth, run, period) &&
82-
isValidSummaryComponent(run, nodeId, componentId)) ||
83-
(isTeacher(auth) && isTeacherOfRun(auth, run));
77+
return (isStudent(auth) && isStudentInRunAndPeriod(auth, run, period)
78+
&& isValidSummaryComponent(run, nodeId, componentId)) || isTeacherOfRun(auth, run);
8479
}
8580

8681
private boolean isAllowedToGetData(Authentication auth, Run run, String nodeId,
8782
String componentId) throws IOException, JSONException, ObjectNotFoundException {
88-
return (isStudent(auth) && isStudentInRun(auth, run) &&
89-
isValidSummaryComponent(run, nodeId, componentId)) ||
90-
(isTeacher(auth) && isTeacherOfRun(auth, run));
83+
return (isStudent(auth) && isStudentInRun(auth, run)
84+
&& isValidSummaryComponent(run, nodeId, componentId)) || isTeacherOfRun(auth, run);
9185
}
9286

9387
private boolean isValidSummaryComponent(Run run, String nodeId, String componentId)
9488
throws IOException, JSONException, ObjectNotFoundException {
9589
List<ProjectComponent> projectComponents = getProjectComponents(run);
9690
for (ProjectComponent projectComponent : projectComponents) {
97-
if (projectComponent.getString("type").equals(SUMMARY_TYPE) &&
98-
projectComponent.getString("summaryNodeId").equals(nodeId) &&
99-
projectComponent.getString("summaryComponentId").equals(componentId)) {
91+
if (projectComponent.getString("type").equals(SUMMARY_TYPE)
92+
&& projectComponent.getString("summaryNodeId").equals(nodeId)
93+
&& projectComponent.getString("summaryComponentId").equals(componentId)) {
10094
return true;
10195
}
10296
}

0 commit comments

Comments
 (0)