public function getVisibleAnnouncementsByWorkspace(Workspace $workspace, array $roles)
 {
     if (in_array('ROLE_ADMIN', $roles) || in_array("ROLE_WS_MANAGER_{$workspace->getGuid()}", $roles)) {
         return $this->announcementRepo->findVisibleByWorkspace($workspace);
     }
     return $this->announcementRepo->findVisibleByWorkspaceAndRoles($workspace, $roles);
 }
 /**
  * Returns the workspace tools visible by a set of roles.
  *
  * @param string[]  $roles
  * @param Workspace $workspace
  *
  * @return Tool[]
  *
  * @throws \RuntimeException
  */
 public function findDisplayedByRolesAndWorkspace(array $roles, Workspace $workspace, $orderedToolType = 0)
 {
     if (count($roles) === 0) {
         return array();
     } else {
         $isAdmin = false;
         foreach ($roles as $role) {
             if ($role === 'ROLE_ADMIN' || $role === 'ROLE_WS_MANAGER_' . $workspace->getGuid()) {
                 $isAdmin = true;
             }
         }
         if (!$isAdmin) {
             $dql = '
                 SELECT t
                 FROM Claroline\\CoreBundle\\Entity\\Tool\\Tool t
                 JOIN t.orderedTools ot
                 JOIN ot.rights r
                 JOIN r.role rr
                 LEFT JOIN t.plugin p
                 WHERE ot.workspace = :workspace
                 AND ot.type = :type
                 AND rr.name IN (:roleNames)
                 AND BIT_AND(r.mask, 1) = 1
                 AND (
                     CONCAT(p.vendorName, p.bundleName) IN (:bundles)
                     OR p.id is NULL
                 )
                 ORDER BY ot.order
             ';
             $query = $this->_em->createQuery($dql);
             $query->setParameter('workspace', $workspace);
             $query->setParameter('roleNames', $roles);
             $query->setParameter('type', $orderedToolType);
             $query->setParameter('bundles', $this->bundles);
         } else {
             $dql = '
                 SELECT tool
                 FROM Claroline\\CoreBundle\\Entity\\Tool\\Tool tool
                 JOIN tool.orderedTools ot
                 LEFT JOIN tool.plugin p
                 WHERE ot.workspace = :workspace
                 AND tool.isDisplayableInWorkspace = true
                 AND (
                     CONCAT(p.vendorName, p.bundleName) IN (:bundles)
                     OR tool.plugin is NULL
                 )
                 ORDER BY ot.order
             ';
             $query = $this->_em->createQuery($dql);
             $query->setParameter('workspace', $workspace);
             $query->setParameter('bundles', $this->bundles);
         }
         return $query->getResult();
     }
 }
 /**
  * @param \Claroline\CoreBundle\Entity\Workspace\Workspace $source
  * @param \Claroline\CoreBundle\Entity\Workspace\Workspace $workspace
  * @param \Claroline\CoreBundle\Entity\User $user
  */
 private function duplicateWorkspaceRoles(Workspace $source, Workspace $workspace, User $user)
 {
     $guid = $workspace->getGuid();
     $roles = $source->getRoles();
     $unusedRolePartName = '_' . $source->getGuid();
     foreach ($roles as $role) {
         $roleName = str_replace($unusedRolePartName, '', $role->getName());
         $createdRole = $this->roleManager->createWorkspaceRole($roleName . '_' . $guid, $role->getTranslationKey(), $workspace, $role->isReadOnly());
         if ($roleName === 'ROLE_WS_MANAGER') {
             $user->addRole($createdRole);
             $this->om->persist($user);
         }
     }
 }
Example #4
0
 public function isWorkspaceManager(Workspace $workspace, TokenInterface $token)
 {
     $managerRoleName = 'ROLE_WS_MANAGER_' . $workspace->getGuid();
     return in_array($managerRoleName, $this->ut->getRoles($token)) ? true : false;
 }
