Skip to content

Commit 6746254

Browse files
committed
Merge remote-tracking branch 'origin/module-login-as-customer' into issue-110
# Conflicts: # app/code/Magento/LoginAsCustomerUi/etc/adminhtml/system.xml
2 parents 227e170 + dc7ba27 commit 6746254

File tree

63 files changed

+1683
-631
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1683
-631
lines changed

app/code/Magento/LoginAsCustomer/Cron/DeleteExpiredAuthenticationData.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

app/code/Magento/LoginAsCustomer/Model/ResourceModel/DeleteExpiredAuthenticationData.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,15 @@ public function __construct(
5050
/**
5151
* @inheritdoc
5252
*/
53-
public function execute(): void
53+
public function execute(int $userId): void
5454
{
5555
$connection = $this->resourceConnection->getConnection();
5656
$tableName = $this->resourceConnection->getTableName('login_as_customer');
5757

58-
$timePoint = date(
59-
'Y-m-d H:i:s',
60-
$this->dateTime->gmtTimestamp() - $this->config->getAuthenticationDataExpirationTime()
61-
);
62-
6358
$connection->delete(
6459
$tableName,
6560
[
66-
'created_at < ?' => $timePoint
61+
'admin_id = ?' => $userId
6762
]
6863
);
6964
}

app/code/Magento/LoginAsCustomer/Model/ResourceModel/GetAuthenticationDataBySecret.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ public function execute(string $secretKey): AuthenticationDataInterface
8585
/** @var AuthenticationDataInterface $authenticationData */
8686
$authenticationData = $this->authenticationDataFactory->create(
8787
[
88-
'customerId' => (int)$data['admin_id'],
89-
'adminId' => (int)$data['customer_id'],
88+
'customerId' => (int)$data['customer_id'],
89+
'adminId' => (int)$data['admin_id'],
9090
'extensionAttributes' => null,
9191
]
9292
);

app/code/Magento/LoginAsCustomer/Model/ResourceModel/DeleteAuthenticationDataBySecret.php renamed to app/code/Magento/LoginAsCustomer/Model/ResourceModel/IsLoginAsCustomerSessionActive.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
namespace Magento\LoginAsCustomer\Model\ResourceModel;
99

1010
use Magento\Framework\App\ResourceConnection;
11-
use Magento\LoginAsCustomerApi\Api\DeleteAuthenticationDataBySecretInterface;
11+
use Magento\LoginAsCustomerApi\Api\IsLoginAsCustomerSessionActiveInterface;
1212

1313
/**
1414
* @inheritdoc
1515
*/
16-
class DeleteAuthenticationDataBySecret implements DeleteAuthenticationDataBySecretInterface
16+
class IsLoginAsCustomerSessionActive implements IsLoginAsCustomerSessionActiveInterface
1717
{
1818
/**
1919
* @var ResourceConnection
@@ -32,16 +32,18 @@ public function __construct(
3232
/**
3333
* @inheritdoc
3434
*/
35-
public function execute(string $secret): void
35+
public function execute(int $customerId, int $userId): bool
3636
{
37-
$connection = $this->resourceConnection->getConnection();
3837
$tableName = $this->resourceConnection->getTableName('login_as_customer');
38+
$connection = $this->resourceConnection->getConnection();
39+
40+
$query = $connection->select()
41+
->from($tableName)
42+
->where('customer_id = ?', $customerId)
43+
->where('admin_id = ?', $userId);
44+
45+
$result = $connection->fetchRow($query);
3946

40-
$connection->delete(
41-
$tableName,
42-
[
43-
'secret = ?' => $secret
44-
]
45-
);
47+
return false !== $result;
4648
}
4749
}

app/code/Magento/LoginAsCustomer/etc/crontab.xml

Lines changed: 0 additions & 16 deletions
This file was deleted.

app/code/Magento/LoginAsCustomer/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
<preference for="Magento\LoginAsCustomerApi\Api\DeleteAuthenticationDataBySecretInterface" type="Magento\LoginAsCustomer\Model\ResourceModel\DeleteAuthenticationDataBySecret"/>
1414
<preference for="Magento\LoginAsCustomerApi\Api\DeleteExpiredAuthenticationDataInterface" type="Magento\LoginAsCustomer\Model\ResourceModel\DeleteExpiredAuthenticationData"/>
1515
<preference for="Magento\LoginAsCustomerApi\Api\ConfigInterface" type="Magento\LoginAsCustomer\Model\Config"/>
16+
<preference for="Magento\LoginAsCustomerApi\Api\IsLoginAsCustomerSessionActiveInterface" type="Magento\LoginAsCustomer\Model\ResourceModel\IsLoginAsCustomerSessionActive"/>
1617
</config>

app/code/Magento/LoginAsCustomerApi/Api/DeleteExpiredAuthenticationDataInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
interface DeleteExpiredAuthenticationDataInterface
1616
{
1717
/**
18-
* Delete expired authentication data
18+
* Delete expired authentication data by user id.
1919
*
20+
* @param int $userId
2021
* @return void
2122
*/
22-
public function execute(): void;
23+
public function execute(int $userId): void;
2324
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\LoginAsCustomerApi\Api;
9+
10+
/**
11+
* Check if Login as Customer session is still active.
12+
*
13+
* @api
14+
*/
15+
interface IsLoginAsCustomerSessionActiveInterface
16+
{
17+
/**
18+
* Check if Login as Customer session is still active.
19+
*
20+
* @param int $customerId
21+
* @param int $userId
22+
* @return bool
23+
*/
24+
public function execute(int $customerId, int $userId): bool;
25+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\LoginAsCustomerLog\Api\Data;
9+
10+
use Magento\Framework\Api\ExtensibleDataInterface;
11+
12+
/**
13+
* Data interface for login as customer log.
14+
*
15+
* @api
16+
*/
17+
interface LogInterface extends ExtensibleDataInterface
18+
{
19+
const LOG_ID = 'log_id';
20+
const TIME = 'time';
21+
const CUSTOMER_ID = 'customer_id';
22+
const CUSTOMER_EMAIL = 'customer_email';
23+
const USER_ID = 'user_id';
24+
const USERNAME = 'user_name';
25+
26+
/**
27+
* Set login as customer log id.
28+
*
29+
* @param int $logId
30+
* @return void
31+
*/
32+
public function setLogId(int $logId): void;
33+
34+
/**
35+
* Retrieve login as customer log id.
36+
*
37+
* @return null|int
38+
*/
39+
public function getLogId(): ?int;
40+
41+
/**
42+
* Set login as customer log time.
43+
*
44+
* @param string $time
45+
* @return void
46+
*/
47+
public function setTime(string $time): void;
48+
49+
/**
50+
* Retrieve login as customer log time.
51+
*
52+
* @return null|string
53+
*/
54+
public function getTime(): ?string;
55+
56+
/**
57+
* Set login as customer log user id.
58+
*
59+
* @param int $userId
60+
* @return void
61+
*/
62+
public function setUserId(int $userId): void;
63+
64+
/**
65+
* Retrieve login as customer log user id.
66+
*
67+
* @return null|int
68+
*/
69+
public function getUserId(): ?int;
70+
71+
/**
72+
* Set login as customer log user name.
73+
*
74+
* @param string $userName
75+
* @return void
76+
*/
77+
public function setUserName(string $userName): void;
78+
79+
/**
80+
* Retrieve login as customer log user name.
81+
*
82+
* @return null|string
83+
*/
84+
public function getUserName(): ?string;
85+
86+
/**
87+
* Set login as customer log customer id.
88+
*
89+
* @param int $customerId
90+
* @return void
91+
*/
92+
public function setCustomerId(int $customerId): void;
93+
94+
/**
95+
* Retrieve login as customer log customer id.
96+
*
97+
* @return null|int
98+
*/
99+
public function getCustomerId(): ?int;
100+
101+
/**
102+
* Set login as customer log customer email.
103+
*
104+
* @param string $customerEmail
105+
* @return void
106+
*/
107+
public function setCustomerEmail(string $customerEmail): void;
108+
109+
/**
110+
* Retrieve login as customer log customer email.
111+
*
112+
* @return null|string
113+
*/
114+
public function getCustomerEmail(): ?string;
115+
116+
/**
117+
* Set log extension attributes.
118+
*
119+
* @param \Magento\LoginAsCustomerLog\Api\Data\LogExtensionInterface $extensionAttributes
120+
* @return void
121+
*/
122+
public function setExtensionAttributes(LogExtensionInterface $extensionAttributes): void;
123+
124+
/**
125+
* Retrieve log extension attributes.
126+
*
127+
* @return \Magento\LoginAsCustomerLog\Api\Data\LogExtensionInterface
128+
*/
129+
public function getExtensionAttributes(): LogExtensionInterface;
130+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\LoginAsCustomerLog\Api\Data;
9+
10+
use \Magento\Framework\Api\SearchResultsInterface;
11+
12+
/**
13+
* Login as customer log entity search results interface.
14+
*
15+
* @api
16+
*/
17+
interface LogSearchResultsInterface extends SearchResultsInterface
18+
{
19+
/**
20+
* Get log list.
21+
*
22+
* @return \Magento\LoginAsCustomerLog\Api\Data\LogInterface[]
23+
*/
24+
public function getItems();
25+
26+
/**
27+
* Set log list.
28+
*
29+
* @param \Magento\LoginAsCustomerLog\Api\Data\LogInterface[] $items
30+
* @return void
31+
*/
32+
public function setItems(array $items);
33+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\LoginAsCustomerLog\Api;
9+
10+
use Magento\Framework\Api\SearchCriteriaInterface;
11+
use Magento\LoginAsCustomerLog\Api\Data\LogSearchResultsInterface;
12+
13+
/**
14+
* Get login as customer log list considering search criteria.
15+
*
16+
* @api
17+
*/
18+
interface GetLogsListInterface
19+
{
20+
/**
21+
* Retrieve list of log entities.
22+
*
23+
* @param SearchCriteriaInterface $searchCriteria
24+
* @return LogSearchResultsInterface
25+
*/
26+
public function execute(SearchCriteriaInterface $searchCriteria): LogSearchResultsInterface;
27+
}

0 commit comments

Comments
 (0)