Skip to content

Commit fbecb6d

Browse files
authored
Merge pull request #173 from learnweb/fix/anonymous-files
Hide author of files in anonymous posts
2 parents 867cfa4 + 9967f57 commit fbecb6d

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

post.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,14 @@
490490
empty($post->id) ? null : $post->id,
491491
mod_moodleoverflow_post_form::attachment_options($moodleoverflow));
492492

493+
if ($draftitemid && $edit && \mod_moodleoverflow\anonymous::is_post_anonymous($discussion, $moodleoverflow, $post->userid) && $post->userid != $USER->id) {
494+
$usercontext = context_user::instance($USER->id);
495+
$anonymousstr = get_string('anonymous', 'moodleoverflow');
496+
foreach (get_file_storage()->get_area_files($usercontext->id, 'user', 'draft', $draftitemid) as $file) {
497+
$file->set_author($anonymousstr);
498+
}
499+
}
500+
493501
// Prepare the form.
494502
$formarray = array(
495503
'course' => $course,

tests/behat/anonymous.feature

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
@mod @mod_moodleoverflow @javascript
2+
Feature: Use moodleoverflow anonymously
3+
4+
Background:
5+
Given the following "users" exist:
6+
| username | firstname | lastname | email |
7+
| teacher1 | Teacher | 1 | teacher1@example.com |
8+
| student1 | Student | 1 | student1@example.com |
9+
And the following "courses" exist:
10+
| fullname | shortname | category |
11+
| Course 1 | C1 | 0 |
12+
And the following "course enrolments" exist:
13+
| user | course | role |
14+
| teacher1 | C1 | editingteacher |
15+
| student1 | C1 | student |
16+
And the following "activity" exists:
17+
| activity | moodleoverflow |
18+
| course | C1 |
19+
| name | Test moodleoverflow name |
20+
| anonymous | 2 |
21+
22+
@_file_upload
23+
Scenario: Other people should not see the questioners name in anonymous mode, not even as file author.
24+
Given I am on the "Test moodleoverflow name" "Activity" page logged in as "student1"
25+
And I press "Add a new discussion topic"
26+
And I set the following fields to these values:
27+
| Subject | This is Nina |
28+
| Message | She is nice. |
29+
And I upload "mod/moodleoverflow/tests/fixtures/NH.jpg" file to "Attachment" filemanager
30+
And I press "Post to forum"
31+
Then I should see "Anonymous (You)"
32+
When I am on the "Test moodleoverflow name" "Activity" page logged in as "teacher1"
33+
And I follow "This is Nina"
34+
Then I should not see "Student 1"
35+
And I should see "Questioner"
36+
Given I follow "Edit"
37+
And I click on "NH.jpg" "link"
38+
Then the field "Author" matches value "Anonymous"

0 commit comments

Comments
 (0)