@@ -836,6 +836,41 @@ protected function _setFolderPrivacy($folder, $privacyCode)
836
836
}
837
837
}
838
838
839
+
840
+ /**
841
+ * helper function to return listing of permissions for a resource.
842
+ * @return A list with three keys: privacy, user, group; privacy will be the
843
+ resource's privacy string [Public|Private]; user will be a list of
844
+ (user_id, policy, email); group will be a list of (group_id, policy, name).
845
+ policy for user and group will be a policy string [Admin|Write|Read].
846
+ */
847
+ protected function _listResourcePermissions ($ policyStatus , $ userPolicies , $ groupPolicies )
848
+ {
849
+ $ privacyStrings = array (MIDAS_PRIVACY_PUBLIC => "Public " , MIDAS_PRIVACY_PRIVATE => "Private " );
850
+ $ privilegeStrings = array (MIDAS_POLICY_ADMIN => "Admin " , MIDAS_POLICY_WRITE => "Write " , MIDAS_POLICY_READ => "Read " );
851
+
852
+ $ return = array ('privacy ' => $ privacyStrings [$ policyStatus ]);
853
+
854
+ $ userPoliciesOutput = array ();
855
+ foreach ($ userPolicies as $ userPolicy )
856
+ {
857
+ $ user = $ userPolicy ->getUser ();
858
+ $ userPoliciesOutput [] = array ('user_id ' => $ user ->getUserId (), 'policy ' => $ privilegeStrings [$ userPolicy ->getPolicy ()], 'email ' => $ user ->getEmail ());
859
+ }
860
+ $ return ['user ' ] = $ userPoliciesOutput ;
861
+
862
+ $ groupPoliciesOutput = array ();
863
+ foreach ($ groupPolicies as $ groupPolicy )
864
+ {
865
+ $ group = $ groupPolicy ->getGroup ();
866
+ $ groupPoliciesOutput [] = array ('group_id ' => $ group ->getGroupId (), 'policy ' => $ privilegeStrings [$ groupPolicy ->getPolicy ()], 'name ' => $ group ->getName ());
867
+ }
868
+ $ return ['group ' ] = $ groupPoliciesOutput ;
869
+
870
+ return $ return ;
871
+ }
872
+
873
+
839
874
/**
840
875
* Create a folder or update an existing one if one exists by the uuid passed.
841
876
* If a folder is requested to be created with the same parentid and name as
@@ -1124,8 +1159,6 @@ public function folderListPermissions($args)
1124
1159
$ userDao = $ this ->_getUser ($ args );
1125
1160
1126
1161
$ folderpolicygroupModel = MidasLoader::loadModel ('Folderpolicygroup ' );
1127
- $ groupModel = MidasLoader::loadModel ('Group ' );
1128
- $ anonymousGroup = $ groupModel ->load (MIDAS_GROUP_ANONYMOUS_KEY );
1129
1162
$ folderModel = MidasLoader::loadModel ('Folder ' );
1130
1163
$ folderId = $ args ['folder_id ' ];
1131
1164
$ folder = $ folderModel ->load ($ folderId );
@@ -1139,30 +1172,7 @@ public function folderListPermissions($args)
1139
1172
throw new Exception ("Admin privileges required on the folder to list permissions. " , MIDAS_INVALID_POLICY );
1140
1173
}
1141
1174
1142
- $ privacyStrings = array (MIDAS_PRIVACY_PUBLIC => "Public " , MIDAS_PRIVACY_PRIVATE => "Private " );
1143
- $ privilegeStrings = array (MIDAS_POLICY_ADMIN => "Admin " , MIDAS_POLICY_WRITE => "Write " , MIDAS_POLICY_READ => "Read " );
1144
-
1145
- $ return = array ('privacy ' => $ privacyStrings [$ folderpolicygroupModel ->computePolicyStatus ($ folder )]);
1146
-
1147
- $ userPolicies = $ folder ->getFolderpolicyuser ();
1148
- $ userPoliciesOutput = array ();
1149
- foreach ($ userPolicies as $ userPolicy )
1150
- {
1151
- $ user = $ userPolicy ->getUser ();
1152
- $ userPoliciesOutput [] = array ('user_id ' => $ user ->getUserId (), 'policy ' => $ privilegeStrings [$ userPolicy ->getPolicy ()], 'email ' => $ user ->getEmail ());
1153
- }
1154
- $ return ['user ' ] = $ userPoliciesOutput ;
1155
-
1156
- $ groupPolicies = $ folder ->getFolderpolicygroup ();
1157
- $ groupPoliciesOutput = array ();
1158
- foreach ($ groupPolicies as $ groupPolicy )
1159
- {
1160
- $ group = $ groupPolicy ->getGroup ();
1161
- $ groupPoliciesOutput [] = array ('group_id ' => $ group ->getGroupId (), 'policy ' => $ privilegeStrings [$ groupPolicy ->getPolicy ()], 'name ' => $ group ->getName ());
1162
- }
1163
- $ return ['group ' ] = $ groupPoliciesOutput ;
1164
-
1165
- return $ return ;
1175
+ return $ this ->_listResourcePermissions ($ folderpolicygroupModel ->computePolicyStatus ($ folder ), $ folder ->getFolderpolicyuser (), $ folder ->getFolderpolicygroup ());
1166
1176
}
1167
1177
1168
1178
/**
0 commit comments