Skip to content

Fix avatar image bug. Fixes #586#595

Merged
A1L13N merged 5 commits into
alphaonelabs:mainfrom
abdelrahman390:avatar-image-update-fixed
May 11, 2025
Merged

Fix avatar image bug. Fixes #586#595
A1L13N merged 5 commits into
alphaonelabs:mainfrom
abdelrahman390:avatar-image-update-fixed

Conversation

@abdelrahman390
Copy link
Copy Markdown
Contributor

@abdelrahman390 abdelrahman390 commented May 10, 2025

Related issues

Fixes #586

Checklist

  • [x ] Did you run the pre-commit? (If not, your PR will most likely not pass — please ensure it passes pre-commit)
  • [ x] Did you test the change? (Ensure you didn’t just prompt the AI and blindly commit — test the code and confirm it works)
  • [ x] Added screenshots to the PR description (if applicable)

Fixed avatar image bug that happens when trying to update the avatar.

Annotation 2025-05-11 015115

Summary by CodeRabbit

  • New Features

    • Combined profile updates and avatar upload into a single form submission on the profile page.
  • Enhancements

    • Improved avatar upload handling to prevent unnecessary uploads when the avatar is unchanged.
    • Streamlined user experience with optimized form submission logic.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 10, 2025

"""

Walkthrough

The profile page template was updated to merge the avatar upload and profile update into a single form. JavaScript was added to manage avatar input changes, ensuring the avatar field is only included in submissions when modified. This streamlines profile updates and optimizes avatar upload handling. Additionally, debugging print statements were added to the profile view to log POST and FILES data on form submission.

Changes

File(s) Change Summary
web/templates/profile.html Combined avatar and profile forms into one, updated avatar input handling, and added JavaScript for form logic
web/views.py Added print statements inside profile view POST handler to log request.POST and request.FILES for debugging

Assessment against linked issues

Objective Addressed Explanation
Fix avatar update so that updating the avatar does not clear or remove other profile fields' values (#586)
"""
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Hello @abdelrahman390, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request addresses a bug related to updating the avatar image on the user profile page, as described in issue #586. The changes involve modifying the profile template to correctly handle avatar updates. Specifically, the form structure has been adjusted to ensure the avatar is only included in the form data if it has been changed by the user. This prevents unnecessary avatar uploads and potential issues with the update process.

Highlights

  • Bug Fix: Addresses a bug where updating the avatar image was not working correctly.
  • Template Modification: Adjusts the profile template (profile.html) to handle avatar updates more efficiently.
  • Conditional Avatar Submission: Implements logic to only include the avatar in the form submission if it has been changed, optimizing the update process.

Changelog

  • web/templates/profile.html
    • The profile picture section is now wrapped within the main form.
    • The main form is now identified with the id 'main-form'.
    • A hidden avatar field is added for form processing.
    • JavaScript code is added to handle avatar changes and conditional form submission.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A profile's face,
New image, a fresh embrace,
Bugs squashed with care.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request addresses a bug related to avatar image updates. The changes involve modifying the profile template to include the avatar upload form within a larger form and adding JavaScript to handle avatar changes. Overall, the approach seems reasonable, but there are a few areas that could be improved for clarity and efficiency.

Summary of Findings

  • Form submission handling: The JavaScript code intercepts the form submission to conditionally include the avatar file. This approach might introduce complexity and potential issues with form validation and other form elements. Consider alternative approaches, such as using a hidden field to indicate whether the avatar has been changed.
  • Session storage usage: The use of session storage to track avatar changes might not be reliable across different browsers or sessions. Consider using a more robust mechanism, such as a hidden input field within the form.

Merge Readiness

The pull request addresses the reported issue, but the current implementation introduces some complexity. Addressing the feedback regarding form submission handling and session storage usage would improve the code's reliability and maintainability. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging. I recommend that the pull request not be merged until the high severity issues are addressed.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2c9c03c and 4706ce3.

