Skip to content

Commit

Permalink
Merge pull request #173 from learnweb/fix/anonymous-files
Browse files Browse the repository at this point in the history
Hide author of files in anonymous posts
  • Loading branch information
NinaHerrmann committed Jan 19, 2024
2 parents 867cfa4 + 9967f57 commit fbecb6d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
8 changes: 8 additions & 0 deletions post.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,14 @@
empty($post->id) ? null : $post->id,
mod_moodleoverflow_post_form::attachment_options($moodleoverflow));

if ($draftitemid && $edit && \mod_moodleoverflow\anonymous::is_post_anonymous($discussion, $moodleoverflow, $post->userid) && $post->userid != $USER->id) {
$usercontext = context_user::instance($USER->id);
$anonymousstr = get_string('anonymous', 'moodleoverflow');
foreach (get_file_storage()->get_area_files($usercontext->id, 'user', 'draft', $draftitemid) as $file) {
$file->set_author($anonymousstr);
}
}

// Prepare the form.
$formarray = array(
'course' => $course,
Expand Down
38 changes: 38 additions & 0 deletions tests/behat/anonymous.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@mod @mod_moodleoverflow @javascript
Feature: Use moodleoverflow anonymously

Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "activity" exists:
| activity | moodleoverflow |
| course | C1 |
| name | Test moodleoverflow name |
| anonymous | 2 |

@_file_upload
Scenario: Other people should not see the questioners name in anonymous mode, not even as file author.
Given I am on the "Test moodleoverflow name" "Activity" page logged in as "student1"
And I press "Add a new discussion topic"
And I set the following fields to these values:
| Subject | This is Nina |
| Message | She is nice. |
And I upload "mod/moodleoverflow/tests/fixtures/NH.jpg" file to "Attachment" filemanager
And I press "Post to forum"
Then I should see "Anonymous (You)"
When I am on the "Test moodleoverflow name" "Activity" page logged in as "teacher1"
And I follow "This is Nina"
Then I should not see "Student 1"
And I should see "Questioner"
Given I follow "Edit"
And I click on "NH.jpg" "link"
Then the field "Author" matches value "Anonymous"

0 comments on commit fbecb6d

Please sign in to comment.