@@ -345,7 +345,6 @@ object DatasetResource {
345
345
}
346
346
347
347
@ Produces (Array (MediaType .APPLICATION_JSON , " image/jpeg" , " application/pdf" ))
348
- @ RolesAllowed (Array (" REGULAR" , " ADMIN" ))
349
348
@ Path (" /dataset" )
350
349
class DatasetResource {
351
350
private val ERR_USER_HAS_NO_ACCESS_TO_DATASET_MESSAGE = " User has no read access to this dataset"
@@ -359,20 +358,27 @@ class DatasetResource {
359
358
private def getDashboardDataset (
360
359
ctx : DSLContext ,
361
360
did : UInteger ,
362
- uid : UInteger
361
+ uid : Option [UInteger ],
362
+ isPublic : Boolean = false
363
363
): DashboardDataset = {
364
- if (! userHasReadAccess(ctx, did, uid)) {
364
+ if (
365
+ (isPublic && ! isDatasetPublic(ctx, did)) ||
366
+ (! isPublic && (! userHasReadAccess(ctx, did, uid.get)))
367
+ ) {
365
368
throw new ForbiddenException (ERR_USER_HAS_NO_ACCESS_TO_DATASET_MESSAGE )
366
369
}
367
370
368
371
val targetDataset = getDatasetByID(ctx, did)
369
- val userAccessPrivilege = getDatasetUserAccessPrivilege(ctx, did, uid)
372
+ val userAccessPrivilege =
373
+ if (isPublic) DatasetUserAccessPrivilege .NONE
374
+ else getDatasetUserAccessPrivilege(ctx, did, uid.get)
375
+ val isOwner = ! isPublic && (targetDataset.getOwnerUid == uid.get)
370
376
371
377
DashboardDataset (
372
378
targetDataset,
373
379
getOwner(ctx, did).getEmail,
374
380
userAccessPrivilege,
375
- targetDataset.getOwnerUid == uid ,
381
+ isOwner ,
376
382
List (),
377
383
calculateDatasetVersionSize(did)
378
384
)
@@ -401,6 +407,7 @@ class DatasetResource {
401
407
}
402
408
403
409
@ POST
410
+ @ RolesAllowed (Array (" REGULAR" , " ADMIN" ))
404
411
@ Path (" /create" )
405
412
@ Consumes (Array (MediaType .MULTIPART_FORM_DATA ))
406
413
def createDataset (
@@ -477,6 +484,7 @@ class DatasetResource {
477
484
}
478
485
479
486
@ POST
487
+ @ RolesAllowed (Array (" REGULAR" , " ADMIN" ))
480
488
@ Path (" /delete" )
481
489
def deleteDataset (datasetIDs : DatasetIDs , @ Auth user : SessionUser ): Response = {
482
490
val uid = user.getUid
@@ -501,6 +509,7 @@ class DatasetResource {
501
509
@ POST
502
510
@ Consumes (Array (MediaType .APPLICATION_JSON ))
503
511
@ Produces (Array (MediaType .APPLICATION_JSON ))
512
+ @ RolesAllowed (Array (" REGULAR" , " ADMIN" ))
504
513
@ Path (" /update/name" )
505
514
def updateDatasetName (
506
515
modificator : DatasetNameModification ,
@@ -525,6 +534,7 @@ class DatasetResource {
525
534
@ POST
526
535
@ Consumes (Array (MediaType .APPLICATION_JSON ))
527
536
@ Produces (Array (MediaType .APPLICATION_JSON ))
537
+ @ RolesAllowed (Array (" REGULAR" , " ADMIN" ))
528
538
@ Path (" /update/description" )
529
539
def updateDatasetDescription (
530
540
modificator : DatasetDescriptionModification ,
@@ -548,6 +558,7 @@ class DatasetResource {
548
558
}
549
559
550
560
@ POST
561
+ @ RolesAllowed (Array (" REGULAR" , " ADMIN" ))
551
562
@ Path (" /{did}/update/publicity" )
552
563
def toggleDatasetPublicity (
553
564
@ PathParam (" did" ) did : UInteger ,
@@ -574,6 +585,7 @@ class DatasetResource {
574
585
}
575
586
576
587
@ POST
588
+ @ RolesAllowed (Array (" REGULAR" , " ADMIN" ))
577
589
@ Path (" /{did}/version/create" )
578
590
@ Consumes (Array (MediaType .MULTIPART_FORM_DATA ))
579
591
def createDatasetVersion (
@@ -607,6 +619,7 @@ class DatasetResource {
607
619
* @return list of user accessible DashboardDataset objects
608
620
*/
609
621
@ GET
622
+ @ RolesAllowed (Array (" REGULAR" , " ADMIN" ))
610
623
@ Path (" " )
611
624
def listDatasets (
612
625
@ Auth user : SessionUser
@@ -684,28 +697,36 @@ class DatasetResource {
684
697
}
685
698
686
699
@ GET
700
+ @ RolesAllowed (Array (" REGULAR" , " ADMIN" ))
687
701
@ Path (" /{did}/version/list" )
688
702
def getDatasetVersionList (
689
703
@ PathParam (" did" ) did : UInteger ,
690
704
@ Auth user : SessionUser
691
705
): List [DatasetVersion ] = {
692
706
val uid = user.getUid
693
707
withTransaction(context)(ctx => {
694
-
695
708
if (! userHasReadAccess(ctx, did, uid)) {
696
709
throw new ForbiddenException (ERR_USER_HAS_NO_ACCESS_TO_DATASET_MESSAGE )
697
710
}
698
- val result : java.util.List [DatasetVersion ] = ctx
699
- .selectFrom(DATASET_VERSION )
700
- .where(DATASET_VERSION .DID .eq(did))
701
- .orderBy(DATASET_VERSION .CREATION_TIME .desc()) // or .asc() for ascending
702
- .fetchInto(classOf [DatasetVersion ])
711
+ fetchDatasetVersions(ctx, did)
712
+ })
713
+ }
703
714
704
- result.asScala.toList
715
+ @ GET
716
+ @ Path (" /{did}/publicVersion/list" )
717
+ def getPublicDatasetVersionList (
718
+ @ PathParam (" did" ) did : UInteger
719
+ ): List [DatasetVersion ] = {
720
+ withTransaction(context)(ctx => {
721
+ if (! isDatasetPublic(ctx, did)) {
722
+ throw new ForbiddenException (ERR_USER_HAS_NO_ACCESS_TO_DATASET_MESSAGE )
723
+ }
724
+ fetchDatasetVersions(ctx, did)
705
725
})
706
726
}
707
727
708
728
@ GET
729
+ @ RolesAllowed (Array (" REGULAR" , " ADMIN" ))
709
730
@ Path (" /{did}/version/latest" )
710
731
def retrieveLatestDatasetVersion (
711
732
@ PathParam (" did" ) did : UInteger ,
@@ -753,65 +774,53 @@ class DatasetResource {
753
774
}
754
775
755
776
@ GET
777
+ @ RolesAllowed (Array (" REGULAR" , " ADMIN" ))
756
778
@ Path (" /{did}/version/{dvid}/rootFileNodes" )
757
779
def retrieveDatasetVersionRootFileNodes (
758
780
@ PathParam (" did" ) did : UInteger ,
759
781
@ PathParam (" dvid" ) dvid : UInteger ,
760
782
@ Auth user : SessionUser
761
783
): DatasetVersionRootFileNodesResponse = {
762
784
val uid = user.getUid
785
+ withTransaction(context)(ctx =>
786
+ fetchDatasetVersionRootFileNodes(ctx, did, dvid, Some (uid), isPublic = false )
787
+ )
788
+ }
763
789
764
- withTransaction(context)(ctx => {
765
- val dataset = getDashboardDataset(ctx, did, uid)
766
- val targetDatasetPath = PathUtils .getDatasetPath(did)
767
- val datasetVersion = getDatasetVersionByID(ctx, dvid)
768
- val datasetName = dataset.dataset.getName
769
- val fileNodes = GitVersionControlLocalFileStorage .retrieveRootFileNodesOfVersion(
770
- targetDatasetPath,
771
- datasetVersion.getVersionHash
772
- )
773
- val versionHash = getDatasetVersionByID(ctx, dvid).getVersionHash
774
- val size = calculateDatasetVersionSize(did, Some (versionHash))
775
- val ownerFileNode = DatasetFileNode
776
- .fromPhysicalFileNodes(
777
- Map ((dataset.ownerEmail, datasetName, datasetVersion.getName) -> fileNodes.asScala.toList)
778
- )
779
- .head
780
-
781
- DatasetVersionRootFileNodesResponse (
782
- ownerFileNode.children.get
783
- .find(_.getName == datasetName)
784
- .head
785
- .children
786
- .get
787
- .find(_.getName == datasetVersion.getName)
788
- .head
789
- .children
790
- .get,
791
- size
792
- )
793
- })
790
+ @ GET
791
+ @ Path (" /{did}/publicVersion/{dvid}/rootFileNodes" )
792
+ def retrievePublicDatasetVersionRootFileNodes (
793
+ @ PathParam (" did" ) did : UInteger ,
794
+ @ PathParam (" dvid" ) dvid : UInteger
795
+ ): DatasetVersionRootFileNodesResponse = {
796
+ withTransaction(context)(ctx =>
797
+ fetchDatasetVersionRootFileNodes(ctx, did, dvid, None , isPublic = true )
798
+ )
794
799
}
795
800
796
801
@ GET
802
+ @ RolesAllowed (Array (" REGULAR" , " ADMIN" ))
797
803
@ Path (" /{did}" )
798
804
def getDataset (
799
805
@ PathParam (" did" ) did : UInteger ,
800
806
@ Auth user : SessionUser
801
807
): DashboardDataset = {
802
808
val uid = user.getUid
803
- withTransaction(context)(ctx => {
804
- val dashboardDataset = getDashboardDataset(ctx, did, uid)
805
- val size = calculateDatasetVersionSize(did)
806
- dashboardDataset.copy(size = size)
807
- })
809
+ withTransaction(context)(ctx => fetchDataset(ctx, did, Some (uid), isPublic = false ))
810
+ }
811
+
812
+ @ GET
813
+ @ Path (" /public/{did}" )
814
+ def getPublicDataset (
815
+ @ PathParam (" did" ) did : UInteger
816
+ ): DashboardDataset = {
817
+ withTransaction(context)(ctx => fetchDataset(ctx, did, None , isPublic = true ))
808
818
}
809
819
810
820
@ GET
811
821
@ Path (" /file" )
812
822
def retrieveDatasetSingleFile (
813
- @ QueryParam (" path" ) pathStr : String ,
814
- @ Auth user : SessionUser
823
+ @ QueryParam (" path" ) pathStr : String
815
824
): Response = {
816
825
val decodedPathStr = URLDecoder .decode(pathStr, StandardCharsets .UTF_8 .name())
817
826
@@ -863,6 +872,7 @@ class DatasetResource {
863
872
* @return A Response containing the dataset version as a ZIP file.
864
873
*/
865
874
@ GET
875
+ @ RolesAllowed (Array (" REGULAR" , " ADMIN" ))
866
876
@ Path (" /version-zip" )
867
877
def retrieveDatasetVersionZip (
868
878
@ QueryParam (" did" ) did : UInteger ,
@@ -935,4 +945,77 @@ class DatasetResource {
935
945
.`type`(" application/zip" )
936
946
.build()
937
947
}
948
+
949
+ @ GET
950
+ @ Path (" /datasetUserAccess" )
951
+ def datasetUserAccess (
952
+ @ QueryParam (" did" ) did : UInteger
953
+ ): java.util.List [UInteger ] = {
954
+ val records = context
955
+ .select(DATASET_USER_ACCESS .UID )
956
+ .from(DATASET_USER_ACCESS )
957
+ .where(DATASET_USER_ACCESS .DID .eq(did))
958
+ .fetch()
959
+
960
+ records.getValues(DATASET_USER_ACCESS .UID )
961
+ }
962
+
963
+ private def fetchDatasetVersions (ctx : DSLContext , did : UInteger ): List [DatasetVersion ] = {
964
+ ctx
965
+ .selectFrom(DATASET_VERSION )
966
+ .where(DATASET_VERSION .DID .eq(did))
967
+ .orderBy(DATASET_VERSION .CREATION_TIME .desc()) // Change to .asc() for ascending order
968
+ .fetchInto(classOf [DatasetVersion ])
969
+ .asScala
970
+ .toList
971
+ }
972
+
973
+ private def fetchDatasetVersionRootFileNodes (
974
+ ctx : DSLContext ,
975
+ did : UInteger ,
976
+ dvid : UInteger ,
977
+ uid : Option [UInteger ],
978
+ isPublic : Boolean
979
+ ): DatasetVersionRootFileNodesResponse = {
980
+ val dataset = getDashboardDataset(ctx, did, uid, isPublic)
981
+ val targetDatasetPath = PathUtils .getDatasetPath(did)
982
+ val datasetVersion = getDatasetVersionByID(ctx, dvid)
983
+ val datasetName = dataset.dataset.getName
984
+ val fileNodes = GitVersionControlLocalFileStorage .retrieveRootFileNodesOfVersion(
985
+ targetDatasetPath,
986
+ datasetVersion.getVersionHash
987
+ )
988
+ val versionHash = datasetVersion.getVersionHash
989
+ val size = calculateDatasetVersionSize(did, Some (versionHash))
990
+
991
+ val ownerFileNode = DatasetFileNode
992
+ .fromPhysicalFileNodes(
993
+ Map ((dataset.ownerEmail, datasetName, datasetVersion.getName) -> fileNodes.asScala.toList)
994
+ )
995
+ .head
996
+
997
+ DatasetVersionRootFileNodesResponse (
998
+ ownerFileNode.children.get
999
+ .find(_.getName == datasetName)
1000
+ .head
1001
+ .children
1002
+ .get
1003
+ .find(_.getName == datasetVersion.getName)
1004
+ .head
1005
+ .children
1006
+ .get,
1007
+ size
1008
+ )
1009
+ }
1010
+
1011
+ private def fetchDataset (
1012
+ ctx : DSLContext ,
1013
+ did : UInteger ,
1014
+ uid : Option [UInteger ],
1015
+ isPublic : Boolean
1016
+ ): DashboardDataset = {
1017
+ val dashboardDataset = getDashboardDataset(ctx, did, uid, isPublic)
1018
+ val size = calculateDatasetVersionSize(did)
1019
+ dashboardDataset.copy(size = size)
1020
+ }
938
1021
}
0 commit comments