diff options
author | C. Montero Luque <cmonteroluque@users.noreply.github.com> | 2016-02-09 22:00:24 +0100 |
---|---|---|
committer | C. Montero Luque <cmonteroluque@users.noreply.github.com> | 2016-02-09 22:00:24 +0100 |
commit | 962d0c3290fc5b881c579d553373f3facaa3ab3e (patch) | |
tree | 90764075266a7708ba5ef899a5bdd4e60cbb03be /lib | |
parent | a39c7591d6b0bfcb323cd14a5c1164576eaf7559 (diff) | |
parent | 03d0fb4e3f9734b36e015baa90901b222d03689c (diff) | |
download | nextcloud-server-962d0c3290fc5b881c579d553373f3facaa3ab3e.tar.gz nextcloud-server-962d0c3290fc5b881c579d553373f3facaa3ab3e.zip |
Merge pull request #22252 from owncloud/consolidate-user-set-quota
Consolidate getQuota and setQuota methods in User instance
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/avatar.php | 4 | ||||
-rw-r--r-- | lib/private/server.php | 4 | ||||
-rw-r--r-- | lib/private/user/user.php | 39 | ||||
-rw-r--r-- | lib/private/util.php | 6 | ||||
-rw-r--r-- | lib/public/iuser.php | 19 |
5 files changed, 59 insertions, 13 deletions
diff --git a/lib/private/avatar.php b/lib/private/avatar.php index ef7d99fd292..bf25fd3a551 100644 --- a/lib/private/avatar.php +++ b/lib/private/avatar.php @@ -121,7 +121,7 @@ class Avatar implements IAvatar { $this->remove(); $this->folder->newFile('avatar.'.$type)->putContent($data); - $this->user->triggerChange(); + $this->user->triggerChange('avatar'); } /** @@ -137,7 +137,7 @@ class Avatar implements IAvatar { $avatar->delete(); } } - $this->user->triggerChange(); + $this->user->triggerChange('avatar'); } /** diff --git a/lib/private/server.php b/lib/private/server.php index 0d1bed4e7d2..b52c5188a7b 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -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, $value) { /** @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, 'value' => $value)); }); return $userSession; }); diff --git a/lib/private/user/user.php b/lib/private/user/user.php index 516c1d443c6..cd9991796ec 100644 --- a/lib/private/user/user.php +++ b/lib/private/user/user.php @@ -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', $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', $mailAddress); } /** @@ -339,6 +340,36 @@ class User implements IUser { } /** + * 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', $quota); + } + + /** * get the avatar image if it exists * * @param int $size @@ -386,9 +417,9 @@ class User implements IUser { return $url; } - public function triggerChange() { + public function triggerChange($feature, $value = null) { if ($this->emitter) { - $this->emitter->emit('\OC\User', 'changeUser', array($this)); + $this->emitter->emit('\OC\User', 'changeUser', array($this, $feature, $value)); } } diff --git a/lib/private/util.php b/lib/private/util.php index 28541eff773..6e15d742bed 100644 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -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{ diff --git a/lib/public/iuser.php b/lib/public/iuser.php index 454d45eae76..8dbec43d3c1 100644 --- a/lib/public/iuser.php +++ b/lib/public/iuser.php @@ -178,4 +178,23 @@ interface IUser { * @since 9.0.0 */ public function setEMailAddress($mailAddress); + + /** + * get the users' quota in human readable form. If a specific quota is not + * set for the user, the default value is returned. If a default setting + * was not set otherwise, it is return as 'none', i.e. quota is not limited. + * + * @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); } |