Commit 1d516e17 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge "Bug 1566122: Add token set institution to user's institution"

parents 455be95e 380a44e1
...@@ -960,7 +960,9 @@ function webservice_token_submit(Pieform $form, $values) { ...@@ -960,7 +960,9 @@ function webservice_token_submit(Pieform $form, $values) {
else { else {
// just pass the first one for the moment // just pass the first one for the moment
$service = array_shift($services); $service = array_shift($services);
$token = webservice_generate_token(EXTERNAL_TOKEN_PERMANENT, $service, $dbuser->id); $auth_instance = webservice_validate_user($dbuser);
$institution = $auth_instance ? $auth_instance->institution : 'mahara';
$token = webservice_generate_token(EXTERNAL_TOKEN_PERMANENT, $service, $dbuser->id, $institution);
$dbtoken = get_record('external_tokens', 'token', $token); $dbtoken = get_record('external_tokens', 'token', $token);
redirect('/webservice/admin/tokenconfig.php?token=' . $dbtoken->id); redirect('/webservice/admin/tokenconfig.php?token=' . $dbtoken->id);
} }
......
...@@ -149,8 +149,15 @@ function mahara_external_atom_returns() { ...@@ -149,8 +149,15 @@ function mahara_external_atom_returns() {
function webservice_validate_user($dbuser) { function webservice_validate_user($dbuser) {
global $SESSION; global $SESSION;
if (!empty($dbuser)) { if (!empty($dbuser)) {
$auth_instance = get_record('auth_instance', 'id', $dbuser->authinstance, 'active', 1); if ($auth_instance = get_record_sql("SELECT * FROM {auth_instance}
if ($auth_instance->authname == 'webservice') { WHERE authname = 'webservice'
AND active = 1
AND institution = (
SELECT institution FROM {auth_instance}
WHERE id = ?
AND active = 1
)", array($dbuser->authinstance))) {
// User belongs to an institution that contains the 'webservice' auth method
$memberships = count_records('usr_institution', 'usr', $dbuser->id); $memberships = count_records('usr_institution', 'usr', $dbuser->id);
if ($memberships == 0) { if ($memberships == 0) {
// auth instance should be a mahara one // auth instance should be a mahara one
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment