-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add preview access for non-public forms in form-fields API #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Task T23 - Preview access for non-public forms in form-fields API | ||
|
|
||
| Goal | ||
| - Allow authenticated staff with `unfold_fobi.view_formentryproxy` permission | ||
| to preview non-public forms via `GET /api/fobi-form-fields/{slug}/`. | ||
| - No new settings or configuration — use Django's built-in permission system. | ||
|
|
||
| Problem statement | ||
| - The endpoint filters `FormEntry.objects.get(slug=slug, is_public=True)`, | ||
| so non-public forms always return 404. | ||
| - Admin users building forms need to preview them before publishing. | ||
|
|
||
| Suggested Skills | ||
| - Primary: `$unfold-dev-advanced`. | ||
|
|
||
| Dependencies | ||
| - T17/T17a, T18, T19 (current form-fields endpoint features). | ||
|
|
||
| Scope | ||
| - `src/unfold_fobi/api/views.py` — modify `get_form_fields` access logic. | ||
| - `tests/api/` — tests for preview access. | ||
|
|
||
| Non-goals | ||
| - No configurable hook or setting. | ||
| - No site-scope logic in the package. | ||
| - No changes to the PUT submission endpoint. | ||
|
|
||
| Implementation requirements | ||
| - Change the lookup from `get(slug=slug, is_public=True)` to `get(slug=slug)`. | ||
| - After lookup, apply access control: | ||
| - Public form: serve to anyone (unchanged). | ||
| - Non-public form: serve only if `request.user.has_perm("unfold_fobi.view_formentryproxy")`. | ||
| - Otherwise: return 404 (not 403, to prevent information leakage). | ||
| - Add `"is_preview": true/false` to the response envelope so the frontend can | ||
| show a preview indicator or disable submission. | ||
| - Keep `@never_cache`. | ||
|
|
||
| Deliverables | ||
| - Updated `get_form_fields` view. | ||
| - `is_preview` flag in response. | ||
| - Tests: | ||
| - Public form: anonymous gets 200, `is_preview` is false. | ||
| - Non-public form: anonymous gets 404. | ||
| - Non-public form: staff with permission gets 200, `is_preview` is true. | ||
| - Non-public form: staff without permission gets 404. | ||
| - `poetry run pytest -q` passes. | ||
|
|
||
| Acceptance Criteria | ||
| - Public forms behave exactly as before. | ||
| - Non-public forms are accessible to users with `view_formentryproxy` permission. | ||
| - `is_preview` flag distinguishes preview from public access. | ||
| - `poetry run pytest -q` passes. | ||
|
|
||
| Tests to run | ||
| - `poetry run pytest -q` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚨 question (security): Preview access is granted solely on a global permission, which may be too broad for private forms.
Using only the global
fobi.view_formentrypermission means any user with that permission can preview all non-public forms, regardless of ownership or relationship to the form. If previews are meant to be more restricted, consider changing this to an object-level or ownership-based check, or introducing a dedicated, narrower preview permission.