Skip to content

Commit 5344e89

Browse files
Merge remote-tracking branch '36971/patch-2' into comm_voted_v3
2 parents d25f618 + a3adc65 commit 5344e89

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

setup/src/Magento/Setup/Model/AdminAccount.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ class AdminAccount
1717
/**#@+
1818
* Data keys
1919
*/
20-
const KEY_USER = 'admin-user';
21-
const KEY_PASSWORD = 'admin-password';
22-
const KEY_EMAIL = 'admin-email';
23-
const KEY_FIRST_NAME = 'admin-firstname';
24-
const KEY_LAST_NAME = 'admin-lastname';
25-
const KEY_PREFIX = 'db-prefix';
20+
public const KEY_USER = 'admin-user';
21+
public const KEY_PASSWORD = 'admin-password';
22+
public const KEY_EMAIL = 'admin-email';
23+
public const KEY_FIRST_NAME = 'admin-firstname';
24+
public const KEY_LAST_NAME = 'admin-lastname';
25+
public const KEY_PREFIX = 'db-prefix';
2626
/**#@- */
2727

2828
/**
@@ -154,8 +154,7 @@ private function trackPassword($adminId, $passwordHash)
154154
}
155155

156156
/**
157-
* Validates that the username and email both match the user,
158-
* and that password exists and is different from user name.
157+
* Validate that the username and email both match the user,and that password exists and is different from username.
159158
*
160159
* @return void
161160
* @throws \Exception If the username and email do not both match data provided to install
@@ -164,12 +163,14 @@ private function trackPassword($adminId, $passwordHash)
164163
public function validateUserMatches()
165164
{
166165
if (empty($this->data[self::KEY_PASSWORD])) {
166+
// phpcs:ignore Magento2.Exceptions.DirectThrow
167167
throw new \Exception(
168168
'"Password" is required. Enter and try again.'
169169
);
170170
}
171171

172172
if (strcasecmp($this->data[self::KEY_PASSWORD], $this->data[self::KEY_USER]) == 0) {
173+
// phpcs:ignore Magento2.Exceptions.DirectThrow
173174
throw new \Exception(
174175
'Password cannot be the same as the user name.'
175176
);
@@ -191,6 +192,7 @@ public function validateUserMatches()
191192
if ((strcasecmp($email, $this->data[self::KEY_EMAIL]) == 0) &&
192193
(strcasecmp($username, $this->data[self::KEY_USER]) != 0)) {
193194
// email matched but username did not
195+
// phpcs:ignore Magento2.Exceptions.DirectThrow
194196
throw new \Exception(
195197
'An existing user has the given email but different username. '
196198
. 'Username and email both need to match an existing user or both be new.'
@@ -199,6 +201,7 @@ public function validateUserMatches()
199201
if ((strcasecmp($username, $this->data[self::KEY_USER]) == 0) &&
200202
(strcasecmp($email, $this->data[self::KEY_EMAIL]) != 0)) {
201203
// username matched but email did not
204+
// phpcs:ignore Magento2.Exceptions.DirectThrow
202205
throw new \Exception(
203206
'An existing user has the given username but different email. '
204207
. 'Username and email both need to match an existing user or both be new.'
@@ -236,30 +239,30 @@ private function saveAdminUserRole($adminId)
236239
}
237240

238241
/**
239-
* Gets the "Administrators" role id, the special role created by data fixture in Authorization module.
242+
* Gets an administrators role id, the special role created by data fixture in Authorization module.
240243
*
241-
* @return int The id of the Administrators role
242-
* @throws \Exception If Administrators role not found or problem connecting with database.
244+
* @return int The id of an administrators role
245+
* @throws \Exception If an administrators role not found or problem connecting with database.
243246
*/
244247
private function retrieveAdministratorsRoleId()
245248
{
246-
// Get Administrators role id to use as parent_id
249+
// Get an administrators role id to use as parent_id
247250
$administratorsRoleData = [
248251
'parent_id' => 0,
249252
'tree_level' => 1,
250253
'role_type' => Group::ROLE_TYPE,
251254
'user_id' => 0,
252255
'user_type' => UserContextInterface::USER_TYPE_ADMIN,
253-
'role_name' => 'Administrators',
254256
];
255257
$result = $this->connection->fetchRow(
256258
'SELECT * FROM ' . $this->getTableName('authorization_role') . ' ' .
257259
'WHERE parent_id = :parent_id AND tree_level = :tree_level AND role_type = :role_type AND ' .
258-
'user_id = :user_id AND user_type = :user_type AND role_name = :role_name',
260+
'user_id = :user_id AND user_type = :user_type ORDER BY sort_order DESC',
259261
$administratorsRoleData
260262
);
261263
if (empty($result)) {
262-
throw new \Exception('No Administrators role was found, data fixture needs to be run');
264+
// phpcs:ignore Magento2.Exceptions.DirectThrow
265+
throw new \Exception('No administrators role was found, data fixture needs to be run');
263266
} else {
264267
// Found at least one, use first
265268
return $result['role_id'];

setup/src/Magento/Setup/Test/Unit/Model/AdminAccountTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,13 @@ public function testSaveUserExistsNewAdminRole(): void
180180
'SELECT * FROM ' . $this->prefix .
181181
'authorization_role WHERE parent_id = :parent_id AND tree_level = :tree_level ' .
182182
'AND role_type = :role_type AND user_id = :user_id ' .
183-
'AND user_type = :user_type AND role_name = :role_name',
183+
'AND user_type = :user_type ORDER BY sort_order DESC',
184184
[
185185
'parent_id' => 0,
186186
'tree_level' => 1,
187187
'role_type' => 'G',
188188
'user_id' => 0,
189189
'user_type' => 2,
190-
'role_name' => 'Administrators',
191190
],
192191
null,
193192
$administratorRoleData
@@ -298,14 +297,13 @@ public function testSaveNewUserNewAdminRole(): void
298297
'SELECT * FROM ' . $this->prefix .
299298
'authorization_role WHERE parent_id = :parent_id AND tree_level = :tree_level ' .
300299
'AND role_type = :role_type AND user_id = :user_id ' .
301-
'AND user_type = :user_type AND role_name = :role_name',
300+
'AND user_type = :user_type ORDER BY sort_order DESC',
302301
[
303302
'parent_id' => 0,
304303
'tree_level' => 1,
305304
'role_type' => 'G',
306305
'user_id' => 0,
307306
'user_type' => 2,
308-
'role_name' => 'Administrators',
309307
],
310308
null,
311309
$administratorRoleData
@@ -375,7 +373,7 @@ public function testSaveExceptionEmailNotMatch(): void
375373
public function testSaveExceptionSpecialAdminRoleNotFound(): void
376374
{
377375
$this->expectException('Exception');
378-
$this->expectExceptionMessage('No Administrators role was found, data fixture needs to be run');
376+
$this->expectExceptionMessage('No administrators role was found, data fixture needs to be run');
379377
$this->dbAdapter->expects($this->exactly(3))->method('fetchRow')->willReturn([]);
380378
$this->dbAdapter->expects($this->once())->method('lastInsertId')->willReturn(1);
381379

0 commit comments

Comments
 (0)