コード例 #1
0
 /**
  * Process integrations from config files for the given array of integration names
  *
  * @param array $integrationNames
  * @return array
  */
 public function processIntegrationConfig(array $integrationNames)
 {
     if (empty($integrationNames)) {
         return [];
     }
     /** @var array $integrations */
     $integrations = $this->_integrationConfig->getIntegrations();
     foreach ($integrationNames as $name) {
         $integrationDetails = $integrations[$name];
         $integrationData = [Integration::NAME => $name];
         if (isset($integrationDetails[Converter::KEY_EMAIL])) {
             $integrationData[Integration::EMAIL] = $integrationDetails[Converter::KEY_EMAIL];
         }
         if (isset($integrationDetails[Converter::KEY_AUTHENTICATION_ENDPOINT_URL])) {
             $integrationData[Integration::ENDPOINT] = $integrationDetails[Converter::KEY_AUTHENTICATION_ENDPOINT_URL];
         }
         if (isset($integrationDetails[Converter::KEY_IDENTITY_LINKING_URL])) {
             $integrationData[Integration::IDENTITY_LINK_URL] = $integrationDetails[Converter::KEY_IDENTITY_LINKING_URL];
         }
         $integrationData[Integration::SETUP_TYPE] = Integration::TYPE_CONFIG;
         // If it already exists, update it
         $integration = $this->_integrationService->findByName($name);
         if ($integration->getId()) {
             //If Integration already exists, update it.
             //For now we will just overwrite the integration with same name but we will need a long term solution
             $integrationData[Integration::ID] = $integration->getId();
             $this->_integrationService->update($integrationData);
         } else {
             $this->_integrationService->create($integrationData);
         }
     }
     return $integrationNames;
 }
コード例 #2
0
 public function testProcessIntegrationConfigSuccess()
 {
     $this->_integrationConfigMock->expects($this->once())->method('getIntegrations')->will($this->returnValue(['TestIntegration1' => ['email' => '*****@*****.**', 'endpoint_url' => 'http://endpoint.com', 'identity_link_url' => 'http://www.example.com/identity'], 'TestIntegration2' => ['email' => '*****@*****.**']]));
     $intLookupData1 = new \Magento\Framework\Object(['id' => 1, Integration::NAME => 'TestIntegration1', Integration::SETUP_TYPE => 1]);
     $intUpdateData1 = [Integration::ID => 1, Integration::NAME => 'TestIntegration1', Integration::EMAIL => '*****@*****.**', Integration::ENDPOINT => 'http://endpoint.com', Integration::IDENTITY_LINK_URL => 'http://www.example.com/identity', Integration::SETUP_TYPE => 1];
     $integrationsData2 = [Integration::NAME => 'TestIntegration2', Integration::EMAIL => '*****@*****.**', Integration::SETUP_TYPE => 1];
     $this->_integrationServiceMock->expects($this->at(0))->method('findByName')->with('TestIntegration1')->will($this->returnValue($intLookupData1));
     $this->_integrationServiceMock->expects($this->once())->method('create')->with($integrationsData2);
     $this->_integrationServiceMock->expects($this->at(2))->method('findByName')->with('TestIntegration2')->will($this->returnValue(new \Magento\Framework\Object([])));
     $this->_integrationServiceMock->expects($this->once())->method('update')->with($intUpdateData1);
     $this->_integrationManager->processIntegrationConfig(['TestIntegration1', 'TestIntegration2']);
 }
コード例 #3
0
 /**
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testAfterProcessIntegrationConfigSuccess()
 {
     $testIntegration1Resource = ['Magento_Customer::manage', 'Magento_Customer::online', 'Magento_Sales::create', 'Magento_SalesRule::quote'];
     $testIntegration2Resource = ['Magento_Catalog::product_read'];
     $this->integrationConfigMock->expects($this->once())->method('getIntegrations')->will($this->returnValue(['TestIntegration1' => ['resources' => $testIntegration1Resource], 'TestIntegration2' => ['resources' => $testIntegration2Resource]]));
     $firstInegrationId = 1;
     $integrationsData1 = new \Magento\Framework\Object(['id' => $firstInegrationId, Integration::NAME => 'TestIntegration1', Integration::EMAIL => '*****@*****.**', Integration::ENDPOINT => 'http://endpoint.com', Integration::SETUP_TYPE => 1]);
     $secondIntegrationId = 2;
     $integrationsData2 = new \Magento\Framework\Object(['id' => $secondIntegrationId, Integration::NAME => 'TestIntegration2', Integration::EMAIL => '*****@*****.**', Integration::SETUP_TYPE => 1]);
     $this->integrationServiceMock->expects($this->at(0))->method('findByName')->with('TestIntegration1')->will($this->returnValue($integrationsData1));
     $this->integrationServiceMock->expects($this->at(1))->method('findByName')->with('TestIntegration2')->will($this->returnValue($integrationsData2));
     $this->apiSetupPlugin->afterProcessIntegrationConfig($this->subjectMock, ['TestIntegration1', 'TestIntegration2']);
 }
コード例 #4
0
ファイル: Access.php プロジェクト: shabbirvividads/magento2
 /**
  * Initiate AccessToken request operation
  *
  * @return void
  */
 public function execute()
 {
     try {
         $requestUrl = $this->_helper->getRequestUrl($this->getRequest());
         $request = $this->_helper->prepareRequest($this->getRequest(), $requestUrl);
         // Request access token in exchange of a pre-authorized token
         $response = $this->_oauthService->getAccessToken($request, $requestUrl, $this->getRequest()->getMethod());
         //After sending the access token, update the integration status to active;
         $consumer = $this->_intOauthService->loadConsumerByKey($request['oauth_consumer_key']);
         $this->_integrationService->findByConsumerId($consumer->getId())->setStatus(IntegrationModel::STATUS_ACTIVE)->save();
     } catch (\Exception $exception) {
         $response = $this->_helper->prepareErrorResponse($exception, $this->getResponse());
     }
     $this->getResponse()->setBody(http_build_query($response));
 }
コード例 #5
0
 /**
  * Process integration resource permissions after the integration is created
  *
  * @param \Magento\Integration\Model\Resource\Setup $subject
  * @param string[] $integrationNames Name of integrations passed as array from the invocation chain
  *
  * @return string[]
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterInitIntegrationProcessing(\Magento\Integration\Model\Resource\Setup $subject, $integrationNames)
 {
     if (empty($integrationNames)) {
         return [];
     }
     /** @var array $integrations */
     $integrations = $this->_integrationConfig->getIntegrations();
     foreach ($integrationNames as $name) {
         if (isset($integrations[$name])) {
             $integration = $this->_integrationService->findByName($name);
             if ($integration->getId()) {
                 $this->integrationAuthorizationService->grantPermissions($integration->getId(), $integrations[$name]['resources']);
             }
         }
     }
     return $integrationNames;
 }
コード例 #6
0
ファイル: Manager.php プロジェクト: shabbirvividads/magento2
 /**
  * Process integration resource permissions after the integration is created
  *
  * @param ConfigBasedIntegrationManager $subject
  * @param string[] $integrationNames Name of integrations passed as array from the invocation chain
  *
  * @return string[]
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterProcessIntegrationConfig(ConfigBasedIntegrationManager $subject, $integrationNames)
 {
     if (empty($integrationNames)) {
         return [];
     }
     /** @var array $integrations */
     $integrations = $this->_integrationConfig->getIntegrations();
     foreach ($integrationNames as $name) {
         if (isset($integrations[$name])) {
             $integration = $this->_integrationService->findByName($name);
             if ($integration->getId()) {
                 $this->integrationAuthorizationService->grantPermissions($integration->getId(), $integrations[$name]['resources']);
             }
         }
     }
     return $integrationNames;
 }
コード例 #7
0
ファイル: SetupTest.php プロジェクト: Atlis/docker-magento2
 /**
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testAfterInitIntegrationProcessingSuccess()
 {
     $testIntegration1Resource = array('Magento_Customer::manage', 'Magento_Customer::online', 'Magento_Sales::create', 'Magento_SalesRule::quote');
     $testIntegration2Resource = array('Magento_Catalog::product_read');
     $this->integrationConfigMock->expects($this->once())->method('getIntegrations')->will($this->returnValue(array('TestIntegration1' => array('resources' => $testIntegration1Resource), 'TestIntegration2' => array('resources' => $testIntegration2Resource))));
     $integrationsData1 = new \Magento\Framework\Object(array('id' => 1, Integration::NAME => 'TestIntegration1', Integration::EMAIL => '*****@*****.**', Integration::ENDPOINT => 'http://endpoint.com', Integration::SETUP_TYPE => 1));
     $integrationsData2 = new \Magento\Framework\Object(array('id' => 2, Integration::NAME => 'TestIntegration2', Integration::EMAIL => '*****@*****.**', Integration::SETUP_TYPE => 1));
     $this->integrationServiceMock->expects($this->at(0))->method('findByName')->with('TestIntegration1')->will($this->returnValue($integrationsData1));
     $this->integrationServiceMock->expects($this->at(1))->method('findByName')->with('TestIntegration2')->will($this->returnValue($integrationsData2));
     $userIdentifierMock1 = $this->getMockBuilder('\\Magento\\Authz\\Model\\UserIdentifier')->disableOriginalConstructor()->getMock();
     $this->userIdentifierFactoryMock->expects($this->at(0))->method('create')->with(UserIdentifier::USER_TYPE_INTEGRATION, 1)->will($this->returnValue($userIdentifierMock1));
     $userIdentifierMock2 = $this->getMockBuilder('\\Magento\\Authz\\Model\\UserIdentifier')->disableOriginalConstructor()->getMock();
     $this->userIdentifierFactoryMock->expects($this->at(1))->method('create')->with(UserIdentifier::USER_TYPE_INTEGRATION, 2)->will($this->returnValue($userIdentifierMock2));
     $this->authzServiceMock->expects($this->at(0))->method('grantPermissions')->with($userIdentifierMock1, $testIntegration1Resource);
     $this->authzServiceMock->expects($this->at(1))->method('grantPermissions')->with($userIdentifierMock2, $testIntegration2Resource);
     $this->apiSetupPlugin->afterInitIntegrationProcessing($this->subjectMock, array('TestIntegration1', 'TestIntegration2'));
 }
コード例 #8
0
ファイル: Setup.php プロジェクト: Atlis/docker-magento2
 /**
  * Process integration resource permissions after the integration is created
  *
  * @param \Magento\Integration\Model\Resource\Setup $subject
  * @param string[] $integrationNames Name of integrations passed as array from the invocation chain
  *
  * @return string[]
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterInitIntegrationProcessing(\Magento\Integration\Model\Resource\Setup $subject, $integrationNames)
 {
     if (empty($integrationNames)) {
         return array();
     }
     /** @var array $integrations */
     $integrations = $this->_integrationConfig->getIntegrations();
     foreach ($integrationNames as $name) {
         if (isset($integrations[$name])) {
             $integration = $this->_integrationService->findByName($name);
             if ($integration->getId()) {
                 $userIdentifier = $this->_userIdentifierFactory->create(UserIdentifier::USER_TYPE_INTEGRATION, $integration->getId());
                 $this->_authzService->grantPermissions($userIdentifier, $integrations[$name]['resources']);
             }
         }
     }
     return $integrationNames;
 }