Commit bfa5f882 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1678668: Adding webservice auth via adding external app



When we add an app configuration via
Administration -> Webservices -> External apps

We can check and make sure the 'webservice' auth instance exists for
the institution we choose.

behatnotneeded

Change-Id: I5012346c290ad94990cd48dcc1e5dc5b9ee694d9
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 703af39e
......@@ -243,6 +243,7 @@ $string['erroruser'] = 'Invalid user specified';
$string['authorise'] = 'Authorise application access';
$string['oauth_access'] = 'This application will have access to your users\' details and resources';
$string['oauth_instructions'] = 'If you wish to grant access to this application, then click "Authorise application access". If you do not want to grant access, press "Cancel".';
$string['setauthinstancefailed'] = 'Setting "Web service" authentication to institution "%s" failed. Please try adding it via Administration -> Institutions -> Settings page';
// running webservices messages
$string['accesstofunctionnotallowed'] = 'Access to the function %s() is not allowed. Please check if a service containing the function is enabled. In the service settings: If the service is restricted, check that the user is listed. Still in the service settings check for IP restriction or if the service requires a capability.';
......
......@@ -84,6 +84,17 @@ function webservices_add_application_submit(Pieform $form, $values) {
redirect('/webservice/admin/oauthv1sregister.php');
}
else {
// New application added - now check that institution has 'webservices' auth
// Get auth priority we need for the ensure_record_exists function
$priorities = get_record_sql("SELECT MAX(priority) AS maxpriority, (
SELECT priority FROM {auth_instance}
WHERE institution = ? AND authname = 'webservice') AS webservicepriority
FROM {auth_instance} WHERE institution = ?", array($values['institution'], $values['institution']));
$priority = is_null($priorities->webservicepriority) ? $priorities->maxpriority + 1 : $priorities->webservicepriority;
if (!ensure_record_exists('auth_instance', (object) array('institution' => $values['institution'], 'authname' => 'webservice'),
(object) array('institution' => $values['institution'], 'authname' => 'webservice', 'active' => 1, 'priority' => $priority, 'instancename' => 'webservice'))) {
$SESSION->add_error_msg(get_string('setauthinstancefailed', 'auth.webservice', institution_display_name($values['institution'])));
}
redirect('/webservice/admin/oauthv1sregister.php?edit=' . $c->id);
}
......
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