Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
moodle
moodle
Commits
c7e7229c
Commit
c7e7229c
authored
Nov 19, 2021
by
Juan Leyva
Browse files
MDL-67807 webservice: Return concurrent sessions information
parent
eab63d2c
Changes
2
Hide whitespace changes
Inline
Side-by-side
webservice/externallib.php
View file @
c7e7229c
...
@@ -214,6 +214,12 @@ class core_webservice_external extends external_api {
...
@@ -214,6 +214,12 @@ class core_webservice_external extends external_api {
// Current theme.
// Current theme.
$siteinfo
[
'theme'
]
=
clean_param
(
$PAGE
->
theme
->
name
,
PARAM_THEME
);
// We always clean to avoid problem with old sites.
$siteinfo
[
'theme'
]
=
clean_param
(
$PAGE
->
theme
->
name
,
PARAM_THEME
);
// We always clean to avoid problem with old sites.
$siteinfo
[
'limitconcurrentlogins'
]
=
(
int
)
$CFG
->
limitconcurrentlogins
;
if
(
!
empty
(
$CFG
->
limitconcurrentlogins
))
{
// For performance, only when enabled.
$siteinfo
[
'usersessionscount'
]
=
$DB
->
count_records
(
'sessions'
,
[
'userid'
=>
$USER
->
id
]);
}
return
$siteinfo
;
return
$siteinfo
;
}
}
...
@@ -283,6 +289,9 @@ class core_webservice_external extends external_api {
...
@@ -283,6 +289,9 @@ class core_webservice_external extends external_api {
'usercalendartype'
=>
new
external_value
(
PARAM_PLUGIN
,
'Calendar typed used by the user.'
,
VALUE_OPTIONAL
),
'usercalendartype'
=>
new
external_value
(
PARAM_PLUGIN
,
'Calendar typed used by the user.'
,
VALUE_OPTIONAL
),
'userissiteadmin'
=>
new
external_value
(
PARAM_BOOL
,
'Whether the user is a site admin or not.'
,
VALUE_OPTIONAL
),
'userissiteadmin'
=>
new
external_value
(
PARAM_BOOL
,
'Whether the user is a site admin or not.'
,
VALUE_OPTIONAL
),
'theme'
=>
new
external_value
(
PARAM_THEME
,
'Current theme for the user.'
,
VALUE_OPTIONAL
),
'theme'
=>
new
external_value
(
PARAM_THEME
,
'Current theme for the user.'
,
VALUE_OPTIONAL
),
'limitconcurrentlogins'
=>
new
external_value
(
PARAM_INT
,
'Number of concurrent sessions allowed'
,
VALUE_OPTIONAL
),
'usersessionscount'
=>
new
external_value
(
PARAM_INT
,
'Number of active sessions for current user.
Only returned when limitconcurrentlogins is used.'
,
VALUE_OPTIONAL
),
)
)
);
);
}
}
...
...
webservice/tests/externallib_test.php
View file @
c7e7229c
...
@@ -166,6 +166,24 @@ class core_webservice_externallib_testcase extends externallib_advanced_testcase
...
@@ -166,6 +166,24 @@ class core_webservice_externallib_testcase extends externallib_advanced_testcase
$this
->
assertTrue
(
$siteinfo
[
'userissiteadmin'
]);
$this
->
assertTrue
(
$siteinfo
[
'userissiteadmin'
]);
$this
->
assertEmpty
(
$USER
->
theme
);
$this
->
assertEmpty
(
$USER
->
theme
);
$this
->
assertEquals
(
$PAGE
->
theme
->
name
,
$siteinfo
[
'theme'
]);
$this
->
assertEquals
(
$PAGE
->
theme
->
name
,
$siteinfo
[
'theme'
]);
$this
->
assertEquals
(
$CFG
->
limitconcurrentlogins
,
$siteinfo
[
'limitconcurrentlogins'
]);
$this
->
assertFalse
(
isset
(
$siteinfo
[
'usersessionscount'
]));
$CFG
->
limitconcurrentlogins
=
1
;
$record
=
new
stdClass
();
$record
->
state
=
0
;
$record
->
sessdata
=
null
;
$record
->
userid
=
$USER
->
id
;
$record
->
timemodified
=
time
();
$record
->
firstip
=
$record
->
lastip
=
'10.0.0.1'
;
$record
->
sid
=
md5
(
'hokus1'
);
$record
->
timecreated
=
time
();
$DB
->
insert_record
(
'sessions'
,
$record
);
$siteinfo
=
core_webservice_external
::
get_site_info
();
$siteinfo
=
external_api
::
clean_returnvalue
(
core_webservice_external
::
get_site_info_returns
(),
$siteinfo
);
$this
->
assertEquals
(
$CFG
->
limitconcurrentlogins
,
$siteinfo
[
'limitconcurrentlogins'
]);
$this
->
assertEquals
(
1
,
$siteinfo
[
'usersessionscount'
]);
}
}
/**
/**
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment