setquota.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 Björn Schießle <bjoern@schiessle.org>
  8. * @author Christopher Schäpers <kondou@ts.unde.re>
  9. * @author Felix Moeller <mail@felixmoeller.de>
  10. * @author Georg Ehrke <georg@owncloud.com>
  11. * @author Lukas Reschke <lukas@statuscode.ch>
  12. * @author Morris Jobke <hey@morrisjobke.de>
  13. * @author Robin Appelman <robin@icewind.nl>
  14. * @author Thomas Müller <thomas.mueller@tmit.eu>
  15. *
  16. * @license AGPL-3.0
  17. *
  18. * This code is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU Affero General Public License, version 3,
  20. * as published by the Free Software Foundation.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU Affero General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Affero General Public License, version 3,
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>
  29. *
  30. */
  31. OC_JSON::checkSubAdminUser();
  32. OCP\JSON::callCheck();
  33. $username = isset($_POST["username"]) ? (string)$_POST["username"] : '';
  34. $isUserAccessible = false;
  35. $currentUserObject = \OC::$server->getUserSession()->getUser();
  36. $targetUserObject = \OC::$server->getUserManager()->get($username);
  37. if($targetUserObject !== null && $currentUserObject !== null) {
  38. $isUserAccessible = \OC::$server->getGroupManager()->getSubAdmin()->isUserAccessible($currentUserObject, $targetUserObject);
  39. }
  40. if(($username === '' && !OC_User::isAdminUser(OC_User::getUser()))
  41. || (!OC_User::isAdminUser(OC_User::getUser())
  42. && !$isUserAccessible)) {
  43. $l = \OC::$server->getL10N('core');
  44. OC_JSON::error(array( 'data' => array( 'message' => $l->t('Authentication error') )));
  45. exit();
  46. }
  47. //make sure the quota is in the expected format
  48. $quota= (string)$_POST["quota"];
  49. if($quota !== 'none' and $quota !== 'default') {
  50. $quota= OC_Helper::computerFileSize($quota);
  51. $quota=OC_Helper::humanFileSize($quota);
  52. }
  53. // Return Success story
  54. if($username) {
  55. $targetUserObject->setQuota($quota);
  56. }else{//set the default quota when no username is specified
  57. if($quota === 'default') {//'default' as default quota makes no sense
  58. $quota='none';
  59. }
  60. \OC::$server->getAppConfig()->setValue('files', 'default_quota', $quota);
  61. }
  62. OC_JSON::success(array("data" => array( "username" => $username , 'quota' => $quota)));