Skip to content

OpenConceptLab/ocl_issues#2888 | An organization's banner can be uploaded and removed - #1129

Open
paynejd wants to merge 7 commits into
OpenConceptLab/ocl_issues-2888-banner-checkpointfrom
OpenConceptLab/ocl_issues-2888-banner-upload
Open

paynejd wants to merge 7 commits into
OpenConceptLab/ocl_issues-2888-banner-checkpointfrom
OpenConceptLab/ocl_issues-2888-banner-upload

Conversation

@paynejd

@paynejd paynejd commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Adds POST and DELETE /orgs/:org/banner/, the API half of OpenConceptLab/ocl_issues#2888: an organization's admins can upload the banner that its Overview page shows, instead of hosting the image somewhere else. The first commit is @snyaggarwal's endpoint, as he wrote it. The commits after it are what changed since.

It goes on top of #1116, so this PR's base is that branch. Please merge #1116 first.

What it does

  • POST {"base64": "<data URL>"} stores a PNG, JPEG or GIF of at most 2 MB, sets overview.background.image to its address and returns the overview. The rest of overview and the About text stay as they are.
  • DELETE removes the banner.
  • Both need an admin of the organization, or staff, as its logo does.

What changed since the first commit

  • The write checkpoint is asked about set_banner before anything is stored, as PUT /orgs/:org/overview/ does. A refusal is a 403 with the policy's body. Removing a banner isn't asked about. The default policy allows everything.
  • One size limit, 2 MB, for everyone, in place of the orgs.banner_file_size_kb capability. An image that's too large is a 400 that says so, decided before it's decoded.
  • Each upload gets its own file name. With the same name twice, the address stayed the same and browsers could go on showing the old image. A name in the request isn't used.
  • Anything that isn't such an image is a 400, including data whose content isn't of the type it says. Some of it was a server error.
  • The file that's replaced or removed is deleted only if its address is exactly one that an upload here gives. If it can't be deleted, that's logged and the request still succeeds.

Tests

  • All tests pass: 4,304 without Elasticsearch and 815 with it. pylint -j0 core/ exits 0.
  • Taking out the checkpoint, the new names or the ownership check each fails at least one test.

Deploying

No migration and no setting. The capability was never in a release, so there's nothing to remove.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AaZ4qWierCikGzbXQj3GN3

snyaggarwal and others added 6 commits December 4, 2026 02:40
…ited by the orgs.banner_file_size_kb capability
…point, has one size limit, and gets a new file name

- POST /orgs/:org/banner/ asks the policy about `set_banner` before it stores anything, as a change of
  overview.background.image does. Removing a banner isn't asked about.
- One limit of 2 MB for every image replaces the orgs.banner_file_size_kb capability.
- Each upload is stored under its own name, so browsers don't show the image it replaces. The name sent with the image
  isn't used.
- Data that isn't a PNG, JPEG or GIF, whatever type it says it is, is a 400.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWierCikGzbXQj3GN3
…tever JSON the overview and the request hold

- A body that isn't an object is a 400.
- An overview, or its background, that isn't an object no longer fails an upload, and removing a banner that isn't there
  changes nothing.
- A replaced file that can't be deleted no longer fails the request: the organization has its new banner by then.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWierCikGzbXQj3GN3
… deleted never fails the request, whichever storage is used

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWierCikGzbXQj3GN3
…e is down

Deleting its file is best effort from the start: connecting to storage can fail too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWierCikGzbXQj3GN3
… an upload's is deleted with its banner

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWierCikGzbXQj3GN3
@paynejd
paynejd requested a review from snyaggarwal December 4, 2026 08:50
@paynejd

paynejd commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 1 (codex-cli 0.171.0, commit 2d7ebde)

Verdict: 6 findings, 3 of them P0 or P1.

  • F1.1 (P1) core/orgs/views.py:147: A top-level JSON array or scalar returns 500 instead of 400.
  • F1.2 (P1) core/orgs/models.py:79: The upload accepts and stores truncated files that contain an image signature but cannot render.
  • F1.3 (P1) core/orgs/models.py:103: The storage URL prefix is the only ownership check before deleting an object.
  • F1.4 (P2) core/orgs/models.py:110: The banner endpoint assumes existing overview values are objects and can also rewrite the overview when there is no image to remove.
  • F1.5 (P2) core/orgs/models.py:94: A concurrent About edit can restore a banner URL after its file has been deleted.
  • F1.6 (P2) core/orgs/models.py:97: A failed storage deletion leaves a public banner file that retrying DELETE cannot remove.
