private function updatePermissionMasksAndMenus()
 {
     $this->log('Updating resource permissions...');
     $resourceTypes = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findAll();
     foreach ($resourceTypes as $resourceType) {
         $permissionMap = $this->mm->getPermissionMap($resourceType);
         if (!in_array('administrate', $permissionMap)) {
             $mask = $this->mm->getDecoder($resourceType, 'edit');
             $mask->setName('administrate');
             $this->om->persist($mask);
             $maskDecoder = new MaskDecoder();
             $maskDecoder->setValue(pow(2, count($permissionMap) + 1));
             $maskDecoder->setName('edit');
             $maskDecoder->setResourceType($resourceType);
             $this->om->persist($maskDecoder);
         }
     }
     $this->om->flush();
     //remove the "write perm" text.
     $textType = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findOneByName('text');
     $mask = $this->mm->getDecoder($textType, 'write');
     if ($mask) {
         $this->om->remove($mask);
     }
     $fileType = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findOneByName('file');
     $menuItem = $this->mm->getMenuFromNameAndResourceType('update_file', $fileType);
     $mask = $this->mm->getDecoder($fileType, 'edit');
     $menuItem->setValue($mask->getValue());
     $this->om->persist($menuItem);
     //edit the "change-file" menu
     $this->om->flush();
 }
 /**
  * Loads one meta type (document) and four resource types handled by the platform core :
  * - File
  * - Directory
  * - Link
  * - Text
  * All these resource types have the 'document' meta type.
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     // resource type attributes : name, listable, navigable, class
     $resourceTypes = array(array('file', true), array('directory', true), array('text', true), array('resource_shortcut', false), array('activity', true));
     $types[] = array();
     foreach ($resourceTypes as $attributes) {
         $type = new ResourceType();
         $type->setName($attributes[0]);
         $type->setExportable($attributes[1]);
         $manager->persist($type);
         $this->container->get('claroline.manager.mask_manager')->addDefaultPerms($type);
         $types[$attributes[0]] = $type;
     }
     //add special actions.
     $composeDecoder = new MaskDecoder();
     $composeDecoder->setValue(pow(2, 10));
     $composeDecoder->setName('compose');
     $composeDecoder->setResourceType($types['activity']);
     $manager->persist($composeDecoder);
     $activityMenu = new MenuAction();
     $activityMenu->setName('compose');
     $activityMenu->setAsync(false);
     $activityMenu->setIsCustom(true);
     $activityMenu->setValue(pow(2, 10));
     $activityMenu->setResourceType($types['activity']);
     $activityMenu->setIsForm(false);
     $manager->persist($activityMenu);
     $updateFile = new MenuAction();
     $updateFile->setName('update_file');
     $updateFile->setAsync(true);
     $updateFile->setIsCustom(true);
     $updateFile->setIsForm(false);
     $updateFile->setResourceType($types['file']);
     //16 is default for edit
     $updateFile->setValue(16);
     $manager->persist($updateFile);
     $fileAction = new ActivityRuleAction();
     $fileAction->setAction('resource-read');
     $fileAction->setResourceType($types['file']);
     $manager->persist($fileAction);
     $textAction = new ActivityRuleAction();
     $textAction->setAction('resource-read');
     $textAction->setResourceType($types['text']);
     $manager->persist($textAction);
     $badgeAwardAction = new ActivityRuleAction();
     $badgeAwardAction->setAction('badge-awarding');
     $manager->persist($badgeAwardAction);
 }
Exemple #3
0
 public function postUpdate()
 {
     $em = $this->container->get('doctrine.orm.entity_manager');
     $typeText = $em->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findOneByName('text');
     $decoder = $em->getRepository('ClarolineCoreBundle:Resource\\MaskDecoder')->findOneBy(array('resourceType' => $typeText, 'name' => 'write'));
     if (!$decoder) {
         $updateTextDecoder = new MaskDecoder();
         $updateTextDecoder->setValue(pow(2, 6));
         $updateTextDecoder->setName('write');
         $updateTextDecoder->setResourceType($typeText);
         $em->persist($updateTextDecoder);
         $this->log("Adding 'write' permissions for resource 'text'");
         $em->flush();
     } else {
         $this->log("The 'write' permissions for resource 'text' already exists");
     }
 }
Exemple #4
0
 /**
  * @param array $actions
  * @param ResourceType $resourceType
  */
 private function updateCustomAction($actions, ResourceType $resourceType)
 {
     $decoderRepo = $this->em->getRepository('Claroline\\CoreBundle\\Entity\\Resource\\MaskDecoder');
     $existingDecoders = $decoderRepo->findBy(array('resourceType' => $resourceType));
     $exp = count($existingDecoders);
     $newDecoders = array();
     foreach ($actions as $action) {
         $decoder = $decoderRepo->findOneBy(array('name' => $action['name'], 'resourceType' => $resourceType));
         if (!$decoder) {
             if (array_key_exists($action['name'], $newDecoders)) {
                 $decoder = $newDecoders[$action['name']];
             } else {
                 $decoder = new MaskDecoder();
                 $decoder->setName($action['name'])->setResourceType($resourceType)->setValue(pow(2, $exp));
                 $this->em->persist($decoder);
                 $newDecoders[$action['name']] = $decoder;
                 $exp++;
             }
         }
         if (isset($action['menu_name'])) {
             $menuAction = $this->em->getRepository('ClarolineCoreBundle:Resource\\MenuAction')->findOneByName($action['menu_name']);
             if (null === $menuAction) {
                 $menuAction = new MenuAction();
                 $menuAction->setName($action['menu_name'])->setResourceType($resourceType)->setIsForm($action['is_form'])->setValue($decoder->getValue());
                 $this->em->persist($menuAction);
             }
         }
     }
     $this->em->flush();
 }
Exemple #5
0
 public function maskDecoder(ResourceType $type, $permission, $value)
 {
     $decoder = new MaskDecoder();
     $decoder->setResourceType($type);
     $decoder->setName($permission);
     $decoder->setValue($value);
     $this->om->persist($decoder);
     return $decoder;
 }
Exemple #6
0
 /**
  * Adds the default action to a resource type.
  *
  * @param \Claroline\CoreBundle\Entity\Resource\ResourceType $type
  */
 public function addDefaultPerms(ResourceType $type)
 {
     $createdPerms = array();
     for ($i = 0, $size = count(self::$defaultActions); $i < $size; $i++) {
         $maskDecoder = new MaskDecoder();
         $maskDecoder->setValue(pow(2, $i));
         $maskDecoder->setName(self::$defaultActions[$i]);
         $maskDecoder->setResourceType($type);
         $this->om->persist($maskDecoder);
         $createdPerms[self::$defaultActions[$i]] = $maskDecoder;
     }
     foreach (self::$defaultMenus as $action => $data) {
         foreach ($data as $name => $isForm) {
             $menu = new MenuAction();
             $menu->setName($name);
             $menu->setAsync(true);
             $menu->setIsCustom(false);
             $menu->setValue($createdPerms[$action]->getValue());
             $menu->setResourceType($type);
             $menu->setIsForm($isForm);
             $this->om->persist($menu);
         }
     }
     $this->om->flush();
 }