Commit c494940d authored by Aaron Wells's avatar Aaron Wells Committed by Robert Lyon
Browse files

Bug 1600099: Hide the institution connections link if no connection definitions

If the site doesn't yet have any plugins installed that define webservice
connections, then the institution connection manager screen can't be used.
In which case, we should hide the link to avoid confusing users.

Change-Id: Ia9351995485331ea5d6fc94fcdf69eafbfa18c01
behatnotneeded: Can't readily test in Behat
parent 8ff2f254
......@@ -958,13 +958,16 @@ EOF;
}
function build_institutions_html($filter, $showdefault, $query, $limit, $offset, &$count=null) {
global $USER;
global $USER, $CFG;
$institutions = Institution::count_members($filter, $showdefault, $query, $limit, $offset, $count);
require_once($CFG->docroot . '/webservice/lib.php');
$smarty = smarty_core();
$smarty->assign('institutions', $institutions);
$smarty->assign('siteadmin', $USER->get('admin'));
$smarty->assign('webserviceconnections', (bool) count(webservice_connection_definitions()));
$data['tablerows'] = $smarty->fetch('admin/users/institutionsresults.tpl');
$pagination = build_pagination(array(
......
......@@ -23,12 +23,14 @@
{if !$institution->site}</a>{/if}</td>
<td class="center">{if $institution->suspended}<span class="suspended">{str tag="suspendedinstitution" section=admin}</span>{/if}</td>
<td class="controls">
<a class="btn-link btn btn-xs pull-right" href="{$WWWROOT}webservice/admin/connections.php?i={$institution->name}">
<span class="icon icon-plug icon-lg text-default" role="presentation" aria-hidden="true"></span>
<span class="sr-only">
{str(tag=connectspecific arg1=$institution->displayname)|escape:html|safe}
</span>
</a>
{if $webserviceconnections}
<a class="btn-link btn btn-xs pull-right" href="{$WWWROOT}webservice/admin/connections.php?i={$institution->name}">
<span class="icon icon-plug icon-lg text-default" role="presentation" aria-hidden="true"></span>
<span class="sr-only">
{str(tag=connectspecific arg1=$institution->displayname)|escape:html|safe}
</span>
</a>
{/if}
<form action="" method="post">
<input type="hidden" name="i" value="{$institution->name}">
<button type="submit" name="edit" value="1" class="btn-link btn btn-xs pull-right" alt="{str(tag=editspecific arg1=$institution->displayname)|escape:html|safe}">
......
......@@ -31,6 +31,7 @@ define('SECTION_PAGE', 'connections');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once(dirname(dirname(__FILE__)) . '/lib.php');
require_once(dirname(dirname(dirname(__FILE__))) . '/lib/upgrade.php');
require_once($CFG->docroot . '/webservice/lib.php');
define('TITLE', get_string('webservices_title', 'auth.webservice'));
define('SUBSECTIONHEADING', get_string('connections', 'auth.webservice'));
......@@ -92,61 +93,6 @@ if ($reorder && $json) {
}
function webservice_connection_definitions() {
$connections = array();
$plugins = array();
$plugins['blocktype'] = array();
foreach (plugin_types() as $plugin) {
// this has to happen first because of broken artefact/blocktype ordering
$plugins[$plugin] = array();
$plugins[$plugin]['installed'] = array();
$plugins[$plugin]['notinstalled'] = array();
}
foreach (array_keys($plugins) as $plugin) {
if (table_exists(new XMLDBTable($plugin . '_installed'))) {
if ($installed = plugins_installed($plugin, true)) {
foreach ($installed as $i) {
$key = $i->name;
if ($plugin == 'blocktype') {
$key = blocktype_single_to_namespaced($i->name, $i->artefactplugin);
}
if (!safe_require_plugin($plugin, $key)) {
continue;
}
if ($i->active) {
$classname = generate_class_name($plugin, $key);
if (method_exists($classname, 'define_webservice_connections')) {
$conns = call_static_method($classname, 'define_webservice_connections');
if (!empty($conns)) {
$connections[$classname] = array('connections' => $conns, 'type' => $plugin, 'key' => $key);
}
}
}
if ($plugin == 'artefact') {
safe_require('artefact', $key);
if ($types = call_static_method(generate_class_name('artefact', $i->name), 'get_artefact_types')) {
foreach ($types as $t) {
$classname = generate_artefact_class_name($t);
if (method_exists($classname, 'define_webservice_connections')) {
$conns = call_static_method($classname, 'define_webservice_connections');
if (!empty($conns)) {
$connections[$classname] = array('connections' => $conns, 'type' => $plugin, 'key' => $key);
}
}
}
}
}
}
}
}
}
return $connections;
}
/**
* Custom webservices config page
* - activate/deactivate webservices comletely
......
......@@ -331,6 +331,65 @@ function webservice_function_info($function, $strictness=MUST_EXIST) {
return $function;
}
/**
* Returns a list of all of the webservice connection definitions declared
* by all of the installed plugins.
*/
function webservice_connection_definitions() {
$connections = array();
$plugins = array();
$plugins['blocktype'] = array();
foreach (plugin_types() as $plugin) {
// this has to happen first because of broken artefact/blocktype ordering
$plugins[$plugin] = array();
$plugins[$plugin]['installed'] = array();
$plugins[$plugin]['notinstalled'] = array();
}
foreach (array_keys($plugins) as $plugin) {
if (table_exists(new XMLDBTable($plugin . '_installed'))) {
if ($installed = plugins_installed($plugin, true)) {
foreach ($installed as $i) {
$key = $i->name;
if ($plugin == 'blocktype') {
$key = blocktype_single_to_namespaced($i->name, $i->artefactplugin);
}
if (!safe_require_plugin($plugin, $key)) {
continue;
}
if ($i->active) {
$classname = generate_class_name($plugin, $key);
if (method_exists($classname, 'define_webservice_connections')) {
$conns = call_static_method($classname, 'define_webservice_connections');
if (!empty($conns)) {
$connections[$classname] = array('connections' => $conns, 'type' => $plugin, 'key' => $key);
}
}
}
if ($plugin == 'artefact') {
safe_require('artefact', $key);
if ($types = call_static_method(generate_class_name('artefact', $i->name), 'get_artefact_types')) {
foreach ($types as $t) {
$classname = generate_artefact_class_name($t);
if (method_exists($classname, 'define_webservice_connections')) {
$conns = call_static_method($classname, 'define_webservice_connections');
if (!empty($conns)) {
$connections[$classname] = array('connections' => $conns, 'type' => $plugin, 'key' => $key);
}
}
}
}
}
}
}
}
}
return $connections;
}
/**
* General web service library
*/
......
Markdown is supported
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