MDL-52586 webservices: Return the default user home page
authorJuan Leyva <juanleyvadelgado@gmail.com>
Tue, 22 Dec 2015 15:50:58 +0000 (16:50 +0100)
committerJuan Leyva <juanleyvadelgado@gmail.com>
Tue, 22 Dec 2015 15:50:58 +0000 (16:50 +0100)
webservice/externallib.php
webservice/tests/externallib_test.php

index e1d0bc8..b3dc59a 100644 (file)
@@ -193,6 +193,9 @@ class core_webservice_external extends external_api {
         // 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);
 
+        // User home page.
+        $siteinfo['userhomepage'] = get_home_page();
+
         return $siteinfo;
     }
 
@@ -251,7 +254,10 @@ class core_webservice_external extends external_api {
                                     '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)
+                                            VALUE_OPTIONAL),
+                'userhomepage' => new external_value(PARAM_INT,
+                                                        'the default home page for the user: 0 for the site home, 1 for dashboard',
+                                                        VALUE_OPTIONAL)
             )
         );
     }
index 6bb6061..5c80986 100644 (file)
@@ -124,6 +124,8 @@ class core_webservice_externallib_testcase extends externallib_advanced_testcase
         $this->assertEquals(get_max_upload_file_size($maxbytes), $siteinfo['usermaxuploadfilesize']);
         $this->assertEquals(true, $siteinfo['usercanmanageownfiles']);
 
+        $this->assertEquals(HOMEPAGE_MY, $siteinfo['userhomepage']);
+
         // Now as admin.
         $this->setAdminUser();
 
@@ -138,6 +140,11 @@ class core_webservice_externallib_testcase extends externallib_advanced_testcase
         $externaltoken->creatorid = $USER->id;
         $externaltoken->timecreated = time();
         $DB->insert_record('external_tokens', $externaltoken);
+
+        // Set a home page by user preferences.
+        $CFG->defaulthomepage = HOMEPAGE_USER;
+        set_user_preference('user_home_page_preference', HOMEPAGE_SITE);
+
         $siteinfo = core_webservice_external::get_site_info();
 
         // We need to execute the return values cleaning process to simulate the web service server.
@@ -147,6 +154,8 @@ class core_webservice_externallib_testcase extends externallib_advanced_testcase
         $this->assertEquals(USER_CAN_IGNORE_FILE_SIZE_LIMITS, $siteinfo['usermaxuploadfilesize']);
         $this->assertEquals(true, $siteinfo['usercanmanageownfiles']);
 
+        $this->assertEquals(HOMEPAGE_SITE, $siteinfo['userhomepage']);
+
     }
 
 }