📒 Files selected for processing (1)
  • web/templates/profile.html (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Run Tests
🔇 Additional comments (4)
web/templates/profile.html (4)

33-38: Consolidated form structure correctly merges avatar and profile updates
Wrapping both avatar upload and profile fields inside a single <form> with enctype="multipart/form-data" and including {% csrf_token %} is the right approach. Defaulting the action to the current URL is acceptable if your view handles both avatar and profile changes.


41-45: Ensure SVG output is safe from XSS
You’re rendering raw SVG via {{ user.profile.custom_avatar.svg|safe }}. Please verify that custom_avatar.svg is sanitized server-side (e.g., via a whitelist sanitizer) before marking it safe to avoid potential XSS.


47-47: Ordering of avatar conditions is correct
Using elif user.profile.avatar ensures that a standard uploaded avatar only displays when there’s no custom_avatar. The fallback priority looks solid.


79-81: Username and full name display logic is sound
Conditionally rendering {{ user.get_full_name }} only when nonempty enhances clarity without clutter. Nicely done.

Comment thread web/templates/profile.html
Comment thread web/templates/profile.html
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 10, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (1)
web/templates/profile.html (1)

72-77: ⚠️ Potential issue

Remove inline onchange to avoid premature submission
The inline onchange="this.form.submit()" triggers an immediate submission, bypassing your sessionStorage logic and submit handler. Remove this attribute so the JS listener exclusively manages form submissions:

-<input type="file"
-       id="avatar-upload"
-       name="avatar"
-       accept="image/*"
-       class="hidden"
-       onchange="this.form.submit()" />
+<input type="file"
+       id="avatar-upload"
+       name="avatar"
+       accept="image/*"
+       class="hidden" />
♻️ Duplicate comments (1)
web/templates/profile.html (1)

61-64: Add accessible label for initial/avatar fallback
The fallback <div> (showing the user’s initial) still lacks an ARIA role and label. Screen readers will ignore it without an explicit role or aria-label. Please add, for example:

<div role="img" aria-label="{{ user.username }}'s avatar" 
     class="w-32 h-32 rounded-full bg-orange-500 …"></div>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4706ce3 and 81d559c.

📒 Files selected for processing (2)
  • web/templates/profile.html (3 hunks)
  • web/views.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build-and-test
  • GitHub Check: Run Tests
🔇 Additional comments (4)
web/templates/profile.html (4)

33-37: Form merge and enctype are correctly applied
Consolidating the avatar upload and profile update into a single <form> with id="main-form" and enctype="multipart/form-data" is the right approach for handling file uploads alongside other fields. Good job on ensuring CSRF protection remains in place.


530-537: JS change listener correctly flags avatar updates
The event listener on avatarInput cleanly sets sessionStorage.avatarChanged when a user selects a new file. This separation of concerns (setting a flag, deferring actual submission) is well done.


539-545: JS submit handler disables unused input
Disabling the file input when avatarChanged'true' is an effective way to omit it from the submission. Using form.submit() afterward ensures the disabled field is not serialized.


547-550: Reset flag and submit via JS
Clearing sessionStorage.avatarChanged and invoking mainForm.submit() (which bypasses the JS listener) is correct. This guarantees that the disabled state doesn’t lock the form for future submissions.

Comment thread web/templates/profile.html
Comment thread web/views.py Outdated
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 10, 2025
@A1L13N
Copy link
Copy Markdown
Contributor

A1L13N commented May 11, 2025

@coderabbitai review and approve

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 11, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@A1L13N I'll review this PR for you. Let me gather the necessary information about the changes first.


🏁 Script executed:

#!/bin/bash
# Get the PR diff to see the actual code changes
git diff --stat HEAD^1 HEAD

# Show the actual diff of the changes
git diff HEAD^1 HEAD

# Look at issue #586 to understand the problem being fixed
gh issue view 586

# Get the content of the changed files to understand the context
echo "=== web/templates/profile.html ==="
cat web/templates/profile.html

echo "=== web/views.py ==="
cat web/views.py

Length of output: 97758


@A1L13N After examining the PR changes, I'll review this fix for the avatar image bug (issue #586).


🏁 Script executed:

#!/bin/bash
# Fetch PR diff to see the exact changes
gh pr diff 595

Length of output: 5633


@A1L13N I've completed my review of the PR that fixes the avatar image bug (issue #586). This is a good solution to the problem.

What was the bug?

When users tried to update their avatar image, all other profile fields were being cleared because the avatar was submitting in a separate form that didn't include the other field values.

How does this fix work?

  1. The PR combines the avatar upload and profile form into a single form with id="main-form"
  2. It adds JavaScript that:
    • Tracks when the avatar is changed using sessionStorage
    • Disables the file input when it hasn't changed (to optimize file uploads)
    • Ensures all form fields are submitted together

This approach preserves all profile field values when updating the avatar image, which fixes the issue described in #586.

The implementation is clean and maintains a good user experience. I approve this pull request.

@A1L13N A1L13N merged commit 5039828 into alphaonelabs:main May 11, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants