Skip to content

ZA | 25-SDC-JULY | Luke Manyamazi | Sprint 1 | New Feature Rebloom - #58

Closed
Luke-Manyamazi wants to merge 0 commit into
CodeYourFuture:mainfrom
Luke-Manyamazi:New-feature-rebloom
Closed

ZA | 25-SDC-JULY | Luke Manyamazi | Sprint 1 | New Feature Rebloom#58
Luke-Manyamazi wants to merge 0 commit into
CodeYourFuture:mainfrom
Luke-Manyamazi:New-feature-rebloom

Conversation

@Luke-Manyamazi

@Luke-Manyamazi Luke-Manyamazi commented Dec 13, 2025

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

  1. Add a "re-bloom" button so users can share a bloom to their own feed and followers.
  2. UI should clearly show original author and who re-bloomed it, distinguishing it from the user’s own blooms.
  3. Display rebloom count on each bloom; timestamp can reflect rebloom time to indicate when it was shared.

Questions

Ask any questions you have for your reviewer.

@Luke-Manyamazi Luke-Manyamazi added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 13, 2025
Comment thread backend/data/blooms.py Outdated
Comment on lines +63 to +64
# Returning 0 or raising an error are typical ways to indicate failure
return 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think any other code in this codebases uses magic return values to indicate errors, and the code that calls this doesn't pass this error back to the client. You need to handle errors differently here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point — using magic return values hides failures from the caller.
I’ve refactored the rebloom logic to raise exceptions instead.

Comment thread backend/data/blooms.py Outdated
Comment on lines +74 to +75
print(f"Error adding rebloom: User with ID {user_id} not found.")
return None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This doesn't bubble the error back up to the caller - the caller will need to know this failed.

This applies throughout your change.

Comment thread backend/endpoints.py Outdated
})

@jwt_required()
def check_rebloom_status(bloom_id_str):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What are the trade-offs of having this be a stand-alone function that's called per bloom vs including this information up-front when getting a list of blooms?

