Esempio n. 1
0
 public function __construct(SecurityCheckerInterface $securityChecker, $title)
 {
     $this->securityChecker = $securityChecker;
     $rootNavigationItem = new NavigationItem($title);
     $section = new NavigationItem('');
     $media = new NavigationItem('navigation.media');
     $media->setIcon('image');
     if ($this->securityChecker->hasPermission('sulu.media.collections', 'view')) {
         $collections = new DataNavigationItem('navigation.media.collections', '/admin/api/collections?sortBy=title', $media);
         $collections->setId('collections-edit');
         $collections->setAction('media/collections/root');
         $collections->setInstanceName('collections');
         $collections->setDataNameKey('title');
         $collections->setDataResultKey('collections');
         $collections->setShowAddButton(true);
         $collections->setTitleTranslationKey('navigation.media.collections');
         $collections->setNoDataTranslationKey('');
         $collections->setAddButtonTranslationKey('navigation.media.collections.add');
         $collections->setSearchTranslationKey('navigation.media.collections.search');
     }
     if ($media->hasChildren()) {
         $section->addChild($media);
         $rootNavigationItem->addChild($section);
     }
     $this->setNavigation(new Navigation($rootNavigationItem));
 }
 /**
  * {@inheritdoc}
  */
 public function getNavigationItems(array $options = [])
 {
     $content = new ContentNavigationItem('content-navigation.contents.content');
     $content->setId('tab-content');
     $content->setAction('content');
     $content->setComponent('content/form@sulucontent');
     $seo = new ContentNavigationItem('content-navigation.contents.seo');
     $seo->setId('tab-seo');
     $seo->setAction('seo');
     $seo->setComponent('content/seo@sulucontent');
     $seo->setDisplay(['edit']);
     $excerpt = new ContentNavigationItem('content-navigation.contents.excerpt');
     $excerpt->setId('tab-excerpt');
     $excerpt->setAction('excerpt');
     $excerpt->setComponent('content/excerpt@sulucontent');
     $excerpt->setDisplay(['edit']);
     $settings = new ContentNavigationItem('content-navigation.contents.settings');
     $settings->setId('tab-settings');
     $settings->setAction('settings');
     $settings->setComponent('content/settings@sulucontent');
     $settings->setDisplay(['edit']);
     $navigation = [$content, $seo, $excerpt, $settings];
     $securityContext = 'sulu.webspaces.' . $options['webspace'];
     if ($this->enabledSecurity && $this->securityChecker->hasPermission($securityContext, 'security')) {
         $permissions = new ContentNavigationItem('Permissions');
         $permissions->setAction('permissions');
         $permissions->setDisplay(['edit']);
         $permissions->setComponent('permission-tab@sulusecurity');
         $permissions->setComponentOptions(['display' => 'form', 'type' => SecurityBehavior::class, 'securityContext' => $securityContext]);
         $navigation[] = $permissions;
     }
     return $navigation;
 }
Esempio n. 3
0
 public function __construct(WebspaceManagerInterface $webspaceManager, SecurityCheckerInterface $securityChecker, SessionManagerInterface $sessionManager, $title)
 {
     $this->webspaceManager = $webspaceManager;
     $this->securityChecker = $securityChecker;
     $this->sessionManager = $sessionManager;
     $rootNavigationItem = new NavigationItem($title);
     $section = new NavigationItem('navigation.webspaces');
     $rootNavigationItem->addChild($section);
     /** @var Webspace $webspace */
     foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) {
         if ($this->securityChecker->hasPermission(self::SECURITY_CONTEXT_PREFIX . $webspace->getKey(), 'view')) {
             $webspaceItem = new NavigationItem($webspace->getName());
             $webspaceItem->setIcon('bullseye');
             $indexUuid = $this->sessionManager->getContentNode($webspace->getKey())->getIdentifier();
             $indexPageItem = new NavigationItem('navigation.webspaces.index-page');
             $indexPageItem->setAction('content/contents/' . $webspace->getKey() . '/edit:' . $indexUuid . '/details');
             $webspaceItem->addChild($indexPageItem);
             $contentItem = new NavigationItem('navigation.webspaces.content');
             $contentItem->setAction('content/contents/' . $webspace->getKey());
             $webspaceItem->addChild($contentItem);
             $section->addChild($webspaceItem);
         }
     }
     $this->setNavigation(new Navigation($rootNavigationItem));
 }
