Skip to content

Commit 6b2f3ad

Browse files
committed
CABPI-364: AdobeStock UI changes
1 parent 74d27af commit 6b2f3ad

File tree

7 files changed

+135
-30
lines changed

7 files changed

+135
-30
lines changed

app/code/Magento/AdminAdobeIms/Block/Adminhtml/SignIn.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ private function getDefaultComponentConfig(): array
137137
'profileUrl' => $this->getUrl(self::ADOBE_IMS_USER_PROFILE),
138138
'logoutUrl' => $this->getUrl(self::ADOBE_IMS_USER_LOGOUT),
139139
'user' => $this->getUserData(),
140+
'isGlobalSignInEnabled' => $this->isGlobalSignInEnabled(),
140141
'loginConfig' => [
141142
'url' => $this->config->getAuthUrl(),
142143
'callbackParsingParams' => [
@@ -221,4 +222,18 @@ private function getDefaultUserData(): array
221222
'image' => '',
222223
];
223224
}
225+
226+
/**
227+
* Check if global sign in is enabled
228+
*
229+
* @return bool
230+
*/
231+
private function isGlobalSignInEnabled(): bool
232+
{
233+
if ($this->adminAdobeImsConfig->enabled()) {
234+
return true;
235+
}
236+
237+
return false;
238+
}
224239
}