Comment thread backend/data/blooms.py Outdated
try:
# First create the new bloom
rebloom_bloom_id = add_bloom(
sender=sender_user, # <<< Use the fully hydrated User object

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AFAICT add_bloom only actually uses the sender ID, an no other data from the sender - might it be simpler to make add_bloom take just the id, and change the other call-sites from sender to sender.id, rather than needing to add a whole extra database roundtrip to turn the sender ID into a sender, just to take only the ID back out of it?

Comment thread backend/data/users.py Outdated
This is necessary for operations like reblooming where only the ID is known.
"""
with db_cursor() as cur:
# NOTE: Adjust column names if they are different in your 'users' table

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What does this comment mean?

Comment thread backend/endpoints.py Outdated
rebloom_id = blooms.add_rebloom(
user_id=current_user.id,
original_bloom_id=bloom_id,
content=original_bloom.content # FIX: .content not ['content']

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is this comment about?

Comment thread backend/main.py Outdated
app.json = CustomJsonProvider(app)

# Configure CORS to handle preflight requests
# --- CORS FIX APPLIED HERE ---

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Things seemed to be working ok without this change - why did you need to change it?

Comment thread db/schema.sql Outdated
);

-- Add rebloom_count to blooms table (to track total reblooms)
ALTER TABLE blooms ADD COLUMN rebloom_count INTEGER DEFAULT 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ideally you wouldn't need to track rebloom counts in the database - there is a race condition here where values can get out of date (e.g. if you create a rebloom but haven't updated this count yet).

Instead, use SQL relationships to compute this - in a query, you should be able to compute the count of blooms which have this ID as an original_bloom_id

Your Python and JS code for querying a Bloom shouldn't have to change, but it removes the need for you to update the original bloom from the python side.

Comment thread db/schema.sql Outdated
ALTER TABLE blooms ADD COLUMN original_bloom_id BIGINT REFERENCES blooms(id);

-- Create reblooms table to track the rebloom relationship
CREATE TABLE reblooms (

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This table shouldn't need to exist - all of the information should already be present in the blooms table for you to do some joins to infer this information.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As far as I can tell this table isn't used any more, but it's still created? Please remove.

Comment thread front-end/components/bloom.mjs Outdated

const rebloomIndicator = document.createElement('div');
rebloomIndicator.className = 'rebloom-indicator';
rebloomIndicator.innerHTML = `

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There's an XSS vulnerability here by using innerHTML

@illicitonion illicitonion added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jan 21, 2026
@Luke-Manyamazi

Copy link
Copy Markdown
Author

Hi Daniel

I have done the following:

  1. Fixed rebloom creation by fetching full User objects and preventing missing argument errors.
  2. Removed rebloom_count updates in Python; counts are now computed dynamically via SQL to avoid race conditions.
  3. Secured frontend against XSS by replacing innerHTML with safe DOM methods and properly encoding hashtags and usernames.
  4. Improved endpoint error handling, type checks, and JWT integration for login, registration, and rebloom actions.

@Luke-Manyamazi Luke-Manyamazi added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Legacy-Code The name of the module. labels Feb 15, 2026

@illicitonion illicitonion left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A lot of this is looking a lot better, but there's still a lot of unrelated changes in here, and a bunch of unused code. Please take a look, and make sure:

  1. You've addressed and resolved all comments.
  2. All of the code in this PR is needed and related to this change.

It's much harder for a reviewer to see if your code is working or look for issues when half of the change isn't related.

Comment thread backend/data/users.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This file seems to have a lot of unrelated changes to it?

Comment thread backend/endpoints.py Outdated

already_rebloomed = blooms.has_user_rebloomed(current_user.id, bloom_id)

if already_rebloomed:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This kind of "toggle" behaviour can be complicated to support well in clients - they may retry requests (e.g. if the network blipped) which can accidentally undo changes.

In general I'd recommend API design where a user clearly expresses intent to rebloom or un-rebloom something, and will get an error if that's not possible, rather than sometimes undoing the action. The UI can re-use the same button, but it should typically talk to a different backend endpoint.

Comment thread db/schema.sql Outdated
ALTER TABLE blooms ADD COLUMN original_bloom_id BIGINT REFERENCES blooms(id);

-- Create reblooms table to track the rebloom relationship
CREATE TABLE reblooms (

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As far as I can tell this table isn't used any more, but it's still created? Please remove.

@illicitonion illicitonion removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 17, 2026
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Purple Forest Kanban Feb 17, 2026
@Luke-Manyamazi

Copy link
Copy Markdown
Author

Mistakenly closed this PR

@Luke-Manyamazi

Copy link
Copy Markdown
Author

Opening it to finish with review edits

@github-project-automation github-project-automation Bot moved this from Done to Backlog in Purple Forest Kanban Feb 18, 2026

@illicitonion illicitonion left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This generally looks decent, but it doesn't look like it works for me?

I ran it locally, and when I first logged in I got an error prompt.
I dismissed it and tried to rebloom something, and got an error alert" Unexpected token '<', "<!DOCTYPE "... is not valid JSON

Comment thread backend/endpoints.py Outdated
@Luke-Manyamazi

Copy link
Copy Markdown
Author

"Hi Daniel, I’ve refactored the Rebloom feature to address your feedback:

Fixed XSS: Replaced innerHTML with createTextNode for safe rendering.

Removed Race Conditions: rebloom_count is now calculated via SQL subqueries instead of a manual column.

JSON Fix: Standardized all error responses to jsonify() to resolve the Unexpected token < crash.

Efficiency: Streamlined add_bloom to accept sender_id directly, removing redundant DB lookups.

@Luke-Manyamazi Luke-Manyamazi added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 📅 Sprint 1 Assigned during Sprint 1 of this module labels Mar 7, 2026
@Luke-Manyamazi

Copy link
Copy Markdown
Author

Hi Daniel, I was getting an error while trying to rebloom, but it's fixed now.

Here’s a summary of the changes:

Fix: Rebloom Functionality & Auth Persistence
I resolved the 404/422 errors by aligning the frontend and backend layers:
Database: Added the missing rebloom_id column to the blooms table.
Routing: Corrected the fetch URL in bloom.mjs (removed the /api prefix) to match the Flask route.
Auth: Fixed the "Token: null" issue by ensuring apiService saves the JWT to localStorage during login/signup.
The feature now successfully creates reblooms with a valid 200 OK response.

@github-project-automation github-project-automation Bot moved this from Backlog to Done in Purple Forest Kanban Apr 17, 2026
@Luke-Manyamazi
Luke-Manyamazi deleted the New-feature-rebloom branch April 21, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Legacy-Code The name of the module. Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 1 Assigned during Sprint 1 of this module

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants