public function testRemoveUserRoleAction()
 {
     $preCount = count($this->userOrga->getRoles());
     $this->logIn($this->adminOrga);
     $this->client->request('GET', "/api/users/{$this->userOrga->getId()}/roles/{$this->baseRole->getId()}/remove.json");
     $data = $this->client->getResponse()->getContent();
     $data = json_decode($data, true);
     $this->assertEquals($preCount - 1, count($data['roles']));
 }
 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;
 }
 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();
 }
 /**
  * @EXT\Route(
  *     "/user/{user}/workspaces/page/{page}/max/{max}",
  *     name="claro_admin_user_workspaces",
  *     defaults={"page"=1, "max"=50},
  *     options={"expose"=true}
  * )
  * @EXT\Template
  *
  * @param User $user
  * @param int  $page
  * @param int  $max
  *
  * @return array
  */
 public function userWorkspaceListAction(User $user, $page, $max)
 {
     $pager = $this->workspaceManager->getOpenableWorkspacesByRolesPager($user->getRoles(), $page, $max);
     return ['user' => $user, 'pager' => $pager, 'page' => $page, 'max' => $max];
 }
 /**
  * @EXT\Route(
  *     "/workspace/manager/activity/{activityId}/evaluations/page/{page}",
  *     name="claro_workspace_manager_activity_evaluations_show",
  *     defaults={"page"=1}
  * )
  * @EXT\ParamConverter("currentUser", options={"authenticatedUser" = true})
  * @EXT\ParamConverter(
  *      "activity",
  *      class="ClarolineCoreBundle:Resource\Activity",
  *      options={"id" = "activityId", "strictId" = true}
  * )
  * @EXT\Template("ClarolineCoreBundle:Tool/workspace/analytics:workspaceManagerActivityEvaluations.html.twig")
  *
  * Displays evaluations of an activity for each user of the workspace
  *
  * @return Response
  *
  * @throws \Exception
  */
 public function workspaceManagerActivityEvaluationsShowAction(User $currentUser, Activity $activity, $page)
 {
     $roleNames = $currentUser->getRoles();
     $workspace = $activity->getResourceNode()->getWorkspace();
     $isWorkspaceManager = $this->isWorkspaceManager($workspace, $roleNames);
     if (!$isWorkspaceManager) {
         throw new AccessDeniedException();
     }
     $resourceNode = $activity->getResourceNode();
     $activityParams = $activity->getParameters();
     $roles = $this->roleManager->getRolesWithRightsByResourceNode($resourceNode);
     $usersPager = $this->userManager->getUsersByRolesIncludingGroups($roles, $page);
     $users = array();
     foreach ($usersPager as $user) {
         $users[] = $user;
     }
     $allEvaluations = $this->activityManager->getEvaluationsByUsersAndActivityParams($users, $activityParams);
     $evaluations = array();
     foreach ($allEvaluations as $evaluation) {
         $user = $evaluation->getUser();
         $evaluations[$user->getId()] = $evaluation;
     }
     $nbSuccess = 0;
     foreach ($users as $user) {
         if (!isset($evaluations[$user->getId()])) {
             $evaluations[$user->getId()] = $this->activityManager->createBlankEvaluation($user, $activityParams);
         }
         $status = $evaluations[$user->getId()]->getStatus();
         if ($status === AbstractEvaluation::STATUS_COMPLETED || $status === AbstractEvaluation::STATUS_PASSED) {
             $nbSuccess++;
         }
     }
     $progress = count($users) > 0 ? round($nbSuccess / count($users), 2) * 100 : 0;
     $ruleScore = null;
     if ($activityParams->getEvaluationType() === AbstractEvaluation::TYPE_AUTOMATIC && count($activityParams->getRules()) > 0) {
         $rule = $activityParams->getRules()->first();
         $score = $rule->getResult();
         $scoreMax = $rule->getResultMax();
         if (!is_null($score)) {
             $ruleScore = $score;
             if (!is_null($scoreMax)) {
                 $ruleScore .= ' / ' . $scoreMax;
             }
         }
     }
     return array('analyticsTab' => 'activities', 'activity' => $activity, 'activityParams' => $activityParams, 'workspace' => $workspace, 'users' => $usersPager, 'page' => $page, 'evaluations' => $evaluations, 'ruleScore' => $ruleScore, 'progress' => $progress);
 }
Beispiel #6
0
 /**
  * Logs the current user
  */
 public function logUser(User $user)
 {
     $this->strictEventDispatcher->dispatch('log', 'Log\\LogUserLogin', array($user));
     $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
     $this->container->get('security.token_storage')->setToken($token);
 }
 public function findWorkspacesByManager(User $user, $executeQuery = true)
 {
     $roles = $user->getRoles();
     $managerRoles = [];
     foreach ($roles as $role) {
         if (strpos('_' . $role, 'ROLE_WS_MANAGER')) {
             $managerRoles[] = $role;
         }
     }
     $dql = "\n            SELECT w\n            FROM Claroline\\CoreBundle\\Entity\\Workspace\\Workspace w\n            JOIN w.roles r\n            WHERE r.name IN (:roleNames)\n\n        ";
     $query = $this->_em->createQuery($dql);
     $query->setParameter('roleNames', $managerRoles);
     return $executeQuery ? $query->getResult() : $query;
 }
Beispiel #8
0
 /**
  * Logs the current user.
  */
 public function logUser(User $user)
 {
     $this->strictEventDispatcher->dispatch('log', 'Log\\LogUserLogin', [$user]);
     $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
     $this->tokenStorage->setToken($token);
 }
 private function isWorkspaceManager(Workspace $workspace, User $user)
 {
     $isWorkspaceManager = false;
     $managerRole = 'ROLE_WS_MANAGER_' . $workspace->getGuid();
     $roleNames = $user->getRoles();
     if (in_array('ROLE_ADMIN', $roleNames) || in_array($managerRole, $roleNames)) {
         $isWorkspaceManager = true;
     }
     return $isWorkspaceManager;
 }
 /**
  * @Route(
  *     "edit/activity/past/evaluation/{pastEvaluationId}",
  *     name="claro_activity_past_evaluation_edit",
  *     options={"expose"=true}
  * )
  * @ParamConverter("currentUser", options={"authenticatedUser" = true})
  * @ParamConverter(
  *      "pastEvaluation",
  *      class="ClarolineCoreBundle:Activity\PastEvaluation",
  *      options={"id" = "pastEvaluationId", "strictId" = true}
  * )
  * @Template()
  */
 public function editActivityPastEvaluationAction(User $currentUser, PastEvaluation $pastEvaluation)
 {
     $isWorkspaceManager = false;
     $activityParams = $pastEvaluation->getActivityParameters();
     $activity = $activityParams->getActivity();
     if (!is_null($activity)) {
         $workspace = $activity->getResourceNode()->getWorkspace();
         $roleNames = $currentUser->getRoles();
         $isWorkspaceManager = $this->isWorkspaceManager($workspace, $roleNames);
     }
     if (!$isWorkspaceManager) {
         throw new AccessDeniedException();
     }
     $form = $this->formFactory->create(new ActivityPastEvaluationType(), $pastEvaluation);
     $form->handleRequest($this->request);
     if ($form->isValid()) {
         $this->activityManager->editPastEvaluation($pastEvaluation);
         return new Response('success', 204);
     }
     return array('form' => $form->createView(), 'pastEvaluation' => $pastEvaluation);
 }