diff options
author | Frank Karlitschek <frank@owncloud.org> | 2012-07-23 19:43:28 +0200 |
---|---|---|
committer | Frank Karlitschek <frank@owncloud.org> | 2012-07-23 19:43:28 +0200 |
commit | 21631be2ff0fc1ce9181d619cfd793b5482d18b7 (patch) | |
tree | 27c4998f99148c503c035da789d09f07652c334e /lib/ocs.php | |
parent | e7e1f234dd38732c0667e46f036fd0894b54ef4b (diff) | |
download | nextcloud-server-21631be2ff0fc1ce9181d619cfd793b5482d18b7.tar.gz nextcloud-server-21631be2ff0fc1ce9181d619cfd793b5482d18b7.zip |
make it generic and implement a dummy call for quota set
Diffstat (limited to 'lib/ocs.php')
-rw-r--r-- | lib/ocs.php | 101 |
1 files changed, 74 insertions, 27 deletions
diff --git a/lib/ocs.php b/lib/ocs.php index 48f34cc6397..0cd7888fcf9 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -168,15 +168,31 @@ class OC_OCS { OC_OCS::privatedatadelete($format, $app, $key); // CLOUD - // quotaget - GET QUOTA parameter - }elseif(($method=='get') and ($ex[$paracount-5] == 'v1.php') and ($ex[$paracount-4]=='cloud') and ($ex[$paracount-3] == 'files') and ($ex[$paracount-2] == 'quota')){ - OC_OCS::quotaget($format); + // quotaget + }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'quota')){ + $user=$ex[$paracount-3]; + OC_OCS::quotaget($format,$user); + + // quotaset + }elseif(($method=='post') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'quota')){ + $user=$ex[$paracount-3]; + $quota = self::readData('post', 'quota', 'int'); + OC_OCS::quotaset($format,$user,$quota); // add more calls here // please document all the call in the draft spec // http://www.freedesktop.org/wiki/Specifications/open-collaboration-services-1.7#CLOUD +// TODO: +// users +// groups +// bookmarks +// sharing +// versioning +// news (rss) + + }else{ $txt='Invalid query, please check the syntax. API specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n"; @@ -545,35 +561,66 @@ class OC_OCS { // CLOUD API ############################################# /** - * get the quota of the current user + * get the quota of a user * @param string $format + * @param string $user * @return string xml/json */ - private static function quotaGet($format) { - $user=OC_OCS::checkpassword(); - - // calculate the disc space - $user_dir = '/'.$user.'/files'; - OC_Filesystem::init($user_dir); - $rootInfo=OC_FileCache::get(''); - $sharedInfo=OC_FileCache::get('/Shared'); - $used=$rootInfo['size']-$sharedInfo['size']; - $free=OC_Filesystem::free_space(); - $total=$free+$used; - if($total==0) $total=1; // prevent division by zero - $relative=round(($used/$total)*10000)/100; - - $xml=array(); - $xml['quota']=$total; - $xml['free']=$free; - $xml['used']=$used; - $xml['relative']=$relative; - - $txt=OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'cloud', 'full', 1, count($xml), 0); - echo($txt); - + private static function quotaGet($format,$user) { + $login=OC_OCS::checkpassword(); + if(OC_Group::inGroup($login, 'admin') or ($login==$user)) { + + if(OC_User::userExists($user)){ + // calculate the disc space + $user_dir = '/'.$user.'/files'; + OC_Filesystem::init($user_dir); + $rootInfo=OC_FileCache::get(''); + $sharedInfo=OC_FileCache::get('/Shared'); + $used=$rootInfo['size']-$sharedInfo['size']; + $free=OC_Filesystem::free_space(); + $total=$free+$used; + if($total==0) $total=1; // prevent division by zero + $relative=round(($used/$total)*10000)/100; + + $xml=array(); + $xml['quota']=$total; + $xml['free']=$free; + $xml['used']=$used; + $xml['relative']=$relative; + + $txt=OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'cloud', 'full', 1, count($xml), 0); + echo($txt); + }else{ + echo self::generateXml('', 'fail', 300, 'User does not exist'); + } + }else{ + echo self::generateXml('', 'fail', 300, 'You don´t have permission to access this ressource.'); + } } + /** + * set the quota of a user + * @param string $format + * @param string $user + * @param string $quota + * @return string xml/json + */ + private static function quotaSet($format,$user,$quota) { + $login=OC_OCS::checkpassword(); + if(OC_Group::inGroup($login, 'admin')) { + + // todo + // not yet implemented + // edit logic here + error_log('OCS call: user:'.$user.' quota:'.$quota); + + $xml=array(); + $txt=OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'cloud', 'full', 1, count($xml), 0); + echo($txt); + }else{ + echo self::generateXml('', 'fail', 300, 'You don´t have permission to access this ressource.'); + } + } } |