MDL-64821 mod_forum: don't show name of deleted user

When a user account is deleted don't render the user's name in
the forum. Instead we render "Deleted user".
This commit is contained in:
Ryan Wyllie 2019-09-09 15:44:48 +08:00
parent b97622a01c
commit 23e0ceca16
14 changed files with 102 additions and 46 deletions

View File

@ -51,6 +51,7 @@ class author {
'lastname' => $author->get_last_name(),
'fullname' => $author->get_full_name(),
'email' => $author->get_email(),
'deleted' => $author->is_deleted(),
'middlename' => $author->get_middle_name(),
'firstnamephonetic' => $author->get_first_name_phonetic(),
'lastnamephonetic' => $author->get_last_name_phonetic(),

View File

@ -45,6 +45,8 @@ class author {
private $fullname;
/** @var string $email Email */
private $email;
/** @var bool $deleted Deleted */
private $deleted;
/** @var string $middlename Middle name */
private $middlename;
/** @var string $firstnamephonetic Phonetic spelling of first name */
@ -78,6 +80,7 @@ class author {
string $lastname,
string $fullname,
string $email,
bool $deleted,
string $middlename = null,
string $firstnamephonetic = null,
string $lastnamephonetic = null,
@ -90,6 +93,7 @@ class author {
$this->lastname = $lastname;
$this->fullname = $fullname;
$this->email = $email;
$this->deleted = $deleted;
$this->middlename = $middlename;
$this->firstnamephonetic = $firstnamephonetic;
$this->lastnamephonetic = $lastnamephonetic;
@ -151,6 +155,15 @@ class author {
return $this->email;
}
/**
* Is the author deleted?
*
* @return bool
*/
public function is_deleted() : bool {
return !empty($this->deleted);
}
/**
* Return the middle name.
*

View File

@ -91,6 +91,12 @@ class author extends exporter {
'default' => null,
'null' => NULL_ALLOWED
],
'isdeleted' => [
'type' => PARAM_BOOL,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
],
'groups' => [
'multiple' => true,
'optional' => true,
@ -143,41 +149,56 @@ class author extends exporter {
$context = $this->related['context'];
if ($this->canview) {
$groups = array_map(function($group) use ($urlfactory, $context) {
$imageurl = null;
$groupurl = null;
if (!$group->hidepicture) {
$imageurl = get_group_picture_url($group, $group->courseid, true);
}
if (course_can_view_participants($context)) {
$groupurl = $urlfactory->get_author_group_url($group);
}
if ($author->is_deleted()) {
return [
'id' => $group->id,
'name' => $group->name,
'id' => $author->get_id(),
'fullname' => get_string('deleteduser', 'mod_forum'),
'isdeleted' => true,
'groups' => [],
'urls' => [
'image' => $imageurl ? $imageurl->out(false) : null,
'group' => $groupurl ? $groupurl->out(false) : null
'profile' => ($urlfactory->get_author_profile_url($author))->out(false),
'profileimage' => ($urlfactory->get_author_profile_image_url($author, $authorcontextid))->out(false)
]
];
}, $this->authorgroups);
} else {
$groups = array_map(function($group) use ($urlfactory, $context) {
$imageurl = null;
$groupurl = null;
if (!$group->hidepicture) {
$imageurl = get_group_picture_url($group, $group->courseid, true);
}
if (course_can_view_participants($context)) {
$groupurl = $urlfactory->get_author_group_url($group);
}
return [
'id' => $author->get_id(),
'fullname' => $author->get_full_name(),
'groups' => $groups,
'urls' => [
'profile' => ($urlfactory->get_author_profile_url($author))->out(false),
'profileimage' => ($urlfactory->get_author_profile_image_url($author, $authorcontextid))->out(false)
]
];
return [
'id' => $group->id,
'name' => $group->name,
'urls' => [
'image' => $imageurl ? $imageurl->out(false) : null,
'group' => $groupurl ? $groupurl->out(false) : null
]
];
}, $this->authorgroups);
return [
'id' => $author->get_id(),
'fullname' => $author->get_full_name(),
'isdeleted' => false,
'groups' => $groups,
'urls' => [
'profile' => ($urlfactory->get_author_profile_url($author))->out(false),
'profileimage' => ($urlfactory->get_author_profile_image_url($author, $authorcontextid))->out(false)
]
];
}
} else {
// The author should be anonymised.
return [
'id' => null,
'fullname' => get_string('forumauthorhidden', 'mod_forum'),
'isdeleted' => null,
'groups' => [],
'urls' => [
'profile' => null,

View File

@ -386,7 +386,7 @@ class post extends exporter {
$author,
$authorcontextid,
$authorgroups,
($canview && !$isdeleted),
$canview,
$this->related
);
$exportedauthor = $authorexporter->export($output);
@ -402,10 +402,6 @@ class post extends exporter {
$subject = $isdeleted ? get_string('forumsubjectdeleted', 'forum') : get_string('forumsubjecthidden', 'forum');
$message = $isdeleted ? get_string('forumbodydeleted', 'forum') : get_string('forumbodyhidden', 'forum');
$timecreated = null;
if ($isdeleted) {
$exportedauthor->fullname = null;
}
}
$replysubject = $subject;

View File

@ -172,6 +172,7 @@ class entity {
$record->lastname,
fullname($record),
$record->email,
$record->deleted,
$record->middlename,
$record->firstnamephonetic,
$record->lastnamephonetic,

View File

@ -120,8 +120,8 @@ class discussion_list extends db_table_vault {
// - Most recent editor.
$thistable = new dml_table(self::TABLE, $alias, $alias);
$posttable = new dml_table('forum_posts', 'fp', 'p_');
$firstauthorfields = \user_picture::fields('fa', null, self::FIRST_AUTHOR_ID_ALIAS, self::FIRST_AUTHOR_ALIAS);
$latestuserfields = \user_picture::fields('la', null, self::LATEST_AUTHOR_ID_ALIAS, self::LATEST_AUTHOR_ALIAS);
$firstauthorfields = \user_picture::fields('fa', ['deleted'], self::FIRST_AUTHOR_ID_ALIAS, self::FIRST_AUTHOR_ALIAS);
$latestuserfields = \user_picture::fields('la', ['deleted'], self::LATEST_AUTHOR_ID_ALIAS, self::LATEST_AUTHOR_ALIAS);
$fields = implode(', ', [
$thistable->get_field_select(),

View File

@ -65,7 +65,7 @@ class extract_user {
$alias = $this->alias;
return array_map(function($record) use ($idalias, $alias) {
return user_picture::unalias($record, null, $idalias, $alias);
return user_picture::unalias($record, ['deleted'], $idalias, $alias);
}, $records);
}
}

View File

@ -146,6 +146,7 @@ $string['delete'] = 'Delete';
$string['deleteddiscussion'] = 'The discussion topic has been deleted';
$string['deletedpost'] = 'The post has been deleted';
$string['deletedposts'] = 'Those posts have been deleted';
$string['deleteduser'] = 'Deleted user';
$string['deletesure'] = 'Are you sure you want to delete this post?';
$string['deletesureplural'] = 'Are you sure you want to delete this post and all replies? ({$a} posts)';
$string['digestmailheader'] = 'This is your daily digest of new posts from the {$a->sitename} forums. To change your default forum email preferences, go to {$a->userprefs}.';

View File

@ -236,14 +236,14 @@
{{/readonly}}
</div>
</div>
{{$subject}}
<h2
class="h1 font-weight-bold post-subject mt-n2"
data-region-content="forum-post-core-subject"
data-reply-subject="{{replysubject}}"
>{{{subject}}}</h2>
{{/subject}}
{{/isdeleted}}
{{$subject}}
<h2
class="h1 font-weight-bold post-subject mt-n2"
data-region-content="forum-post-core-subject"
data-reply-subject="{{replysubject}}"
>{{{subject}}}</h2>
{{/subject}}
{{#hasreplycount}}
<span class="sr-only">{{#str}} numberofreplies, mod_forum, {{replycount}} {{/str}}</span>
{{/hasreplycount}}

View File

@ -31,7 +31,11 @@
}}
{{< mod_forum/forum_discussion_modern_first_post }}
{{$subject}}
<h3 class="sr-only" data-region-content="forum-post-core-subject">{{{subject}}}</h3>
<h3
{{#isdeleted}}class="h6 font-weight-bold"{{/isdeleted}}
{{^isdeleted}}class="sr-only"{{/isdeleted}}
data-region-content="forum-post-core-subject"
>{{{subject}}}</h3>
{{/subject}}
{{$footer}}
{{^isdeleted}}

View File

@ -47,6 +47,7 @@ class mod_forum_entities_author_testcase extends advanced_testcase {
'person',
'test person',
'test@example.com',
false,
'middle',
'tteeeeest',
'ppppeeerssson',
@ -60,6 +61,7 @@ class mod_forum_entities_author_testcase extends advanced_testcase {
$this->assertEquals('person', $author->get_last_name());
$this->assertEquals('test person', $author->get_full_name());
$this->assertEquals('test@example.com', $author->get_email());
$this->assertEquals(false, $author->is_deleted());
$this->assertEquals('middle', $author->get_middle_name());
$this->assertEquals('tteeeeest', $author->get_first_name_phonetic());
$this->assertEquals('ppppeeerssson', $author->get_last_name_phonetic());

View File

@ -49,7 +49,8 @@ class mod_forum_entities_discussion_summary_testcase extends advanced_testcase {
'test',
'person',
'test person',
'test@example.com'
'test@example.com',
false
);
$lastauthor = new author_entity(
2,
@ -57,7 +58,8 @@ class mod_forum_entities_discussion_summary_testcase extends advanced_testcase {
'test 2',
'person 2',
'test 2 person 2',
'test2@example.com'
'test2@example.com',
false
);
$discussion = new discussion_entity(
1,

View File

@ -57,7 +57,8 @@ class mod_forum_exporters_author_testcase extends advanced_testcase {
'test',
'user',
'test user',
'test@example.com'
'test@example.com',
false
);
$exporter = new author_exporter($author, 1, [], true, [
@ -95,7 +96,8 @@ class mod_forum_exporters_author_testcase extends advanced_testcase {
'test',
'user',
'test user',
'test@example.com'
'test@example.com',
false
);
$group = $datagenerator->create_group(['courseid' => $course->id]);
@ -132,7 +134,8 @@ class mod_forum_exporters_author_testcase extends advanced_testcase {
'test',
'user',
'test user',
'test@example.com'
'test@example.com',
false
);
$group = $datagenerator->create_group(['courseid' => $course->id]);

View File

@ -548,6 +548,7 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
$exporteduser2 = [
'id' => (int) $user2->id,
'fullname' => fullname($user2),
'isdeleted' => false,
'groups' => [],
'urls' => [
'profile' => $urlfactory->get_author_profile_url($user2entity),
@ -562,6 +563,7 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
'id' => (int) $user3->id,
'fullname' => fullname($user3),
'groups' => [],
'isdeleted' => false,
'urls' => [
'profile' => $urlfactory->get_author_profile_url($user3entity),
'profileimage' => $urlfactory->get_author_profile_image_url($user3entity),
@ -642,6 +644,16 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
// Delete one user, to test that we still receive posts by this user.
delete_user($user3);
$exporteduser3 = [
'id' => (int) $user3->id,
'fullname' => get_string('deleteduser', 'mod_forum'),
'groups' => [],
'isdeleted' => true,
'urls' => [
'profile' => $urlfactory->get_author_profile_url($user3entity),
'profileimage' => $urlfactory->get_author_profile_image_url($user3entity),
]
];
// Create what we expect to be returned when querying the discussion.
$expectedposts = array(