userlist.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Michael Gapczynski
  6. * @copyright 2012 Michael Gapczynski mtgap@owncloud.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. OC_JSON::callCheck();
  23. OC_JSON::checkSubAdminUser();
  24. if (isset($_GET['offset'])) {
  25. $offset = $_GET['offset'];
  26. } else {
  27. $offset = 0;
  28. }
  29. if (isset($_GET['limit'])) {
  30. $limit = $_GET['limit'];
  31. } else {
  32. $limit = 10;
  33. }
  34. if (isset($_GET['gid']) && !empty($_GET['gid'])) {
  35. $gid = $_GET['gid'];
  36. if ($gid === '_everyone') {
  37. $gid = false;
  38. }
  39. } else {
  40. $gid = false;
  41. }
  42. if (isset($_GET['pattern']) && !empty($_GET['pattern'])) {
  43. $pattern = $_GET['pattern'];
  44. } else {
  45. $pattern = '';
  46. }
  47. $users = array();
  48. $userManager = \OC_User::getManager();
  49. if (OC_User::isAdminUser(OC_User::getUser())) {
  50. if($gid !== false) {
  51. $batch = OC_Group::displayNamesInGroup($gid, $pattern, $limit, $offset);
  52. } else {
  53. $batch = OC_User::getDisplayNames($pattern, $limit, $offset);
  54. }
  55. foreach ($batch as $uid => $displayname) {
  56. $user = $userManager->get($uid);
  57. $users[] = array(
  58. 'name' => $uid,
  59. 'displayname' => $displayname,
  60. 'groups' => OC_Group::getUserGroups($uid),
  61. 'subadmin' => OC_SubAdmin::getSubAdminsGroups($uid),
  62. 'quota' => OC_Preferences::getValue($uid, 'files', 'quota', 'default'),
  63. 'storageLocation' => $user->getHome(),
  64. 'lastLogin' => $user->getLastLogin(),
  65. );
  66. }
  67. } else {
  68. $groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
  69. if($gid !== false && in_array($gid, $groups)) {
  70. $groups = array($gid);
  71. } elseif($gid !== false) {
  72. //don't you try to investigate loops you must not know about
  73. $groups = array();
  74. }
  75. $batch = OC_Group::usersInGroups($groups, $pattern, $limit, $offset);
  76. foreach ($batch as $uid) {
  77. $user = $userManager->get($uid);
  78. // Only add the groups, this user is a subadmin of
  79. $userGroups = array_intersect(OC_Group::getUserGroups($uid), OC_SubAdmin::getSubAdminsGroups(OC_User::getUser()));
  80. $users[] = array(
  81. 'name' => $uid,
  82. 'displayname' => $user->getDisplayName(),
  83. 'groups' => $userGroups,
  84. 'quota' => OC_Preferences::getValue($uid, 'files', 'quota', 'default'),
  85. 'storageLocation' => $user->getHome(),
  86. 'lastLogin' => $user->getLastLogin(),
  87. );
  88. }
  89. }
  90. OC_JSON::success(array('data' => $users));