Esempio n. 4
0
 public function __construct(WebspaceManagerInterface $webspaceManager, SecurityCheckerInterface $securityChecker, SessionManagerInterface $sessionManager, $title)
 {
     $this->webspaceManager = $webspaceManager;
     $this->securityChecker = $securityChecker;
     $this->sessionManager = $sessionManager;
     $rootNavigationItem = new NavigationItem($title);
     $section = new NavigationItem('navigation.webspaces');
     $section->setPosition(10);
     $rootNavigationItem->addChild($section);
     $position = 10;
     /** @var Webspace $webspace */
     foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) {
         if ($this->securityChecker->hasPermission(self::SECURITY_CONTEXT_PREFIX . $webspace->getKey(), PermissionTypes::VIEW)) {
             $webspaceItem = new NavigationItem($webspace->getName());
             $webspaceItem->setPosition($position++);
             $webspaceItem->setIcon('bullseye');
             $indexUuid = $this->sessionManager->getContentNode($webspace->getKey())->getIdentifier();
             $indexPageItem = new NavigationItem('navigation.webspaces.index-page');
             $indexPageItem->setPosition(10);
             $indexPageItem->setAction('content/contents/' . $webspace->getKey() . '/edit:' . $indexUuid . '/content');
             $webspaceItem->addChild($indexPageItem);
             $contentItem = new NavigationItem('navigation.webspaces.content');
             $contentItem->setPosition(20);
             $contentItem->setAction('content/contents/' . $webspace->getKey());
             $webspaceItem->addChild($contentItem);
             $webspaceSettingsItem = new NavigationItem('navigation.webspaces.settings');
             $webspaceSettingsItem->setPosition(30);
             $webspaceSettingsItem->setAction(sprintf('content/webspace/settings:%s/general', $webspace->getKey()));
             $webspaceItem->addChild($webspaceSettingsItem);
             $section->addChild($webspaceItem);
         }
     }
     $this->setNavigation(new Navigation($rootNavigationItem));
 }
Esempio n. 5
0
 public function __construct(SecurityCheckerInterface $securityChecker, $title)
 {
     $this->securityChecker = $securityChecker;
     $rootNavigationItem = new NavigationItem($title);
     $section = new NavigationItem('navigation.modules');
     $section->setPosition(20);
     $contacts = new NavigationItem('navigation.contacts');
     $contacts->setPosition(30);
     $contacts->setIcon('user');
     if ($this->securityChecker->hasPermission('sulu.contact.people', PermissionTypes::VIEW)) {
         $people = new NavigationItem('navigation.contacts.people');
         $people->setPosition(10);
         $people->setIcon('users');
         $people->setAction('contacts/contacts');
         $contacts->addChild($people);
     }
     if ($this->securityChecker->hasPermission('sulu.contact.organizations', PermissionTypes::VIEW)) {
         $companies = new NavigationItem('navigation.contacts.companies');
         $companies->setPosition(20);
         $companies->setIcon('building');
         $companies->setAction('contacts/accounts');
         $contacts->addChild($companies);
     }
     if ($contacts->hasChildren()) {
         $rootNavigationItem->addChild($section);
         $section->addChild($contacts);
     }
     $this->setNavigation(new Navigation($rootNavigationItem));
 }
