Skip to content

Commit

Permalink
MDL-66804 user: consistent user access times in privacy export.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden committed Sep 30, 2019
1 parent 9528b1f commit 8208292
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 4 additions & 4 deletions user/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,10 @@ protected static function export_user(\stdClass $user, \context $context) {
'calendartype' => $user->calendartype,
'theme' => $user->theme,
'timezone' => $user->timezone,
'firstaccess' => transform::datetime($user->firstaccess),
'lastaccess' => transform::datetime($user->lastaccess),
'lastlogin' => transform::datetime($user->lastlogin),
'currentlogin' => $user->currentlogin,
'firstaccess' => $user->firstaccess ? transform::datetime($user->firstaccess) : null,
'lastaccess' => $user->lastaccess ? transform::datetime($user->lastaccess) : null,
'lastlogin' => $user->lastlogin ? transform::datetime($user->lastlogin) : null,
'currentlogin' => $user->currentlogin ? transform::datetime($user->currentlogin) : null,
'lastip' => $user->lastip,
'secret' => $user->secret,
'picture' => $user->picture,
Expand Down
12 changes: 11 additions & 1 deletion user/tests/privacy_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use \core_privacy\tests\provider_testcase;
use \core_user\privacy\provider;
use \core_privacy\local\request\approved_userlist;
use \core_privacy\local\request\transform;

require_once($CFG->dirroot . "/user/lib.php");

Expand Down Expand Up @@ -59,7 +60,11 @@ public function test_get_contexts_for_userid() {
*/
public function test_export_user_data() {
$this->resetAfterTest();
$user = $this->getDataGenerator()->create_user();
$user = $this->getDataGenerator()->create_user([
'firstaccess' => 1535760000,
'lastaccess' => 1541030400,
'currentlogin' => 1541030400,
]);
$course = $this->getDataGenerator()->create_course();
$context = \context_user::instance($user->id);

Expand Down Expand Up @@ -125,6 +130,11 @@ public function test_export_user_data() {
$this->assertTrue(array_key_exists('firstname', $userdata));
$this->assertTrue(array_key_exists('lastname', $userdata));
$this->assertTrue(array_key_exists('email', $userdata));
// Check access times.
$this->assertEquals(transform::datetime($user->firstaccess), $userdata['firstaccess']);
$this->assertEquals(transform::datetime($user->lastaccess), $userdata['lastaccess']);
$this->assertNull($userdata['lastlogin']);
$this->assertEquals(transform::datetime($user->currentlogin), $userdata['currentlogin']);
}

/**
Expand Down

0 comments on commit 8208292

Please sign in to comment.