findings.json
{
 "reviewer": "codex-cli 0.171.0",
 "perspective": "defects",
 "mode": "full",
 "commit": "2d7ebde3",
 "verdict": "findings",
 "prior": [],
 "findings": [
  {
   "id": "F1.1",
   "severity": "P1",
   "tag": null,
   "file": "core/orgs/views.py",
   "line": 147,
   "claim": "A top-level JSON array or scalar returns 500 instead of 400.",
   "scenario": "An authorized admin with a permitting policy posts `[]` as JSON. The parser returns a list, and `request.data.get('base64')` raises `AttributeError` before validation.",
   "action": "Validate that the parsed body is an object before reading `base64`. Add a request-level test for a top-level array and scalar.",
   "lines_delta": null,
   "confidence": "high"
  },
  {
   "id": "F1.2",
   "severity": "P1",
   "tag": null,
   "file": "core/orgs/models.py",
   "line": 79,
   "claim": "The upload accepts and stores truncated files that contain an image signature but cannot render.",
   "scenario": "A PNG data URL containing only the eight-byte PNG signature passes validation, replaces the current banner, and returns 200. The positive PNG integration test uses exactly this payload, so it never verifies a usable image.",
   "action": "Verify that the decoded bytes form a complete image of the declared type before storage. Use valid PNG, JPEG, and GIF fixtures and assert that signature-only payloads return 400 without storing anything.",
   "lines_delta": null,
   "confidence": "high"
  },
  {
   "id": "F1.3",
   "severity": "P1",
   "tag": null,
   "file": "core/orgs/models.py",
   "line": 103,
   "claim": "The storage URL prefix is the only ownership check before deleting an object.",
   "scenario": "An admin sets the overview image to an existing, manually managed object under the organization's banner folder. Replacing or removing the banner deletes that object even though the upload endpoint never stored it. The deletion test expects removal of `old.png`, a name this endpoint cannot generate.",
   "action": "Track uploaded object keys against the organization record and delete only keys with verified ownership. Test that replacement and removal leave an untracked object under the same prefix intact.",
   "lines_delta": null,
   "confidence": "high"
  },
  {
   "id": "F1.4",
   "severity": "P2",
   "tag": null,
   "file": "core/orgs/models.py",
   "line": 110,
   "claim": "The banner endpoint assumes existing overview values are objects and can also rewrite the overview when there is no image to remove.",
   "scenario": "The existing overview API accepts `{\"background\":\"blue\"}`. A subsequent banner upload stores the file and then returns 500 when `dict('blue')` raises. Deleting a banner from the already-supported overview `{\"background\":null}` silently changes it to `{}` even though it had no image.",
   "action": "Handle existing JSON shapes explicitly before uploading. Make deletion a no-op when no image exists and preserve unrelated overview values.",
   "lines_delta": null,
   "confidence": "high"
  },
  {
   "id": "F1.5",
   "severity": "P2",
   "tag": null,
   "file": "core/orgs/models.py",
   "line": 94,
   "claim": "A concurrent About edit can restore a banner URL after its file has been deleted.",
   "scenario": "An About edit loads the organization while banner A is current. A concurrent upload saves banner B and deletes A. The About edit then saves its stale organization instance, writing the old overview back along with the new text. The organization now points to deleted banner A.",
   "action": "Limit organization detail updates to the fields they own so an About edit cannot overwrite the overview. Cover the interleaving in a concurrency test.",
   "lines_delta": null,
   "confidence": "high"
  },
  {
   "id": "F1.6",
   "severity": "P2",
   "tag": null,
   "file": "core/orgs/models.py",
   "line": 97,
   "claim": "A failed storage deletion leaves a public banner file that retrying DELETE cannot remove.",
   "scenario": "The organization update commits, then S3 returns a transient error during object deletion. The request returns 500. On retry, the overview no longer holds the old key, so the endpoint returns 204 while the file remains public.",
   "action": "Persist the verified key for retryable cleanup as part of the overview update and test recovery after a storage deletion failure.",
   "lines_delta": null,
   "confidence": "high"
  }
 ]
}