Esempio n. 6
0
 public function postAction(Request $request)
 {
     try {
         $identifier = $request->get('id');
         $type = $request->get('type');
         $permissions = $request->get('permissions');
         $securityContext = $request->get('securityContext');
         if (!$identifier) {
             throw new MissingParameterException(static::class, 'id');
         }
         if (!$type) {
             throw new MissingParameterException(static::class, 'class');
         }
         if (!is_array($permissions)) {
             throw new RestException('The "permissions" must be passed as an array');
         }
         if ($securityContext) {
             $this->securityChecker->checkPermission($securityContext, PermissionTypes::SECURITY);
         }
         // transfer all permission strings to booleans
         foreach ($permissions as &$permission) {
             array_walk($permission, function (&$permissionLine) {
                 $permissionLine = $permissionLine === 'true' || $permissionLine === true;
             });
         }
         $this->accessControlManager->setPermissions($type, $identifier, $permissions);
         return $this->viewHandler->handle(View::create(['id' => $identifier, 'type' => $type, 'permissions' => $permissions]));
     } catch (RestException $exc) {
         return $this->viewHandler->handle(View::create($exc->toArray(), 400));
     }
 }
 public function setUp()
 {
     $this->accessControlManager = $this->prophesize(AccessControlManagerInterface::class);
     $this->securityChecker = $this->prophesize(SecurityCheckerInterface::class);
     $this->roleRepository = $this->prophesize(RoleRepositoryInterface::class);
     $this->viewHandler = $this->prophesize(ViewHandlerInterface::class);
     $this->permissionController = new PermissionController($this->accessControlManager->reveal(), $this->securityChecker->reveal(), $this->roleRepository->reveal(), $this->viewHandler->reveal());
 }
 /**
  * {@inheritdoc}
  */
 public function getNavigationItems(array $options = [])
 {
     if (!$this->securityChecker->hasPermission(WebsiteAdmin::getAnalyticsSecurityContext($options['webspace']), PermissionTypes::VIEW)) {
         return [];
     }
     $analytics = new ContentNavigationItem('content-navigation.webspace.analytics');
     $analytics->setId('tab-analytics');
     $analytics->setAction('analytics');
     $analytics->setPosition(20);
     $analytics->setComponent('webspace/settings/analytics@suluwebsite');
     return [$analytics];
 }
 /**
  * {@inheritdoc}
  */
 public function getNavigationItems(array $options = [])
 {
     if (!$this->securityChecker->hasPermission(CustomUrlAdmin::getCustomUrlSecurityContext($options['webspace']), PermissionTypes::VIEW)) {
         return [];
     }
     $contentNavigationItem = new ContentNavigationItem('content-navigation.webspace.custom-url');
     $contentNavigationItem->setId('tab-custom-urls');
     $contentNavigationItem->setAction('custom-urls');
     $contentNavigationItem->setPosition(40);
     $contentNavigationItem->setComponent('webspace/settings/custom-url@sulucustomurl');
     return [$contentNavigationItem];
 }
 public function getNavigationItems(array $options = [])
 {
     $navigation = [];
     if ($this->securityChecker->hasPermission('sulu.security.users', 'view')) {
         $permissions = new ContentNavigationItem('content-navigation.security.permissions');
         $permissions->setAction('permissions');
         $permissions->setComponent('users@sulusecurity');
         $permissions->setDisplay(['edit']);
         $navigation[] = $permissions;
     }
     return $navigation;
 }
 /**
  * {@inheritdoc}
  */
 public function getNavigationItems(array $options = [])
 {
     if (!$this->securityChecker->hasPermission(SnippetAdmin::getDefaultSnippetsSecurityContext($options['webspace']), PermissionTypes::VIEW) || !$this->defaultEnabled) {
         return [];
     }
     $snippets = new ContentNavigationItem('content-navigation.webspace.snippets');
     $snippets->setId('tab-snippets');
     $snippets->setAction('snippets');
     $snippets->setPosition(25);
     $snippets->setComponent('webspace/settings/snippets@sulusnippet');
     return [$snippets];
 }
Esempio n. 12
0
 /**
  * @param SecurityCheckerInterface $securityChecker
  * @param string                   $title
  */
 public function __construct(SecurityCheckerInterface $securityChecker, $title)
 {
     $this->securityChecker = $securityChecker;
     $rootNavigationItem = new NavigationItem($title);
     $section = new NavigationItem('');
     if ($this->securityChecker->hasPermission('sulu.event.events', 'view')) {
         $shop = new NavigationItem('sulu.navigation.events');
         $shop->setIcon('calendar');
         $shop->setAction('events');
         $section->addChild($shop);
         $rootNavigationItem->addChild($section);
     }
     $this->setNavigation(new Navigation($rootNavigationItem));
 }
Esempio n. 13
0
 public function __construct(SecurityCheckerInterface $securityChecker, $title)
 {
     $this->securityChecker = $securityChecker;
     $rootNavigationItem = new NavigationItem($title);
     $section = new NavigationItem('navigation.modules');
     $section->setPosition(20);
     if ($this->securityChecker->hasPermission('sulu.media.collections', PermissionTypes::VIEW)) {
         $media = new NavigationItem('navigation.media');
         $media->setPosition(20);
         $media->setIcon('image');
         $media->setAction('media/collections');
         $section->addChild($media);
         $rootNavigationItem->addChild($section);
     }
     $this->setNavigation(new Navigation($rootNavigationItem));
 }
Esempio n. 14
0
 /**
  * Checks if the action is allowed for the current user, and throws an Exception otherwise.
  *
  * @param FilterControllerEvent $event
  *
  * @throws AccessDeniedException
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $controllerDefinition = $event->getController();
     $controller = $controllerDefinition[0];
     if (!$controller instanceof SecuredControllerInterface && !$controller instanceof SecuredObjectControllerInterface) {
         return;
     }
     $request = $event->getRequest();
     // find appropriate permission type for request
     $permission = '';
     switch ($request->getMethod()) {
         case 'GET':
             $permission = PermissionTypes::VIEW;
             break;
         case 'POST':
             if ($controllerDefinition[1] == 'postAction') {
                 // means that the ClassResourceInterface has to be used
                 $permission = PermissionTypes::ADD;
             } else {
                 $permission = PermissionTypes::EDIT;
             }
             break;
         case 'PUT':
         case 'PATCH':
             $permission = PermissionTypes::EDIT;
             break;
         case 'DELETE':
             $permission = PermissionTypes::DELETE;
             break;
     }
     $securityContext = null;
     $locale = $controller->getLocale($request);
     $objectType = null;
     $objectId = null;
     if ($controller instanceof SecuredObjectControllerInterface) {
         $objectType = $controller->getSecuredClass();
         $objectId = $controller->getSecuredObjectId($request);
     }
     // check permission
     if ($controller instanceof SecuredControllerInterface) {
         $securityContext = $controller->getSecurityContext();
     }
     if ($securityContext !== null) {
         $this->securityChecker->checkPermission(new SecurityCondition($securityContext, $locale, $objectType, $objectId), $permission);
     }
 }
Esempio n. 15
0
 public function __construct(SecurityCheckerInterface $securityChecker, $title)
 {
     $this->securityChecker = $securityChecker;
     $rootNavigationItem = new NavigationItem($title);
     $section = new NavigationItem('');
     $settings = new NavigationItem('navigation.settings');
     $settings->setIcon('cog');
     if ($this->securityChecker->hasPermission('sulu.settings.categories', 'view')) {
         $categories = new NavigationItem('navigation.settings.categories', $settings);
         $categories->setAction('settings/categories');
     }
     if ($settings->hasChildren()) {
         $section->addChild($settings);
         $rootNavigationItem->addChild($section);
     }
     $this->setNavigation(new Navigation($rootNavigationItem));
 }
Esempio n. 16
0
 public function __construct(SecurityCheckerInterface $securityChecker, WebspaceManagerInterface $webspaceManager, $defaultEnabled, $title)
 {
     $this->securityChecker = $securityChecker;
     $this->webspaceManager = $webspaceManager;
     $this->defaultEnabled = $defaultEnabled;
     $rootNavigationItem = new NavigationItem($title);
     $section = new NavigationItem('navigation.modules');
     $section->setPosition(20);
     if ($this->securityChecker->hasPermission('sulu.global.snippets', 'view')) {
         $snippet = new NavigationItem('navigation.snippets');
         $snippet->setPosition(10);
         $snippet->setIcon('sticky-note-o');
         $snippet->setAction('snippet/snippets');
         $section->addChild($snippet);
         $rootNavigationItem->addChild($section);
     }
     $this->setNavigation(new Navigation($rootNavigationItem));
 }
 /**
  * {@inheritdoc}
  */
 public function getNavigationItems(array $options = [])
 {
     $content = new ContentNavigationItem('content-navigation.contents.content');
     $content->setId('tab-content');
     $content->setPosition(10);
     $content->setAction('content');
     $content->setComponent('content/form@sulucontent');
     $content->setDisplayConditions([new DisplayCondition('linked', DisplayCondition::OPERATOR_EQUAL, null), new DisplayCondition('shadowOn', DisplayCondition::OPERATOR_EQUAL, false)]);
     $seo = new ContentNavigationItem('content-navigation.contents.seo');
     $seo->setId('tab-seo');
     $seo->setPosition(20);
     $seo->setAction('seo');
     $seo->setComponent('content/seo@sulucontent');
     $seo->setDisplay(['edit']);
     $seo->setDisplayConditions([new DisplayCondition('url', DisplayCondition::OPERATOR_NOT_EQUAL, ''), new DisplayCondition('linked', DisplayCondition::OPERATOR_EQUAL, null), new DisplayCondition('shadowOn', DisplayCondition::OPERATOR_EQUAL, false)]);
     $excerpt = new ContentNavigationItem('content-navigation.contents.excerpt');
     $excerpt->setId('tab-excerpt');
     $excerpt->setPosition(30);
     $excerpt->setAction('excerpt');
     $excerpt->setComponent('content/excerpt@sulucontent');
     $excerpt->setDisplay(['edit']);
     $excerpt->setDisplayConditions([new DisplayCondition('url', DisplayCondition::OPERATOR_NOT_EQUAL, ''), new DisplayCondition('linked', DisplayCondition::OPERATOR_NOT_EQUAL, 'internal'), new DisplayCondition('shadowOn', DisplayCondition::OPERATOR_EQUAL, false)]);
     $settings = new ContentNavigationItem('content-navigation.contents.settings');
     $settings->setId('tab-settings');
     $settings->setPosition(40);
     $settings->setAction('settings');
     $settings->setComponent('content/settings@sulucontent');
     $settings->setDisplay(['edit']);
     $settings->setDisplayConditions([new DisplayCondition('url', DisplayCondition::OPERATOR_NOT_EQUAL, '')]);
     $navigation = [$content, $seo, $excerpt, $settings];
     $securityContext = 'sulu.webspaces.' . $options['webspace'];
     if ($this->enabledSecurity && $this->securityChecker->hasPermission($securityContext, PermissionTypes::SECURITY)) {
         $permissions = new ContentNavigationItem('content-navigation.contents.permissions');
         $permissions->setId('tab-permissions');
         $permissions->setAction('permissions');
         $permissions->setPosition(50);
         $permissions->setDisplay(['edit']);
         $permissions->setComponent('permission-tab@sulusecurity');
         $permissions->setComponentOptions(['display' => 'form', 'type' => SecurityBehavior::class, 'securityContext' => $securityContext]);
         $permissions->setDisplayConditions([new DisplayCondition('url', DisplayCondition::OPERATOR_NOT_EQUAL, '')]);
         $navigation[] = $permissions;
     }
     return $navigation;
 }
