Skip to content

Commit 3bccc73

Browse files
author
Cari Spruiell
committed
Merge remote-tracking branch 'api/MAGETWO-54231-Broken-Integration' into pull-request
2 parents a5cd7c8 + bc86310 commit 3bccc73

File tree

1 file changed

+20
-9
lines changed
  • app/code/Magento/User/Model/ResourceModel

1 file changed

+20
-9
lines changed

app/code/Magento/User/Model/ResourceModel/User.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $user)
186186
*/
187187
public function _clearUserRoles(ModelUser $user)
188188
{
189-
$conditions = ['user_id = ?' => (int)$user->getId()];
189+
$conditions = ['user_id = ?' => (int)$user->getId(), 'user_type = ?' => UserContextInterface::USER_TYPE_ADMIN];
190190
$this->getConnection()->delete($this->getTable('authorization_role'), $conditions);
191191
}
192192

@@ -255,13 +255,13 @@ public function delete(\Magento\Framework\Model\AbstractModel $user)
255255
$uid = $user->getId();
256256
$connection->beginTransaction();
257257
try {
258-
$conditions = ['user_id = ?' => $uid];
259-
260-
$connection->delete($this->getMainTable(), $conditions);
261-
$connection->delete($this->getTable('authorization_role'), $conditions);
258+
$connection->delete($this->getMainTable(), ['user_id = ?' => $uid]);
259+
$connection->delete(
260+
$this->getTable('authorization_role'),
261+
['user_id = ?' => $uid, 'user_type = ?' => UserContextInterface::USER_TYPE_ADMIN]
262+
);
262263
} catch (\Magento\Framework\Exception\LocalizedException $e) {
263264
throw $e;
264-
return false;
265265
} catch (\Exception $e) {
266266
$connection->rollBack();
267267
return false;
@@ -329,7 +329,11 @@ public function deleteFromRole(\Magento\Framework\Model\AbstractModel $user)
329329

330330
$dbh = $this->getConnection();
331331

332-
$condition = ['user_id = ?' => (int)$user->getId(), 'parent_id = ?' => (int)$user->getRoleId()];
332+
$condition = [
333+
'user_id = ?' => (int)$user->getId(),
334+
'parent_id = ?' => (int)$user->getRoleId(),
335+
'user_type = ?' => UserContextInterface::USER_TYPE_ADMIN
336+
];
333337

334338
$dbh->delete($this->getTable('authorization_role'), $condition);
335339
return $this;
@@ -348,9 +352,16 @@ public function roleUserExists(\Magento\Framework\Model\AbstractModel $user)
348352

349353
$dbh = $this->getConnection();
350354

351-
$binds = ['parent_id' => $user->getRoleId(), 'user_id' => $user->getUserId()];
355+
$binds = [
356+
'parent_id' => $user->getRoleId(),
357+
'user_id' => $user->getUserId(),
358+
'user_type' => UserContextInterface::USER_TYPE_ADMIN
359+
];
352360

353-
$select = $dbh->select()->from($roleTable)->where('parent_id = :parent_id')->where('user_id = :user_id');
361+
$select = $dbh->select()->from($roleTable)
362+
->where('parent_id = :parent_id')
363+
->where('user_type = :user_type')
364+
->where('user_id = :user_id');
354365

355366
return $dbh->fetchCol($select, $binds);
356367
} else {

0 commit comments

Comments
 (0)