@DI\Observe("open_tool_workspace_users")

@param DisplayToolEvent $event
@throws \Claroline\CoreBundle\Listener\NoHttpRequestException
514257
public function onDisplay(DisplayToolEvent $event)
    {
        if (!$this->request) {
            throw new NoHttpRequestException();
        }

        $subRequest = $this->request->duplicate(
            array(),
            null,
            array(
                '_controller' => 'ClarolineCoreBundle:Tool\Roles:usersList',
                'workspace' => $event->getWorkspace(),
                'page' => 1,
                'search' => '',
                'max' => 50,
                'order' => 'id'
            )
        );
        $response = $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
        $event->setContent($response->getContent());
    }
933469
public function onDisplayWorkspace(DisplayToolEvent $event)
    {
        $orderedTabs = [];
        $workspace = $event->getWorkspace();

        $tabs = $this->finder->search(HomeTab::class, [
            'filters' => ['workspace' => $workspace->getUuid()],
        ]);

        // but why ? finder should never give you an empty row
        $tabs = array_filter($tabs['data'], function ($data) {
            return $data !== [];
        });

        foreach ($tabs as $tab) {
            $orderedTabs[$tab['position']] = $tab;
        }
        ksort($orderedTabs);

        $content = $this->templating->render(
            'ClarolineCoreBundle:tool:home.html.twig', [
                'workspace' => $workspace,
                'editable' => $this->authorization->isGranted(['home', 'edit'], $workspace),
                'context' => [
                    'type' => Widget::CONTEXT_WORKSPACE,
                    'data' => $this->serializer->serialize($workspace),
                ],
                'tabs' => array_values($orderedTabs),
            ]
        );

        $event->setContent($content);
        $event->stopPropagation();
    }
1268101
public function onDisplayWorkspaceHome(DisplayToolEvent $event)
    {
        $params = array(
            '_controller' => 'ClarolineCoreBundle:Workspace:displayWorkspaceHomeTab',
            'workspace' => $event->getWorkspace()->getId(),
            'tabId' => -1
        );
        $subRequest = $this->container->get('request')->duplicate(array(), null, $params);
        $response = $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);

        $event->setContent($response->getContent());
    }
1078171
public function onOpenDesktopTool(DisplayToolEvent $event)
    {
        $params = array();
        $params['_controller'] = 'ClarolineMessageBundle:Message:listReceived';
        $params['page'] = 1;
        $params['search'] = '';
        $subRequest = $this->request->duplicate(array(), null, $params);
        $response = $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
        $event->setContent($response->getContent());
        $event->stopPropagation();
    }
513779
public function onDisplayTool(OpenAdministrationToolEvent $event)
    {
        $content = $this->templating->render(
            'ClarolineCoreBundle:administration:users.html.twig', [
                // todo : put it in the async load of form
                'parameters' => $this->parametersSerializer->serialize(),
                'profile' => $this->profileSerializer->serialize(),
                'platformRoles' => $this->finder->search('Claroline\CoreBundle\Entity\Role', [
                    'filters' => ['type' => Role::PLATFORM_ROLE],
                ]),
            ]
        );

        $event->setResponse(new Response($content));
        $event->stopPropagation();
    }
607965
public function onDisplayTool(OpenAdministrationToolEvent $event)
    {
        $content = $this->templating->render(
            'ClarolineCoreBundle:administration:parameters.html.twig', [
                'context' => [
                    'type' => Tool::ADMINISTRATION,
                ],
                'parameters' => $this->serializer->serialize(),
                'availableLocales' => array_keys($this->localeManager->getImplementedLocales()),
            ]
        );

        $event->setResponse(new Response($content));
        $event->stopPropagation();
    }
607001
public function onDisplayTool(OpenAdministrationToolEvent $event)
    {
        $content = $this->templating->render(
            'ClarolineCoreBundle:administration:technical.html.twig', [
                'context' => [
                    'type' => Tool::ADMINISTRATION,
                ],
                'parameters' => $this->serializer->serialize(),
                'adminTools' => array_map(function (AdminTool $tool) {
                    return $tool->getName();
                }, $this->om->getRepository(AdminTool::class)->findAll()),
            ]
        );

        $event->setResponse(new Response($content));
        $event->stopPropagation();
    }
1012761
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        if (!$request) {
            return;
        }

        if (!$request->hasSession()) {
            return;
        }

        if($request->isXmlHttpRequest()){
            return;
        }

        $adminCode = $request->get('_sonata_admin');

        if (!is_null($adminCode)) {
            $this->admin = $this->adminPool->getAdminByAdminCode($adminCode);
            $this->admin->setRequest($request);
            if (!$this->admin) {
                throw new \RuntimeException(sprintf(
                    'Unable to find the admin class related to the current controller (%s)',
                    get_class($this)
                ));
            }

            foreach ($this->admin->getExtensions() as $extension) {
                $this->setTrackedAction($extension);
            }
            $this->setTrackedAction($this->admin);
        }
    }
1297089
public function onPrepareWorkspaceInitializeSSHAgent(WorkspaceEvent $event, $eventName, EventDispatcherInterface $eventDispatcher)
    {
        $this->host = $event->getHost();

        $connection = $this->ensureConnection($this->host);

        $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::NOTICE, 'Initializing SSH agent...', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_IN_PROGRESS)));

        $result = $connection->executeCommand('eval $(ssh-agent)');
        if ($result->isSuccessful()) {
            $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::NOTICE, 'Initialized SSH agent. {output}', $eventName, $this, array('output' => trim($result->getOutput()), 'event.task.action' => TaskInterface::ACTION_COMPLETED, 'output.resetLine' => true)));

            foreach ($this->keys as $key) {
                $this->addKeyToSSHAgent($event->getWorkspace(), $connection, $key, $eventName, $eventDispatcher);
            }
        } else {
            $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::WARNING, 'Failed initializing SSH agent.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_FAILED, 'output.resetLine' => true)));
        }
    }
