Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide author of files in anonymous posts #173

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading