Exemplo n.º 1
0
 /**
  * Retrieves all descendants of given ResourceNode and updates their
  * accessibility dates.
  *
  * @param ResourceNode $node A directory
  * @param datetime $accessibleFrom
  * @param datetime $accessibleUntil
  */
 public function changeAccessibilityDate(ResourceNode $node, $accessibleFrom, $accessibleUntil)
 {
     if ($node->getResourceType()->getName() === 'directory') {
         $descendants = $this->resourceNodeRepo->findDescendants($node);
         foreach ($descendants as $descendant) {
             $descendant->setAccessibleFrom($accessibleFrom);
             $descendant->setAccessibleUntil($accessibleUntil);
             $this->om->persist($descendant);
         }
         $this->om->flush();
     }
 }
 /**
  * @EXT\Route(
  *     "/node/{node}/icon/edit/form",
  *     name="claro_resource_icon_edit_form",
  *     options={"expose"=true}
  * )
  * @EXT\Template("ClarolineCoreBundle:Resource:iconEditForm.html.twig")
  *
  * Displays the resource properties form.
  *
  * @param ResourceNode $node
  *
  * @return Response
  */
 public function iconEditFormAction(ResourceNode $node)
 {
     $collection = new ResourceCollection(array($node));
     $this->checkAccess('EDIT', $collection);
     $username = $node->getCreator()->getUsername();
     $isDir = $node->getResourceType()->getName() === 'directory';
     $form = $this->formFactory->create(new ResourceIconType($username), $node);
     return array('form' => $form->createView(), 'nodeId' => $node->getId(), 'isDir' => $isDir);
 }
