1414import java .util .concurrent .Executor ;
1515import java .util .stream .Collectors ;
1616
17+ import ch .ethz .seb .sps .domain .model .EntityType ;
1718import ch .ethz .seb .sps .domain .model .service .DistinctMetadataWindowForExam ;
1819import ch .ethz .seb .sps .domain .model .service .UserListForApplicationSearch ;
1920import ch .ethz .seb .sps .server .datalayer .dao .ExamDAO ;
21+ import ch .ethz .seb .sps .server .servicelayer .*;
2022import jakarta .servlet .http .HttpServletRequest ;
2123import jakarta .servlet .http .HttpServletResponse ;
2224
4648import ch .ethz .seb .sps .server .datalayer .batis .mapper .SessionRecordDynamicSqlSupport ;
4749import ch .ethz .seb .sps .server .datalayer .dao .GroupDAO ;
4850import ch .ethz .seb .sps .server .datalayer .dao .NoResourceFoundException ;
49- import ch .ethz .seb .sps .server .servicelayer .GroupService ;
50- import ch .ethz .seb .sps .server .servicelayer .GroupingService ;
51- import ch .ethz .seb .sps .server .servicelayer .PaginationService ;
52- import ch .ethz .seb .sps .server .servicelayer .ProctoringService ;
5351import ch .ethz .seb .sps .utils .Constants ;
5452import ch .ethz .seb .sps .utils .Result ;
5553import io .swagger .v3 .oas .annotations .Operation ;
@@ -75,6 +73,7 @@ public class AdminProctorController {
7573 private final ProctoringService proctoringService ;
7674 private final PaginationService paginationService ;
7775 private final GroupingService groupingService ;
76+ private final UserService userService ;
7877
7978 public AdminProctorController (
8079 final GroupDAO groupDAO ,
@@ -84,6 +83,7 @@ public AdminProctorController(
8483 final ProctoringService proctoringService ,
8584 final PaginationService paginationService ,
8685 final GroupingService groupingService ,
86+ final UserService userService ,
8787 @ Qualifier (value = ServiceConfig .SCREENSHOT_DOWNLOAD_API_EXECUTOR ) final Executor downloadExecutor ) {
8888
8989 this .downloadExecutor = downloadExecutor ;
@@ -94,6 +94,7 @@ public AdminProctorController(
9494 this .paginationService = paginationService ;
9595 this .proctoringService = proctoringService ;
9696 this .groupingService = groupingService ;
97+ this .userService = userService ;
9798 }
9899
99100 @ RequestMapping (
@@ -838,8 +839,8 @@ public List<Long> getScreenshotTimestamps(
838839
839840
840841 @ Operation (
841- summary = "Get a list of all running exams in the given time frame" ,
842- description = "Get a list of all exams which don't have a termination time and their start time is in the given time frame" ,
842+ summary = "Get a list of all exams in the given time frame" ,
843+ description = "Get a list of all exams which start time is in the given time frame" ,
843844 requestBody = @ io .swagger .v3 .oas .annotations .parameters .RequestBody (
844845 content = { @ Content (mediaType = MediaType .APPLICATION_FORM_URLENCODED_VALUE ) }),
845846 parameters = {
@@ -863,10 +864,13 @@ public List<Exam> getExamsStarted(
863864 @ RequestParam (name = API .PARAM_FROM_TIME , required = false ) final Long fromTime ,
864865 @ RequestParam (name = API .PARAM_TO_TIME , required = false ) final Long toTime ,
865866 final HttpServletRequest request ){
866-
867+
867868 final FilterMap filterMap = new FilterMap (request );
868-
869- return this .examDAO .getExamsStarted (filterMap )
869+ final Set <Long > granted = this .userService
870+ .getIdsWithReadEntityPrivilege (EntityType .EXAM )
871+ .getOrThrow ();
872+ return this .examDAO
873+ .getExamsWithin (filterMap , granted )
870874 .getOrThrow ()
871875 .stream ()
872876 .toList ();
@@ -890,8 +894,17 @@ public List<Exam> getExamsStarted(
890894 produces = MediaType .APPLICATION_JSON_VALUE )
891895 public List <Long > getGroupIdsForExam (
892896 @ PathVariable (name = API .PARAM_EXAM_ID ) final Long examId ){
893-
894- return this .groupDAO .getGroupIdsForExam (examId )
897+
898+ Exam exam = examDAO
899+ .byPK (examId )
900+ .getOrThrow ();
901+
902+ if (!userService .hasGrant (API .PrivilegeType .READ , exam )) {
903+ return Collections .emptyList ();
904+ }
905+
906+ return this .groupDAO
907+ .getGroupIdsForExam (examId )
895908 .getOrThrow ()
896909 .stream ()
897910 .toList ();
@@ -915,14 +928,14 @@ public List<Long> getGroupIdsForExam(
915928 produces = MediaType .APPLICATION_JSON_VALUE )
916929 public List <String > getDistinctMetadataAppForExam (
917930 @ RequestParam (name = API .PARAM_GROUP_IDS , required = false ) final String groupIds ){
918-
919- return this .screenshotDataDAO .getDistinctMetadataAppForExam (getIdListFromParameter (groupIds ))
931+
932+ return this .screenshotDataDAO
933+ .getDistinctMetadataAppForExam (getIdListFromParameter (groupIds ))
920934 .getOrThrow ()
921935 .stream ()
922936 .toList ();
923937 }
924-
925-
938+
926939 @ Operation (
927940 summary = "Get a list of metadata window titles for a given exam" ,
928941 description = "Returns a list of distinct window titles for a given exam (via groupIds) & metadata application" ,
@@ -945,6 +958,7 @@ public DistinctMetadataWindowForExam getDistinctMetadataWindowForExam(
945958 @ RequestParam (name = API .SCREENSHOT_META_DATA_APPLICATION , required = true ) final String metadataApplication ,
946959 @ RequestParam (name = API .PARAM_GROUP_IDS , required = true ) final String groupIds ){
947960
961+ // TODO Apply user rights
948962 return this .proctoringService .getDistinctMetadataWindowForExam (metadataApplication , getIdListFromParameter (groupIds ));
949963 }
950964
@@ -974,6 +988,7 @@ public List<UserListForApplicationSearch> getUserListForApplicationSearch(
974988 @ RequestParam (name = API .SCREENSHOT_META_DATA_ACTIVE_WINDOW_TITLE , required = true ) final String metadataWindowTitle ,
975989 @ RequestParam (name = API .PARAM_GROUP_IDS , required = true ) final String groupIds ){
976990
991+ // TODO Apply user rights?
977992 return this .screenshotDataDAO
978993 .getUserListForApplicationSearch (metadataApplication , metadataWindowTitle , getIdListFromParameter (groupIds ))
979994 .getOrThrow ();
@@ -1005,6 +1020,7 @@ public List<Long> getTimestampListForApplicationSearch(
10051020 @ RequestParam (name = API .SCREENSHOT_META_DATA_APPLICATION , required = true ) final String metadataApplication ,
10061021 @ RequestParam (name = API .SCREENSHOT_META_DATA_ACTIVE_WINDOW_TITLE , required = true ) final String metadataWindowTitle ){
10071022
1023+ // TODO Apply user rights?
10081024 return this .screenshotDataDAO
10091025 .getTimestampListForApplicationSearch (sessionUuid , metadataApplication , metadataWindowTitle )
10101026 .getOrThrow ();
@@ -1054,11 +1070,21 @@ private Result<List<Date>> queryMatchingDaysForSessionSearch(final FilterMap fil
10541070 }
10551071
10561072 private List <Long > getIdListFromParameter (final String ids ){
1073+ // check if user at least has read right for a group
1074+ final Collection <Long > readPrivilegedPredication = this .groupService .getReadPrivilegedPredication ();
1075+
10571076 String [] idsString = StringUtils .split (ids , Constants .LIST_SEPARATOR_CHAR );
10581077 List <Long > idsList = new ArrayList <>();
10591078
10601079 for (String s : idsString ) {
1061- idsList .add (Long .parseLong (s ));
1080+ try {
1081+ Long id = Long .parseLong (s );
1082+ if (readPrivilegedPredication .contains (id )) {
1083+ idsList .add (id );
1084+ }
1085+ } catch (Exception e ) {
1086+ log .error ("Failed to parse group id (pk): {} error: {}" ,s , e .getMessage ());
1087+ }
10621088 }
10631089
10641090 return idsList ;
0 commit comments