예제 #1
0
 /**
  * Returns the ancestors of a message (the message itself is also returned).
  *
  * @param Message $message
  *
  * @return array[Message]
  */
 public function findAncestors(Message $message, User $user)
 {
     $dql = "\n            SELECT m\n            FROM Claroline\\MessageBundle\\Entity\\Message m\n            JOIN m.userMessages um\n            JOIN um.user u\n            WHERE m.lft BETWEEN m.lft AND m.rgt\n            AND m.root = {$message->getRoot()}\n            AND m.lvl <= {$message->getLvl()}\n            AND (\n                u.id = :userid\n                OR m.user = :userid\n            )\n        ";
     $query = $this->_em->createQuery($dql);
     $query->setParameter('userid', $user->getId());
     return $query->getResult();
 }
예제 #2
0
 public function registerUserToCursusHierarchy($platformName, User $user, $cursusId)
 {
     $targetPlatformUrl = $this->friendRepo->findOneByName($platformName);
     $url = 'clarolinecursusbundle/api/users/' . $user->getId() . '/tos/' . $cursusId . '/cursus/hierarchy/add.json';
     $serverOutput = $this->apiManager->url($targetPlatformUrl, $url);
     return json_decode($serverOutput, true);
 }
예제 #3
0
 protected function setUp()
 {
     parent::setUp();
     $this->persister = $this->client->getContainer()->get('claroline.library.testing.persister');
     //users
     $this->john = $this->persister->user('john');
     $roleAdmin = $this->persister->role('ROLE_ADMIN');
     $this->teacherRole = $this->persister->role('ROLE_TEACHER');
     $this->baseRole = $this->persister->role('ROLE_BASE');
     $this->admin = $this->persister->user('admin');
     $this->admin->addRole($roleAdmin);
     //organization
     $organization = $this->persister->organization('organization');
     $this->adminOrga = $this->persister->user('adminOrga');
     $this->groupOrga = $this->persister->group('groupOrga');
     $this->groupOrga->addRole($this->baseRole);
     $this->groupBase = $this->persister->group('groupBase');
     $this->groupOrga->addOrganization($organization);
     $this->adminOrga->addAdministratedOrganization($organization);
     //persist
     $this->persister->persist($this->groupOrga);
     $this->persister->persist($this->adminOrga);
     $this->persister->persist($this->admin);
     $this->persister->flush();
 }
 /**
  * @Route("/regenerate_rss", name="icap_notification_regenerate_rss_url")
  * @Template("IcapNotificationBundle:Parameters:config.html.twig")
  * @ParamConverter("user", options={"authenticatedUser" = true})
  */
 public function regenerateRssUrlAction(User $user)
 {
     $parametersManager = $this->getParametersManager();
     $parameters = $parametersManager->regenerateRssId($user->getId());
     $types = $parametersManager->allTypesList($parameters);
     return array('types' => $types, 'rssId' => $parameters->getRssId());
 }
예제 #5
0
 public function request($method, $uri, User $user = null, array $parameters = [])
 {
     if (!$this->client instanceof Client) {
         throw new \Exception('This method requires a client property of type ' . 'Symfony\\Component\\BrowserKit\\Client');
     }
     $server = $user ? ['PHP_AUTH_USER' => $user->getUsername(), 'PHP_AUTH_PW' => $user->getPlainPassword()] : [];
     return $this->client->request($method, $uri, $parameters, [], $server);
 }
예제 #6
0
 public function findByUser(User $user, $showAll = false)
 {
     $qb = $this->createQueryBuilder('f')->leftJoin('f.panelFacets', 'pf')->leftJoin('pf.fieldsFacet', 'ff')->leftJoin('ff.fieldsFacetValue', 'ffv');
     if (!$showAll) {
         $qb->join('f.roles', 'frole')->join('pf.panelFacetsRole', 'pfr')->andWhere('frole in (:roles)')->andWhere('pfr.role in (:roles)')->andWhere('pfr.canOpen = true')->setParameter('roles', $user->getEntityRoles());
     }
     return $qb->getQuery()->getResult();
 }
예제 #7
0
 /**
  * @param User $user
  * @param bool $executeQuery
  *
  * @return Query|array
  */
 public function findByUserWithAccessToken(User $user, $executeQuery = true)
 {
     $query = $this->getEntityManager()->createQuery('SELECT c, at
             FROM ClarolineCoreBundle:Oauth\\Client c
             JOIN c.accessTokens at
             WHERE at.user = :userId')->setParameter('userId', $user->getId());
     return $executeQuery ? $query->getResult() : $query;
 }
 private function getUserKey(User $user)
 {
     if ($user === null) {
         return 'anonymous';
     } else {
         return $user->getId();
     }
 }
 /**
  * @param User $user
  * @param bool $getQuery
  *
  * @return Query|array
  */
 public function findByUser(User $user, $getQuery = false)
 {
     $query = $this->getEntityManager()->createQuery('SELECT bc, b, bt
             FROM IcapBadgeBundle:BadgeClaim bc
             JOIN bc.badge b
             JOIN b.translations bt
             WHERE bc.user = :userId')->setParameter('userId', $user->getId());
     return $getQuery ? $query : $query->getResult();
 }
예제 #10
0
 /**
  * @param User $user
  * @param bool $executeQuery
  *
  * @return Query|array
  */
 public function findByUser(User $user, $executeQuery = true)
 {
     $query = $this->getEntityManager()->createQuery('SELECT b, ub, bt
             FROM IcapBadgeBundle:Badge b
             JOIN b.userBadges ub
             JOIN b.translations bt
             WHERE ub.user = :userId')->setParameter('userId', $user->getId());
     return $executeQuery ? $query->getResult() : $query;
 }
 /**
  * @param User $user
  * @param bool $executeQuery
  *
  * @return Query|array
  */
 public function findByUser(User $user, $executeQuery = true)
 {
     $query = $this->getEntityManager()->createQuery('SELECT badgeCollection, userBadges
             FROM IcapBadgeBundle:BadgeCollection badgeCollection
             LEFT JOIN badgeCollection.userBadges userBadges
             WHERE badgeCollection.user = :userId
             ORDER BY badgeCollection.name ASC')->setParameter('userId', $user->getId());
     return $executeQuery ? $query->getResult() : $query;
 }
 /**
  *  Admin or not
  *
  * @param User $user
  * @return boolean
  */
 public function adminOrNot(User $user)
 {
     $adminInnova = false;
     // TODO : change service to @security.authorization_checker
     if ($this->securityContext->isGranted('ROLE_ADMIN' === true) && $this->get('security.context')->getToken()->getUser()->getId() == $user->getId()) {
         $adminInnova = true;
     }
     return $adminInnova;
 }
예제 #13
0
 public function checkRights(User $user, $theRight)
 {
     if ($this->authorization->isGranted('ROLE_ADMIN')) {
         return true;
     }
     $roles = $user->getEntityRoles();
     $rights = $this->rightsRepo->findPresenceRightsByRolesAndValue($roles, $theRight);
     return count($rights) > 0;
 }
예제 #14
0
 /**
  * @param Workspace $workspace
  * @param User      $user
  *
  * @return User
  */
 public function workspaceUser(Workspace $workspace, User $user)
 {
     $role = new Role();
     $role->setName("ROLE_WS_{$workspace->getName()}_{$user->getUsername()}");
     $role->setTranslationKey($role->getName());
     $role->setWorkspace($workspace);
     $user->addRole($role);
     $this->om->persist($role);
     $this->om->persist($user);
     return $user;
 }
예제 #15
0
 protected function persistUser($username)
 {
     $user = new User();
     $user->setFirstName($username);
     $user->setLastName($username);
     $user->setUsername($username);
     $user->setPassword($username);
     $user->setMail($username . '@mail.com');
     $this->om->persist($user);
     return $user;
 }
 public function __construct(Cursus $cursus, User $user)
 {
     $details = [];
     $details['username'] = $user->getUsername();
     $details['firsName'] = $user->getFirstName();
     $details['lastName'] = $user->getLastName();
     $details['cursusId'] = $cursus->getId();
     $details['cursusTitle'] = $cursus->getTitle();
     $details['cursusCode'] = $cursus->getCode();
     parent::__construct(self::ACTION, $details, $user);
 }
예제 #17
0
 /**
  * @param Wiki $wiki
  * @param bool $isAdmin
  * @param User $user
  *
  * @return Tree $tree
  */
 public function buildSectionTree(Wiki $wiki, $isAdmin, User $user = null)
 {
     $queryBuilder = $this->createQueryBuilder('section')->join('section.activeContribution', 'contribution')->select('section, contribution')->andWhere('section.root = :rootId')->orderBy('section.root, section.left', 'ASC')->setParameter('rootId', $wiki->getRoot()->getId());
     $queryBuilder->andWhere($queryBuilder->expr()->orX('section.deleted = :deleted', $queryBuilder->expr()->isNull('section.deleted')))->setParameter('deleted', false);
     if ($isAdmin === false) {
         $queryBuilder->andWhere($queryBuilder->expr()->orX('section.visible = :visible', 'section.author = :userId'))->setParameter('visible', true)->setParameter('userId', $user->getId());
     }
     $options = ['decorate' => false];
     $tree = $this->buildTree($queryBuilder->getQuery()->getArrayResult(), $options);
     return $tree;
 }
예제 #18
0
 /**
  * @param string $username
  *
  * @return User
  */
 public function user($username, $withWorkspace = false)
 {
     $user = new User();
     $user->setFirstName($username);
     $user->setLastName($username);
     $user->setUsername($username);
     $user->setPassword($username);
     $user->setMail($username . '@mail.com');
     $user->setGuid($username);
     $this->om->persist($user);
     if (!$this->userRole) {
         $this->userRole = $this->role('ROLE_USER');
         $this->om->persist($this->userRole);
     }
     $user->addRole($this->userRole);
     if ($withWorkspace) {
         $workspace = new Workspace();
         $workspace->setName($username);
         $workspace->setCreator($user);
         $workspace->setCode($username);
         $workspace->setGuid($username);
         $this->om->persist($workspace);
         $user->setPersonalWorkspace($workspace);
     }
     return $user;
 }
 public function createInwicastUserIfNotExists(User $user, $token, Mediacenter $mediacenter)
 {
     $connection = $this->connectionFactory->createConnection($mediacenter->getDatabaseParameters());
     $qb = $connection->createQueryBuilder();
     $qb->select('usr.username, usr.token')->from('mdcr_inwicast_user_tokens', 'usr')->where('usr.username = :username')->andWhere('usr.tokenapp = :platform')->setParameter("username", $user->getUsername())->setParameter("platform", $this->platformName);
     $result = $qb->execute()->fetch();
     if (!$result) {
         //$qb_insert = $connection->createQueryBuilder();
         $sql = "INSERT INTO mdcr_inwicast_user_tokens" . " (`username`, `firstname`, `lastname`, `email`, `userrole`, `token`, `tokendate`, `tokenapp`)" . " VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
         $query = $connection->prepare($sql);
         $query->bindValue(1, $user->getUsername());
         $query->bindValue(2, $user->getFirstName());
         $query->bindValue(3, $user->getLastName());
         $query->bindValue(4, $user->getMail());
         $query->bindValue(5, $user->getPlatformRole()->getName());
         $query->bindValue(6, $token);
         $query->bindValue(7, date('Y-m-d H:i:s'));
         $query->bindValue(8, $this->platformName);
         $query->execute();
     } else {
         $qb_update = $connection->createQueryBuilder();
         $qb_update->update('mdcr_inwicast_user_tokens')->set('token', '?')->set('tokendate', '?')->set('tokenapp', '?')->where('username = ?')->setParameter(0, $token)->setParameter(1, date('Y-m-d H:i:s'))->setParameter(2, $this->platformName)->setParameter(3, $user->getUsername());
         $qb_update->execute();
     }
     return true;
 }
예제 #20
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $objectManager)
 {
     /** @var \Claroline\CoreBundle\Manager\UserManager $userCreator */
     $userCreator = $this->container->get('claroline.manager.user_manager');
     /** @var \Claroline\CoreBundle\Manager\RoleManager $roleManager */
     $roleManager = $this->container->get('claroline.manager.role_manager');
     /** @var \Claroline\CoreBundle\Repository\ResourceNodeRepository $resourceRepo */
     $resourceRepo = $objectManager->getRepository('ClarolineCoreBundle:Resource\\ResourceNode');
     foreach ($this->users as $names => $role) {
         $namesArray = explode(' ', $names);
         $firstName = $namesArray[0];
         $lastName = isset($namesArray[1]) ? $namesArray[1] : '';
         $username = $firstName . ucfirst($lastName);
         $user = new User();
         $user->setAdministrativeCode('UCL-' . $username . '-' . rand(0, 1000));
         $user->setFirstName($firstName);
         $lastName = $lastName == '' ? 'Doe' : $lastName;
         $user->setLastName($lastName);
         $user->setUserName($username);
         $user->setPlainPassword($username);
         $user->setMail('mail_' . uniqid() . '@claroline.net');
         $objectManager->persist($user);
         $roleManager->associateRole($user, $this->getReference("role/{$role}"));
         if ($this->withWorkspace) {
             $userCreator->createUser($user);
             $this->addReference("workspace/{$names}", $user->getPersonalWorkspace());
             $this->addReference("directory/{$names}", $resourceRepo->findWorkspaceRoot($user->getPersonalWorkspace()));
         } else {
             $objectManager->persist($user);
         }
         $this->addReference("user/{$names}", $user);
         $objectManager->flush();
     }
 }
 private function logClient(User $user, Client $client, $firewall = 'main')
 {
     $tokenStorage = $client->getContainer()->get('security.token_storage');
     $token = new UsernamePasswordToken($user, $user->getPlainPassword(), $firewall, $user->getRoles());
     $tokenStorage->setToken($token);
     //now we generate the cookie !
     //@see http://symfony.com/doc/current/cookbook/testing/simulating_authentication.html
     $session = $client->getContainer()->get('session');
     $session->set('_security_' . $firewall, serialize($token));
     $session->save();
     $cookie = new Cookie($session->getName(), $session->getId());
     $client->getCookieJar()->set($cookie);
     return $client;
 }
 /**
  * @EXT\Route(
  *     "/login",
  *     name="claro_o365_login"
  * )
  *
  * @return RedirectResponse
  */
 public function loginAction()
 {
     $this->authHelper->GetAuthenticationHeaderFor3LeggedFlow($_GET['code']);
     $jsonResponse = $this->graphHelper->getMeEntry();
     $userResponse = new O365ResponseUser($jsonResponse);
     $userManager = $this->get('claroline.manager.user_manager');
     $email = $userResponse->getEmail();
     $user = $userManager->getUserByEmail($email);
     if ($user === null) {
         $missingProperties = $userResponse->validate();
         if (count($missingProperties) > 0) {
             return $this->render('FormaLibreOfficeConnectBundle:Authentication:missingProperties.html.twig', ['missingProperties' => $missingProperties]);
         }
         $user = new User();
         $user->setFirstName($userResponse->getNickname());
         $user->setLastName($userResponse->getRealName());
         $user->setUsername($userResponse->getUsername());
         $user->setPlainPassword($userResponse->getEmail());
         $user->setMail($userResponse->getEmail());
         $user->setIsMailValidated(true);
         $userManager->createUser($user, false);
     }
     $userRepo = $this->get('doctrine.orm.entity_manager')->getRepository('ClarolineCoreBundle:User');
     $securityContext = $this->get('security.context');
     $userLoaded = $userRepo->loadUserByUsername($user->getUsername());
     $providerKey = 'main';
     $token = new UsernamePasswordToken($userLoaded, $userLoaded->getPassword(), $providerKey, $userLoaded->getRoles());
     $securityContext->setToken($token);
     $userManager->logUser($user);
     return $this->get('claroline.authentication_handler')->onAuthenticationSuccess($this->get('request'), $token);
 }
예제 #23
0
 public function user($username)
 {
     $user = new User();
     $user->setFirstName($username);
     $user->setLastName($username);
     $user->setUsername($username);
     $user->setPassword($username);
     $user->setMail($username . '@mail.com');
     $user->setGuid($username);
     $this->om->persist($user);
     if (!$this->userRole) {
         $this->userRole = new Role();
         $this->userRole->setName('ROLE_USER');
         $this->userRole->setTranslationKey('user');
         $this->om->persist($this->userRole);
     }
     $user->addRole($this->userRole);
     $workspace = new Workspace();
     $workspace->setName($username);
     $workspace->setCreator($user);
     $workspace->setCode($username);
     $workspace->setGuid($username);
     $this->om->persist($workspace);
     $user->setPersonalWorkspace($workspace);
     $this->om->flush();
     return $user;
 }
 public function __construct(CourseSession $session, User $user)
 {
     $course = $session->getCourse();
     $details = array();
     $details['username'] = $user->getUsername();
     $details['firsName'] = $user->getFirstName();
     $details['lastName'] = $user->getLastName();
     $details['sessionId'] = $session->getId();
     $details['sessionName'] = $session->getName();
     $details['sessionCreationDate'] = $session->getCreationDate()->format('d/m/Y H:i:s');
     $details['courseId'] = $course->getId();
     $details['courseTitle'] = $course->getTitle();
     $details['courseCode'] = $course->getCode();
     parent::__construct(self::ACTION, $details, $user);
 }
 public function findByUser(User $user)
 {
     $dql = '
         SELECT pf
         FROM Claroline\\CoreBundle\\Entity\\Facet\\PanelFacet pf
         JOIN pf.panelFacetsRole pfr
         JOIN pfr.role r
         JOIN pf.facet f
         JOIN f.frole
         WHERE (r.name in (:roles) AND pfr.isVisible = true)
         AND frole.name : (:roles)
     ';
     $query = $this->_em->createQuery($dql);
     $query->setParameter('roles', $user->getRoles());
     return $query->getResult();
 }
 public function findByWorkspaceAndUser(Workspace $workspace, User $user)
 {
     $dql = '
         SELECT rwt, t
         FROM Claroline\\CoreBundle\\Entity\\Workspace\\RelWorkspaceTag rwt
         JOIN rwt.workspace w
         JOIN rwt.tag t
         JOIN t.user u
         WHERE u.id = :userId
         AND w.id = :workspaceId
     ';
     $query = $this->_em->createQuery($dql);
     $query->setParameter('userId', $user->getId());
     $query->setParameter('workspaceId', $workspace->getId());
     return $query->getResult();
 }
예제 #27
0
 /**
  * Compute spent time for each user in a given workspace.
  */
 public function getDashboardWorkspaceSpentTimes(Workspace $workspace, User $user, $all = false)
 {
     $datas = [];
     // user(s) concerned by the query
     if ($all) {
         // get all users involved in the workspace
         $ids = $this->getWorkspaceUsersIds($workspace);
     } else {
         // only the current user
         $ids[] = $user->getId();
     }
     // for each user (ie user ids) -> get first 'workspace-enter' event for the given workspace
     foreach ($ids as $uid) {
         $userSqlSelect = 'SELECT first_name, last_name FROM claro_user WHERE id = :uid';
         $userSqlSelectStmt = $this->em->getConnection()->prepare($userSqlSelect);
         $userSqlSelectStmt->bindValue('uid', $uid);
         $userSqlSelectStmt->execute();
         $userData = $userSqlSelectStmt->fetch();
         // select first "workspace-enter" actions for the given user and workspace
         $selectEnterEventOnThisWorkspace = "SELECT DISTINCT date_log FROM claro_log WHERE workspace_id = :wid AND action = 'workspace-enter' AND doer_id = :uid ORDER BY date_log ASC LIMIT 1";
         $selectEnterEventOnThisWorkspaceStmt = $this->em->getConnection()->prepare($selectEnterEventOnThisWorkspace);
         $selectEnterEventOnThisWorkspaceStmt->bindValue('uid', $uid);
         $selectEnterEventOnThisWorkspaceStmt->bindValue('wid', $workspace->getId());
         $selectEnterEventOnThisWorkspaceStmt->execute();
         $enterOnThisWorksapceDateResult = $selectEnterEventOnThisWorkspaceStmt->fetch();
         $refDate = $enterOnThisWorksapceDateResult['date_log'];
         $total = 0;
         if ($refDate) {
             $total = $this->computeTimeForUserAndWorkspace($refDate, $uid, $workspace->getId(), 0);
         }
         $datas[] = ['user' => ['id' => $uid, 'firstName' => $userData['first_name'], 'lastName' => $userData['last_name']], 'time' => $total];
     }
     return $datas;
 }
 public function __construct(SessionEvent $sessionEvent, User $user)
 {
     $session = $sessionEvent->getSession();
     $course = $session->getCourse();
     $details = [];
     $details['username'] = $user->getUsername();
     $details['firsName'] = $user->getFirstName();
     $details['lastName'] = $user->getLastName();
     $details['sessionEventId'] = $sessionEvent->getId();
     $details['sessionEventName'] = $sessionEvent->getName();
     $details['sessionId'] = $session->getId();
     $details['sessionName'] = $session->getName();
     $details['courseId'] = $course->getId();
     $details['courseTitle'] = $course->getTitle();
     $details['courseCode'] = $course->getCode();
     parent::__construct(self::ACTION, $details, $user);
 }
예제 #29
0
 /**
  * Add the default properties accesses for each roles
  */
 public function addDefaultProperties()
 {
     $properties = User::getEditableProperties();
     $this->om->startFlushSuite();
     foreach ($properties as $property => $editable) {
         $this->addProperties($property, $editable);
     }
     $this->om->endFlushSuite();
 }
 public function testPutOrganizationActionIsProtected()
 {
     $orga = $this->persister->organization('orga');
     $this->persister->flush();
     $this->logIn($this->john);
     $fields = array('name' => 'rename', 'email' => '*****@*****.**', 'administrators' => $this->admin->getId());
     $form = array('organization_form' => $fields);
     $this->client->request('PUT', "/api/organizations/{$orga->getId()}.json", $form);
     $this->assertEquals(403, $this->client->getResponse()->getStatusCode());
 }