/** * @EXT\Route( * "/contactable/groups/page/{page}", * name="claro_message_contactable_groups", * options={"expose"=true}, * defaults={"page"=1, "search"=""} * ) * @EXT\Route( * "/contactable/groups/page/{page}/search/{search}", * name="claro_message_contactable_groups_search", * options={"expose"=true}, * defaults={"page"=1} * ) * @EXT\ParamConverter("user", options={"authenticatedUser" = true}) * @EXT\Template() * * @param int $page * @param string $search * @param User $user * * @return Response */ public function contactableGroupsListAction(User $user, $page, $search) { $trimmedSearch = trim($search); if ($user->hasRole('ROLE_ADMIN')) { if ($trimmedSearch === '') { $groups = $this->groupManager->getAllGroups($page); } else { $groups = $this->groupManager->getAllGroupsBySearch($page, $trimmedSearch); } } else { $groups = []; $workspaces = $this->workspaceManager->getWorkspacesByUserAndRoleNames($user, ['ROLE_WS_MANAGER']); // retrieve all groups of workspace that user is manager if (count($workspaces) > 0) { if ($trimmedSearch === '') { $groups = $this->groupManager->getGroupsByWorkspaces($workspaces); } else { $groups = $this->groupManager->getGroupsByWorkspacesAndSearch($workspaces, $search); } } // get groups in which user is subscribed $userGroups = $user->getGroups(); $userGroupsFinal = []; if ($trimmedSearch === '') { $userGroupsFinal = $userGroups; } else { $upperSearch = strtoupper($trimmedSearch); foreach ($userGroups as $userGroup) { $upperName = strtoupper($userGroup->getName()); if (strpos($upperName, $upperSearch) !== false) { $userGroupsFinal[] = $userGroup; } } } // merge the 2 groups array foreach ($userGroupsFinal as $userGroupFinal) { if (!in_array($userGroupFinal, $groups, true)) { $groups[] = $userGroupFinal; } } $groups = $this->pagerFactory->createPagerFromArray($groups, $page); } return ['groups' => $groups, 'search' => $search]; }
/** * @todo Security context verification. * @EXT\Route( * "/{workspaceId}/remove/user/{userId}", * name="claro_workspace_delete_user", * options={"expose"=true}, * requirements={"workspaceId"="^(?=.*[1-9].*$)\d*$"} * ) * @EXT\Method({"DELETE", "GET"}) * @EXT\ParamConverter( * "workspace", * class="ClarolineCoreBundle:Workspace\Workspace", * options={"id" = "workspaceId", "strictId" = true} * ) * @EXT\ParamConverter( * "user", * class="ClarolineCoreBundle:User", * options={"id" = "userId", "strictId" = true} * ) * * Removes an user from a workspace. * * @param Workspace $workspace * @param \Claroline\CoreBundle\Entity\User $user * * @return Response */ public function removeUserAction(Workspace $workspace, User $user) { try { $roles = $this->roleManager->getRolesByWorkspace($workspace); $this->roleManager->checkWorkspaceRoleEditionIsValid(array($user), $workspace, $roles); foreach ($roles as $role) { if ($user->hasRole($role->getName())) { $this->roleManager->dissociateRole($user, $role); $this->eventDispatcher->dispatch('log', 'Log\\LogRoleUnsubscribe', array($role, $user, $workspace)); } } $this->tagManager->deleteAllRelationsFromWorkspaceAndUser($workspace, $user); $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles()); $this->tokenStorage->setToken($token); return new Response('success', 204); } catch (LastManagerDeleteException $e) { return new Response('cannot_delete_unique_manager', 200, array('XXX-Claroline-delete-last-manager')); } }
private function generateWorkspaceRestrictions(User $user) { $restrictions = []; if (!$user->hasRole('ROLE_ADMIN')) { $restrictions = $this->workspaceManager->getWorkspacesByUser($user); } return $restrictions; }