You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

setquota.php 2.5KB

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