-
Notifications
You must be signed in to change notification settings - Fork 643
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
Remove course template from user page and user talk page when user disenrolls #5507
Remove course template from user page and user talk page when user disenrolls #5507
Conversation
…user pages and user talk pages when users are disenrolled.
…user from a course when the user gets removed.
def remove_assignment_and_enrollment_templates | ||
remove_assignment_templates | ||
make_disenrollment_edits | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created this because got a "Method has too many lines" offense from rubocop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better way to reorganize this code would be to extract some of the setup and guard code at the start of the method. Ideally, the code in a method is at roughly the same level of abstraction, and the most detailed bits are the first ones to extract.
Extracting these two lines does not really make the method any easier to understand, which is the purpose behind that rubocop rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, I see your point. I tried to do that on 9939233
talk_page = "User_talk:#{disenrolling_user.username}" | ||
talk_summary = "removing {{#{template_name(@templates, 'user_talk')}}}" | ||
remove_content_from_page(talk_page, talk_template, talk_summary) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sanity checks:
- Should I do something with the template in sandbox to revert the
add_template_to_sandbox
action? - Should I take
enrollment_edits_enabled
into account for disenrolling? I mean, validate thedisenroll_from_course
action, similar to how it's done forenroll_in_course
, by checking theenrollment_edits_enabled
flag in thevalidate
method.
def validate(action)
yield unless course_edits_allowed?
# action-specific checks
case action
when :update_course
yield unless @course.wiki_course_page_enabled?
when :update_assignments, :remove_assignment
yield unless @course.assignment_edits_enabled?
when :enroll_in_course
yield unless @course.enrollment_edits_enabled?
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's necessary, as that's not a place other editors will look to understand the context for the un-enrolled student's edits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I edited the message adding a second question after you answered, so just checking you saw both questions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I missed the second question. I think yes, checking enrollment_edits_enabled?
for this action makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the check and spec for that on 00cf010
Note: I was able to enable wiki edits on my local environment, and I reproduced this by adding and then removing my own user to a course. The history of how my user page and user talk page was modified can be check on https://en.wikipedia.org/w/index.php?title=User:Gabinaluz&action=history. I didn't feel very confident reproducing that for fear of unintentional changes, so I didn't try more than that. |
CI failed with the following errors:
Will check if something is related to my changes. Edit: the error for the wiki pageviews seems to be
It doesn't look like it's related to my changes. |
It looks like the edit summaries were buggy: |
…r page and user page talk, and update tests to catch the bug. Before this commit, when the course template was deleted, an extra newline character was mistakenly added.
Oh good point.
You can check that on https://en.wikipedia.org/w/index.php?title=User:Gabinaluz&action=history On the other hand, while taking a look at your point, I noticed a small bug in the disenrollment action, that wasn't caught by the tests. If you compare the last two versions, you can notice that an extra new line is added when removing the course template, which is wrong. I modified the tests to catch the error, and then fixed it using a regular expression on 48d7a55 |
# If content to remove does not exist on initial page, then there is nothing | ||
# to remove | ||
return unless initial_page_content&.include?(content) | ||
new_page_content = initial_page_content.gsub(/#{Regexp.quote(content)}(\n)?/, '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added an optional new line in the regexp, but maybe we can use just something like #{Regexp.quote(content)}\n
, as the new line should be always added when writing the course template
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the newline should be removed if present, but if there is not a newline, it should still remove the template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Then it looks like using /#{Regexp.quote(content)}(\n)?/
(as it's now) is the right way. If the new line after the content exists, it will match the content and the new line. If the new line doesn't exist, it will match only the content.
Let me know if there is something for me to review. Otherwise, I understand I already addressed all the suggestions/questions.
Suspect IssuesThis pull request was deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
I sent a request to join to wiki-education organization for Sentry because I cannot see the issue in Sentry |
@gabina that error is definitely not related to your change; I haven't deployed it to Programs & Events Dashboard yet. |
What this PR does
The purpose of this PR is to add a way to remove course templates from user page and user talk page when user gets dis-enrolled from a specific course.
When a user enrolls in a course, a template pointing to the course is added to the user page and the user talk page (example user page with participating template: https://en.wikipedia.org/wiki/User:Jfitz19)
This PR adds a new
DisenrollFromCourseWorker
worker to remove course templates from user page and user talk page. It basically "reverts" what theEnrollInCourseWorker
does (except for the user's sandbox action).Now, when a user gets removed from a course, the
EnrollmentController#remove
schedules a job for theDisenrollFromCourseWorker
to remove the participating templates from user page and user talk page.Closes #2842
Screenshots
Open questions and concerns