/**
  * @param Request $request
  * @return Response
  */
 protected function handle(Request $request)
 {
     /* Get array of groups that this user is an admin of */
     $groupsWhereUserIsAdmin = GetGroupArray(Auth::getUserId());
     if (empty($groupsWhereUserIsAdmin)) {
         $text = _("You have no permission to manage any group.");
         return $this->render('include/base.html.twig', $this->mergeWithDefault(array('content' => $text)));
     }
     $folder_pk = intval($request->get('folder'));
     $upload_pk = intval($request->get('upload'));
     $perm_upload_pk = intval($request->get('permupk'));
     $perm = intval($request->get('perm'));
     $newgroup = intval($request->get('newgroup'));
     $newperm = intval($request->get('newperm'));
     $public_perm = $request->get('public', -1);
     /* @var $folderDao FolderDao */
     $folderDao = $this->getObject('dao.folder');
     $root_folder_pk = $folderDao->getRootFolder(Auth::getUserId())->getId();
     if (empty($folder_pk)) {
         $folder_pk = $root_folder_pk;
     }
     $UploadList = FolderListUploads_perm($folder_pk, Auth::PERM_WRITE);
     if (empty($upload_pk) && !empty($UploadList)) {
         $upload_pk = $UploadList[0]['upload_pk'];
     }
     if (!empty($perm_upload_pk)) {
         $this->uploadPermDao->updatePermissionId($perm_upload_pk, $perm);
     } else {
         if (!empty($newgroup) && !empty($newperm)) {
             $this->insertPermission($newgroup, $upload_pk, $newperm, $UploadList);
             $newperm = $newgroup = 0;
         } else {
             if ($public_perm >= 0) {
                 $this->uploadPermDao->setPublicPermission($upload_pk, $public_perm);
             }
         }
     }
     $vars = array('folderStructure' => $folderDao->getFolderStructure($root_folder_pk), 'groupArray' => $groupsWhereUserIsAdmin, 'uploadId' => $upload_pk, 'folderId' => $folder_pk, 'baseUri' => Traceback_uri() . '?mod=upload_permissions', 'newPerm' => $newperm, 'newGroup' => $newgroup, 'uploadList' => $UploadList, 'permNames' => $GLOBALS['PERM_NAMES']);
     if (!empty($UploadList)) {
         $vars['publicPerm'] = $this->uploadPermDao->getPublicPermission($upload_pk);
         $permGroups = $this->uploadPermDao->getPermissionGroups($upload_pk);
         $vars['permGroups'] = $permGroups;
         $additableGroups = array(0 => '-- select group --');
         foreach ($groupsWhereUserIsAdmin as $gId => $gName) {
             if (!array_key_exists($gId, $permGroups)) {
                 $additableGroups[$gId] = $gName;
             }
         }
         $vars['additableGroups'] = $additableGroups;
     }
     $vars['gumJson'] = json_encode($this->getGroupMembers($groupsWhereUserIsAdmin));
     if (!empty($upload_pk)) {
         $vars['permNamesWithReuse'] = $this->getPermNamesWithReuse($upload_pk);
     }
     return $this->render('upload_permissions.html.twig', $this->mergeWithDefault($vars));
 }
 public function testAccessibilityViaPublicForQualifiedUser()
 {
     $this->testDb->createPlainTables(array('perm_upload', 'groups'));
     $this->testDb->insertData(array('groups'));
     $_SESSION[Auth::USER_LEVEL] = Auth::PERM_READ;
     $accessibilityByNone = $this->uploadPermissionDao->isAccessible($uploadId = 2, $groupId = 2);
     assertThat($accessibilityByNone, equalTo(false));
     $this->uploadPermissionDao->setPublicPermission($uploadId, Auth::PERM_READ);
     $accessibilityByPublic = $this->uploadPermissionDao->isAccessible($uploadId, $groupId);
     assertThat($accessibilityByPublic, equalTo(true));
 }