]> source.dussan.org Git - nextcloud-server.git/commitdiff
Consolidate getQuota and setQuota methods in User instance
authorArthur Schiwon <blizzz@owncloud.com>
Tue, 9 Feb 2016 16:16:43 +0000 (17:16 +0100)
committerArthur Schiwon <blizzz@owncloud.com>
Tue, 9 Feb 2016 16:16:43 +0000 (17:16 +0100)
apps/files_trashbin/lib/trashbin.php
apps/files_versions/lib/storage.php
apps/provisioning_api/lib/users.php
apps/user_ldap/lib/user/user.php
lib/private/server.php
lib/private/user/user.php
lib/private/util.php
lib/public/iuser.php
settings/ajax/setquota.php
settings/controller/userscontroller.php

index ca3a8b178a20460c53ebf0229c69ff98a8d948a7..c91cfe082fdd907573b32c4dbd98a4c16b53acaa 100644 (file)
@@ -564,11 +564,8 @@ class Trashbin {
                $config = \OC::$server->getConfig();
 
                $softQuota = true;
-               $quota = $config->getUserValue($user, 'files', 'quota', null);
+               $quota = \OC::$server->getUserManager()->get($user)->getQuota();
                $view = new \OC\Files\View('/' . $user);
-               if ($quota === null || $quota === 'default') {
-                       $quota = $config->getAppValue('files', 'default_quota', null);
-               }
                if ($quota === null || $quota === 'none') {
                        $quota = \OC\Files\Filesystem::free_space('/');
                        $softQuota = false;
index 88a4126dabdfd1a3cfa77ea670e6afddc7aa97c3..47acec1d7634ae77b043ecc1787e018db8d872f7 100644 (file)
@@ -653,11 +653,9 @@ class Storage {
                        $versionsFileview = new \OC\Files\View('/'.$uid.'/files_versions');
 
                        // get available disk space for user
+                       $user = \OC::$server->getUserManager()->get($uid);
                        $softQuota = true;
-                       $quota = $config->getUserValue($uid, 'files', 'quota', null);
-                       if ( $quota === null || $quota === 'default') {
-                               $quota = $config->getAppValue('files', 'default_quota', null);
-                       }
+                       $quota = $user->getQuota();
                        if ( $quota === null || $quota === 'none' ) {
                                $quota = \OC\Files\Filesystem::free_space('/');
                                $softQuota = false;
index efb10a508658421ffa15c99b4c508d863298e71e..c609c7bd849d6b7d31094d88574b9f812cc8f3de 100644 (file)
@@ -278,7 +278,7 @@ class Users {
                                                $quota = \OCP\Util::humanFileSize($quota);
                                        }
                                }
-                               $this->config->setUserValue($targetUserId, 'files', 'quota', $quota);
+                               $targetUser->setQuota($quota);
                                break;
                        case 'password':
                                $targetUser->setPassword($parameters['_put']['value']);
index 3bc790a6c109fdf8156789449c0f52bb6832f35b..8b70c9e237404ab53c675a2e11e60374b2a81769 100644 (file)
@@ -456,7 +456,7 @@ class User {
                        }
                }
                if(!is_null($quota)) {
-                       $this->config->setUserValue($this->uid, 'files', 'quota', $quota);
+                       $user = $this->userManager->get($this->uid)->setQuota($quota);
                }
        }
 
index 0d1bed4e7d227bcf1e8dbde0ee01a24949431f1f..9dfae86009097a0bd93be4fac25fd419941f14b6 100644 (file)
@@ -244,9 +244,9 @@ class Server extends ServerContainer implements IServerContainer {
                        $userSession->listen('\OC\User', 'logout', function () {
                                \OC_Hook::emit('OC_User', 'logout', array());
                        });
-                       $userSession->listen('\OC\User', 'changeUser', function ($user) {
+                       $userSession->listen('\OC\User', 'changeUser', function ($user, $feature) {
                                /** @var $user \OC\User\User */
-                               \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user));
+                               \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature));
                        });
                        return $userSession;
                });
index 516c1d443c6553809a4a4f12da0ec70ea69544d7..0f230d468fdc3268579126193d1531883d95331e 100644 (file)
@@ -30,6 +30,7 @@
 namespace OC\User;
 
 use OC\Hooks\Emitter;
+use OC_Helper;
 use OCP\IAvatarManager;
 use OCP\IImage;
 use OCP\IURLGenerator;
