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

System for discouraging assignment of specific articles #5495

Merged

Conversation

Abishekcs
Copy link
Contributor

@Abishekcs Abishekcs commented Oct 4, 2023

closes #5477

What this PR does

This pull request addresses the issue documented in #5477. It introduces a feature that displays a warning message to students and administrators when they select a discouraged article/assignment.

Affected Pages:

  • /courses/[institution_name]/[course_name]/articles/available
  • /courses/[institution_name]/[course_name]/article_finder
  • /courses/[institution_name]/[course_name]/students/articles/[user]
  • /courses/[institution_name]/[course_name/home

Screenshots

Before:

For Admin :

Before.Admin.webm

For Student :

Before.Student.webm

After:

For Admin:

After.Admin.mp4

For Student:

After.Student.mp4

Note:

For testing a category from wikipedia set blocked_assignment_category: [Category Name] in application.yml (used in assignment_manager.rb) and also run dailyupdate

@Abishekcs Abishekcs changed the title System for discouraging assignment of specific articles [WIP] System for discouraging assignment of specific articles Oct 20, 2023
@Abishekcs Abishekcs marked this pull request as ready for review October 20, 2023 10:05
@Abishekcs Abishekcs requested a review from pppery October 20, 2023 10:33
Copy link

@pppery pppery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see nothing obviously wrong with this code, but I'm not an expert here.

@Abishekcs
Copy link
Contributor Author

I see nothing obviously wrong with this code, but I'm not an expert here.

okay np.

@Abishekcs
Copy link
Contributor Author

@ragesoss, your review would be greatly appreciated whenever you have the time.

@ragesoss
Copy link
Member

Thanks for taking on such a big issue @Abishekcs!

I think I would prefer a somewhat different approach. The first major suggestion I have is to rely on the existing Category table rather than create a new record type in the database. These records are already designed to query Wikipedia for the titles in a category and save them, so I don't think there will be a need for any database changes.

I also think that the majority of the logic for this feature should be on the server. AssignmentManager is the natural place to handle checking for whether a new assignment is one that ought to be blocked or requires a warning confirmation.

I suggest breaking it up into two parts, beginning with implementing a system that just completely prevents creating assignments that are in a certain category. This would be relatively easy to handle in terms of data flow: AssignmentManager should check against the category, raise a specific error (similar to the existing DuplicateAssignmentError), and then AssignmentsController should rescue that error and return a good error message and error status to the frontend. (The Category will need to be routinely refreshed, which can be done via a worker that gets scheduled via DailyUpdate.)

A follow-up could then extend it to handle articles that are discouraged but not prevented altogether. We could do this either by adding a way to acknowledge the warning and resubmit from the frontend, or by triggering an Alert when a discouraged articles is assigned and then sending an email to the user and/or the instructor with details about discouraged articles and why they should consider choosing a different article instead. Hmmm... after thinking through it, I guess the frontend approach will be better there, because one goal would be to prevent the noise of adding additional templates to the talk page of the article (even if they later get removed).

@Abishekcs
Copy link
Contributor Author

Sure, I will make the changes you have suggested. Thank you for the review .

@Abishekcs
Copy link
Contributor Author

Abishekcs commented Nov 15, 2023

@ragesoss , I have moved the logic for discouraged assignments to AssignmentManager and am now utilizing the existing category. I would appreciate a review whenever you have the time.(Updated the Screenshots)

@Abishekcs Abishekcs requested a review from TheTrio November 16, 2023 07:52
@Abishekcs Abishekcs requested a review from ragesoss November 22, 2023 18:59
@Abishekcs
Copy link
Contributor Author

Abishekcs commented Nov 22, 2023

@ragesoss, I have removed the warning feature for this PR and kept the feature for blocked assignment. Currently, I am writing test code for this PR.

@ragesoss
Copy link
Member

@Abishekcs sounds good. Give me a ping when the tests are done. I will likely have some time to review it next week if it's ready then.

@Abishekcs
Copy link
Contributor Author

@ragesoss the test code is done for this PR. I would appreciate a review whenever you have the time.

@ragesoss
Copy link
Member

it's on my todo list.

@Abishekcs Abishekcs requested a review from ragesoss November 30, 2023 12:53
…eate_assignment

Move the check against discouraged articles into the create_assignment method, parallel to the existing pattern for handling DuplicateAssignmentError. This simplifies the code structure, ensures the same clean title flow is applied, and maintains consistency in error handling.
…eManager

Replace CategoryImporter with #refresh_titles, ensuring uniqueness with find_or_create_by.
Refactor and enable Wiki Education-only features for update_wiki_discouraged_article.
@Abishekcs Abishekcs force-pushed the DiscouragedAssignment branch from b9fad9c to 4047e05 Compare December 5, 2023 18:57
@Abishekcs
Copy link
Contributor Author

Abishekcs commented Dec 5, 2023

I fixed it by updated the selenium-webdriver gem, and I've pushed that update. If you rebase and bundle install, hopefully the tests will work properly for you now.

@ragesoss the test is working properly now.
For this, Failed examples:
rspec ./spec/lib/importers/revision_score_importer_spec.rb:205 # RevisionScoreImporter.update_revision_scores_for_all_wikis imports data and calcuates an article completeness score for available wikis its working fine locally.

@ragesoss
Copy link
Member

ragesoss commented Dec 5, 2023

Great. That failure is unrelated to your PR, so the tests seem to be in order. I will continue trying out and reviewing it soon. Thanks!

@@ -265,6 +265,7 @@ en:
article: The article %{title} is now assigned to you.
article_link: Article
article_link_wikidata: Item
discouraged_article: The article is discouraged by Wiki Education.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't actually being used, because the message is being set already where the error is raised. I suggest using the interpolation syntax.

I suggest the key blocked_assignment, and a message like "%{title} could not be assigned because it is on the Wikipedia community's Wiki Education assignment blocklist."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I will make the changes

@@ -104,6 +105,14 @@ def set_article_from_database
@article = exact_title_matches.first
end

def check_wiki_edu_discouraged_article
category = Category.where('name = ? AND article_titles LIKE ?',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the better way to do this is to find the category first, and then check whether the title is included in the catetgory's array of titles. Using LIKE might result in mismatches, such as blocking the assignment of "Animal" when "Animal rights" is on the blocklist.

@ragesoss
Copy link
Member

I tested this out, and it works the way I would expect. With the additional changes I requested, this will be ready to merge.

…rror message and enhance blocklist check

Refactors error messaging to use interpolation syntax and introduces 'blocked_assignment' key.
Improves blocklist check by finding the category first, ensuring accurate determinations and avoiding potential mismatches.
@Abishekcs Abishekcs requested a review from ragesoss December 12, 2023 14:55
@Abishekcs
Copy link
Contributor Author

I tested this out, and it works the way I would expect. With the additional changes I requested, this will be ready to merge.

@ragesoss , I have made the requested changes for this.

@Abishekcs
Copy link
Contributor Author

@ragesoss any update on this PR😅 ?

@ragesoss
Copy link
Member

ragesoss commented Jan 5, 2024

@Abishekcs yes, i'm happy with the PR and it is ready to merge, but I have not yet introduced this new feature to the Wikipedia community or finalized the category name to so, so I don't want to merge and deploy it yet. Doing that introduction is near the top of my todo list now that I am back from vacation; I hope to get it started today.

@ragesoss
Copy link
Member

The on-wiki discussion about this has not really come to a conclusion, in particular with regards to the category name or how the community wants to use it... but I'd like to go ahead and merge it and deploy it so that it's ready whenever we do come to consensus. So... what happens if this gets deployed but there is no blocked_assignment_category value set?

@Abishekcs
Copy link
Contributor Author

@ragesoss by this So... what happens if this gets deployed but there is no blocked_assignment_category value set? do you mean if there is no ENV set for blocked_assignment_category 😅?

@ragesoss
Copy link
Member

Yes, that's what I mean. Is it safe to deploy it without such a value, so that it just would not do anything? If not, can it be easily adjusted to behave like that?

@Abishekcs
Copy link
Contributor Author

@ragesoss, ENV['blocked_assignment_category'] is used in two places:

a) In AssignmentManager, it is used to find a category by name. It simply returns null if there is no value set for ENV['blocked_assignment_category'] when I test it locally.

b) The second place is in WikiDiscouragedArticleManager, which is used in dailyupdate. I think for the second part, I will add an if statement to check if ENV is set. Since it might cause trouble with other daily updates.

