Merge branch 'MDL-49425-master' of git://github.com/jleyva/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 24 Mar 2015 23:39:39 +0000 (00:39 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 24 Mar 2015 23:39:39 +0000 (00:39 +0100)
webservice/externallib.php
webservice/tests/externallib_test.php

index da4ce3e..f26c949 100644 (file)
@@ -76,8 +76,9 @@ class core_webservice_external extends external_api {
         $params = self::validate_parameters(self::get_site_info_parameters(),
                       array('serviceshortnames'=>$serviceshortnames));
 
+        $context = context_user::instance($USER->id);
         $profileimageurl = moodle_url::make_pluginfile_url(
-                context_user::instance($USER->id)->id, 'user', 'icon', null, '/', 'f1');
+                $context->id, 'user', 'icon', null, '/', 'f1');
 
         // Site information.
         $siteinfo =  array(
@@ -177,6 +178,18 @@ class core_webservice_external extends external_api {
             'value' => ($CFG->mnet_dispatcher_mode == 'strict') ? 1 : 0
         );
 
+        // User can manage own files.
+        $siteinfo['usercanmanageownfiles'] = has_capability('moodle/user:manageownfiles', $context);
+
+        // User quota. 0 means user can ignore the quota.
+        $siteinfo['userquota'] = 0;
+        if (!has_capability('moodle/user:ignoreuserquota', $context)) {
+            $siteinfo['userquota'] = $CFG->userquota;
+        }
+
+        // User max upload file size. -1 means the user can ignore the upload file size.
+        $siteinfo['usermaxuploadfilesize'] = get_user_max_upload_file_size($context, $CFG->maxbytes);
+
         return $siteinfo;
     }
 
@@ -228,7 +241,14 @@ class core_webservice_external extends external_api {
                     ),
                     'Advanced features availability',
                     VALUE_OPTIONAL
-                )
+                ),
+                'usercanmanageownfiles' => new external_value(PARAM_BOOL,
+                                            'true if the user can manage his own files', VALUE_OPTIONAL),
+                'userquota' => new external_value(PARAM_INT,
+                                    'user quota (bytes). 0 means user can ignore the quota', VALUE_OPTIONAL),
+                'usermaxuploadfilesize' => new external_value(PARAM_INT,
+                                            'user max upload file size (bytes). -1 means the user can ignore the upload file size',
+                                            VALUE_OPTIONAL)
             )
         );
     }
index 801679d..9e1b0a9 100644 (file)
@@ -47,6 +47,11 @@ class core_webservice_externallib_testcase extends externallib_advanced_testcase
         set_config('release', '2.4dev (Build: 20120823)');
         set_config('version', '2012083100.00');
 
+        $maxbytes = 10485760;
+        $userquota = 5242880;
+        set_config('maxbytes', $maxbytes);
+        set_config('userquota', $userquota);
+
         // Set current user
         $user = array();
         $user['username'] = 'johnd';
@@ -113,6 +118,33 @@ class core_webservice_externallib_testcase extends externallib_advanced_testcase
             }
         }
 
+        $this->assertEquals($userquota, $siteinfo['userquota']);
+        $this->assertEquals($maxbytes, $siteinfo['usermaxuploadfilesize']);
+        $this->assertEquals(true, $siteinfo['usercanmanageownfiles']);
+
+        // Now as admin.
+        $this->setAdminUser();
+
+        // Set a fake token for the user admin.
+        $_POST['wstoken'] = 'testtoken';
+        $externaltoken = new stdClass();
+        $externaltoken->token = 'testtoken';
+        $externaltoken->tokentype = 0;
+        $externaltoken->userid = $USER->id;
+        $externaltoken->externalserviceid = $externalserviceid;
+        $externaltoken->contextid = 1;
+        $externaltoken->creatorid = $USER->id;
+        $externaltoken->timecreated = time();
+        $DB->insert_record('external_tokens', $externaltoken);
+        $siteinfo = core_webservice_external::get_site_info();
+
+        // We need to execute the return values cleaning process to simulate the web service server.
+        $siteinfo = external_api::clean_returnvalue(core_webservice_external::get_site_info_returns(), $siteinfo);
+
+        $this->assertEquals(0, $siteinfo['userquota']);
+        $this->assertEquals(USER_CAN_IGNORE_FILE_SIZE_LIMITS, $siteinfo['usermaxuploadfilesize']);
+        $this->assertEquals(true, $siteinfo['usercanmanageownfiles']);
+
     }
 
 }