app/code/Magento/AdminAdobeIms/Model/GetAccessTokenProxy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct(
4949
/**
5050
* @inheritdoc
5151
*/
52-
public function execute(int $adminUserId = null): ?string //
52+
public function execute(int $adminUserId = null): ?string
5353
{
5454
if ($this->adminAdobeImsConfig->enabled()) {
5555
return $this->getAccessTokenFromSession->execute($adminUserId);

app/code/Magento/AdminAdobeIms/Model/GetAccessTokenSession.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,8 @@ public function __construct(Auth $auth)
3030
/**
3131
* @inheritdoc
3232
*/
33-
public function execute(int $adminUserId = null): ?string //
33+
public function execute(int $adminUserId = null): ?string
3434
{
35-
$session = $this->auth->getAuthStorage();
36-
$accessToken = $session->getAdobeAccessToken();
37-
38-
if (!$accessToken) {
39-
return null;
40-
}
41-
42-
return $accessToken;
35+
return $this->auth->getAuthStorage()->getAdobeAccessToken() ?? null;
4336
}
4437
}

app/code/Magento/AdminAdobeIms/Model/UserAuthorizedSession.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,16 @@ public function __construct(
4343
*/
4444
public function execute(int $adminUserId = null): bool
4545
{
46-
if (!empty($this->auth->getUser()->getId()) && !empty($this->auth->getAuthStorage()->getAdobeAccessToken())) {
47-
$token = $this->auth->getAuthStorage()->getAdobeAccessToken();
48-
49-
try {
50-
$isTokenValid = $this->imsConnection->validateToken($token);
51-
} catch (AuthorizationException $e) {
52-
return false;
53-
}
54-
55-
if ($isTokenValid) {
56-
return true;
57-
}
46+
$token = $this->auth->getAuthStorage()->getAdobeAccessToken();
47+
48+
if (empty($token) || empty($this->auth->getUser()->getId())) {
49+
return false;
50+
}
51+
52+
try {
53+
return $this->imsConnection->validateToken($token);
54+
} catch (AuthorizationException $e) {
55+
return false;
5856
}
59-
return false;
6057
}
6158
}

app/code/Magento/AdminAdobeIms/Service/ImsConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class ImsConfig extends Config
2222
{
23-
public const XML_PATH_ENABLED = 'adobe_ims/integration/admin/enabled';
23+
public const XML_PATH_ENABLED = 'adobe_ims/integration/admin_enabled';
2424
public const XML_PATH_LOGGING_ENABLED = 'adobe_ims/integration/logging_enabled';
2525
public const XML_PATH_ORGANIZATION_ID = 'adobe_ims/integration/organization_id';
2626
public const XML_PATH_API_KEY = 'adobe_ims/integration/api_key';

app/code/Magento/AdobeIms/Test/Unit/Block/Adminhtml/SignInTest.php renamed to app/code/Magento/AdminAdobeIms/Test/Unit/Block/Adminhtml/SignInTest.php

Lines changed: 105 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\AdobeIms\Test\Unit\Block\Adminhtml;
8+
namespace Magento\AdminAdobeIms\Test\Unit\Block\Adminhtml;
99

10-
use Magento\AdobeIms\Block\Adminhtml\SignIn as SignInBlock;
10+
use Magento\AdminAdobeIms\Block\Adminhtml\SignIn as SignInBlock;
11+
use Magento\AdminAdobeIms\Model\Auth;
12+
use Magento\AdminAdobeIms\Service\ImsConfig;
1113
use Magento\AdobeImsApi\Api\ConfigInterface;
1214
use Magento\AdobeImsApi\Api\ConfigProviderInterface;
1315
use Magento\AdobeImsApi\Api\Data\UserProfileInterface;
@@ -19,6 +21,7 @@
1921
use Magento\Framework\Serialize\Serializer\JsonHexTag;
2022
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2123
use Magento\Framework\UrlInterface;
24+
use Magento\User\Model\User;
2225
use PHPUnit\Framework\MockObject\MockObject;
2326
use PHPUnit\Framework\TestCase;
2427

@@ -62,6 +65,16 @@ class SignInTest extends TestCase
6265
*/
6366
private $signInBlock;
6467

68+
/**
69+
* @var ImsConfig|MockObject
70+
*/
71+
private ImsConfig $adminAdobeImsConfig;
72+
73+
/**
74+
* @var Auth|MockObject
75+
*/
76+
private Auth $auth;
77+
6578
/**
6679
* Prepare test objects.
6780
*/
@@ -83,6 +96,8 @@ protected function setUp(): void
8396
$this->userAuthorizedMock = $this->createMock(UserAuthorizedInterface::class);
8497
$this->userProfileRepositoryMock = $this->createMock(UserProfileRepositoryInterface::class);
8598
$this->jsonHexTag = $this->createMock(JsonHexTag::class);
99+
$this->adminAdobeImsConfig = $this->createMock(ImsConfig::class);
100+
$this->auth = $this->createMock(Auth::class);
86101

87102
$objectManager = new ObjectManager($this);
88103
$this->signInBlock = $objectManager->getObject(
@@ -93,7 +108,10 @@ protected function setUp(): void
93108
'userContext' => $this->userContextMock,
94109
'userAuthorized' => $this->userAuthorizedMock,
95110
'userProfileRepository' => $this->userProfileRepositoryMock,
96-
'json' => $this->jsonHexTag
111+
'json' => $this->jsonHexTag,
112+
[],
113+
'adminAdobeImsConfig' => $this->adminAdobeImsConfig,
114+
'auth' => $this->auth
97115
]
98116
);
99117
}
@@ -126,6 +144,8 @@ public function testGetComponentJsonConfig(
126144
->method('getUserId')
127145
->willReturn($userId);
128146

147+
$this->adminAdobeImsConfig->method('enabled')->willReturn(false);
148+
129149
$userRepositoryWillReturn = $userExists
130150
? $this->returnValue($userProfile)
131151
: $this->throwException(new NoSuchEntityException());
@@ -149,13 +169,63 @@ public function testGetComponentJsonConfig(
149169
$this->assertEquals($serializedResult, $this->signInBlock->getComponentJsonConfig());
150170
}
151171

172+
/**
173+
* @dataProvider userDataProviderWithAdminAdobeImsEnabled
174+
* @param int $userId
175+
* @param bool $userExists
176+
* @param array $userData
177+
* @param array $configProviderData
178+
* @param array $expectedData
179+
*/
180+
public function testGetComponentJsonConfigWithAdminAdobeImsEnabled(
181+
int $userId,
182+
bool $userExists,
183+
array $userData,
184+
array $configProviderData,
185+
array $expectedData
186+
): void {
187+
$this->userAuthorizedMock->expects($this->once())
188+
->method('execute')
189+
->willReturn($userData['isAuthorized']);
190+
191+
$userProfile = $this->createMock(User::class);
192+
$userProfile->method('getFirstName')->willReturn($userData['firstname']);
193+
$userProfile->method('getLastName')->willReturn($userData['lastname']);
194+
$userProfile->method('getEmail')->willReturn($userData['email']);
195+
196+
$this->adminAdobeImsConfig->method('enabled')->willReturn(true);
197+
$this->auth->method('getUser')->willReturn($userProfile);
198+
$this->userContextMock->method('getUserId')->willReturn($userId);
199+
200+
$userRepositoryWillReturn = $userExists
201+
? $this->returnValue($userProfile)
202+
: $this->throwException(new NoSuchEntityException());
203+
$this->userProfileRepositoryMock
204+
->method('getByUserId')
205+
->with($userId)
206+
->will($userRepositoryWillReturn);
207+
208+
$configProviderMock = $this->createMock(ConfigProviderInterface::class);
209+
$configProviderMock->method('get')->willReturn($configProviderData);
210+
$this->signInBlock->setData('configProviders', [$configProviderMock]);
211+
212+
$serializedResult = 'Some result';
213+
$this->jsonHexTag->expects($this->once())
214+
->method('serialize')
215+
->with($expectedData)
216+
->willReturn($serializedResult);
217+
218+
$this->assertEquals($serializedResult, $this->signInBlock->getComponentJsonConfig());
219+
}
220+
152221
/**
153222
* Returns default component config
154223
*
155224
* @param array $userData
225+
* @param bool $isGlobalSignInEnabled
156226
* @return array
157227
*/
158-
private function getDefaultComponentConfig(array $userData): array
228+
private function getDefaultComponentConfig(array $userData, bool $isGlobalSignInEnabled = false): array
159229
{
160230
return [
161231
'component' => 'Magento_AdobeIms/js/signIn',
@@ -172,7 +242,8 @@ private function getDefaultComponentConfig(array $userData): array
172242
'successCode' => self::RESPONSE_SUCCESS_CODE,
173243
'errorCode' => self::RESPONSE_ERROR_CODE
174244
]
175-
]
245+
],
246+
'isGlobalSignInEnabled' => $isGlobalSignInEnabled
176247
];
177248
}
178249