129987
public function openWorkspaceToolConfig(Workspace $workspace, Tool $tool)
    {
        $this->checkAccess($workspace);
        $event = $this->eventDispatcher->dispatch(
            strtolower('configure_workspace_tool_' . $tool->getName()),
            'ConfigureWorkspaceTool',
            array($tool, $workspace)
        );

        return new Response($event->getContent());
    }
689898
public function onDisplayWorkspaceAgenda(DisplayToolEvent $event)
    {
        $workspace = $event->getWorkspace();
        $content = $this->templating->render('ClarolineOpenBadgeBundle::workspace.html.twig', ['workspace' => $workspace]);

        $event->setContent($content);
    }
448804
public function onKernelRequest(GetResponseEvent $event): void
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();
        $route = $request->attributes->get('_route');

        if ($route !== null && !$request->attributes->get('requires_license')) {
            return;
        }

        if ($request->get('lic') === 'active' || $this->kernel->getEnvironment() !== 'prod') {
            return;
        }

        // Checking for whitelisted users
        try {
            /** @noinspection NullPointerExceptionInspection */
            $user = $this->tokenStorage->getToken()->getUser();
            if ($user instanceof TenantInterface) {
                if ($user->isWhiteListed()) {
                    return;
                }

                $today = \date('Y-m-d');
                $whitelist = $this->kernel->getContainer()->getParameter('license_whitelist');
                /** @noinspection ForeachSourceInspection */
                foreach ($whitelist as $allowed) {
                    if ($today <= $allowed['valid_till'] && $allowed['client_key'] === $user->getClientKey()) {
                        return;
                    }
                }
            }
        } catch (\Throwable $e) {
            // Do nothing
        }

        $url = $this->router->generate('atlassian_connect_unlicensed', $request->query->all());
        $response = new RedirectResponse($url);
        $event->setResponse($response);
    }
1361575
public function onDisplayTool(OpenAdministrationToolEvent $event)
    {
        $iconSets = $this->iconSetManager->listIconSetsByType(IconSetTypeEnum::RESOURCE_ICON_SET);

        // TODO : do it front side
        $iconSetChoices = [];
        foreach ($iconSets as $set) {
            $iconSetChoices[$set->getName()] = $set->getName();
        }

        $content = $this->templating->render(
            'ClarolineCoreBundle:administration:appearance.html.twig', [
                'context' => [
                    'type' => Tool::ADMINISTRATION,
                ],
                'parameters' => $this->serializer->serialize(),
                'iconSetChoices' => $iconSetChoices,
            ]
        );

        $event->setResponse(new Response($content));
        $event->stopPropagation();
    }
1047499
public function onKernelRequest(GetResponseEvent $event): void
    {
        $request = $event->getRequest();

        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType() || !$this->isAdminSiteAccess($request)) {
            return;
        }

        $additionalTranslations = $this->configResolver->getParameter('user_preferences.additional_translations');
        $preferableLocales = $this->userLanguagePreferenceProvider->getPreferredLocales($request);
        $locale = null;

        foreach ($preferableLocales as $preferableLocale) {
            if (\in_array($preferableLocale, $this->availableTranslations, true)
                || \in_array($preferableLocale, $additionalTranslations, true)
            ) {
                $locale = $preferableLocale;
                break;
            }
        }
        $locale = $locale ?? reset($preferableLocales);
        $request->setLocale($locale);
        $request->attributes->set('_locale', $locale);
        // Set of the current locale on the translator service is needed because RequestLocaleListener has lower
        // priority than LocaleListener and messages are not translated on login, forgot and reset password pages.
        $this->translator->setLocale($locale);
    }
701943
public function onWorkspacesDelete(GenericDatasEvent $event)
    {
        $workspaces = $event->getDatas();
        $ids = array();

        foreach ($workspaces as $workspace) {
            $ids[] = $workspace->getId();
        }
        $this->tagManager->removeTaggedObjectsByClassAndIds(
            'Claroline\CoreBundle\Entity\Workspace\Workspace',
            $ids
        );
    }
820003
public function onWorkspaceToolOpen(DisplayToolEvent $event)
    {
        $workspace = $event->getWorkspace();

        if (!$this->authorization->isGranted(['claroline_planned_notification_tool', 'OPEN'], $workspace)) {
            throw new AccessDeniedException();
        }
        $content = $this->templating->render(
            'ClarolinePlannedNotificationBundle:planned_notification_tool:tool_open.html.twig', [
                'workspace' => $workspace,
                'canEdit' => $this->authorization->isGranted(['claroline_planned_notification_tool', 'EDIT'], $workspace),
            ]
        );
        $event->setContent($content);
        // /    $event->stopPropagation();
    }
602449
public function onWorkspaceUsersConfigureMessage(ContactAdditionalActionEvent $event)
    {
        $user = $event->getUser();

            $menu = $event->getMenu();
            $messageMenuLink = $menu->addChild(
                $this->translator->trans('messages', array(), 'platform'),
                array('route' => 'claro_message_show')
            )
            ->setExtra('icon', 'fa fa-envelope')
            ->setExtra('qstring', 'userIds[]=' . $user->getId())
            ->setExtra('title', $this->translator->trans('message', array(), 'platform'));
    }