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

Commit e5e6211

Browse files
committed
Settings "delete" action: accept multiple values parameters [] for users, workspaces, groups and roles.
1 parent 4bb318b commit e5e6211

File tree

3 files changed

+70
-33
lines changed

3 files changed

+70
-33
lines changed

core/src/plugins/access.ajxp_conf/src/RepositoriesManager.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -718,15 +718,26 @@ public function delete(ServerRequestInterface $requestInterface, ResponseInterfa
718718
$mess = LocaleService::getMessages();
719719
$httpVars = $requestInterface->getParsedBody();
720720

721-
$repId = InputFilter::sanitize(isSet($httpVars["workspaceId"]) ? $httpVars["workspaceId"] : $httpVars["repository_id"]);
722-
$repo = RepositoryService::findRepositoryByIdOrAlias($repId);
723-
if(!is_object($repo)){
724-
$res = -1;
725-
}else{
726-
$res = RepositoryService::deleteRepository($repId);
721+
$repositories = "";
722+
if(isSet($httpVars["repository_id"])) $repositories = $httpVars["repository_id"];
723+
else if(isSet($httpVars["workspaceId"])) $repositories = $httpVars["workspaceId"];
724+
if(!is_array($repositories)){
725+
$repositories = [$repositories];
727726
}
728-
if ($res == -1) {
729-
throw new PydioException($mess[427]);
727+
$repositories = array_map(function($r){
728+
return InputFilter::sanitize($r, InputFilter::SANITIZE_ALPHANUM);
729+
}, $repositories);
730+
731+
foreach($repositories as $repId){
732+
$repo = RepositoryService::findRepositoryByIdOrAlias($repId);
733+
if(!is_object($repo)){
734+
$res = -1;
735+
}else{
736+
$res = RepositoryService::deleteRepository($repId);
737+
}
738+
if ($res == -1) {
739+
throw new PydioException($mess[427]);
740+
}
730741
}
731742

732743
$message = new UserMessage($mess["ajxp_conf.59"]);

core/src/plugins/access.ajxp_conf/src/RolesManager.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,20 @@ public function delete(ServerRequestInterface $requestInterface, ResponseInterfa
506506

507507
$mess = LocaleService::getMessages();
508508
$httpVars = $requestInterface->getParsedBody();
509-
510-
$roleId = InputFilter::sanitize(isSet($httpVars["roleId"]) ? $httpVars["roleId"] : $httpVars["role_id"], InputFilter::SANITIZE_DIRNAME);
511-
if (RolesService::getRole($roleId) === false) {
512-
throw new PydioException($mess["ajxp_conf.67"]);
509+
$roles = "";
510+
if(isSet($httpVars["role_id"])) $roles = $httpVars["role_id"];
511+
else if(isSet($httpVars["roleId"])) $roles = $httpVars["roleId"];
512+
if(!is_array($roles)){
513+
$roles = [$roles];
514+
}
515+
516+
foreach($roles as $roleId){
517+
$roleId = InputFilter::sanitize($roleId);
518+
if (RolesService::getRole($roleId) === false) {
519+
throw new PydioException($mess["ajxp_conf.67"]);
520+
}
521+
RolesService::deleteRole($roleId);
513522
}
514-
RolesService::deleteRole($roleId);
515523

516524
$message = new UserMessage($mess["ajxp_conf.68"]);
517525
$reload = new ReloadMessage();

core/src/plugins/access.ajxp_conf/src/UsersManager.php

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -662,29 +662,47 @@ public function usersActions(ServerRequestInterface $requestInterface, ResponseI
662662
*/
663663
public function delete(ServerRequestInterface $requestInterface, ResponseInterface $responseInterface){
664664

665-
$mess = LocaleService::getMessages();
666-
$httpVars = $requestInterface->getParsedBody();
667665
/** @var ContextInterface $ctx */
668-
$ctx = $requestInterface->getAttribute("ctx");
669-
670-
if (isSet($httpVars["group"])) {
671-
672-
$groupPath = $httpVars["group"];
673-
$groupPath = preg_replace('/^\/data\/users/', '', $groupPath);
674-
$basePath = PathUtils::forwardSlashDirname($groupPath);
675-
$basePath = ($ctx->hasUser() ? $ctx->getUser()->getRealGroupPath($basePath) : $basePath);
676-
$gName = basename($groupPath);
677-
UsersService::deleteGroup($basePath, $gName);
678-
679-
$resultMessage = $mess["ajxp_conf.128"];
666+
$ctx = $requestInterface->getAttribute("ctx");
667+
$mess = LocaleService::getMessages();
668+
$httpVars = $requestInterface->getParsedBody();
669+
$groups = [];
670+
$users = [];
671+
if(isSet($httpVars['group'])) {
672+
if(is_array($httpVars['group'])) $groups = $httpVars['group'];
673+
else $groups[] = $httpVars['group'];
674+
$groups = array_map(function ($g) {
675+
return InputFilter::sanitize($g, InputFilter::SANITIZE_DIRNAME);
676+
}, $groups);
677+
}else if(isSet($httpVars['user_id'])) {
678+
if(is_array($httpVars['user_id']))$users = $httpVars['user_id'];
679+
else $users[] = $httpVars['user_id'];
680+
$users = array_map(function ($u) {
681+
return InputFilter::sanitize($u, InputFilter::SANITIZE_EMAILCHARS);
682+
}, $users);
683+
}
684+
$resultMessage ='';
685+
if (count($groups)) {
686+
foreach($groups as $groupPath){
687+
$groupPath = preg_replace('/^\/data\/users/', '', $groupPath);
688+
if(empty($groupPath)){
689+
throw new PydioException("Oups trying to delete top-level role, there must be something wrong!");
690+
}
691+
$basePath = PathUtils::forwardSlashDirname($groupPath);
692+
$basePath = ($ctx->hasUser() ? $ctx->getUser()->getRealGroupPath($basePath) : $basePath);
693+
$gName = basename($groupPath);
694+
UsersService::deleteGroup($basePath, $gName);
695+
}
696+
$resultMessage = $mess["ajxp_conf.128"] . " (".count($groups).")";
697+
} else if(count($users)) {
680698

681-
} else {
682-
if(empty($httpVars["user_id"]) || UsersService::isReservedUserId($httpVars["user_id"])
683-
|| $ctx->getUser()->getId() === $httpVars["user_id"]) {
684-
throw new PydioException($mess["ajxp_conf.61"]);
699+
foreach($users as $userId){
700+
if(UsersService::isReservedUserId($userId) || $ctx->getUser()->getId() === $userId) {
701+
throw new PydioException($mess["ajxp_conf.61"]);
702+
}
703+
UsersService::deleteUser($userId);
685704
}
686-
UsersService::deleteUser($httpVars["user_id"]);
687-
$resultMessage = $mess["ajxp_conf.60"];
705+
$resultMessage = $mess["ajxp_conf.60"] . " (".count($users).")";
688706
}
689707

690708
$message = new UserMessage($resultMessage);

0 commit comments

Comments
 (0)