@@ -281,4 +352,33 @@ public function userDataProvider(): array
281352
]
282353
];
283354
}
355+
356+
/**
357+
* @return array
358+
*/
359+
public function userDataProviderWithAdminAdobeImsEnabled(): array
360+
{
361+
return [
362+
'Existing authorized user with Admin Adobe IMS enabled' => [
363+
15,
364+
true,
365+
[
366+
'isAuthorized' => true,
367+
'firstname' => 'John',
368+
'lastname' => 'Doe',
369+
'email' => 'john@email.com',
370+
],
371+
[],
372+
$this->getDefaultComponentConfig(
373+
[
374+
'isAuthorized' => true,
375+
'name' => 'John Doe',
376+
'email' => 'john@email.com',
377+
'image' => ''
378+
],
379+
true
380+
)
381+
]
382+
];
383+
}
284384
}

app/code/Magento/AdminAdobeIms/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<default>
1010
<adobe_ims>
1111
<integration>
12+
<admin_enabled>0</admin_enabled>
1213
<admin>
13-
<enabled>0</enabled>
1414
<auth_url_pattern><![CDATA[https://ims-na1-stg1.adobelogin.com/ims/authorize/v2?client_id=#{client_id}&redirect_uri=#{redirect_uri}&locale=#{locale}&scope=#{scope}&response_type=code]]></auth_url_pattern>
1515
<reauth_url_pattern><![CDATA[https://ims-na1-stg1.adobelogin.com/ims/authorize/v2?client_id=#{client_id}&redirect_uri=#{redirect_uri}&locale=#{locale}&scope=#{scope}&response_type=code&reauth=check]]></reauth_url_pattern>
1616
<scopes>

0 commit comments

Comments
 (0)