Skip to content

fix: Improve CSV badge awarding with validation and error reporting#875

Open
Marvinrose wants to merge 3 commits intofedora-infra:swatantryafrom
Marvinrose:feature/csv-badge-awarding-fixes-swatantrya
Open

fix: Improve CSV badge awarding with validation and error reporting#875
Marvinrose wants to merge 3 commits intofedora-infra:swatantryafrom
Marvinrose:feature/csv-badge-awarding-fixes-swatantrya

Conversation

@Marvinrose
Copy link
Copy Markdown

Fix: CSV badge awarding with validation and error reporting

Fixes #348

Problem

The existing award_from_csv() had multiple issues:

  • In Python 3, file lines are bytes not str, causing .split(",") to silently fail
  • No validation for missing or empty file uploads
  • No feedback to the admin on what happened, the original requester specifically asked to know which accounts weren't found
  • No handling of malformed CSV lines

Changes

  • Added .decode("utf-8") fix for Python 3 bytes handling
  • Added file presence and empty filename validation
  • Added detailed summary flash messages covering:
    • Successful awards count
    • Users that didn't exist and were auto-created
    • Skipped duplicates (already awarded)
    • Badge IDs not found in the system
    • Malformed lines that couldn't be parsed
  • Added tests

@Marvinrose
Copy link
Copy Markdown
Author

Hi @gridhead,
I noticed after submitting this, that award_from_csv in tahrir/views/admin.py is a part of the legacy code scheduled for removal in #904. Would you prefer I close this and instead implement CSV badge awarding as a new endpoint in tahrir/endpoints/?

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.

1 participant