Esempio n. 18
0
 /**
  * Check the permissions for all webspaces.
  * Returns true if the user has live permission in all webspaces.
  *
  * @return bool
  */
 private function checkLivePermissionForAllWebspaces()
 {
     foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) {
         $context = ContentAdmin::SECURITY_CONTEXT_PREFIX . $webspace->getKey();
         if (!$this->securityChecker->hasPermission($context, PermissionTypes::LIVE)) {
             return false;
         }
     }
     return true;
 }
Esempio n. 19
0
 public function __construct(SecurityCheckerInterface $securityChecker, $title)
 {
     $this->securityChecker = $securityChecker;
     $rootNavigationItem = new NavigationItem($title);
     $section = new NavigationItem('');
     $sales = new NavigationItem('navigation.sales');
     $sales->setPosition(20);
     $sales->setIcon('shopping-cart');
     if ($this->securityChecker->hasPermission('sulu.sales_order.orders', 'view')) {
         $order = new NavigationItem('navigation.sales.order', $sales);
         $order->setAction('sales/orders');
         $order->setPosition(10);
     }
     if ($sales->hasChildren()) {
         $section->addChild($sales);
         $rootNavigationItem->addChild($section);
     }
     $this->setNavigation(new Navigation($rootNavigationItem));
 }