@@ -140,7 +141,7 @@ class User implements IUser {
                        $result = $this->backend->setDisplayName($this->uid, $displayName);
                        if ($result) {
                                $this->displayName = $displayName;
-                               $this->triggerChange();
+                               $this->triggerChange('displayName');
                        }
                        return $result !== false;
                } else {
@@ -161,7 +162,7 @@ class User implements IUser {
                } else {
                        $this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress);
                }
-               $this->triggerChange();
+               $this->triggerChange('eMailAddress');
        }
 
        /**
@@ -338,6 +339,36 @@ class User implements IUser {
                return $this->config->getUserValue($this->uid, 'settings', 'email', null);
        }
 
+       /**
+        * get the users' quota
+        *
+        * @return string
+        * @since 9.0.0
+        */
+       public function getQuota() {
+               $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default');
+               if($quota === 'default') {
+                       $quota = $this->config->getAppValue('files', 'default_quota', 'none');
+               }
+               return $quota;
+       }
+
+       /**
+        * set the users' quota
+        *
+        * @param string $quota
+        * @return void
+        * @since 9.0.0
+        */
+       public function setQuota($quota) {
+               if($quota !== 'none' and $quota !== 'default') {
+                       $quota= OC_Helper::computerFileSize($quota);
+                       $quota=OC_Helper::humanFileSize($quota);
+               }
+               $this->config->setUserValue($this->uid, 'files', 'quota', $quota);
+               $this->triggerChange('quota');
+       }
+
        /**
         * get the avatar image if it exists
         *
@@ -386,9 +417,9 @@ class User implements IUser {
                return $url;
        }
 
-       public function triggerChange() {
+       public function triggerChange($feature) {
                if ($this->emitter) {
-                       $this->emitter->emit('\OC\User', 'changeUser', array($this));
+                       $this->emitter->emit('\OC\User', 'changeUser', array($this, $feature));
                }
        }
 
index 28541eff773b37b86b056b2efa277b333908cfc4..6e15d742bed18986185e967cd35c6b7d7177ad9a 100644 (file)
@@ -285,11 +285,7 @@ class OC_Util {
         * @return int Quota bytes
         */
        public static function getUserQuota($user) {
-               $config = \OC::$server->getConfig();
-               $userQuota = $config->getUserValue($user, 'files', 'quota', 'default');
-               if ($userQuota === 'default') {
-                       $userQuota = $config->getAppValue('files', 'default_quota', 'none');
-               }
+               $userQuota = \OC::$server->getUserManager()->get($user)->getQuota();
                if($userQuota === 'none') {
                        return \OCP\Files\FileInfo::SPACE_UNLIMITED;
                }else{
index 454d45eae76b250ed5bb4ca01b88e3c86a54f9b2..2d2a2710bf8c6b14b5af33798c882fd84d058b8c 100644 (file)
@@ -178,4 +178,21 @@ interface IUser {
         * @since 9.0.0
         */
        public function setEMailAddress($mailAddress);
+
+       /**
+        * get the users' quota
+        *
+        * @return string
+        * @since 9.0.0
+        */
+       public function getQuota();
+
+       /**
+        * set the users' quota
+        *
+        * @param string $quota
+        * @return void
+        * @since 9.0.0
+        */
+       public function setQuota($quota);
 }
index dbdfb98bc8c8345a1cfb96a37dbd9ca699227db5..94fd7bd1e2b411f5f252285f8c84cd3a6f6cab11 100644 (file)
@@ -56,7 +56,7 @@ if($quota !== 'none' and $quota !== 'default') {
 
 // Return Success story
 if($username) {
-       \OC::$server->getConfig()->setUserValue($username, 'files', 'quota', $quota);
+       $targetUserObject->setQuota($quota);
 }else{//set the default quota when no username is specified
        if($quota === 'default') {//'default' as default quota makes no sense
                $quota='none';
index 17629fe924fc7e443bc9980eab031137d1a090f0..3e5455751abf8a86e02680c71abf0e67a8f26477 100644 (file)
@@ -184,7 +184,7 @@ class UsersController extends Controller {
                        'displayname' => $user->getDisplayName(),
                        'groups' => (empty($userGroups)) ? $this->groupManager->getUserGroupIds($user) : $userGroups,
                        'subadmin' => $subAdminGroups,
-                       'quota' => $this->config->getUserValue($user->getUID(), 'files', 'quota', 'default'),
+                       'quota' => $user->getQuota(),
                        'storageLocation' => $user->getHome(),
                        'lastLogin' => $user->getLastLogin() * 1000,
                        'backend' => $user->getBackendClassName(),