@@ -662,29 +662,47 @@ public function usersActions(ServerRequestInterface $requestInterface, ResponseI
662
662
*/
663
663
public function delete (ServerRequestInterface $ requestInterface , ResponseInterface $ responseInterface ){
664
664
665
- $ mess = LocaleService::getMessages ();
666
- $ httpVars = $ requestInterface ->getParsedBody ();
667
665
/** @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 )) {
680
698
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 );
685
704
}
686
- UsersService::deleteUser ($ httpVars ["user_id " ]);
687
- $ resultMessage = $ mess ["ajxp_conf.60 " ];
705
+ $ resultMessage = $ mess ["ajxp_conf.60 " ] . " ( " .count ($ users ).") " ;
688
706
}
689
707
690
708
$ message = new UserMessage ($ resultMessage );
0 commit comments