Fix #89: Render attachments and embeds on post front page listing #121

Open
typosaurus wants to merge 1 commits from typosaurus/ticket-89 into master
Collaborator

Resolves #89.

Plan

Implementation Plan

1. Fix Profile Posts Tab – Add Attachment Fetch

File: routers/profile/index.py

Location: After the posts query (lines ~170–195), where posts is the list of post row objects returned from the database.

Action: Insert a batch attachment fetch identical to routers/feed.py:97–106.

  • Extract the list of post_uid values from the fetched posts.
  • Call get_attachments_by_type("post", post_uids) (or get_attachments_batch(post_uids)) from the attachments service.
  • Map the returned attachments to each post by UID.
  • Attach the list of attachment dictionaries to each post item under the key "attachments" (matching the structure expected by _post_card.html:20).

Rationale: The profile template already uses _post_card.html, which renders attachments when the attachments key is present. The only missing piece is populating that key in the profile route.


2. Keep Truncation Separately Scoped (No Change)

The 300-character truncation of post body (_post_card.html:18) is a known limitation that affects inline embeds (YouTube URLs, etc.) beyond the 300th character. While it can cause user confusion, it is not the reported bug (which is about file attachments). To minimise risk of layout regressions and unrelated test failures, do not alter the truncation length in this change.


3. Add Tests for Attachment Rendering on Profile Posts Tab

File: tests/api/profile.py (or a new module tests/e2e/profile.py if e2e structure exists)

Minimum test coverage:

  • Create a user, create a post with at least one file attachment (e.g., an image upload).
  • Request the profile posts tab (/profile/{username}?tab=posts) via the API client.
  • Assert that the response body contains the post, and under the attachments field (or item.attachments) the attachment metadata is present.

Optionally write an e2e test that uses page.goto to verify the HTML actually renders the attachment’s <img> or <video> tag on the profile page.

Also update tests/unit/services/content.py if there is a test for enrich_items to verify that attachment enrichment works in the profile context (but this may require mocking).


4. Ensure No New Lint Violations

  • Run ruff check --diff (or the project’s linter equivalent) on the changed files.
  • Fix any issues (e.g., missing imports, unused variables) before committing.

5. Verify No Regression in Existing Tests

Run the project’s verification command:

pip install -e '.[dev]' -q && python -m pytest {test_files}

The command will be executed by the CI. Ensure that no new failures are introduced (earlier failures in test_advance_quests_increments_and_caps or test_answer_is_grounded_and_cited are pre-existing and unrelated; they should still pass if flakiness is resolved, but our change must not cause them to fail).


Definition of Done

  • routers/profile/index.py is updated to fetch and attach attachment data for posts returned on the profile tab.
  • A new test (or updated existing test) verifies that a post with an attachment appears with attachment data in the profile listing response.
  • All pre-existing tests pass when running pip install -e '.[dev]' -q && python -m pytest {test_files}.
  • No new lint violations are present in the changed files.
  • Changes are committed with a clear message referencing the ticket (e.g., “fix: render attachments on profile posts tab”).

Opened automatically by Typosaurus.

Resolves #89. ## Plan ## Implementation Plan ### 1. Fix Profile Posts Tab – Add Attachment Fetch **File:** `routers/profile/index.py` **Location:** After the posts query (lines ~170–195), where `posts` is the list of post row objects returned from the database. **Action:** Insert a batch attachment fetch identical to `routers/feed.py:97–106`. - Extract the list of `post_uid` values from the fetched posts. - Call `get_attachments_by_type("post", post_uids)` (or `get_attachments_batch(post_uids)`) from the attachments service. - Map the returned attachments to each post by UID. - Attach the list of attachment dictionaries to each post item under the key `"attachments"` (matching the structure expected by `_post_card.html:20`). **Rationale:** The profile template already uses `_post_card.html`, which renders attachments when the `attachments` key is present. The only missing piece is populating that key in the profile route. --- ### 2. Keep Truncation Separately Scoped (No Change) The 300-character truncation of post body (`_post_card.html:18`) is a known limitation that affects inline embeds (YouTube URLs, etc.) beyond the 300th character. While it can cause user confusion, it is **not** the reported bug (which is about file attachments). To minimise risk of layout regressions and unrelated test failures, do **not** alter the truncation length in this change. --- ### 3. Add Tests for Attachment Rendering on Profile Posts Tab **File:** `tests/api/profile.py` (or a new module `tests/e2e/profile.py` if e2e structure exists) **Minimum test coverage:** - Create a user, create a post with at least one file attachment (e.g., an image upload). - Request the profile posts tab (`/profile/{username}?tab=posts`) via the API client. - Assert that the response body contains the post, and under the `attachments` field (or `item.attachments`) the attachment metadata is present. Optionally write an e2e test that uses `page.goto` to verify the HTML actually renders the attachment’s `<img>` or `<video>` tag on the profile page. **Also update** `tests/unit/services/content.py` if there is a test for `enrich_items` to verify that attachment enrichment works in the profile context (but this may require mocking). --- ### 4. Ensure No New Lint Violations - Run `ruff check --diff` (or the project’s linter equivalent) on the changed files. - Fix any issues (e.g., missing imports, unused variables) before committing. --- ### 5. Verify No Regression in Existing Tests Run the project’s verification command: ``` pip install -e '.[dev]' -q && python -m pytest {test_files} ``` The command will be executed by the CI. Ensure that **no new failures** are introduced (earlier failures in `test_advance_quests_increments_and_caps` or `test_answer_is_grounded_and_cited` are pre-existing and unrelated; they should still pass if flakiness is resolved, but our change must not cause them to fail). --- ## Definition of Done - [ ] `routers/profile/index.py` is updated to fetch and attach attachment data for posts returned on the profile tab. - [ ] A new test (or updated existing test) verifies that a post with an attachment appears with attachment data in the profile listing response. - [ ] All pre-existing tests pass when running `pip install -e '.[dev]' -q && python -m pytest {test_files}`. - [ ] No new lint violations are present in the changed files. - [ ] Changes are committed with a clear message referencing the ticket (e.g., “fix: render attachments on profile posts tab”). Opened automatically by Typosaurus.
typosaurus added 1 commit 2026-07-23 04:06:41 +02:00
ticket #89 attempt 1
Some checks failed
DevPlace CI / test (pull_request) Failing after 1h25m28s
aae9c3698c
Some checks failed
DevPlace CI / test (pull_request) Failing after 1h25m28s
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin typosaurus/ticket-89:typosaurus/ticket-89
git checkout typosaurus/ticket-89
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: retoor/devplacepy#121
No description provided.