@paynejd

paynejd commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

Answers to pass 1 (fixes in e41ac8d)

  • F1.1 (a body that isn't an object is a 500): fixed, with tests.
  • F1.2 (a file that only starts like an image is accepted): declined. The endpoint checks that the content is of an image type, so that nothing else is hosted there. Whether the image is complete is the admin's to see on the form and on the page, and they can replace it. Decoding it would add an image library, which the API doesn't have, for a result only that organization's own admins can cause.
  • F1.3 (the address is the only ownership check before a deletion): declined at first. The access review below showed it wasn't strict enough, and it's fixed in 3f5f4d5: the address has to be exactly the one an upload gets.
  • F1.4 (an overview or background that isn't an object): fixed, with tests. Removing a banner that isn't there changes nothing.
  • F1.5 (an About edit that started before an upload can write the old overview back): accepted. It needs two admins saving within one request's time, and any two edits of an organization at once already behave so. The form saves the two one after the other.
  • F1.6 (a failed deletion): the request no longer fails. A file that couldn't be deleted stays in storage, as every replaced logo's file does.

@paynejd

paynejd commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 2 (codex-cli 0.171.0, commit e41ac8d)

Verdict: 3 findings, 1 of them P0 or P1.

  • F2.1 (P1) core/orgs/models.py:109: MinIO cleanup errors still turn a saved banner change into an HTTP 500.
  • F2.2 (P2) core/orgs/models.py:88: Reusing an organization mnemonic lets the new organization delete the former organization's banner.
  • F2.3 (P2) core/orgs/models.py:76: Malformed Base64 data URLs can return 200.
findings.json
{
 "reviewer": "codex-cli 0.171.0",
 "perspective": "defects",
 "mode": "verify",
 "commit": "e41ac8df",
 "verdict": "findings",
 "prior": [
  {
   "id": "F1.1",
   "status": "resolved"
  },
  {
   "id": "F1.2",
   "status": "unresolved"
  },
  {
   "id": "F1.3",
   "status": "unresolved"
  },
  {
   "id": "F1.4",
   "status": "resolved"
  },
  {
   "id": "F1.5",
   "status": "unresolved"
  },
  {
   "id": "F1.6",
   "status": "unresolved"
  }
 ],
 "findings": [
  {
   "id": "F2.1",
   "severity": "P1",
   "tag": null,
   "file": "core/orgs/models.py",
   "line": 109,
   "claim": "MinIO cleanup errors still turn a saved banner change into an HTTP 500.",
   "scenario": "An admin removes or replaces an uploaded banner and MinIO returns a deletion error for the old object. The overview change has already been saved when MinIO raises, so the client sees a failure even though the banner was cleared or replaced.",
   "action": "Handle storage cleanup errors after the overview save and add a test that checks the successful response when MinIO raises.",
   "lines_delta": null,
   "confidence": "high"
  },
  {
   "id": "F2.2",
   "severity": "P2",
   "tag": null,
   "file": "core/orgs/models.py",
   "line": 88,
   "claim": "Reusing an organization mnemonic lets the new organization delete the former organization's banner.",
   "scenario": "An organization uploads a banner and is purged, leaving its object in storage. A new organization registers the same mnemonic and sets its overview image to that old public URL. Removing or replacing the image deletes the former organization's file because both organizations share the same storage prefix.",
   "action": "Scope banner keys and deletion checks to the immutable organization ID, and test mnemonic reuse.",
   "lines_delta": null,
   "confidence": "high"
  },
  {
   "id": "F2.3",
   "severity": "P2",
   "tag": null,
   "file": "core/orgs/models.py",
   "line": 76,
   "claim": "Malformed Base64 data URLs can return 200.",
   "scenario": "An admin submits a PNG data URL with an exclamation mark inserted into its Base64 payload. Validation and storage both discard the illegal character, so the endpoint uploads the file and returns 200 instead of rejecting the malformed data URL with 400.",
   "action": "Reject characters outside the Base64 alphabet during validation and add a test with an illegal character embedded in an otherwise valid image payload.",
   "lines_delta": null,
   "confidence": "high"
  }
 ]
}

@paynejd

paynejd commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

Answers to pass 2 (fixes in a2d4d25)

  • F2.1 (a failed deletion in MinIO is still a 500): fixed for every storage service, with a test. It's logged.
  • F2.2 (an organization that reuses a deleted one's name can delete its old banner): accepted. The deleted organization's file belongs to nobody and isn't shown anywhere. Nothing of the new organization's or anyone else's is lost.
  • F2.3 (characters outside the base64 alphabet are skipped): accepted. The check reads the data exactly as the storage services do, so what was checked is what's stored. Data wrapped in lines works for the same reason.

@paynejd

paynejd commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

Codex review, pass 3 (codex-cli 0.171.0, commit a2d4d25)

Verdict: 2 findings, 2 of them P0 or P1.

  • F3.1 (P1) core/orgs/models.py:107: Banner deletion can still return 500 after the overview update commits.
  • F3.2 (P1): About existing code that this change does not touch. It is handled separately.
findings.json
{
 "reviewer": "codex-cli 0.171.0",
 "perspective": "defects",
 "mode": "verify",
 "commit": "a2d4d250",
 "verdict": "findings",
 "prior": [
  {
   "id": "F1.1",
   "status": "resolved"
  },
  {
   "id": "F1.2",
   "status": "unresolved"
  },
  {
   "id": "F1.3",
   "status": "unresolved"
  },
  {
   "id": "F1.4",
   "status": "resolved"
  },
  {
   "id": "F1.5",
   "status": "unresolved"
  },
  {
   "id": "F1.6",
   "status": "unresolved"
  },
  {
   "id": "F2.1",
   "status": "unresolved"
  },
  {
   "id": "F2.2",
   "status": "unresolved"
  },
  {
   "id": "F2.3",
   "status": "unresolved"
  }
 ],
 "findings": [
  {
   "id": "F3.1",
   "severity": "P1",
   "tag": null,
   "file": "core/orgs/models.py",
   "line": 107,
   "claim": "Banner deletion can still return 500 after the overview update commits.",
   "scenario": "An admin deletes a banner while MinIO is temporarily unreachable. The API clears the image in the database, then initializes a storage client. MinIO checks the bucket during initialization, and that call can fail before the cleanup exception handler runs. The admin gets a 500 even though the banner was cleared. Deleting when there is no banner can also return 500.",
   "action": "Skip storage initialization when there is no prior image URL. Put client initialization and object removal inside the best-effort cleanup handler, and test a failure during client initialization.",
   "lines_delta": null,
   "confidence": "high"
  },
  {
   "id": "F3.2",
   "severity": "P1",
   "tag": null,
   "file": null,
   "line": null,
   "claim": "About existing code that this change does not touch. It is handled separately.",
   "scenario": null,
   "action": null,
   "lines_delta": null,
   "confidence": "high"
  }
 ]
}

@paynejd

paynejd commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

Answers to pass 3 (fixes in c82b06d)

  • F3.1 (a 500 when storage can't be reached while a banner is removed): fixed, with a test. Connecting to storage is now part of the best-effort deletion, and storage isn't asked for anything when there was no image.
  • F3.2: not from this change, and left as it is here. It's handled separately.

@paynejd

paynejd commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

Simplification review (a fresh Claude subagent, commit c82b06d)

Four suggestions, none taken:

  • S1 and S2, the view's serializer_class and the remove_banner method: they match the logo's view and upload_base64_banner beside them.
  • S3, test_delete_204_only_image: it's the only test that an emptied background goes from the overview.
  • S4, test_post_200_each_image_type: it's the only test of each type's file name, and test_post_200 checks something else.

Access review (a fresh Claude subagent, commit c82b06d)

It tried to upload or remove a banner without being an admin or staff, to get a banner past the write checkpoint, to store something other than a PNG, JPEG or GIF, and to have a file deleted that isn't the organization's banner.

  • One P1, fixed in 3f5f4d5, with tests: which file is deleted with a banner was decided by how its address begins, and an organization's admins can save any text as that address. It now has to be exactly the address that an upload gets. The log line holds only that name, too.
  • Nothing else of this change's is open. An organization saved by two requests at once keeps the last one's values, banner included, as it does for every field.

@paynejd

paynejd commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits a2d4d25..3f5f4d5 (codex-cli 0.171.0)

Verdict: clean. Those commits broke nothing.

findings.json
{
 "reviewer": "codex-cli 0.171.0",
 "perspective": "defects",
 "mode": "verify",
 "commit": "3f5f4d5e",
 "verdict": "clean",
 "prior": [],
 "findings": []
}

…e image is decoded

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qWierCikGzbXQj3GN3
@paynejd

paynejd commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

Codex check of commits 3f5f4d5..f435f62 (codex-cli 0.171.0)

Verdict: 1 finding, 0 of them P0 or P1.

  • FC.1 (P2) core/orgs/models.py:83: The new size check rejects a valid banner at the limit when its base64 contains spaces the decoder ignores.
findings.json
{
 "reviewer": "codex-cli 0.171.0",
 "perspective": "defects",
 "mode": "final",
 "commit": "f435f625",
 "verdict": "findings",
 "prior": [],
 "findings": [
  {
   "id": "FC.1",
   "severity": "P2",
   "tag": null,
   "file": "core/orgs/models.py",
   "line": 83,
   "claim": "The new size check rejects a valid banner at the limit when its base64 contains spaces the decoder ignores.",
   "scenario": "Upload a valid 2 MiB PNG with two ASCII spaces inside its base64 text. The previous validator accepted it because it decodes to 2,097,152 bytes. The new estimate is 2,097,153 bytes, so the endpoint returns HTTP 400.",
   "action": "Exclude spaces and tabs from the pre-decode size calculation, continue counting line breaks, and add a boundary test for base64 containing spaces.",
   "lines_delta": null,
   "confidence": "high"
  }
 ]
}

Answer. f435f62 decides a banner's size from the length of the base64 text, before it's decoded.

  • FC.1: accepted. Spaces and line breaks inside the base64 count towards the size. Data URLs have none, and it matters only for an image right at the limit.

All tests pass on f435f62: 4,304 without Elasticsearch and 815 with it. pylint -j0 core/ exits 0.

@snyaggarwal snyaggarwal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve. Merge order, as Jon gave it on OpenConceptLab/ocl_online#354: OpenConceptLab/ocl_online_api#130, then #1116, then this. Its base is #1116's branch. #1116 has its own condition before merging (see my comment there), and this waits for that too.

How it fits #1116 and #130

  • POST asks set_banner about the organization as stored, before validating or storing anything. Every upload gets a new file name, so every upload is "a banner other than the one it has", which matches gets_banner() and the contract #130 answers. #130's notice reads the stored overview to choose its wording, and that's still what it receives.
  • DELETE isn't asked about, the same as removing the banner through the overview. So "remove but not replace" still holds after the policy starts refusing.
  • A refused upload stores nothing (tested with the upload mocked). A member who isn't an admin gets the usual 403 without the policy being asked (tested for the upload too).

Other checks

  • Open core: the 2 MB limit is the same for everyone and protects the server. Replacing the per-owner orgs.banner_file_size_kb capability keeps plan-shaped limits out of this code. Constants and messages are neutral.
  • Size before decoding: the decoded size is worked out from the base64 length before b64decode, well under DATA_UPLOAD_MAX_MEMORY_SIZE.
  • Deletion: a file is deleted only if the stored address is exactly public_url_for(<this org's banner folder> + <32 hex>.<ext>). An admin who saves another organization's file address, or a logo's, can't get it deleted. Storage failures are logged, not 500s.
  • Concurrent writes: set_banner_image locks the row and rebuilds overview from it, so the rest of the overview and the About text stay as they are.
  • Edge cases: a body that isn't an object, a type that isn't PNG, JPEG or GIF, content whose bytes don't match its declared type, and an overview or background that isn't an object all have tests.

Already raised in Jon's review passes, and I agree with the answers:

  • F1.2: a truncated image passes the type check.
  • F1.5: overlapping About and upload saves.
  • F2.2: a reused mnemonic.
  • F2.3 and FC.1: base64 whitespace.

No new findings.

This branch has not been deployed

No deployments
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.

2 participants