Пример #1
0
 public function testUseSecretKey()
 {
     $this->_model->setNoSecret(true);
     $this->assertFalse($this->_model->useSecretKey());
     $this->_model->setNoSecret(false);
     $this->assertTrue($this->_model->useSecretKey());
 }
Пример #2
0
 /**
  * Declare headers and content file in response for file download
  *
  * @param string $fileName
  * @param string|array $content set to null to avoid starting output, $contentLength should be set explicitly in
  * that case
  * @param string $baseDir
  * @param string $contentType
  * @param int $contentLength    explicit content length, if strlen($content) isn't applicable
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function create($fileName, $content, $baseDir = DirectoryList::ROOT, $contentType = 'application/octet-stream', $contentLength = null)
 {
     if ($this->_auth->getAuthStorage()->isFirstPageAfterLogin()) {
         return $this->_redirect($this->_backendUrl->getStartupPageUrl());
     }
     return parent::create($fileName, $content, $baseDir, $contentType, $contentLength);
 }
Пример #3
0
 /**
  * Create url for passed item using passed url model
  *
  * @param \Magento\Framework\Object $item
  * @return string
  */
 public function getUrl($item)
 {
     if (!empty($this->_path)) {
         $params = $this->_prepareParameters($item);
         return $this->_urlModel->getUrl($this->_path, $params);
     }
     return '';
 }
Пример #4
0
 public function getElementHtml()
 {
     $buttonBlock = $this->getForm()->getParent()->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Button');
     $params = ['website' => $buttonBlock->getRequest()->getParam('website')];
     $url = $this->_backendUrl->getUrl("*/*/exportmatrixrate", $params);
     $data = ['label' => __('Export CSV'), 'onclick' => "setLocation('" . $url . "conditionName/' + \$('carriers_matrixrate_condition_name').value + '/matrixrate.csv' )", 'class' => ''];
     $html = $buttonBlock->setData($data)->toHtml();
     return $html;
 }
Пример #5
0
 /**
  * @covers \Magento\Cms\Model\Wysiwyg\Config::getConfig
  * @param array $data
  * @param boolean $isAuthorizationAllowed
  * @param array $expectedResults
  *
  * @dataProvider getConfigDataProvider
  */
 public function testGetConfig($data, $isAuthorizationAllowed, $expectedResults)
 {
     $wysiwygPluginSettings = ['wysiwygPluginSettings' => 'wysiwyg is here'];
     $pluginSettings = ['pluginSettings' => 'plugins are here'];
     $this->backendUrlMock->expects($this->atLeastOnce())->method('getUrl')->withConsecutive(['cms/wysiwyg/directive'], ['cms/wysiwyg_images/index']);
     $this->assetRepoMock->expects($this->atLeastOnce())->method('getUrl')->withConsecutive(['mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css'], ['mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css']);
     $this->authorizationMock->expects($this->atLeastOnce())->method('isAllowed')->with('Magento_Cms::media_gallery')->willReturn($isAuthorizationAllowed);
     $this->variableConfigMock->expects($this->any())->method('getWysiwygPluginSettings')->willReturn($wysiwygPluginSettings);
     $this->widgetConfigMock->expects($this->any())->method('getPluginSettings')->willReturn($pluginSettings);
     $config = $this->wysiwygConfig->getConfig($data);
     $this->assertInstanceOf('Magento\\Framework\\Object', $config);
     $this->assertEquals($expectedResults[0], $config->getData('someData'));
     $this->assertEquals($expectedResults[1], $config->getData('wysiwygPluginSettings'));
     $this->assertEquals($expectedResults[2], $config->getData('pluginSettings'));
 }
 /**
  * Force admin to change password
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     if (!$this->observerConfig->isPasswordChangeForced()) {
         return;
     }
     if (!$this->authSession->isLoggedIn()) {
         return;
     }
     $actionList = ['adminhtml_system_account_index', 'adminhtml_system_account_save', 'adminhtml_auth_logout'];
     /** @var \Magento\Framework\App\Action\Action $controller */
     $controller = $observer->getEvent()->getControllerAction();
     /** @var \Magento\Framework\App\RequestInterface $request */
     $request = $observer->getEvent()->getRequest();
     if ($this->authSession->getPciAdminUserIsPasswordExpired()) {
         if (!in_array($request->getFullActionName(), $actionList)) {
             if ($this->authorization->isAllowed('Magento_Backend::myaccount')) {
                 $controller->getResponse()->setRedirect($this->url->getUrl('adminhtml/system_account/'));
                 $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
                 $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_POST_DISPATCH, true);
             } else {
                 /*
                  * if admin password is expired and access to 'My Account' page is denied
                  * than we need to do force logout with error message
                  */
                 $this->authSession->clearStorage();
                 $this->session->clearStorage();
                 $this->messageManager->addErrorMessage(__('Your password has expired; please contact your administrator.'));
                 $controller->getRequest()->setDispatched(false);
             }
         }
     }
 }
Пример #7
0
 /**
  * Update all attribute-dependant index
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return \Magento\CatalogSearch\Model\Fulltext\Observer
  */
 public function eavAttributeChange(\Magento\Framework\Event\Observer $observer)
 {
     $attribute = $observer->getEvent()->getAttribute();
     /* @var $attribute \Magento\Eav\Model\Entity\Attribute */
     $entityType = $this->_eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY);
     /* @var $entityType \Magento\Eav\Model\Entity\Type */
     if ($attribute->getEntityTypeId() != $entityType->getId()) {
         return $this;
     }
     $delete = $observer->getEventName() == 'eav_entity_attribute_delete_after';
     if (!$delete && !$attribute->dataHasChangedFor('is_searchable')) {
         return $this;
     }
     $showNotice = false;
     if ($delete) {
         if ($attribute->getIsSearchable()) {
             $showNotice = true;
         }
     } elseif ($attribute->dataHasChangedFor('is_searchable')) {
         $showNotice = true;
     }
     if ($showNotice) {
         $url = $this->_backendUrl->getUrl('adminhtml/system_cache');
         $this->messageManager->addNotice(__('Attribute setting change related with Search Index. Please run <a href="%1">Rebuild Search Index</a> process.', $url));
     }
     return $this;
 }
Пример #8
0
 /**
  * Return Widgets Insertion Plugin Window URL
  *
  * @param \Magento\Framework\DataObject $config Editor element config
  * @return string
  */
 public function getWidgetWindowUrl($config)
 {
     $params = [];
     $skipped = is_array($config->getData('skip_widgets')) ? $config->getData('skip_widgets') : [];
     if ($config->hasData('widget_filters')) {
         $all = $this->_widgetFactory->create()->getWidgets();
         $filtered = $this->_widgetFactory->create()->getWidgets($config->getData('widget_filters'));
         foreach ($all as $code => $widget) {
             if (!isset($filtered[$code])) {
                 $skipped[] = $widget['@']['type'];
             }
         }
     }
     if (count($skipped) > 0) {
         $params['skip_widgets'] = $this->encodeWidgetsToQuery($skipped);
     }
     return $this->_backendUrl->getUrl('adminhtml/widget/index', $params);
 }
 /**
  * Validate Secret Key
  *
  * @return bool
  */
 protected function _validateSecretKey()
 {
     if (is_array($this->_publicActions) && in_array($this->getRequest()->getActionName(), $this->_publicActions)) {
         return true;
     }
     $secretKey = $this->getRequest()->getParam(\Magento\Backend\Model\UrlInterface::SECRET_KEY_PARAM_NAME, null);
     if (!$secretKey || $secretKey != $this->_backendUrl->getSecretKey()) {
         return false;
     }
     return true;
 }
 /**
  * Check to see if there are any native tax rules created that may affect AvaTax
  *
  * @return array
  */
 public function checkNativeTaxRules()
 {
     $errors = [];
     if ($this->avaTaxConfig->isModuleEnabled() && $this->avaTaxConfig->getTaxMode($this->storeManager->getDefaultStoreView()) != Config::TAX_MODE_NO_ESTIMATE_OR_SUBMIT && !$this->avaTaxConfig->isNativeTaxRulesIgnored()) {
         $taxRules = $this->taxRuleRepository->getList($this->searchCriteriaBuilder->create());
         if (count($taxRules->getItems())) {
             $errors[] = __('You have %1 native Magento Tax Rule(s) configured. ' . 'Please <a href="%2">review the tax rule(s)</a> and delete any that you do not specifically want enabled. ' . 'You should only have rules setup if you want to use them as backup rules in case of AvaTax ' . 'errors (see <a href="#row_tax_avatax_error_handling_header">Error Action setting</a>) ' . 'or if you need to support VAT tax. ' . '<a href="%3">Ignore this notification</a>.', count($taxRules->getItems()), $this->backendUrl->getUrl('tax/rule'), $this->backendUrl->getUrl('avatax/tax/ignoreTaxRuleNotification'));
         }
     }
     return $errors;
 }
Пример #11
0
 /**
  * Process of configuring of current auth storage when login was performed
  *
  * @return \Magento\Backend\Model\Auth\Session
  */
 public function processLogin()
 {
     if ($this->getUser()) {
         $this->regenerateId();
         if ($this->_backendUrl->useSecretKey()) {
             $this->_backendUrl->renewSecretUrls();
         }
         $this->setIsFirstPageAfterLogin(true);
         $this->setAcl($this->_aclBuilder->getAcl());
         $this->setUpdatedAt(time());
     }
     return $this;
 }
Пример #12
0
 /**
  * Retrieve the category product sorter load URL.
  *
  * @param Category $category Category.
  *
  * @return string
  */
 private function getProductSorterLoadUrl(Category $category)
 {
     $storeId = $category->getStoreId();
     if ($storeId === 0) {
         $defaultStoreId = $this->storeManager->getDefaultStoreView()->getId();
         $storeId = current(array_filter($category->getStoreIds()));
         if (in_array($defaultStoreId, $category->getStoreIds())) {
             $storeId = $defaultStoreId;
         }
     }
     $urlParams = ['ajax' => true, 'store' => $storeId];
     return $this->urlBuilder->getUrl('virtualcategory/category_virtual/preview', $urlParams);
 }
Пример #13
0
 /**
  * Checks, whether Magento requires redirection after successful admin login, and redirects user, if needed
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return bool
  */
 protected function _redirectIfNeededAfterLogin(\Magento\Framework\App\RequestInterface $request)
 {
     $requestUri = null;
     // Checks, whether secret key is required for admin access or request uri is explicitly set
     if ($this->_url->useSecretKey()) {
         $requestUri = $this->_url->getUrl('*/*/*', ['_current' => true]);
     } elseif ($request) {
         $requestUri = $request->getRequestUri();
     }
     if (!$requestUri) {
         return false;
     }
     $this->_response->setRedirect($requestUri);
     $this->_actionFlag->set('', \Magento\Framework\App\ActionInterface::FLAG_NO_DISPATCH, true);
     return true;
 }
Пример #14
0
 /**
  * Check whether the latest password is expired
  * Side-effect can be when passwords were changed with different lifetime configuration settings
  *
  * @param array $latestPassword
  * @return void
  */
 private function _checkExpiredPassword($latestPassword)
 {
     if ($latestPassword && $this->observerConfig->_isLatestPasswordExpired($latestPassword)) {
         if ($this->observerConfig->isPasswordChangeForced()) {
             $message = __('It\'s time to change your password.');
         } else {
             $myAccountUrl = $this->url->getUrl('adminhtml/system_account/');
             $message = __('It\'s time to <a href="%1">change your password</a>.', $myAccountUrl);
         }
         $this->messageManager->addNoticeMessage($message);
         $message = $this->messageManager->getMessages()->getLastAddedMessage();
         if ($message) {
             $message->setIdentifier('magento_user_password_expired')->setIsSticky(true);
             $this->authSession->setPciAdminUserIsPasswordExpired(true);
         }
     }
 }
Пример #15
0
 /**
  * Iterate over all config tabs, extract sections and its subsections
  * @param string $itemsSeparator
  * @param string $itemPrefix
  * @return array
  */
 public function getConfigSectionsArray($itemsSeparator = ' ', $itemPrefix = '')
 {
     $sections = array();
     foreach ($this->_configStructure->getTabs() as $tab) {
         /** @var $tab \Magento\Config\Model\Config\Structure\Element\Tab */
         foreach ($tab->getChildren() as $section) {
             /** @var $section \Magento\Config\Model\Config\Structure\Element\Section */
             // We need the label & url again for the sub sections
             $sectionLabel = $itemPrefix . $tab->getLabel() . $itemsSeparator . $section->getLabel();
             $sectionUrl = $this->_url->getUrl('adminhtml/system_config/edit', array('section' => $section->getId()));
             // First add global section to the launcher items...
             $sections[] = ['label' => $sectionLabel, 'value' => $sectionUrl];
             foreach ($section->getChildren() as $subSection) {
                 /** @var $subSection \Magento\Config\Model\Config\Structure\Element\Section */
                 // ...then add all sub sections
                 $sections[] = ['label' => $sectionLabel . $itemsSeparator . $subSection->getLabel(), 'value' => $sectionUrl . '#' . $section->getId() . '_' . $subSection->getId() . '-link'];
             }
         }
     }
     return $sections;
 }
 /**
  * Return Wysiwyg config as \Magento\Framework\DataObject
  *
  * Config options description:
  *
  * enabled:                 Enabled Visual Editor or not
  * hidden:                  Show Visual Editor on page load or not
  * use_container:           Wrap Editor contents into div or not
  * no_display:              Hide Editor container or not (related to use_container)
  * translator:              Helper to translate phrases in lib
  * files_browser_*:         Files Browser (media, images) settings
  * encode_directives:       Encode template directives with JS or not
  *
  * @param array|\Magento\Framework\DataObject $data Object constructor params to override default config values
  * @return \Magento\Framework\DataObject
  */
 public function getConfig($data = [])
 {
     $config = new \Magento\Framework\DataObject();
     $config->setData(['enabled' => $this->isEnabled(), 'hidden' => $this->isHidden(), 'use_container' => false, 'add_variables' => true, 'add_widgets' => true, 'no_display' => false, 'encode_directives' => true, 'baseStaticUrl' => $this->_assetRepo->getStaticViewFileContext()->getBaseUrl(), 'baseStaticDefaultUrl' => str_replace('index.php/', '', $this->_backendUrl->getBaseUrl()) . $this->filesystem->getUri(DirectoryList::STATIC_VIEW) . '/', 'directives_url' => $this->_backendUrl->getUrl('cms/wysiwyg/directive'), 'popup_css' => $this->_assetRepo->getUrl('mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css'), 'content_css' => $this->_assetRepo->getUrl('mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css'), 'width' => '100%', 'height' => '500px', 'plugins' => []]);
     $config->setData('directives_url_quoted', preg_quote($config->getData('directives_url')));
     if ($this->_authorization->isAllowed('Magento_Cms::media_gallery')) {
         $config->addData(['add_images' => true, 'files_browser_window_url' => $this->_backendUrl->getUrl('cms/wysiwyg_images/index'), 'files_browser_window_width' => $this->_windowSize['width'], 'files_browser_window_height' => $this->_windowSize['height']]);
     }
     if (is_array($data)) {
         $config->addData($data);
     }
     if ($config->getData('add_variables')) {
         $settings = $this->_variableConfig->getWysiwygPluginSettings($config);
         $config->addData($settings);
     }
     if ($config->getData('add_widgets')) {
         $settings = $this->_widgetConfig->getPluginSettings($config);
         $config->addData($settings);
     }
     return $config;
 }
Пример #17
0
 /**
  * Return files
  *
  * @param string $path Parent directory path
  * @param string $type Type of storage, e.g. image, media etc.
  * @return \Magento\Framework\Data\Collection\Filesystem
  */
 public function getFilesCollection($path, $type = null)
 {
     if ($this->_coreFileStorageDb->checkDbUsage()) {
         $files = $this->_storageDatabaseFactory->create()->getDirectoryFiles($path);
         /** @var \Magento\MediaStorage\Model\File\Storage\File $fileStorageModel */
         $fileStorageModel = $this->_storageFileFactory->create();
         foreach ($files as $file) {
             $fileStorageModel->saveFile($file);
         }
     }
     $collection = $this->getCollection($path)->setCollectDirs(false)->setCollectFiles(true)->setCollectRecursively(false)->setOrder('mtime', \Magento\Framework\Data\Collection::SORT_ORDER_ASC);
     // Add files extension filter
     if ($allowed = $this->getAllowedExtensions($type)) {
         $collection->setFilesFilter('/\\.(' . implode('|', $allowed) . ')$/i');
     }
     // prepare items
     foreach ($collection as $item) {
         $item->setId($this->_cmsWysiwygImages->idEncode($item->getBasename()));
         $item->setName($item->getBasename());
         $item->setShortName($this->_cmsWysiwygImages->getShortFilename($item->getBasename()));
         $item->setUrl($this->_cmsWysiwygImages->getCurrentUrl() . $item->getBasename());
         if ($this->isImage($item->getBasename())) {
             $thumbUrl = $this->getThumbnailUrl($item->getFilename(), true);
             // generate thumbnail "on the fly" if it does not exists
             if (!$thumbUrl) {
                 $thumbUrl = $this->_backendUrl->getUrl('cms/*/thumbnail', ['file' => $item->getId()]);
             }
             $size = @getimagesize($item->getFilename());
             if (is_array($size)) {
                 $item->setWidth($size[0]);
                 $item->setHeight($size[1]);
             }
         } else {
             $thumbUrl = $this->_assetRepo->getUrl(self::THUMB_PLACEHOLDER_PATH_SUFFIX);
         }
         $item->setThumbUrl($thumbUrl);
     }
     return $collection;
 }
 /**
  * @covers \Magento\Cms\Model\Wysiwyg\Config::getConfig
  * @param array $data
  * @param boolean $isAuthorizationAllowed
  * @param array $expectedResults
  *
  * @dataProvider getConfigDataProvider
  */
 public function testGetConfig($data, $isAuthorizationAllowed, $expectedResults)
 {
     $wysiwygPluginSettings = ['wysiwygPluginSettings' => 'wysiwyg is here'];
     $pluginSettings = ['pluginSettings' => 'plugins are here'];
     $this->backendUrlMock->expects($this->atLeastOnce())->method('getUrl')->withConsecutive(['cms/wysiwyg/directive'], ['cms/wysiwyg_images/index']);
     $this->backendUrlMock->expects($this->once())->method('getBaseUrl')->willReturn('localhost/index.php/');
     $this->assetRepoMock->expects($this->atLeastOnce())->method('getUrl')->withConsecutive(['mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css'], ['mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css']);
     $this->filesystemMock->expects($this->once())->method('getUri')->willReturn('pub/static');
     /** @var \Magento\Framework\View\Asset\ContextInterface|\PHPUnit_Framework_MockObject_MockObject $contextMock */
     $contextMock = $this->getMock(\Magento\Framework\View\Asset\ContextInterface::class);
     $contextMock->expects($this->once())->method('getBaseUrl')->willReturn('localhost/pub/static/');
     $this->assetRepoMock->expects($this->once())->method('getStaticViewFileContext')->willReturn($contextMock);
     $this->authorizationMock->expects($this->atLeastOnce())->method('isAllowed')->with('Magento_Cms::media_gallery')->willReturn($isAuthorizationAllowed);
     $this->variableConfigMock->expects($this->any())->method('getWysiwygPluginSettings')->willReturn($wysiwygPluginSettings);
     $this->widgetConfigMock->expects($this->any())->method('getPluginSettings')->willReturn($pluginSettings);
     $config = $this->wysiwygConfig->getConfig($data);
     $this->assertInstanceOf('Magento\\Framework\\DataObject', $config);
     $this->assertEquals($expectedResults[0], $config->getData('someData'));
     $this->assertEquals($expectedResults[1], $config->getData('wysiwygPluginSettings'));
     $this->assertEquals($expectedResults[2], $config->getData('pluginSettings'));
     $this->assertEquals('localhost/pub/static/', $config->getData('baseStaticUrl'));
     $this->assertEquals('localhost/pub/static/', $config->getData('baseStaticDefaultUrl'));
 }
Пример #19
0
 /**
  * Get url to upload files
  *
  * @return string
  */
 protected function _getUploadUrl()
 {
     return $this->_url->getUrl('catalog/product_gallery/upload');
 }
Пример #20
0
 /**
  * Retrieve menu item url
  *
  * @return string
  */
 public function getUrl()
 {
     if ((bool) $this->_action) {
         return $this->_urlModel->getUrl((string) $this->_action, array('_cache_secret_key' => true));
     }
     return '#';
 }
Пример #21
0
 /**
  * @param string $path
  * @param array $params
  * @return string
  */
 protected function getUrl($path, $params)
 {
     $isBackendStore = \Magento\Store\Model\Store::DEFAULT_STORE_ID === $this->getStoreId() || \Magento\Store\Model\Store::ADMIN_CODE === $this->getStoreId();
     return $isBackendStore ? $this->backendUrlBuilder->getUrl($path, $params) : $this->_storeManager->getStore($this->getStoreId())->getUrl($path, $params);
 }
Пример #22
0
 /**
  * Replace Callback Secret Key
  *
  * @param string[] $match
  * @return string
  */
 protected function _callbackSecretKey($match)
 {
     return \Magento\Backend\Model\UrlInterface::SECRET_KEY_PARAM_NAME . '/' . $this->_url->getSecretKey($match[1], $match[2], $match[3]);
 }
Пример #23
0
 /**
  * Get backend start page URL
  *
  * @return string
  */
 public function getHomePageUrl()
 {
     return $this->_backendUrl->getRouteUrl('adminhtml');
 }
Пример #24
0
 /**
  * Return url of action to get variables
  *
  * @return string
  * @codeCoverageIgnore
  */
 public function getVariablesWysiwygActionUrl()
 {
     return $this->_url->getUrl('adminhtml/system_variable/wysiwygPlugin');
 }
Пример #25
0
 public function testSetRefererOrBaseUrl()
 {
     $this->urlBuilder->expects($this->once())->method('getUrl')->willReturn($this->url);
     $this->redirect->expects($this->once())->method('getRedirectUrl')->with($this->url)->willReturn('test string');
     $this->action->setRefererOrBaseUrl();
 }
Пример #26
0
 /**
  * @return $this
  */
 public function afterSave()
 {
     $this->_backendUrl->renewSecretUrls();
     return $this;
 }
Пример #27
0
 /**
  * Returns URL to controller action which returns new captcha image
  *
  * @return string
  */
 public function getRefreshUrl()
 {
     return $this->_url->getUrl('adminhtml/refresh/refresh', ['_secure' => $this->_config->isSetFlag('web/secure/use_in_adminhtml'), '_nosecret' => true]);
 }
Пример #28
0
 /**
  * @return $this
  */
 protected function _afterSave()
 {
     $this->_backendUrl->renewSecretUrls();
     return $this;
 }
Пример #29
0
 /**
  * @param string $route
  * @param array $params
  * @return string
  */
 public function getBackendUrl($route = '', $params = ['_current' => true])
 {
     return $this->backendUrl->getUrl($route, $params);
 }
Пример #30
0
 /**
  * Return "disable checkout" error message based on the current area context
  *
  * @param $store
  * @return \Magento\Framework\Phrase
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getErrorActionDisableCheckoutMessage($store)
 {
     if ($this->appState->getAreaCode() == \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
         return __($this->getErrorActionDisableCheckoutMessageBackend($store), $this->backendUrl->getUrl('admin/system_config/edit', ['section' => 'tax']), $this->backendUrl->getUrl('avatax/log'));
     } else {
         return __($this->getErrorActionDisableCheckoutMessageFrontend($store));
     }
 }