Skip to content

Commit

Permalink
Merge pull request catalyst#16 from catalyst/issue15
Browse files Browse the repository at this point in the history
Implement core_userlist_provider functions catalyst#15
  • Loading branch information
brendanheywood authored May 29, 2020
2 parents 6324a05 + f2dd8b3 commit ee065d6
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 14 deletions.
25 changes: 13 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,48 @@ sudo: required
cache:
directories:
- $HOME/.composer/cache
- $HOME/.npm

php:
- 7.2

addons:
postgresql: "9.4"
postgresql: "9.6"

services:
- redis-server
- mysql

env:
- DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_36_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_37_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_38_STABLE
- DB=pgsql MOODLE_BRANCH=master
- DB=mysqli MOODLE_BRANCH=MOODLE_31_STABLE
- DB=mysqli MOODLE_BRANCH=MOODLE_35_STABLE
- DB=mysqli MOODLE_BRANCH=MOODLE_36_STABLE
- DB=mysqli MOODLE_BRANCH=MOODLE_38_STABLE
- DB=mysqli MOODLE_BRANCH=master

matrix:
exclude:

before_install:
- cd ../..
- composer selfupdate
- composer create-project -n --no-dev moodlerooms/moodle-plugin-ci ci ^1
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"

install:
- moodle-plugin-ci install
- moodle-plugin-ci install -vvv

script:
- moodle-plugin-ci validate
- moodle-plugin-ci phplint
- moodle-plugin-ci phpcpd
- moodle-plugin-ci phpmd
- moodle-plugin-ci codechecker
# - moodle-plugin-ci csslint # No CSS
# - moodle-plugin-ci csslint # No CSS
- moodle-plugin-ci shifter
# - moodle-plugin-ci jshint # No JS
# - moodle-plugin-ci phpunit # No tests yet
# - moodle-plugin-ci behat # No tests yet
# - moodle-plugin-ci jshint # No JS
- moodle-plugin-ci phpunit
# - moodle-plugin-ci behat # No tests yet
# Privacy Specific tests
- /home/travis/build/moodle/vendor/bin/phpunit "provider_testcase" /home/travis/build/moodle/privacy/tests/provider_test.php
- /home/travis/build/moodle/vendor/bin/phpunit "tool_dataprivacy_expired_contexts_testcase" /home/travis/build/moodle/admin/tool/dataprivacy/tests/expired_contexts_test.php
47 changes: 45 additions & 2 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@

use core_privacy\local\metadata\collection;
use core_privacy\local\request\approved_contextlist;
use core_privacy\local\request\context;
use core_privacy\local\request\approved_userlist;
use \context;
use core_privacy\local\request\contextlist;

use core_privacy\local\request\userlist;
use core_privacy\local\request\writer;

class provider implements
\core_privacy\local\metadata\provider,
\core_privacy\local\request\core_userlist_provider,
\core_privacy\local\request\plugin\provider {

/**
Expand Down Expand Up @@ -154,4 +157,44 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {

$DB->delete_records('auth_basic_master_password', ['userid' => $userid]);
}

/**
* Get the list of users who have data within a context.
*
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
*/
public static function get_users_in_context(userlist $userlist) {
$context = $userlist->get_context();

if ($context->contextlevel != CONTEXT_USER) {
return;
}

$sql = "SELECT mp.userid
FROM {auth_basic_master_password} mp
WHERE mp.userid = :userid";

$params = [
'userid' => $context->instanceid
];

$userlist->add_from_sql('userid', $sql, $params);
}

/**
* Delete multiple users within a single context.
*
* @param approved_userlist $userlist The approved context and user information to delete information for.
*/
public static function delete_data_for_users(approved_userlist $userlist) {
global $DB;
$context = $userlist->get_context();

if ($context->contextlevel != CONTEXT_USER) {
return;
}
$userid = $context->instanceid;

$DB->delete_records('auth_basic_master_password', ['userid' => $userid]);
}
}
40 changes: 40 additions & 0 deletions tests/auth_basic_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
// This file is part of Moodle - http://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/>.
/**
* Base class for unit tests for auth_basic.
*
* @package auth_basic
* @category test
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once($CFG->dirroot.'/auth/basic/auth.php');

class auth_basic_test extends advanced_testcase {
/** @var auth_plugin_basic Keeps the authentication plugin. */
protected $authplugin;
protected function setUp() {
$this->resetAfterTest(true);
$this->authplugin = new \auth_plugin_basic();
}
public function test_login_user() {
$loginsuccessful = $this->authplugin->user_login('username', 'password');
self::assertFalse($loginsuccessful);
}
}

0 comments on commit ee065d6

Please sign in to comment.