Skip to content

Commit e226298

Browse files
committed
Merge branch 'develop' into translate-with-ai
2 parents a262a33 + c5cade4 commit e226298

File tree

5 files changed

+40
-31
lines changed

5 files changed

+40
-31
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
}

src/main/java/org/wise/portal/spring/data/redis/RedisMessageSubscriber.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public void onMessage(Message message, byte[] pattern) {
3737
createAndSendWebSocketMessage("newStudentAchievement", messageJSON, "achievement");
3838
break;
3939
case "annotationToStudent":
40+
case "annotationToClassroom":
4041
createAndSendWebSocketMessage("annotation", messageJSON, "annotation");
4142
break;
4243
case "notification":

src/main/java/org/wise/vle/web/wise5/TeacherPostDataController.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,11 @@ private void sendAnnotationNotificationToStudent(Annotation annotation) {
174174
try {
175175
Notification notification = this.createNotificationForAnnotation(annotation);
176176
Long toWorkgroupId = notification.getToWorkgroup().getId();
177-
broadcastAnnotationToStudent(toWorkgroupId, annotation);
178-
broadcastNotificationToStudent(toWorkgroupId, notification);
177+
this.broadcastAnnotationToStudent(toWorkgroupId, annotation);
178+
if (annotation.getType().equals("inappropriateFlag")) {
179+
this.broadcastAnnotationToClassroom(annotation);
180+
}
181+
this.broadcastNotificationToStudent(toWorkgroupId, notification);
179182
} catch (Exception e) {
180183
e.printStackTrace();
181184
}
@@ -217,7 +220,7 @@ private Notification createNotificationForAnnotation(Annotation annotation) {
217220
return notification;
218221
}
219222

220-
public void broadcastAnnotationToStudent(Long toWorkgroupId, Annotation annotation)
223+
private void broadcastAnnotationToStudent(Long toWorkgroupId, Annotation annotation)
221224
throws JSONException {
222225
annotation.convertToClientAnnotation();
223226
JSONObject message = new JSONObject();
@@ -227,7 +230,17 @@ public void broadcastAnnotationToStudent(Long toWorkgroupId, Annotation annotati
227230
redisPublisher.publish(message.toString());
228231
}
229232

230-
public void broadcastNotificationToStudent(Long toWorkgroupId, Notification notification)
233+
private void broadcastAnnotationToClassroom(Annotation annotation) throws JSONException {
234+
annotation.convertToClientAnnotation();
235+
JSONObject message = new JSONObject();
236+
message.put("type", "annotationToClassroom");
237+
message.put("topic", String.format("/topic/classroom/%s/%s", annotation.getRun().getId(),
238+
annotation.getPeriod().getId()));
239+
message.put("annotation", annotation.toJSON());
240+
redisPublisher.publish(message.toString());
241+
}
242+
243+
private void broadcastNotificationToStudent(Long toWorkgroupId, Notification notification)
231244
throws JSONException {
232245
notification.convertToClientNotification();
233246
JSONObject message = new JSONObject();
@@ -236,4 +249,5 @@ public void broadcastNotificationToStudent(Long toWorkgroupId, Notification noti
236249
message.put("notification", notification.toJSON());
237250
redisPublisher.publish(message.toString());
238251
}
252+
239253
}

0 commit comments

Comments
 (0)