Skip to content

[knowledge-base] Add Contributor Upload Form Backend#780

Merged
jacqsmei merged 9 commits intodevfrom
knowledge-base/contributor/upload-mdfile-backend
May 11, 2025
Merged

[knowledge-base] Add Contributor Upload Form Backend#780
jacqsmei merged 9 commits intodevfrom
knowledge-base/contributor/upload-mdfile-backend

Conversation

@yizou275
Copy link
Contributor

@yizou275 yizou275 commented May 9, 2025

This PR implements the backend of knowledge base contributor's upload page, where they upload the md file of the guide.
I not only include the initial upload page, but also a reupload page, for users whose guide is under "change requested" status and wishes to reupload their guide to address the changes.

Description

The implemented feature of both upload and reupload pages includes the following:

  1. Display a form, where users can select a game and upload their file (In reupload page, user can NOT choose a game.)
  2. File restriction: if they upload a non-md file, after they hit submit, the page shows a validation error
  3. Page access:
    - for upload page, all logged-in users can access this page, and unlogged-in users are redirected to the log in page
    - for reupload page, only logged-in user who authors this guide and is under "change requested" status can access, otherwise will display 403.

File Changes

Specifically, the files I change are:

  • views.py: add the ContributorMdUpload view that handles both upload and reupload according to the logic above
  • forms.py: add the form that takes in a game and a md file; the game field is read-only for reupload, and non-md file type will throw an error
  • urls.py: add the link for upload and reupload
  • contributor_upload.html: modify according to views.py to give an unstylished view of the upload page

Testing

To test it, first pull this branch, load the fixture according to knowledge-base/fixtures/README.md, and then runserver.

  1. First go to upload page as unlogged-in user, check whether they ask you to log in. If so, log in as Admin.
  2. Then check whether the page is displayed properly, including both game and file file.
Screenshot 2025-05-08 at 10 24 55 PM 3. Try upload a random non-md file. Check whether it throws an error. Screenshot 2025-05-08 at 10 26 05 PM 4. Upload a md file, submit the form. Go to admin interface and check whether there is a new Guide object, with matching author, content, and status=pending. Also, pls record the content for Guide 6 and confirm status=change requested, for later purpose.
  1. Then test reupload page. When back, log in as Sam. Go to http://127.0.0.1:8000/knowledge-base/1/reupload, it should throw a 403 (guide author doesn't match); go to http://127.0.0.1:8000/knowledge-base/7/reupload, should throw 403 error (status is NOT requested change). Then go to http://127.0.0.1:8000/knowledge-base/6/reupload, you should then be able to see it displayed, with game field being read-only.
Screenshot 2025-05-08 at 10 34 05 PM
  1. To check whether reupload works correctly, reupload and submit another md file. Then log into Admin interface to check what is saved Guide 6 right now -- check whether content is updated and status is pending again.

AI reference: Consulted ChatGPT on how a site can take in a file from a form and render it into our stored data object. Understood and then modified its example code to accommodate our need.

Yi Zou added 4 commits May 7, 2025 13:44
- write the form.py where user can POST request and upload
 their guide
- user can reupload a guide if they are author of the guide and
 status is "change requested"

 For: #655
…wledge-base/contributor/upload-mdfile-backend
- fix bug that doesn't show error when a non-md file is uploaded

Fix: #655
@yizou275 yizou275 linked an issue May 9, 2025 that may be closed by this pull request
@yizou275 yizou275 self-assigned this May 9, 2025
@yizou275 yizou275 added this to the 2025/Sprint 3 milestone May 9, 2025
@yizou275 yizou275 requested a review from mrollinswaterman May 9, 2025 15:34
Copy link
Contributor

@mrollinswaterman mrollinswaterman left a comment

Choose a reason for hiding this comment

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

All functionality looks good to me! Couple notes on mostly cosmetic/QoL stuff:

  • Might be nice to have something to indicate a file has been uploaded properly. Right now, there's no change on the screen so it's kind of hard to tell.

  • Hand in hand with that, I think /upload and /reupload should redirect to some other page once the a file has successfully been uploaded. Probably just back to the contributor page, but it's up to you.

Other than that, everything looks great! Good stuff.

@yizou275 yizou275 requested a review from jacqsmei May 9, 2025 21:59
…wledge-base/contributor/upload-mdfile-backend
@yizou275
Copy link
Contributor Author

yizou275 commented May 9, 2025

Thank you Miles for this quick and helpful feedback!
Regarding the page after upload, I initially plan that it will redirect to the landing page of knowledge base. This works successfully on my end, but not on Miles' end. As time is limited and this does not affect the correctness of backend update of the database, we agree to merge this version for now, and open a future issue for fixing this bug.

Copy link
Contributor

@jacqsmei jacqsmei left a comment

Choose a reason for hiding this comment

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

nice work! you can make a follow up pr for showing the upload state (maybe some kind of green check if successful, some error handling if not?)

@jacqsmei jacqsmei merged commit 0dcbe7c into dev May 11, 2025
2 checks passed
@jacqsmei
Copy link
Contributor

Issue Score: Excellent

Comments:
Nice work & really thorough testing instructions! And great teamwork in the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Implement Knowledge Base Contributor Markdown Upload Page

3 participants