32 const NAME =
'upload_permissions';
36 private $uploadPermDao;
44 function __construct()
46 parent::__construct(self::NAME, array(
47 self::TITLE => _(
"Edit Uploaded File Permissions"),
48 self::MENU_LIST =>
"Admin::Upload Permissions",
50 self::REQUIRES_LOGIN => TRUE
52 $this->uploadPermDao = $this->
getObject(
'dao.upload.permission');
53 $this->folderDao = $this->
getObject(
'dao.folder');
61 protected function handle(Request $request)
65 if (empty($groupsWhereUserIsAdmin)) {
66 $text = _(
"You have no permission to manage any group.");
67 return $this->
render(
'include/base.html.twig',$this->mergeWithDefault(array(
'content'=>$text)));
70 $folder_pk = intval($request->get(
'folder'));
71 $upload_pk = intval($request->get(
'upload'));
72 $allUploadsPerm = ($request->get(
'alluploadsperm') == 1) ? 1 : 0;
73 $perm_upload_pk = intval($request->get(
'permupk'));
74 $perm = intval($request->get(
'perm'));
75 $newgroup = intval($request->get(
'newgroup'));
76 $newperm = intval($request->get(
'newperm'));
77 $public_perm = $request->get(
'public', -1);
79 $root_folder_pk = $this->folderDao->getRootFolder(Auth::getUserId())->getId();
80 if (empty($folder_pk)) {
81 $folder_pk = $root_folder_pk;
85 if (empty($allUploadsPerm)) {
86 if (empty($upload_pk) && !empty($UploadList)) {
87 $upload_pk = $UploadList[0][
'upload_pk'];
89 if (!empty($perm_upload_pk)) {
90 $this->uploadPermDao->updatePermissionId($perm_upload_pk, $perm);
91 }
else if (!empty($newgroup) && !empty($newperm)) {
92 $this->insertPermission($newgroup,$upload_pk,$newperm,$UploadList);
93 $newperm = $newgroup = 0;
94 }
else if ($public_perm >= 0) {
95 $this->uploadPermDao->setPublicPermission($upload_pk, $public_perm);
98 foreach ($UploadList as $uploadDetails) {
99 $upload_pk = $uploadDetails[
'upload_pk'];
100 if (!empty($newgroup) && !empty($newperm)) {
101 $this->insertPermission($newgroup, $upload_pk, $newperm, $UploadList);
102 }
else if ($public_perm >= 0) {
103 $this->uploadPermDao->setPublicPermission($upload_pk, $public_perm);
108 'folderStructure' => $this->folderDao->getFolderStructure($root_folder_pk),
109 'groupArray' => $groupsWhereUserIsAdmin,
110 'uploadId' => $upload_pk,
111 'allUploadsPerm' => $allUploadsPerm,
112 'folderId' => $folder_pk,
114 'newPerm' => $newperm,
115 'newGroup' => $newgroup,
116 'uploadList' => $UploadList,
117 'permNames' => $GLOBALS[
'PERM_NAMES']
120 if (!empty($UploadList)) {
121 $vars[
'publicPerm'] = $this->uploadPermDao->getPublicPermission($upload_pk);
122 $permGroups = $this->uploadPermDao->getPermissionGroups($upload_pk);
123 $vars[
'permGroups'] = $permGroups;
124 $additableGroups = array(0 =>
'-- select group --');
125 foreach ($groupsWhereUserIsAdmin as $gId=>$gName) {
126 if (!array_key_exists($gId, $permGroups)) {
127 $additableGroups[$gId] = $gName;
130 $vars[
'additableGroups'] = $additableGroups;
132 $vars[
'gumJson'] = json_encode($this->getGroupMembers($groupsWhereUserIsAdmin));
134 if (!empty($upload_pk)) {
135 $vars[
'permNamesWithReuse'] = $this->getPermNamesWithReuse($upload_pk);
138 return $this->
render(
'upload_permissions.html.twig', $this->mergeWithDefault($vars));
141 private function getPermNamesWithReuse($uploadId)
143 $permNamesWithReuse = $GLOBALS[
'PERM_NAMES'];
146 $uploadStatus = $uploadBrowseProxy->getStatus($uploadId);
147 }
catch(\Exception $e) {
148 return $permNamesWithReuse;
150 if ($uploadStatus==UploadStatus::IN_PROGRESS || $uploadStatus==UploadStatus::CLOSED) {
151 foreach ($GLOBALS[
'PERM_NAMES'] as $perm=>$name) {
152 $permNamesWithReuse[$perm|self::MOD_REUSE] = $name._(
' with reuse');
155 return $permNamesWithReuse;
158 private function insertPermission($groupId,$uploadId,$permission,$uploadList)
161 foreach ($uploadList as $uploadEntry) {
162 if ($uploadEntry[
'upload_pk']) {
163 $fileName = $uploadEntry[
'name'];
166 if (empty($fileName)) {
167 throw new \Exception(
'This upload is missing or inaccessible');
170 $reuseBit = $permission&self::MOD_REUSE;
172 $jobId = \JobAddJob(Auth::getUserId(), $groupId, $fileName, $uploadId);
174 $request =
new Request(array(
'uploadToReuse'=>
"$uploadId,".Auth::getGroupId(),
'groupId'=>$groupId));
175 $reuserAgent->scheduleAgent($jobId, $uploadId, $errorMsg, $request);
176 if (!empty($errorMsg)) {
177 throw new Exception($errorMsg);
179 $permission ^= $reuseBit;
181 $this->uploadPermDao->insertPermission($uploadId, $groupId, $permission);
184 private function getGroupMembers($groupsWhereUserIsAdmin)
186 $this->
dbManager->prepare($stmt=__METHOD__,
187 "SELECT user_name,gum.group_fk FROM group_user_member gum, users WHERE user_fk=user_pk");
190 while ($row = $this->
dbManager->fetchArray($res)) {
191 if (array_key_exists($row[
'group_fk'], $groupsWhereUserIsAdmin)) {
192 $gum[] = array($row[
'user_name'], $row[
'group_fk']);
Traceback_uri()
Get the URI without query to this location.
FolderListUploads_perm($ParentFolder, $perm)
Returns an array of uploads in a folder.
render($templateName, $vars=null, $headers=null)
GetGroupArray($user_pk)
Get array of groups that this user has admin access to use UserDao::getAdminGroupMap() ...
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
fo_dbManager * dbManager
fo_dbManager object
#define PERM_READ
Read-only permission.
#define PERM_WRITE
Read-Write permission.