In WikiDiscouragedArticleManager, introduce a conditional check to verify
if 'blocked_assignment_category' is present in the environment variables.
When absent, log an informational message using Rails.logger.
@Abishekcs
Copy link
Contributor Author

Abishekcs commented Feb 15, 2024

test
Ignore the check ENV it was just for testing locally if it gives error.

log

@ragesoss i have added the if statement for WikiDiscouragedArticleManager and for AssignmentManager there is already an if statement to check category is present or not.

@ragesoss
Copy link
Member

Great, thanks!

depth: 0
).refresh_titles
blocked_assignment_category = ENV['blocked_assignment_category']

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer a return unless guard clause here, rather than the branching if statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Abishekcs Abishekcs requested a review from ragesoss February 15, 2024 20:38
@ragesoss
Copy link
Member

Looks like your new change broke the tests. The fix probably involves adding a new entry in config/environments/test.rb.

@Abishekcs
Copy link
Contributor Author

Looks like your new change broke the tests. The fix probably involves adding a new entry in config/environments/test.rb.

It should pass now 😅 added the entry for test ENV.

@ragesoss ragesoss merged commit 6b97fe3 into WikiEducationFoundation:master Feb 26, 2024
1 check passed
@ragesoss
Copy link
Member

Thanks @Abishekcs! This is an exciting feature, and I'm looking forward to seeing it in action.

@Abishekcs
Copy link
Contributor Author

Thanks @Abishekcs! This is an exciting feature, and I'm looking forward to seeing it in action.

Great! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a system for discouraging assignment of specific articles
4 participants