Skip to content

Commit ee065d6

Browse files
Merge pull request catalyst#16 from catalyst/issue15
Implement core_userlist_provider functions catalyst#15
2 parents 6324a05 + f2dd8b3 commit ee065d6

File tree

3 files changed

+98
-14
lines changed

3 files changed

+98
-14
lines changed

.travis.yml

+13-12
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,48 @@ sudo: required
66
cache:
77
directories:
88
- $HOME/.composer/cache
9+
- $HOME/.npm
910

1011
php:
1112
- 7.2
1213

1314
addons:
14-
postgresql: "9.4"
15+
postgresql: "9.6"
1516

1617
services:
17-
- redis-server
1818
- mysql
1919

2020
env:
21-
- DB=pgsql MOODLE_BRANCH=MOODLE_31_STABLE
2221
- DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE
2322
- DB=pgsql MOODLE_BRANCH=MOODLE_36_STABLE
2423
- DB=pgsql MOODLE_BRANCH=MOODLE_37_STABLE
24+
- DB=pgsql MOODLE_BRANCH=MOODLE_38_STABLE
2525
- DB=pgsql MOODLE_BRANCH=master
26-
- DB=mysqli MOODLE_BRANCH=MOODLE_31_STABLE
2726
- DB=mysqli MOODLE_BRANCH=MOODLE_35_STABLE
27+
- DB=mysqli MOODLE_BRANCH=MOODLE_36_STABLE
28+
- DB=mysqli MOODLE_BRANCH=MOODLE_38_STABLE
2829
- DB=mysqli MOODLE_BRANCH=master
2930

30-
matrix:
31-
exclude:
32-
3331
before_install:
3432
- cd ../..
3533
- composer selfupdate
3634
- composer create-project -n --no-dev moodlerooms/moodle-plugin-ci ci ^1
3735
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"
3836

3937
install:
40-
- moodle-plugin-ci install
38+
- moodle-plugin-ci install -vvv
4139

4240
script:
4341
- moodle-plugin-ci validate
4442
- moodle-plugin-ci phplint
4543
- moodle-plugin-ci phpcpd
4644
- moodle-plugin-ci phpmd
4745
- moodle-plugin-ci codechecker
48-
# - moodle-plugin-ci csslint # No CSS
46+
# - moodle-plugin-ci csslint # No CSS
4947
- moodle-plugin-ci shifter
50-
# - moodle-plugin-ci jshint # No JS
51-
# - moodle-plugin-ci phpunit # No tests yet
52-
# - moodle-plugin-ci behat # No tests yet
48+
# - moodle-plugin-ci jshint # No JS
49+
- moodle-plugin-ci phpunit
50+
# - moodle-plugin-ci behat # No tests yet
51+
# Privacy Specific tests
52+
- /home/travis/build/moodle/vendor/bin/phpunit "provider_testcase" /home/travis/build/moodle/privacy/tests/provider_test.php
53+
- /home/travis/build/moodle/vendor/bin/phpunit "tool_dataprivacy_expired_contexts_testcase" /home/travis/build/moodle/admin/tool/dataprivacy/tests/expired_contexts_test.php

classes/privacy/provider.php

+45-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@
2727

2828
use core_privacy\local\metadata\collection;
2929
use core_privacy\local\request\approved_contextlist;
30-
use core_privacy\local\request\context;
30+
use core_privacy\local\request\approved_userlist;
31+
use \context;
3132
use core_privacy\local\request\contextlist;
32-
33+
use core_privacy\local\request\userlist;
34+
use core_privacy\local\request\writer;
3335

3436
class provider implements
3537
\core_privacy\local\metadata\provider,
38+
\core_privacy\local\request\core_userlist_provider,
3639
\core_privacy\local\request\plugin\provider {
3740

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

155158
$DB->delete_records('auth_basic_master_password', ['userid' => $userid]);
156159
}
160+
161+
/**
162+
* Get the list of users who have data within a context.
163+
*
164+
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
165+
*/
166+
public static function get_users_in_context(userlist $userlist) {
167+
$context = $userlist->get_context();
168+
169+
if ($context->contextlevel != CONTEXT_USER) {
170+
return;
171+
}
172+
173+
$sql = "SELECT mp.userid
174+
FROM {auth_basic_master_password} mp
175+
WHERE mp.userid = :userid";
176+
177+
$params = [
178+
'userid' => $context->instanceid
179+
];
180+
181+
$userlist->add_from_sql('userid', $sql, $params);
182+
}
183+
184+
/**
185+
* Delete multiple users within a single context.
186+
*
187+
* @param approved_userlist $userlist The approved context and user information to delete information for.
188+
*/
189+
public static function delete_data_for_users(approved_userlist $userlist) {
190+
global $DB;
191+
$context = $userlist->get_context();
192+
193+
if ($context->contextlevel != CONTEXT_USER) {
194+
return;
195+
}
196+
$userid = $context->instanceid;
197+
198+
$DB->delete_records('auth_basic_master_password', ['userid' => $userid]);
199+
}
157200
}

tests/auth_basic_test.php

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
/**
17+
* Base class for unit tests for auth_basic.
18+
*
19+
* @package auth_basic
20+
* @category test
21+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22+
*/
23+
24+
defined('MOODLE_INTERNAL') || die();
25+
26+
global $CFG;
27+
require_once($CFG->dirroot.'/auth/basic/auth.php');
28+
29+
class auth_basic_test extends advanced_testcase {
30+
/** @var auth_plugin_basic Keeps the authentication plugin. */
31+
protected $authplugin;
32+
protected function setUp() {
33+
$this->resetAfterTest(true);
34+
$this->authplugin = new \auth_plugin_basic();
35+
}
36+
public function test_login_user() {
37+
$loginsuccessful = $this->authplugin->user_login('username', 'password');
38+
self::assertFalse($loginsuccessful);
39+
}
40+
}

0 commit comments

Comments
 (0)