@@ -400,32 +400,33 @@ private function _initApiCommons()
400
400
$ this ->uploadApi = new KwUploadAPI ($ this ->apiSetup );
401
401
}
402
402
403
- /** Return the user id given the arguments */
404
- private function _getUserId ($ args )
403
+ /** Return the user dao */
404
+ private function _getUser ($ args )
405
405
{
406
- if (! array_key_exists ('token ' , $ args ))
406
+ if (array_key_exists ('useSession ' , $ args ))
407
407
{
408
- return 0 ;
408
+ return $ this -> userSession -> Dao ;
409
409
}
410
- $ token = $ args ['token ' ];
411
- $ userapiDao = $ this ->Api_Userapi ->getUserapiFromToken ($ token );
412
- if (!$ userapiDao )
413
- {
414
- throw new Exception ('Invalid token ' , MIDAS_INVALID_TOKEN );
415
- }
416
- return $ userapiDao ->getUserId ();
417
- }
418
-
419
- /** Return the user */
420
- private function _getUser ($ args )
421
- {
422
- $ userid = $ this ->_getUserId ($ args );
423
- if ($ userid == 0 )
410
+ else
424
411
{
425
- return false ;
412
+ if (!array_key_exists ('token ' , $ args ))
413
+ {
414
+ return 0 ;
415
+ }
416
+ $ token = $ args ['token ' ];
417
+ $ userapiDao = $ this ->Api_Userapi ->getUserapiFromToken ($ token );
418
+ if (!$ userapiDao )
419
+ {
420
+ throw new Exception ('Invalid token ' , MIDAS_INVALID_TOKEN );
421
+ }
422
+ $ userid = $ userapiDao ->getUserId ();
423
+ if ($ userid == 0 )
424
+ {
425
+ return false ;
426
+ }
427
+ $ userDao = $ this ->User ->load ($ userid );
428
+ return $ userDao ;
426
429
}
427
- $ userDao = $ this ->User ->load ($ userid );
428
- return $ userDao ;
429
430
}
430
431
431
432
/** Controller action handling REST request */
@@ -732,18 +733,9 @@ function communityGet($args)
732
733
{
733
734
throw new Exception ('Parameter id is not defined ' , MIDAS_INVALID_PARAMETER );
734
735
}
736
+ $ userDao = $ this ->_getUser ($ args );
735
737
736
738
$ communityid = $ args ['id ' ];
737
-
738
- if (array_key_exists ('token ' , $ args ))
739
- {
740
- $ userDao = $ this ->_getUser ($ args );
741
- }
742
- else
743
- {
744
- $ userDao = false ;
745
- }
746
-
747
739
$ community = $ this ->Community ->load ($ communityid );
748
740
749
741
if ($ community === false || !$ this ->Community ->policyCheck ($ community , $ userDao , MIDAS_POLICY_READ ))
@@ -761,18 +753,9 @@ function folderContent($args)
761
753
{
762
754
throw new Exception ('Parameter id is not defined ' , MIDAS_INVALID_PARAMETER );
763
755
}
756
+ $ userDao = $ this ->_getUser ($ args );
764
757
765
758
$ id = $ args ['id ' ];
766
-
767
- if (array_key_exists ('token ' , $ args ))
768
- {
769
- $ userDao = $ this ->_getUser ($ args );
770
- }
771
- else
772
- {
773
- $ userDao = false ;
774
- }
775
-
776
759
$ parent = $ this ->Folder ->load ($ id );
777
760
778
761
if ($ parent === false || !$ this ->Folder ->policyCheck ($ parent , $ userDao , MIDAS_POLICY_READ ))
@@ -855,18 +838,9 @@ function folderGet($args)
855
838
{
856
839
throw new Exception ('Parameter id is not defined ' , MIDAS_INVALID_PARAMETER );
857
840
}
841
+ $ userDao = $ this ->_getUser ($ args );
858
842
859
843
$ id = $ args ['id ' ];
860
-
861
- if (array_key_exists ('token ' , $ args ))
862
- {
863
- $ userDao = $ this ->_getUser ($ args );
864
- }
865
- else
866
- {
867
- $ userDao = false ;
868
- }
869
-
870
844
$ folder = $ this ->Folder ->load ($ id );
871
845
872
846
if ($ folder === false || !$ this ->Folder ->policyCheck ($ folder , $ userDao , MIDAS_POLICY_READ ))
@@ -983,18 +957,9 @@ function itemGet($args)
983
957
{
984
958
throw new Exception ('Parameter id is not defined ' , MIDAS_INVALID_PARAMETER );
985
959
}
960
+ $ userDao = $ this ->_getUser ($ args );
986
961
987
962
$ itemid = $ args ['id ' ];
988
-
989
- if (array_key_exists ('token ' , $ args ))
990
- {
991
- $ userDao = $ this ->_getUser ($ args );
992
- }
993
- else
994
- {
995
- $ userDao = false ;
996
- }
997
-
998
963
$ item = $ this ->Item ->load ($ itemid );
999
964
1000
965
if ($ item === false || !$ this ->Item ->policyCheck ($ item , $ userDao , MIDAS_POLICY_READ ))
@@ -1028,18 +993,9 @@ function itemGetMetadata($args)
1028
993
{
1029
994
throw new Exception ('Parameter id is not defined ' , MIDAS_INVALID_PARAMETER );
1030
995
}
996
+ $ userDao = $ this ->_getUser ($ args );
1031
997
1032
998
$ itemid = $ args ['id ' ];
1033
-
1034
- if (array_key_exists ('token ' , $ args ))
1035
- {
1036
- $ userDao = $ this ->_getUser ($ args );
1037
- }
1038
- else
1039
- {
1040
- $ userDao = false ;
1041
- }
1042
-
1043
999
$ item = $ this ->Item ->load ($ itemid );
1044
1000
1045
1001
if ($ item === false || !$ this ->Item ->policyCheck ($ item , $ userDao , MIDAS_POLICY_READ ))
@@ -1082,18 +1038,9 @@ function folderDownload($args)
1082
1038
{
1083
1039
throw new Exception ('Parameter id is not defined ' , MIDAS_INVALID_PARAMETER );
1084
1040
}
1041
+ $ userDao = $ this ->_getUser ($ args );
1085
1042
1086
1043
$ id = $ args ['id ' ];
1087
-
1088
- if (array_key_exists ('token ' , $ args ))
1089
- {
1090
- $ userDao = $ this ->_getUser ($ args );
1091
- }
1092
- else
1093
- {
1094
- $ userDao = false ;
1095
- }
1096
-
1097
1044
$ folder = $ this ->Folder ->load ($ id );
1098
1045
1099
1046
if ($ folder === false || !$ this ->Folder ->policyCheck ($ folder , $ userDao , MIDAS_POLICY_READ ))
@@ -1111,18 +1058,9 @@ function itemDownload($args)
1111
1058
{
1112
1059
throw new Exception ('Parameter id is not defined ' , MIDAS_INVALID_PARAMETER );
1113
1060
}
1061
+ $ userDao = $ this ->_getUser ($ args );
1114
1062
1115
1063
$ id = $ args ['id ' ];
1116
-
1117
- if (array_key_exists ('token ' , $ args ))
1118
- {
1119
- $ userDao = $ this ->_getUser ($ args );
1120
- }
1121
- else
1122
- {
1123
- $ userDao = false ;
1124
- }
1125
-
1126
1064
$ item = $ this ->Item ->load ($ id );
1127
1065
1128
1066
if ($ item === false || !$ this ->Item ->policyCheck ($ item , $ userDao , MIDAS_POLICY_READ ))
0 commit comments