Esempio n. 20
0
 public function __construct(SecurityCheckerInterface $securityChecker, $title)
 {
     $this->securityChecker = $securityChecker;
     $rootNavigationItem = new NavigationItem($title);
     $section = new NavigationItem('navigation.webspaces');
     $global = new NavigationItem('navigation.global-content');
     $global->setIcon('globe');
     $section->addChild($global);
     if ($this->securityChecker->hasPermission('sulu.global.snippets', 'view')) {
         $snippet = new NavigationItem('navigation.snippets');
         $snippet->setIcon('bullseye');
         $snippet->setAction('snippet/snippets');
         $global->addChild($snippet);
     }
     if ($global->hasChildren()) {
         $rootNavigationItem->addChild($section);
     }
     $this->setNavigation(new Navigation($rootNavigationItem));
 }
Esempio n. 21
0
 public function __construct(SecurityCheckerInterface $securityChecker, $title)
 {
     $this->securityChecker = $securityChecker;
     $rootNavigationItem = new NavigationItem($title);
     $section = new NavigationItem('navigation.modules');
     $section->setPosition(20);
     $settings = new NavigationItem('navigation.settings');
     $settings->setPosition(40);
     $settings->setIcon('gear');
     if ($this->securityChecker->hasPermission('sulu.security.roles', PermissionTypes::VIEW)) {
         $roles = new NavigationItem('security.roles.title', $settings);
         $roles->setPosition(10);
         $roles->setAction('settings/roles');
         $roles->setIcon('gear');
     }
     if ($settings->hasChildren()) {
         $section->addChild($settings);
         $rootNavigationItem->addChild($section);
     }
     $this->setNavigation(new Navigation($rootNavigationItem));
 }
Esempio n. 22
0
 /**
  * @param SecurityCheckerInterface $securityChecker
  * @param TokenStorageInterface $tokenStorage
  * @param RepositoryInterface $repository
  * @param Router $router
  * @param string $title
  */
 public function __construct(SecurityCheckerInterface $securityChecker, TokenStorageInterface $tokenStorage, RepositoryInterface $repository, Router $router, $title)
 {
     $rootNavigationItem = new NavigationItem($title);
     $section = new NavigationItem('');
     $files = new NavigationItem('symcloud.file');
     $files->setIcon('folder-open');
     if ($securityChecker->hasPermission('symcloud.files', 'view') && $tokenStorage->getToken() !== null) {
         $session = $repository->loginByHash($tokenStorage->getToken()->getUser(), 'HEAD');
         $references = $session->getReferences();
         foreach ($references as $reference) {
             $referenceItem = new DataNavigationItem($reference->getName(), $router->generate('get_directory', array('reference' => $reference->getHash(), 'name-as-key' => 'true', 'only-directories' => 'true')));
             $referenceItem->setDataResultKey('children');
             $referenceItem->setAction('symcloud/path:' . $reference->getHash());
             $referenceItem->setShowAddButton(false);
             $files->addChild($referenceItem);
         }
     }
     if ($files->hasChildren()) {
         $rootNavigationItem->addChild($section);
         $section->addChild($files);
     }
     $this->setNavigation(new Navigation($rootNavigationItem));
 }
Esempio n. 23
0
 public function __construct(WebspaceManagerInterface $webspaceManager, SecurityCheckerInterface $securityChecker, $title)
 {
     $this->webspaceManager = $webspaceManager;
     $this->securityChecker = $securityChecker;
     $rootNavigationItem = new NavigationItem($title);
     $section = new NavigationItem('navigation.webspaces');
     $rootNavigationItem->addChild($section);
     /** @var Webspace $webspace */
     foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) {
         if ($this->securityChecker->hasPermission($this->securityContextPrefix . $webspace->getKey(), 'view')) {
             $webspaceItem = new NavigationItem($webspace->getName());
             $webspaceItem->setIcon('bullseye');
             $indexPageItem = new NavigationItem('navigation.webspaces.index-page');
             $indexPageItem->setAction('content/contents/' . $webspace->getKey() . '/edit:index/details');
             $webspaceItem->addChild($indexPageItem);
             $contentItem = new NavigationItem('navigation.webspaces.content');
             $contentItem->setAction('content/contents/' . $webspace->getKey());
             $webspaceItem->addChild($contentItem);
             $section->addChild($webspaceItem);
         }
     }
     $this->setNavigation(new Navigation($rootNavigationItem));
 }
