Skip to content

Commit

Permalink
Merge branch 'MDL-49425-master' of git://github.com/jleyva/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Mar 24, 2015
2 parents fb42902 + 116c4a6 commit 8251b4b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
24 changes: 22 additions & 2 deletions webservice/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ public static function get_site_info($serviceshortnames = array()) {
$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(
Expand Down Expand Up @@ -177,6 +178,18 @@ public static function get_site_info($serviceshortnames = array()) {
'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;
}

Expand Down Expand Up @@ -228,7 +241,14 @@ public static function get_site_info_returns() {
),
'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)
)
);
}
Expand Down
32 changes: 32 additions & 0 deletions webservice/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public function test_get_site_info() {
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';
Expand Down Expand Up @@ -113,6 +118,33 @@ public function test_get_site_info() {
}
}

$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']);

}

}

0 comments on commit 8251b4b

Please sign in to comment.