Example #5
0
 public function findOneBaseWorkspaceRole($roleType, Workspace $workspace)
 {
     $dql = "\n            SELECT r FROM Claroline\\CoreBundle\\Entity\\Role r\n            WHERE r.name = 'ROLE_WS_{$roleType}_{$workspace->getGuid()}'\n        ";
     $query = $this->_em->createQuery($dql);
     return $query->getOneOrNullResult();
 }
 private function isWorkspaceManager(Workspace $workspace, array $roleNames)
 {
     $isWorkspaceManager = false;
     $managerRole = 'ROLE_WS_MANAGER_' . $workspace->getGuid();
     if (in_array('ROLE_ADMIN', $roleNames) || in_array($managerRole, $roleNames)) {
         $isWorkspaceManager = true;
     }
     return $isWorkspaceManager;
 }
 public function exportWorkspace(Workspace $workspace)
 {
     return ['id' => $workspace->getId(), 'guid' => $workspace->getGuid(), 'name' => $workspace->getName(), 'description' => $workspace->getDescription(), 'code' => $workspace->getCode(), 'maxStorageSize' => $workspace->getMaxStorageSize(), 'maxUploadResources' => $workspace->getMaxUploadResources(), 'maxUsers' => $workspace->getMaxUsers(), 'displayable' => $workspace->isDisplayable(), 'creatorId' => $workspace->getCreator()->getId(), 'selfRegistration' => $workspace->getSelfRegistration(), 'registrationValidation' => $workspace->getRegistrationValidation(), 'selfUnregistration' => $workspace->getSelfUnregistration(), 'creationDate' => $workspace->getCreationDate(), 'isPersonal' => $workspace->isPersonal(), 'startDate' => $workspace->getStartDate(), 'endDate' => $workspace->getEndDate(), 'isAccessDate' => $workspace->getIsAccessDate(), 'type' => $workspace->getWorkspaceType()];
 }
 public function findTaggedResourcesByWorkspace(Workspace $workspace, $user = '******', array $roleNames = array('ROLE_ANONYMOUS'))
 {
     $isManager = false;
     foreach ($roleNames as $roleName) {
         if ($roleName === 'ROLE_WS_MANAGER_' . $workspace->getGuid()) {
             $isManager = true;
             break;
         }
     }
     $rightsTest = $isManager ? '' : 'AND rrr.name IN (:roleNames)
         AND BIT_AND(rr.mask, 1) = 1';
     $dql = "\n            SELECT to\n            FROM Claroline\\TagBundle\\Entity\\TaggedObject to\n            WHERE to.objectClass = :objectClass\n            AND to.objectId IN (\n                SELECT DISTINCT r.id\n                FROM Claroline\\CoreBundle\\Entity\\Resource\\ResourceNode r\n                JOIN r.creator c\n                LEFT JOIN r.workspace w\n                LEFT JOIN w.roles wr\n                LEFT JOIN r.rights rr\n                LEFT JOIN rr.role rrr\n                WHERE w = :workspace\n                AND r.active = :active\n                AND (\n                    c.id = :userId\n                    OR (\n                        r.published = true\n                        AND (r.accessibleFrom IS NULL OR r.accessibleFrom <= :currentdate)\n                        AND (r.accessibleUntil IS NULL OR r.accessibleUntil >= :currentdate)\n                    )\n                )\n                {$rightsTest}\n            )\n        ";
     $query = $this->_em->createQuery($dql);
     $query->setParameter('objectClass', 'Claroline\\CoreBundle\\Entity\\Resource\\ResourceNode');
     $query->setParameter('workspace', $workspace);
     $query->setParameter('active', true);
     $userId = $user === 'anon.' ? -1 : $user->getId();
     $query->setParameter('userId', $userId);
     $currentDate = new \DateTime();
     if (!$isManager) {
         $query->setParameter('roleNames', $roleNames);
     }
     $query->setParameter('currentdate', $currentDate->format('Y-m-d H:i:s'));
     return $query->getResult();
 }
Example #9
0
 public function import(array $roles, Workspace $workspace)
 {
     $entityRoles = [];
     foreach ($roles as $role) {
         $roleEntity = null;
         if (!$role['role']['is_base_role']) {
             //check if the role exists in case we're importing everything in an existing workspace
             if (count($this->roleManager->getRolesByName("{$role['role']['name']}_{$workspace->getGuid()}")) === 0) {
                 $roleEntity = $this->roleManager->createWorkspaceRole("{$role['role']['name']}_{$workspace->getGuid()}", $role['role']['translation'], $workspace, false);
             }
         } else {
             $roleEntity = $this->roleManager->createBaseRole($role['role']['name'], $role['role']['translation'], false);
         }
         if ($roleEntity) {
             $entityRoles[$role['role']['name']] = $roleEntity;
         }
     }
     return $entityRoles;
 }
Example #10
0
 private function createTeamManagerRole(Team $team, Workspace $workspace)
 {
     $teamName = $team->getName();
     $roleName = $this->computeValidRoleName(strtoupper(str_replace(' ', '_', $teamName . '_MANAGER')), $workspace->getGuid());
     $roleKey = $this->computeValidRoleTranslationKey($workspace, $teamName . ' manager');
     $role = $this->roleManager->createWorkspaceRole($roleName, $roleKey, $workspace);
     $this->setRightsForOldTeams($workspace, $role);
     return $role;
 }