@@ -186,7 +186,7 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $user)
186
186
*/
187
187
public function _clearUserRoles (ModelUser $ user )
188
188
{
189
- $ conditions = ['user_id = ? ' => (int )$ user ->getId ()];
189
+ $ conditions = ['user_id = ? ' => (int )$ user ->getId (), ' user_type = ? ' => UserContextInterface:: USER_TYPE_ADMIN ];
190
190
$ this ->getConnection ()->delete ($ this ->getTable ('authorization_role ' ), $ conditions );
191
191
}
192
192
@@ -255,13 +255,13 @@ public function delete(\Magento\Framework\Model\AbstractModel $user)
255
255
$ uid = $ user ->getId ();
256
256
$ connection ->beginTransaction ();
257
257
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
+ );
262
263
} catch (\Magento \Framework \Exception \LocalizedException $ e ) {
263
264
throw $ e ;
264
- return false ;
265
265
} catch (\Exception $ e ) {
266
266
$ connection ->rollBack ();
267
267
return false ;
@@ -329,7 +329,11 @@ public function deleteFromRole(\Magento\Framework\Model\AbstractModel $user)
329
329
330
330
$ dbh = $ this ->getConnection ();
331
331
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
+ ];
333
337
334
338
$ dbh ->delete ($ this ->getTable ('authorization_role ' ), $ condition );
335
339
return $ this ;
@@ -348,9 +352,16 @@ public function roleUserExists(\Magento\Framework\Model\AbstractModel $user)
348
352
349
353
$ dbh = $ this ->getConnection ();
350
354
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
+ ];
352
360
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 ' );
354
365
355
366
return $ dbh ->fetchCol ($ select , $ binds );
356
367
} else {
0 commit comments