16 use Symfony\Component\HttpFoundation\Request;
17 use Symfony\Component\HttpFoundation\Response;
21 const NAME =
'upload_permissions';
25 private $uploadPermDao;
33 function __construct()
35 parent::__construct(self::NAME, array(
36 self::TITLE => _(
"Edit Uploaded File Permissions"),
37 self::MENU_LIST =>
"Admin::Upload Permissions",
39 self::REQUIRES_LOGIN =>
true
41 $this->uploadPermDao = $this->
getObject(
'dao.upload.permission');
42 $this->folderDao = $this->
getObject(
'dao.folder');
50 protected function handle(Request $request)
54 if (empty($groupsWhereUserIsAdmin)) {
55 $text = _(
"You have no permission to manage any group.");
56 return $this->
render(
'include/base.html.twig',$this->mergeWithDefault(array(
'content'=>$text)));
59 $folder_pk = intval($request->get(
'folder'));
60 $upload_pk = intval($request->get(
'upload'));
61 $allUploadsPerm = ($request->get(
'alluploadsperm') == 1) ? 1 : 0;
62 $perm_upload_pk = intval($request->get(
'permupk'));
63 $perm = intval($request->get(
'perm'));
64 $newgroup = intval($request->get(
'newgroup'));
65 $newperm = intval($request->get(
'newperm'));
66 $public_perm = $request->get(
'public', -1);
70 $response_from_scheduler =
"";
72 $response_from_scheduler =
"Error: Scheduler is not running!";
76 $res = $this->editPermissionsForUpload($commu_status, $folder_pk, $upload_pk, $allUploadsPerm, $perm_upload_pk, $perm,$newgroup, $newperm, $public_perm);
78 'folderStructure' => $this->folderDao->getFolderStructure($res[
'root_folder_pk']),
79 'groupArray' => $groupsWhereUserIsAdmin,
80 'uploadId' => $res[
'upload_pk'],
81 'allUploadsPerm' => $res[
'allUploadsPerm'],
82 'folderId' => $res[
'folder_pk'],
84 'newPerm' => $res[
'newperm'],
85 'newGroup' => $res[
'newgroup'],
86 'uploadList' => $res[
'UploadList'],
87 'permNames' => $GLOBALS[
'PERM_NAMES'],
88 'message' => $response_from_scheduler
91 if (!empty($vars[
'uploadList'])) {
92 $vars[
'publicPerm'] = $this->uploadPermDao->getPublicPermission($vars[
'uploadId']);
93 $permGroups = $this->uploadPermDao->getPermissionGroups($vars[
'uploadId']);
94 $vars[
'permGroups'] = $permGroups;
95 $additableGroups = array(0 =>
'-- select group --');
96 foreach ($groupsWhereUserIsAdmin as $gId=>$gName) {
97 if (!array_key_exists($gId, $permGroups)) {
98 $additableGroups[$gId] = $gName;
101 $vars[
'additableGroups'] = $additableGroups;
103 $vars[
'gumJson'] = json_encode($this->getGroupMembers($groupsWhereUserIsAdmin));
105 if (!empty($vars[
'uploadId'])) {
106 $vars[
'permNamesWithReuse'] = $this->getPermNamesWithReuse($vars[
'uploadId']);
109 return $this->
render(
'upload_permissions.html.twig', $this->mergeWithDefault($vars));
112 function editPermissionsForUpload($commu_status, $folder_pk,$upload_pk,$allUploadsPerm,$perm_upload_pk,$perm,$newgroup,$newperm,$public_perm)
114 $root_folder_pk = $this->folderDao->getRootFolder(Auth::getUserId())->getId();
115 if (empty($folder_pk)) {
116 $folder_pk = $root_folder_pk;
120 if (empty($allUploadsPerm)) {
121 if (empty($upload_pk) && !empty($UploadList)) {
122 $upload_pk = $UploadList[0][
'upload_pk'];
124 if (!empty($perm_upload_pk)) {
125 $this->uploadPermDao->updatePermissionId($perm_upload_pk, $perm);
126 }
else if (!empty($newgroup) && !empty($newperm)) {
128 $this->insertPermission($newgroup,$upload_pk,$newperm,$UploadList);
130 $newperm = $newgroup = 0;
131 }
else if ($public_perm >= 0) {
132 $this->uploadPermDao->setPublicPermission($upload_pk, $public_perm);
135 foreach ($UploadList as $uploadDetails) {
136 $upload_pk = $uploadDetails[
'upload_pk'];
137 if (!empty($newgroup) && !empty($newperm)) {
139 $this->insertPermission($newgroup, $upload_pk, $newperm, $UploadList);
141 }
else if ($public_perm >= 0) {
142 $this->uploadPermDao->setPublicPermission($upload_pk, $public_perm);
148 'root_folder_pk' => $root_folder_pk,
149 'upload_pk' => $upload_pk,
150 'allUploadsPerm' => $allUploadsPerm,
151 'folder_pk' => $folder_pk,
152 'newperm' => $newperm,
153 'newgroup' => $newgroup,
154 'UploadList' => $UploadList,
158 private function getPermNamesWithReuse($uploadId)
160 $permNamesWithReuse = $GLOBALS[
'PERM_NAMES'];
163 $uploadStatus = $uploadBrowseProxy->getStatus($uploadId);
164 }
catch(\Exception $e) {
165 return $permNamesWithReuse;
167 if ($uploadStatus==UploadStatus::IN_PROGRESS || $uploadStatus==UploadStatus::CLOSED) {
168 foreach ($GLOBALS[
'PERM_NAMES'] as $perm=>$name) {
169 $permNamesWithReuse[$perm|self::MOD_REUSE] = $name._(
' with reuse');
172 return $permNamesWithReuse;
175 function insertPermission($groupId,$uploadId,$permission,$uploadList)
178 foreach ($uploadList as $uploadEntry) {
179 if ($uploadEntry[
'upload_pk']) {
180 $fileName = $uploadEntry[
'name'];
183 if (empty($fileName)) {
184 throw new \Exception(
'This upload is missing or inaccessible');
187 $reuseBit = $permission&self::MOD_REUSE;
189 $jobId = \JobAddJob(Auth::getUserId(), $groupId, $fileName, $uploadId);
191 $request =
new Request(array(
'uploadToReuse'=>
"$uploadId,".Auth::getGroupId(),
'groupId'=>$groupId));
192 $reuserAgent->scheduleAgent($jobId, $uploadId, $errorMsg, $request);
193 if (!empty($errorMsg)) {
194 throw new Exception($errorMsg);
196 $permission ^= $reuseBit;
198 $this->uploadPermDao->insertPermission($uploadId, $groupId, $permission);
201 private function getGroupMembers($groupsWhereUserIsAdmin)
203 $this->
dbManager->prepare($stmt=__METHOD__,
204 "SELECT user_name,gum.group_fk FROM group_user_member gum, users WHERE user_fk=user_pk");
207 while ($row = $this->
dbManager->fetchArray($res)) {
208 if (array_key_exists($row[
'group_fk'], $groupsWhereUserIsAdmin)) {
209 $gum[] = array($row[
'user_name'], $row[
'group_fk']);
Contains the constants and helpers for authentication of user.
render($templateName, $vars=null, $headers=null)
FolderListUploads_perm($ParentFolder, $perm)
Returns an array of uploads in a folder.
Traceback_uri()
Get the URI without query to this location.
GetGroupArray($user_pk)
Get array of groups that this user has admin access to @depricated use UserDao::getAdminGroupMap()
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
fo_communicate_with_scheduler($input, &$output, &$error_msg)
Communicate with scheduler, send commands to the scheduler, then get the output.
#define PERM_WRITE
Read-Write permission.
#define PERM_READ
Read-only permission.
fo_dbManager * dbManager
fo_dbManager object