Skip to content

feat(storage): let property compliance uploads take PDFs [TURNWRK-749] - #47

Open
Echobob wants to merge 1 commit into
mainfrom
turnwrk-749-compliance-pdf-storage-rule
Open

Echobob wants to merge 1 commit into
mainfrom
turnwrk-749-compliance-pdf-storage-rule

Conversation

@Echobob

@Echobob Echobob commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Why

PR 1 of 2: shared storage rule + rules test (PR 2 is the dispatch file input, after sync + rules deploy).

The property compliance tab stores licenses and certificates under properties/{pid}/compliance/{itemId}/. Those documents usually arrive as PDFs, but the properties/{propertyId}/{allPaths=**} match in firebase/storage.rules allowed image/* only. So the tab could take images only.

What changed

Net source lines vs main: +15 (tests excluded): one isPdf() helper, one compliance match, and test:rules now boots the storage emulator too. Nothing is replaced.

  • firebase/storage.rules: a sibling match /properties/{propertyId}/compliance/{allPaths=**} allows writes of image/* or application/pdf when the user is signed in, under the existing isValidSize() cap (< 10 * 1024 * 1024). Storage ORs every matching statement, so the broad properties/** rule is left exactly as it was. A PDF anywhere else under properties/ still matches only that rule, so it is still denied. Reads are unchanged, because the broad rule already covers them.
  • tests/rules/propertyStorage.rules.test.ts: the repo's first Storage rules test (@firebase/rules-unit-testing, storage emulator on 9199).
  • package.json test:rules: --only firestore becomes --only firestore,storage. CI's rules job already runs npm run test:rules, so the new test runs in CI with no workflow edit.
  • vitest.rules.config.ts: the header comment now names both rule files.

What deliberately did NOT change

  • The broad properties/** rule and every other path in storage.rules.
  • .github/workflows/. The rules job's name and comment still say "firestore". They are stale but harmless, and editing them would make this a human merge.
  • Dispatch. Widening the ComplianceItemSheet.tsx file input to image/*,application/pdf is PR 2, after the vendor sync and the rules deploy.
  • No rules deploy from this PR.

Proof

On the old rules (52f0a92), the new test fails for the right reason. That run had 6 tests; the "image elsewhere" case was added afterwards.

× accepts a PDF under compliance/
FirebaseError: Firebase Storage: User does not have permission to access 'properties/prop-1/compliance/item-1/license.pdf'. (storage/unauthorized)
Tests  1 failed | 5 passed (6)

Mutation table. Each one-line break ran the single test file on the storage emulator, and the rules were then restored.

Guard Mutation Result
PDF allowed under compliance/ (isImage() || isPdf()) → isImage() killed: "accepts a PDF under compliance/"
10 MB cap on compliance uploads dropped && isValidSize() killed: "denies a compliance PDF at or over the 10 MB cap"
PDFs stay out of other properties/** paths broad rule isImage() → (isImage() || isPdf()) killed: "denies a PDF anywhere else under properties/"
Signed-in only dropped isAuthenticated() && killed: "denies a signed-out compliance upload"
PDF type is exact isPdf() → return true killed: "denies other document types under compliance/"

Verification

  • npm run test:rules: 7 files, 70 tests passed. That is the 6 existing Firestore files plus the new Storage file of 7 tests: PDF under compliance allowed, image under compliance allowed, image under photos allowed, PDF under photos/ and at the property root denied, a 10 MB PDF denied, text/plain denied, signed-out denied. It was re-run green after the last edit.
  • npm run typecheck: clean. src/ is untouched.
  • The hooks did not run on their own, because this is a wt/ worktree. I ran commit-msg by hand and it passed (exit 0). pre-push is a dispatcher with no repo .guardrails/pre-push, so it does nothing here.
  • git ls-remote origin turnwrk-749-compliance-pdf-storage-rule matches local HEAD.

Before merge / after merge

  • After merge: vendor-sync shared into dispatch, then deploy storage rules from the synced consumer. That production rules deploy is Alan's step.
  • Then PR 2 (dispatch): widen the compliance sheet file input to image/*,application/pdf.

Live check after deploy. Upload a PDF from the compliance sheet on a deployed property. This is the card's Done-when, and it needs the rules deploy plus PR 2.

Refs: TURNWRK-749

🤖 Generated with Claude Code

Licenses and certificates on the property compliance tab usually arrive as
PDFs, but properties/** in storage.rules only allowed images. A sibling match
on properties/{pid}/compliance/** now also accepts application/pdf under the
same 10 MB cap; Storage ORs matching rules, so every other properties/** path
stays image-only. test:rules now boots the storage emulator too, and the first
Storage rules test covers the allow and the denies.

Refs: TURNWRK-749

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@practical-bot practical-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Approve

The focused rules test and exact-head CI provide sufficient pre-merge evidence; production upload remains a post-merge verification after the dispatch sync and deploy.

Check Result Ref
PR metadata and diff ✅ base main, 4 files, 106 additions and 2 deletions (108 changed lines); working tree clean gh pr view 47; git diff origin/main...HEAD
CI typecheck and unit ✅ all steps including typecheck, test:run, build, and vendored checks succeeded on head 16b72f3 GitHub Actions run 47037011267
CI rules tests ✅ test:rules succeeded on head 16b72f3 GitHub Actions run 47037011267
CI secret scan ✅ secret scan succeeded on head 16b72f3 GitHub Actions run 47037011267
Local focused rules test ⚠️ firebase-tools could not spawn the Storage/Firestore emulator because java -version is unavailable npm run test:rules
Mutation claims ⚠️ the PR body mutation claims could not be replayed because the required emulator could not start without Java; the exact-head CI rules job passed PR body mutation table; npm run test:rules
Review record

DESIGN: DESIGN: Put the MIME-type exception in firebase/storage.rules under properties/{propertyId}/compliance/, preserving the existing properties/ image-only rule and 10 MB cap.
DESIGN: DESIGN: Keep all non-compliance properties paths image-only and preserve authentication and size restrictions.
DESIGN: DESIGN: Add emulator-backed tests for compliance PDF allow, non-compliance PDF deny, retained image behavior, size, type, and auth guards, and run them in the declared rules test command.
ADVERSARIAL: ADVERSARIAL: The strongest case against approval is that the new sibling match could accidentally broaden PDFs across properties or the regression tests could be weak; the exact-head CI rules job passed, its test file covers compliance allow and non-compliance denial plus auth/type/size guards, and the diff leaves the broad image-only match unchanged.
NEEDS VERIFICATION: After merge, vendor-sync shared into dispatch, deploy the Storage rules, widen the dispatch compliance input in PR 2, and upload a PDF from the compliance sheet on a deployed property.
REVIEW VERDICT: approve
REVIEWED DIFF: base=main files=4 lines=108
REVIEW RUN: dispatch=rev-sweep-turnwrk-shared-47-16b72f3 thread=a4a8e379-8ac4-4996-91e3-cb7320abcc13 model=codex/gpt-5.6-luna
NOT READ: none

Legend: ✅ approve or pass · ❌ changes requested or fail · 👤 a person approves too · ⚠️ could not run here · ⚪ not re-run

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