setquota.php 2.2 KB

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