Skip to content

Conversation

jacovkim
Copy link

@jacovkim jacovkim commented Dec 5, 2024

Added validation for extension and file size before reading.
Added validation after reading.
Added file size compression.

Some other considerations:

  1. Crop the image after resizing to preserve the ratio
  2. Placeholder image for missing profiles
  3. Might need to replace the current compression method as it's an iterative approach
  4. (Optional) Change public S3 bucket to private with AWS signing

Things to do:

  1. Should disable the "upload" button when the file exceeds the limit when editing
  2. Also clear form after uploading

Copy link

cypress bot commented Dec 5, 2024

csm_web    Run #395

Run Properties:  status check failed Failed #395  •  git commit b57621271c: Image validation and size optimization for Profile image upload from both front-...
Project csm_web
Branch Review feat/profiles2024/images
Run status status check failed Failed #395
Run duration 02m 04s
Commit git commit b57621271c: Image validation and size optimization for Profile image upload from both front-...
Committer Jacob Taegon Kim
View all properties for this run ↗︎

Test results
Tests that failed  Failures 10
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 74
View all changes introduced in this branch ↗︎

Tests for review

Failed  student-course.cy.ts • 2 failed tests • Tests on Firefox

View Output

Test Artifacts
... > should be able to enroll in a section Screenshots
... > should be able to enroll in a section Screenshots
Failed  restricted-courses.cy.ts • 3 failed tests • Tests on Firefox

View Output

Test Artifacts
unwhitelisted courses > should still show unrestricted courses Screenshots
whitelisted courses > should see and enroll in whitelisted courses and sections Screenshots
whitelisted courses > should see whitelisted courses among unrestricted courses Screenshots
Failed  student-course.cy.ts • 2 failed tests • Tests on Chrome

View Output

Test Artifacts
... > should be able to enroll in a section Test Replay Screenshots
... > should be able to enroll in a section Test Replay Screenshots
Failed  restricted-courses.cy.ts • 3 failed tests • Tests on Chrome

View Output

Test Artifacts
unwhitelisted courses > should still show unrestricted courses Test Replay Screenshots
whitelisted courses > should see and enroll in whitelisted courses and sections Test Replay Screenshots
whitelisted courses > should see whitelisted courses among unrestricted courses Test Replay Screenshots

Copy link
Member

@smartspot2 smartspot2 left a comment

Choose a reason for hiding this comment

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

I just did a cursory skim over the PR, but here's some of the feedback I have so far.

Also, did you mean for the target branch to be master here, or is this supposed to be targeting a main feature branch?

Comment on lines 255 to 270
# not very efficient but way to compress image until it meets the file target size.
def compress_image(image, target_size_bytes, img_format):
"""Compress the image until it's smaller than target_size_bytes."""
buffer = BytesIO()
quality = 95 # start with high quality
while True:
buffer.seek(0)
if img_format == "JPEG" or img_format == "JPG":
image.save(buffer, format=img_format, quality=quality)
else:
image.save(buffer, format="PNG", optimze=True)
if buffer.tell() <= target_size_bytes or quality <= 50:
break
quality -= 5 # decrease quality to reduce file size
buffer.seek(0)
return buffer
Copy link
Member

Choose a reason for hiding this comment

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

Is there any particular reason why we're compressing the file? We have a file size limit anyways, which should be sufficient (and can be lowered) if this is for storage concerns.

Copy link
Author

Choose a reason for hiding this comment

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

usually, selfies or phone images tend to be larger than 5MB so allowing 10MB input size and compressing it to 5MB was what I was initially thinking but just realized I didn't change the target size and input limit. But should allowing 10MB then compressing to 5MB to save space make sense?

Copy link
Member

Choose a reason for hiding this comment

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

There should be tests added for uploading images; in particular one should be added where a request is sent using a file stream that never ends, and ensuring that the request is rejected after only reading in the file size limit.

Copy link
Member

Choose a reason for hiding this comment

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

These migration files should be merged together at the end prior to merging to master, to reduce on the number of migration files in the repo.

@edwardneo edwardneo force-pushed the feat/profiles2024/images branch from fdfc29d to 9a79f9b Compare February 1, 2025 07:39
@isabellaalps isabellaalps self-requested a review February 3, 2025 01:43
@isabellaalps
Copy link

  • think it would be nice to add a short description/heading on the profiles landing page to explain what profiles is/does
  • unable to add image to profiles without triggering fatal error

