forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-67748 admin: Add filter to the WS tokens management page
The patch adds ability to filter the list of token by the token value, the user and the service. Also the button to create a new token is made more prominent and easier to spot.
- Loading branch information
Showing
5 changed files
with
196 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
// This file is part of Moodle - https://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Provides the {@see core_webservice\token_filter} class. | ||
* | ||
* @package core_webservice | ||
* @copyright 2020 David Mudrák <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace core_webservice; | ||
|
||
use moodleform; | ||
|
||
/** | ||
* Form allowing to filter displayed tokens. | ||
* | ||
* @copyright 2020 David Mudrák <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class token_filter extends moodleform { | ||
|
||
/** | ||
* Defines the form fields. | ||
*/ | ||
public function definition() { | ||
global $DB; | ||
|
||
$mform = $this->_form; | ||
$presetdata = $this->_customdata; | ||
|
||
$mform->addElement('header', 'tokenfilter', get_string('tokenfilter', 'webservice')); | ||
|
||
if (empty($presetdata->token) && empty($presetdata->users) && empty($presetdata->services)) { | ||
$mform->setExpanded('tokenfilter', false); | ||
} else { | ||
$mform->setExpanded('tokenfilter', true); | ||
} | ||
|
||
// Token. | ||
$mform->addElement('text', 'token', get_string('token', 'core_webservice'), ['size' => 32]); | ||
$mform->setType('token', PARAM_ALPHANUM); | ||
|
||
// User selector. | ||
$attributes = [ | ||
'multiple' => true, | ||
'ajax' => 'core_user/form_user_selector', | ||
'valuehtmlcallback' => function($userid) { | ||
global $DB, $OUTPUT; | ||
|
||
$context = \context_system::instance(); | ||
$fields = \core\user_fields::for_name()->with_identity($context, false); | ||
$record = \core_user::get_user($userid, 'id' . $fields->get_sql()->selects, MUST_EXIST); | ||
|
||
$user = (object)[ | ||
'id' => $record->id, | ||
'fullname' => fullname($record, has_capability('moodle/site:viewfullnames', $context)), | ||
'extrafields' => [], | ||
]; | ||
|
||
foreach ($fields->get_required_fields([\core\user_fields::PURPOSE_IDENTITY]) as $extrafield) { | ||
$user->extrafields[] = (object)[ | ||
'name' => $extrafield, | ||
'value' => s($record->$extrafield) | ||
]; | ||
} | ||
|
||
return $OUTPUT->render_from_template('core_user/form_user_selector_suggestion', $user); | ||
}, | ||
]; | ||
$mform->addElement('autocomplete', 'users', get_string('user'), [], $attributes); | ||
|
||
// Service selector. | ||
$options = $DB->get_records_menu('external_services', null, '', 'id, name'); | ||
$attributes = [ | ||
'multiple' => true, | ||
]; | ||
$mform->addElement('autocomplete', 'services', get_string('service', 'webservice'), $options, $attributes); | ||
|
||
// Action buttons. | ||
$mform->addGroup([ | ||
$mform->createElement('submit', 'submitbutton', get_string('tokenfiltersubmit', 'core_webservice')), | ||
$mform->createElement('submit', 'resetbutton', get_string('tokenfilterreset', 'core_webservice'), [], false), | ||
], 'actionbuttons', '', ' ', false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters