Skip to content

MQE-820: MSI form posts use a single "/admin/" vs "/admin/admin/" URLs used in other areas of the Admin. #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion dev/tests/unit/Util/OperationDefinitionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class OperationDefinitionBuilder
*/
private $metadata = [];

/**
* Determines if api URL should remove magento_backend_name.
* @var bool
*/
private $removeBackend;

/**
* Function which builds an operation defintions based on the fields set by the user.
*
Expand All @@ -54,7 +60,8 @@ public function build()
null,
null,
$this->metadata,
null
null,
false
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class OperationDefinitionObjectHandler implements ObjectHandlerInterface
const ENTITY_OPERATION_OBJECT_KEY = 'key';
const ENTITY_OPERATION_OBJECT_VALUE = 'value';
const ENTITY_OPERATION_REQUIRED = 'required';
const ENTITY_OPERATION_BACKEND_REMOVE = 'removeBackend';

/**
* The singleton instance of this class
Expand Down Expand Up @@ -149,6 +150,7 @@ private function initialize()
$headers = [];
$params = [];
$operationElements = [];
$removeBackend = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_BACKEND_REMOVE] ?? false;

// TODO remove this warning with 2.1.0 release
$backendName = getenv('MAGENTO_BACKEND_NAME');
Expand Down Expand Up @@ -238,6 +240,7 @@ private function initialize()
$params,
$operationElements,
$contentType,
$removeBackend,
$successRegex,
$returnRegex
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ class OperationDefinitionObject
*/
private $returnRegex;

/**
* Determines if operation should remove backend_name from URL.
* @var bool
*/
private $removeBackend;

/**
* OperationDefinitionObject constructor.
* @param string $name
Expand All @@ -116,6 +122,7 @@ class OperationDefinitionObject
* @param array $params
* @param array $metaData
* @param string $contentType
* @param bool $removeBackend
* @param string $successRegex
* @param string $returnRegex
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
Expand All @@ -131,6 +138,7 @@ public function __construct(
$params,
$metaData,
$contentType,
$removeBackend,
$successRegex = null,
$returnRegex = null
) {
Expand All @@ -145,13 +153,15 @@ public function __construct(
$this->operationMetadata = $metaData;
$this->successRegex = $successRegex;
$this->returnRegex = $returnRegex;
$this->removeBackend = $removeBackend;
$this->apiUrl = null;

if (!empty($contentType)) {
$this->contentType = $contentType;
} else {
$this->contentType = 'application/x-www-form-urlencoded';
}

// add content type as a header
$this->headers[] = self::HTTP_CONTENT_TYPE_HEADER . ': ' . $this->contentType;
}
Expand Down Expand Up @@ -231,6 +241,16 @@ public function getHeaders()
return $this->headers;
}

/**
* Getter for removeBackend
*
* @return bool
*/
public function removeUrlBackend()
{
return $this->removeBackend;
}

/**
* Getter for Content-type
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class AdminExecutor extends AbstractExecutor implements CurlInterface
*/
private $response;

/**
* Should executor remove backend_name from api url
* @var bool
*/
private $removeBackend;

/**
* Backend url.
*
Expand All @@ -45,15 +51,17 @@ class AdminExecutor extends AbstractExecutor implements CurlInterface

/**
* Constructor.
* @param bool $removeBackend
*
* @constructor
*/
public function __construct()
public function __construct($removeBackend)
{
if (!isset(parent::$baseUrl)) {
parent::resolveBaseUrl();
}
self::$adminUrl = parent::$baseUrl . getenv('MAGENTO_BACKEND_NAME') . '/';
$this->removeBackend = $removeBackend;
$this->transport = new CurlTransport();
$this->authorize();
}
Expand Down Expand Up @@ -110,6 +118,11 @@ private function setFormKey()
public function write($url, $data = [], $method = CurlInterface::POST, $headers = [])
{
$apiUrl = self::$adminUrl . $url;

if ($this->removeBackend) {
$apiUrl = parent::$baseUrl . ltrim($url, '/');
}

if ($this->formKey) {
$data['form_key'] = $this->formKey;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function executeRequest($dependentEntities)
$this->isJson = true;
$executor = new WebapiExecutor($this->storeCode);
} elseif ($authorization === 'adminFormKey') {
$executor = new AdminExecutor();
$executor = new AdminExecutor($this->operationDefinition->removeUrlBackend());
} elseif ($authorization === 'customerFormKey') {
$executor = new FrontendExecutor(
$this->requestData['customer_email'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<xs:attribute type="operationEnum" name="type" use="required"/>
<xs:attribute type="xs:string" name="url"/>
<xs:attribute type="authEnum" name="auth"/>
<xs:attribute type="xs:boolean" name="removeBackend" use="optional" default="true"/>
<xs:attribute type="xs:string" name="method"/>
<xs:attribute type="xs:string" name="successRegex"/>
<xs:attribute type="xs:string" name="returnRegex"/>
Expand Down