Copy link
Member

@smartspot2 smartspot2 left a comment

Choose a reason for hiding this comment

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

Made a bunch of comments in the thread. Overall, looks pretty good!

Some other miscellaneous things as I tested manually:

  • Coordinators are able to edit anybody else's profile, which shouldn't be happening; I mentioned this as a review comment as well pointing to the section of code responsible. In general, there should be additional testing to ensure that negative constraints are satisfied. (To test, I had to remove the superuser exception in the code.)

  • Putting a blank name does not default to the user's full name. Interestingly, this only occurs when there is no image uploaded. Otherwise, the name defaults as usual. (This is probably because of some query invalidation to display the image once it's uploaded.)

  • I think there should be a button to clear the image if the user wants to delete their profile picture; currently, there is no way to do that, and if a user wants to change their profile picture to the default, they'd need to upload the CSM logo. For initial release, this can probably be deprioritized, but this can probably be relatively easily implemented by adding an "X" icon overlaid with the uplaod icon, and the PUT request can specify null for the file (the backend would then check if the file is null; a file that is not updated would not have a key in the request).

  • The upload icon is a little bit faint when there's an image uploaded; I think either (a) make the icon less transparent, or (b) put a white background on the icon so that the image itself is a little more faint, bringing out the icon more.

    (for example)

    image

  • The links look a little bit out of place; styling the links to fit in a little more with the color scheme could be good? The links on the resources page for worksheets could be good to model off of here. If you'd like, you can use a lighter blue (kinda like the csmentors.org website links) instead of the green to make it more clearly link-like. One big thing is that there shouldn't be a difference between normal links and :visited links on the page.

    (for example)

    image
    image

Comment on lines 99 to 103
<h4>To view and update your profile, click the button below</h4>
<Link className="primary-btn" to="/profile">
<UserIcon width={inlineIconWidth} height={inlineIconHeight} />
Profile
</Link>
Copy link
Member

Choose a reason for hiding this comment

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

This change is the cause of the Cypress test failures; the Cypress tests should change to look for Profile instead, and should make sure that the user is redirected as desired.

@edwardneo
Copy link
Contributor

Ok I addressed most of y'all's comments. There is a working delete button, hyperlink colors are fixed, editing should be fixed. Theoretically this feature is fully functional, but if/when I have time tonight, I'll add a tooltip on the profile landing page to explain what profiles does (like Isabella mentioned) and maybe try adding a page to list all of the mentors for a certain course.

Also, the S3 bucket is currently csm-web-profile-pictures-dev, this can be set in the .env file with the link
AWS_PROFILE_PICTURE_BUCKET_NAME=csm-web-profile-pictures-dev
or it should have been also added to ./setup.sh if y'all would prefer to run that. On prod it will be set manually to the prod profile pictures bucket.

smartspot2
smartspot2 previously approved these changes Sep 6, 2025
Copy link
Member

@smartspot2 smartspot2 left a comment

Choose a reason for hiding this comment

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

Honestly overall this looks pretty good. I'll give a stamp of approval for now, but see my comments for various things I've noticed while testing.

Make sure that all conflicts are resolved and all CI tests pass, and additionally make sure that this is tested on staging before merging into master; check all permissions and do spot checks on functionality to ensure that nothing weird happens on staging. (It's also a good way to check that dependencies are all fine, since you've updated some dependencies in this PR.)

<div className="profile-section-times">
{sectionTimes.map((spacetimes, index) => (
<div key={index} className="profile-section-time">
<ClockIcon /> <span>{spacetimes.map(formatSpacetimeInterval).join(" + ")}</span>
Copy link
Member

Choose a reason for hiding this comment

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

Also I think it'd be pretty cool if clicking on the section time (or a link adjacent) would bring you directly to the section card on the sections page, for ease of enrollment.

Or honestly some way of combining the bios page and sections page in the future would probably good too, ex. incorporating the enroll button on the bios page for reduced friction.

These are all nice-to-have things as extra additions for the future though (feel free to separate this into a separate issue to tackle later).

Copy link
Member

Choose a reason for hiding this comment

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

Something for the future, but some kind of back button to return the user to their previous page could be nice here (there should be some utilities to just pop from the navigation history); having to navigate back using the browser back button is a little bit annoying. After looking at a profile, I naturally look for a back button to go back to what I was looking at before, ex. the sections page, or the bios page.

Not a priority, so this can also be punted to a separate issue.

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.

6 participants