users.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Bart Visscher <bartv@thisnet.nl>
  7. * @author Clark Tomlinson <fallen013@gmail.com>
  8. * @author Daniel Molkentin <daniel@molkentin.de>
  9. * @author Georg Ehrke <oc.list@georgehrke.com>
  10. * @author Jakob Sack <mail@jakobsack.de>
  11. * @author Joas Schilling <coding@schilljs.com>
  12. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  13. * @author Lukas Reschke <lukas@statuscode.ch>
  14. * @author Morris Jobke <hey@morrisjobke.de>
  15. * @author Robin Appelman <robin@icewind.nl>
  16. * @author Roeland Jago Douma <roeland@famdouma.nl>
  17. * @author Stephan Peijnik <speijnik@anexia-it.com>
  18. * @author Thomas Müller <thomas.mueller@tmit.eu>
  19. * @author Thomas Pulzer <t.pulzer@kniel.de>
  20. *
  21. * @license AGPL-3.0
  22. *
  23. * This code is free software: you can redistribute it and/or modify
  24. * it under the terms of the GNU Affero General Public License, version 3,
  25. * as published by the Free Software Foundation.
  26. *
  27. * This program is distributed in the hope that it will be useful,
  28. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. * GNU Affero General Public License for more details.
  31. *
  32. * You should have received a copy of the GNU Affero General Public License, version 3,
  33. * along with this program. If not, see <http://www.gnu.org/licenses/>
  34. *
  35. */
  36. OC_Util::checkSubAdminUser();
  37. \OC::$server->getNavigationManager()->setActiveEntry('core_users');
  38. $userManager = \OC::$server->getUserManager();
  39. $groupManager = \OC::$server->getGroupManager();
  40. $appManager = \OC::$server->getAppManager();
  41. // Set the sort option: SORT_USERCOUNT or SORT_GROUPNAME
  42. $sortGroupsBy = \OC\Group\MetaData::SORT_USERCOUNT;
  43. $config = \OC::$server->getConfig();
  44. if ($config->getSystemValue('sort_groups_by_name', false)) {
  45. $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
  46. } else {
  47. $isLDAPUsed = false;
  48. if ($appManager->isEnabledForUser('user_ldap')) {
  49. $isLDAPUsed =
  50. $groupManager->isBackendUsed('\OCA\User_LDAP\Group_LDAP')
  51. || $groupManager->isBackendUsed('\OCA\User_LDAP\Group_Proxy');
  52. if ($isLDAPUsed) {
  53. // LDAP user count can be slow, so we sort by group name here
  54. $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
  55. }
  56. }
  57. }
  58. $uid = \OC_User::getUser();
  59. $isAdmin = OC_User::isAdminUser($uid);
  60. $isDisabled = true;
  61. $user = $userManager->get($uid);
  62. if ($user) {
  63. $isDisabled = !$user->isEnabled();
  64. }
  65. $groupsInfo = new \OC\Group\MetaData(
  66. $uid,
  67. $isAdmin,
  68. $groupManager,
  69. \OC::$server->getUserSession()
  70. );
  71. $groupsInfo->setSorting($sortGroupsBy);
  72. list($adminGroup, $groups) = $groupsInfo->get();
  73. $recoveryAdminEnabled = $appManager->isEnabledForUser('encryption') &&
  74. $config->getAppValue( 'encryption', 'recoveryAdminEnabled', '0');
  75. if($isAdmin) {
  76. $subAdmins = \OC::$server->getGroupManager()->getSubAdmin()->getAllSubAdmins();
  77. // New class returns IUser[] so convert back
  78. $result = [];
  79. foreach ($subAdmins as $subAdmin) {
  80. $result[] = [
  81. 'gid' => $subAdmin['group']->getGID(),
  82. 'uid' => $subAdmin['user']->getUID(),
  83. ];
  84. }
  85. $subAdmins = $result;
  86. }else{
  87. /* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */
  88. $gids = array();
  89. foreach($groups as $group) {
  90. if (isset($group['id'])) {
  91. $gids[] = $group['id'];
  92. }
  93. }
  94. $subAdmins = false;
  95. }
  96. $disabledUsers = $isLDAPUsed ? 0 : $userManager->countDisabledUsers();
  97. $disabledUsersGroup = [
  98. 'id' => '_disabledUsers',
  99. 'name' => '_disabledUsers',
  100. 'usercount' => $disabledUsers
  101. ];
  102. // load preset quotas
  103. $quotaPreset=$config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
  104. $quotaPreset=explode(',', $quotaPreset);
  105. foreach($quotaPreset as &$preset) {
  106. $preset=trim($preset);
  107. }
  108. $quotaPreset=array_diff($quotaPreset, array('default', 'none'));
  109. $defaultQuota=$config->getAppValue('files', 'default_quota', 'none');
  110. $defaultQuotaIsUserDefined=array_search($defaultQuota, $quotaPreset)===false
  111. && array_search($defaultQuota, array('none', 'default'))===false;
  112. \OC::$server->getEventDispatcher()->dispatch('OC\Settings\Users::loadAdditionalScripts');
  113. $tmpl = new OC_Template("settings", "users/main", "user");
  114. $tmpl->assign('groups', $groups);
  115. $tmpl->assign('sortGroups', $sortGroupsBy);
  116. $tmpl->assign('adminGroup', $adminGroup);
  117. $tmpl->assign('disabledUsersGroup', $disabledUsersGroup);
  118. $tmpl->assign('isAdmin', (int)$isAdmin);
  119. $tmpl->assign('subadmins', $subAdmins);
  120. $tmpl->assign('numofgroups', count($groups) + count($adminGroup));
  121. $tmpl->assign('quota_preset', $quotaPreset);
  122. $tmpl->assign('default_quota', $defaultQuota);
  123. $tmpl->assign('defaultQuotaIsUserDefined', $defaultQuotaIsUserDefined);
  124. $tmpl->assign('recoveryAdminEnabled', $recoveryAdminEnabled);
  125. $tmpl->assign('show_storage_location', $config->getAppValue('core', 'umgmt_show_storage_location', 'false'));
  126. $tmpl->assign('show_last_login', $config->getAppValue('core', 'umgmt_show_last_login', 'false'));
  127. $tmpl->assign('show_email', $config->getAppValue('core', 'umgmt_show_email', 'false'));
  128. $tmpl->assign('show_backend', $config->getAppValue('core', 'umgmt_show_backend', 'false'));
  129. $tmpl->assign('send_email', $config->getAppValue('core', 'umgmt_send_email', 'false'));
  130. $tmpl->printPage();