setquota.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * Copyright (c) 2012, Robin Appelman <icewind1991@gmail.com>
  4. * This file is licensed under the Affero General Public License version 3 or later.
  5. * See the COPYING-README file.
  6. */
  7. OC_JSON::checkSubAdminUser();
  8. OCP\JSON::callCheck();
  9. $username = isset($_POST["username"])?$_POST["username"]:'';
  10. if(($username === '' && !OC_User::isAdminUser(OC_User::getUser()))
  11. || (!OC_User::isAdminUser(OC_User::getUser())
  12. && !OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username))) {
  13. $l = OC_L10N::get('core');
  14. OC_JSON::error(array( 'data' => array( 'message' => $l->t('Authentication error') )));
  15. exit();
  16. }
  17. //make sure the quota is in the expected format
  18. $quota=$_POST["quota"];
  19. if($quota !== 'none' and $quota !== 'default') {
  20. $quota= OC_Helper::computerFileSize($quota);
  21. $quota=OC_Helper::humanFileSize($quota);
  22. }
  23. // Return Success story
  24. if($username) {
  25. OC_Preferences::setValue($username, 'files', 'quota', $quota);
  26. }else{//set the default quota when no username is specified
  27. if($quota === 'default') {//'default' as default quota makes no sense
  28. $quota='none';
  29. }
  30. OC_Appconfig::setValue('files', 'default_quota', $quota);
  31. }
  32. OC_JSON::success(array("data" => array( "username" => $username , 'quota' => $quota)));