Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit 2e3cca8

Browse files
committed
Users and groups deletion: use UsersService and RolesService instead of deleting directly in db to fix caching issues.
1 parent eb1112a commit 2e3cca8

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

core/src/core/src/pydio/Core/Services/UsersService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ public static function deleteUser($userId)
452452
foreach ($subUsers as $deletedUser) {
453453
$authDriver->deleteUser($deletedUser);
454454
}
455+
CacheService::delete(AJXP_CACHE_SERVICE_NS_SHARED, "pydio:user:".$userId);
455456
Controller::applyHook("user.after_delete", array($ctx, $userId));
456457
Logger::info(__CLASS__, "Delete User", array("user_id" => $userId, "sub_user" => implode(",", $subUsers)));
457458
return true;

core/src/plugins/conf.sql/SqlConfDriver.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use Pydio\Conf\Core\AjxpRole;
3636

3737
use Pydio\Core\Services\RepositoryService;
38+
use Pydio\Core\Services\RolesService;
3839
use Pydio\Core\Services\UsersService;
3940
use Pydio\Core\Utils\DBHelper;
4041
use Pydio\Core\Utils\Vars\InputFilter;
@@ -919,16 +920,23 @@ public function relabelGroup($groupPath, $groupLabel)
919920
*/
920921
public function deleteGroup($groupPath)
921922
{
922-
// Delete users of this group, as well as subgroups
923-
$res = dibi::query("SELECT * FROM [ajxp_users] WHERE [groupPath] LIKE %like~ OR [groupPath] = %s ORDER BY [login] ASC", $groupPath."/", $groupPath);
923+
// Delete users of this group
924+
$res = dibi::query("SELECT [login] FROM [ajxp_users] WHERE [groupPath] LIKE %like~ OR [groupPath] = %s ORDER BY [login] ASC", $groupPath."/", $groupPath);
924925
$rows = $res->fetchAll();
925-
$subUsers = array();
926926
foreach ($rows as $row) {
927-
$this->deleteUser($row["login"], $subUsers);
928-
dibi::query("DELETE FROM [ajxp_users] WHERE [login] = %s", $row["login"]);
927+
UsersService::deleteUser($row["login"]);
929928
}
929+
930+
// Delete associated roles
931+
$res = dibi::query("SELECT [groupPath] FROM [ajxp_groups] WHERE [groupPath] LIKE %like~ OR [groupPath] = %s", $groupPath."/", $groupPath);
932+
$rows = $res->fetchAll();
933+
foreach($rows as $row){
934+
RolesService::deleteRole('AJXP_GRP_'.$row['groupPath']);
935+
}
936+
937+
// Now delete groups and subgroups
930938
dibi::query("DELETE FROM [ajxp_groups] WHERE [groupPath] LIKE %like~ OR [groupPath] = %s", $groupPath."/", $groupPath);
931-
dibi::query('DELETE FROM [ajxp_roles] WHERE [role_id] = %s', 'AJXP_GRP_'.$groupPath);
939+
932940
}
933941

934942
/**
@@ -976,12 +984,12 @@ public function deleteUser($userId, &$deletedSubUsers)
976984
dibi::query('DELETE FROM [ajxp_user_prefs] WHERE [login] = %s', $userId);
977985
dibi::query('DELETE FROM [ajxp_user_bookmarks] WHERE [login] = %s', $userId);
978986
dibi::query('DELETE FROM [ajxp_user_teams] WHERE [owner_id] = %s', $userId);
979-
dibi::query('DELETE FROM [ajxp_roles] WHERE [role_id] = %s', 'AJXP_USR_/'.$userId);
980987
dibi::commit();
981988
foreach ($children as $childId) {
982989
$this->deleteUser($childId, $deletedSubUsers);
983990
$deletedSubUsers[] = $childId;
984991
}
992+
RolesService::deleteRole("AJXP_USR_/".$userId);
985993
} catch (DibiException $e) {
986994
throw new \Exception('Failed to delete user, Reason: '.$e->getMessage());
987995
}

0 commit comments

Comments
 (0)