Exemplo n.º 3
0
 public function createDefaultPostRights(ResourceNode $node)
 {
     $workspace = $node->getWorkspace();
     $resourceType = $node->getResourceType();
     $role = $this->roleRepo->findOneBaseWorkspaceRole('COLLABORATOR', $workspace);
     if (!is_null($role)) {
         $postDecoder = $this->maskManager->getDecoder($resourceType, 'post');
         if (!is_null($postDecoder)) {
             $rights = $this->rightsManager->getOneByRoleAndResource($role, $node);
             $value = $postDecoder->getValue();
             $mask = $rights->getMask();
             $permissions = $mask | $value;
             $this->rightsManager->editPerms($permissions, $role, $node);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * @EXT\Route(
  *     "/{node}/rights/users/with/rights/ordered/by/{orderedBy}/order/{order}/page/{page}/max/{max}/form/search/{search}",
  *     name="claro_resources_rights_users_with_rights_form",
  *     options={"expose"=true},
  *     defaults={"search"="","ordered"="firstName","order"="ASC","page"=1,"max"=50}
  * )
  * @EXT\Template("ClarolineCoreBundle:Resource:resourcesRightsUsersWithRightsForm.html.twig")
  *
  * Displays the resource rights form for all users.
  *
  * @param ResourceNode $node
  * @param string $search
  * @param string $orderedBy
  * @param string $order
  * @param int $page
  * @param int $max
  *
  * @return Response
  */
 public function resourcesRightsUsersWithRightsFormAction(ResourceNode $node, $search = '', $orderedBy = 'firstName', $order = 'ASC', $page = 1, $max = 50)
 {
     $collection = new ResourceCollection(array($node));
     $this->checkAccess('ADMINISTRATE', $collection);
     $isDir = $node->getResourceType()->getName() === 'directory';
     $resourceType = $node->getResourceType();
     $mask = $this->maskManager->decodeMask($resourceType->getDefaultMask(), $resourceType);
     $users = empty($search) ? $this->userManager->getUsersWithRights($node, $orderedBy, $order, $page, $max) : $this->userManager->getSearchedUsersWithRights($node, $search, $orderedBy, $order, $page, $max);
     $roleKeys = array();
     $usersRoles = array();
     $usersRights = array();
     foreach ($users as $user) {
         $roleKeys[] = $user->getUsername();
     }
     $usersRolesRaw = $this->roleManager->getUserRolesByTranslationKeys($roleKeys);
     foreach ($usersRolesRaw as $userRole) {
         $usersRoles[$userRole->getTranslationKey()] = $userRole;
     }
     $userRolesRights = $this->rightsManager->getUserRolesResourceRights($node, $roleKeys);
     foreach ($userRolesRights as $right) {
         $usersRights[$right->getRole()->getTranslationKey()] = $right;
     }
     return array('resource' => $node, 'isDir' => $isDir, 'mask' => $mask, 'users' => $users, 'usersRoles' => $usersRoles, 'usersRights' => $usersRights, 'orderedBy' => $orderedBy, 'order' => $order, 'max' => $max, 'search' => $search);
 }
Exemplo n.º 5
0
 /**
  * Return the resource rights as a readable array. This array can be used for the resource creation.
  * @param ResourceNode $node
  *
  * @return array
  */
 public function getCustomRoleRights(ResourceNode $node)
 {
     $perms = array();
     foreach ($node->getRights() as $right) {
         //if not ROLE_ANONYMOUS nor ROLE_USER because they're added automatically in ResourceManager::createRights
         if ($right->getRole()->getName() !== 'ROLE_ANONYMOUS' && $right->getRole()->getName() !== 'ROLE_USER') {
             $rolePerms = $this->maskManager->decodeMask($right->getMask(), $node->getResourceType());
             $perms[$right->getRole()->getName()] = $rolePerms;
             $perms[$right->getRole()->getName()]['role'] = $right->getRole();
             //no implementation for rights creations yet
             $perms[$right->getRole()->getName()]['create'] = array();
         }
     }
     return $perms;
 }
Exemplo n.º 6
0
 private function getPermsArray(ResourceNode $node)
 {
     $rights = $node->getRights();
     $roles = [];
     foreach ($rights as $right) {
         $perms = $this->maskManager->decodeMask($right->getMask(), $node->getResourceType());
         //we only keep workspace in the current workspace and platform roles
         if ($right->getRole()->getWorkspace() === $node->getWorkspace()) {
             //creation rights are missing here but w/e
             $name = $this->roleManager->getWorkspaceRoleBaseName($right->getRole());
             $data = array('name' => $name, 'rights' => $perms);
             //don't keep the role manager
             if (!strpos('_' . $name, 'ROLE_WS_MANAGER')) {
                 $roles[] = array('role' => $data);
             }
         }
     }
     return $roles;
 }
Exemplo n.º 7
0
 /**
  * @EXT\Route(
  *     "/custom/{action}/{node}",
  *     name="claro_resource_action",
  *     options={"expose"=true}
  * )
  *
  * Handles any custom action (i.e. not defined in this controller) on a
  * resource of a given type.
  *
  * If the ResourceType is null, it's an action (resource action) valides for all type of resources.
  *
  * @param string       $action       the action
  * @param ResourceNode $node         the resource
  *
  * @throws \Exception
  * @return Response
  */
 public function customAction($action, ResourceNode $node)
 {
     $type = $node->getResourceType();
     $menuAction = $this->maskManager->getMenuFromNameAndResourceType($action, $type);
     if (!$menuAction) {
         throw new \Exception("The menu {$action} doesn't exists");
     }
     $collection = new ResourceCollection(array($node));
     if ($menuAction->getResourceType() === null) {
         if (!$this->authorization->isGranted('ROLE_USER')) {
             throw new AccessDeniedException('You must be log in to execute this action !');
         }
         $this->checkAccess('open', $collection);
         $eventName = 'resource_action_' . $action;
     } else {
         $permToCheck = $this->maskManager->getByValue($type, $menuAction->getValue());
         $this->checkAccess($permToCheck->getName(), $collection);
         $eventName = $action . '_' . $type->getName();
     }
     $event = $this->dispatcher->dispatch($eventName, 'CustomActionResource', array($this->resourceManager->getResourceFromNode($node)));
     return $event->getResponse();
 }
Exemplo n.º 8
0
 /**
  * @todo find the method wich generate the url from tinymce
  *
  * @param ResourceNode $node
  */
 public function generateDisplayedUrlForTinyMce(ResourceNode $node)
 {
     if (strpos('_' . $node->getMimeType(), 'image') > 0) {
         $url = $this->router->generate('claro_file_get_media', ['node' => $node->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
         return "<img style='max-width: 100%;' src='{$url}' alt='{$node->getName()}'>";
     }
     if (strpos('_' . $node->getMimeType(), 'video') > 0) {
         $url = $this->router->generate('claro_file_get_media', ['node' => $node->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
         return "<source type='{$node->getMimeType()}' src='{$url}'></source>";
     }
     $url = $this->router->generate('claro_resource_open', ['resourceType' => $node->getResourceType()->getName(), 'node' => $node->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
     return "<a href='{$url}'>{$node->getName()}</a>";
 }
Exemplo n.º 9
0
 /**
  * @EXT\Route(
  *     "/resources/widget/resource/{resourceNode}/open",
  *     name="claro_tag_resource_from_widget_open",
  *     options={"expose"=true}
  * )
  */
 public function resourceFromWidgetOpenAction(ResourceNode $resourceNode)
 {
     $resourceType = $resourceNode->getResourceType();
     if ($resourceType->getName() === 'directory') {
         $route = $this->router->generate('claro_workspace_open_tool', array('toolName' => 'resource_manager', 'workspaceId' => $resourceNode->getWorkspace()->getId()));
         $route .= '?#resources/' . $resourceNode->getId();
         return new RedirectResponse($route);
     } else {
         $route = $this->router->generate('claro_resource_open_short', array('node' => $resourceNode->getId()));
         return new RedirectResponse($route);
     }
 }
Exemplo n.º 10
0
 /**
  *  Getting the users that have the $selectedright rights
  *  Excluded the admin profil.
  * For a resource
  *
  * @return array UserIds array of user objects|array
  */
 public function getUsersForResourceByRights(ResourceNode $node, $selectedright = 'open', $excludeAdmin = true)
 {
     //        $this->container->get('icap.manager.dropzone_voter')->isAllowToEdit($dropzone);
     //getting the ressource node
     //   $ressourceNode = $dropzone->getResourceNode();
     // getting the rights of the ressource node
     $rights = $node->getRights();
     // will contain the user's ids.
     $userIds = array();
     $test = array();
     // searching for roles with the 'open' right
     foreach ($rights as $ressourceRight) {
         $role = $ressourceRight->getRole();
         //  current role
         $mask = $ressourceRight->getMask();
         // current mask
         // getting decoded rights.
         $decodedRights = $this->maskManager->decodeMask($mask, $node->getResourceType());
         $checkrights = array_key_exists($selectedright, $decodedRights) && $decodedRights[$selectedright] == true;
         // if this role is allowed to $selectedright (and this role is not an Admin role)
         $checkrights = $excludeAdmin ? $checkrights && $role->getName() != 'ROLE_ADMIN' : $checkrights;
         if ($checkrights) {
             $users = $role->getUsers();
             foreach ($users as $user) {
                 array_push($userIds, $user);
             }
         }
     }
     //$users = array_unique($users);
     return $userIds;
 }