Esempio n. 24
0
 /**
  * @return array
  */
 private function getAllowedIndexes()
 {
     $allowedIndexNames = [];
     $indexNames = $this->searchManager->getIndexNames();
     foreach ($indexNames as $indexName) {
         $indexConfiguration = $this->indexConfigurationProvider->getIndexConfiguration($indexName);
         if (!$indexConfiguration) {
             $allowedIndexNames[] = $indexName;
             continue;
         }
         if ($this->securityChecker->hasPermission($indexConfiguration->getSecurityContext(), 'view')) {
             $allowedIndexNames[] = $indexName;
         }
     }
     return $allowedIndexNames;
 }
Esempio n. 25
0
 /**
  * @return array
  */
 private function getAllowedIndexes()
 {
     $allowedIndexNames = [];
     $indexNames = $this->searchManager->getIndexNames();
     foreach ($indexNames as $indexName) {
         $indexConfiguration = $this->indexConfigurationProvider->getIndexConfiguration($indexName);
         if (!$indexConfiguration) {
             $allowedIndexNames[] = $indexName;
             continue;
         }
         $contexts = $indexConfiguration->getContexts();
         if ($this->securityChecker->hasPermission($indexConfiguration->getSecurityContext(), PermissionTypes::VIEW) && (empty($contexts) || array_search('admin', $contexts) !== false)) {
             $allowedIndexNames[] = $indexName;
         }
     }
     return $allowedIndexNames;
 }
Esempio n. 26
0
 public function testIsGrantedWithoutToken()
 {
     $this->tokenStorage->getToken()->willReturn(null);
     $this->authorizationChecker->isGranted(Argument::any(), Argument::any())->willReturn(false);
     $this->assertTrue($this->securityChecker->checkPermission('sulu.media.collection', 'view'));
 }
Esempio n. 27
0
 /**
  * {@inheritdoc}
  */
 public function delete($id, $checkSecurity = false)
 {
     $mediaEntity = $this->getEntityById($id);
     if ($checkSecurity) {
         $this->securityChecker->checkPermission(new SecurityCondition('sulu.media.collections', null, Collection::class, $mediaEntity->getCollection()->getId()), 'delete');
     }
     /** @var File $file */
     foreach ($mediaEntity->getFiles() as $file) {
         /** @var FileVersion $fileVersion */
         foreach ($file->getFileVersions() as $fileVersion) {
             $this->formatManager->purge($mediaEntity->getId(), $fileVersion->getName(), $fileVersion->getStorageOptions());
             $this->storage->remove($fileVersion->getStorageOptions());
         }
     }
     $this->em->remove($mediaEntity);
     $this->em->flush();
 }
Esempio n. 28
0
 public function testDelete()
 {
     $collection = $this->prophesize(Collection::class);
     $collection->getId()->willReturn(2);
     $file = $this->prophesize(File::class);
     $fileVersion = $this->prophesize(FileVersion::class);
     $file->getFileVersions()->willReturn([$fileVersion->reveal()]);
     $fileVersion->getId()->willReturn(1);
     $fileVersion->getName()->willReturn('test');
     $fileVersion->getStorageOptions()->willReturn(json_encode(['segment' => '01', 'fileName' => 'test.jpg']));
     $media = $this->prophesize(Media::class);
     $media->getCollection()->willReturn($collection);
     $media->getFiles()->willReturn([$file->reveal()]);
     $media->getId()->willReturn(1);
     $this->formatManager->purge(1, 'test', json_encode(['segment' => '01', 'fileName' => 'test.jpg']))->shouldBeCalled();
     $this->mediaRepository->findMediaById(1)->willReturn($media);
     $this->securityChecker->checkPermission(new SecurityCondition('sulu.media.collections', null, Collection::class, 2), 'delete')->shouldBeCalled();
     $this->storage->remove(json_encode(['segment' => '01', 'fileName' => 'test.jpg']))->shouldBeCalled();
     $this->mediaManager->delete(1, true);
 }