fix: decouple share access from owner session state#1062
Open
aarushlohit wants to merge 1 commit into
Open
Conversation
- Add user_id FK to SharedSnippet model to track ownership
- Require authentication on POST /share/ (owner must be logged in to create)
- Keep GET /share/{token} public — accessible regardless of owner session
- Return user_id in ShareRecord response
- Add test for share accessible after owner logout
- Update existing tests for authenticated creation
Fixes imDarshanGK#545
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Description
Fix share permissions being incorrectly coupled to owner's session state.
Problem:
SharedSnippethad nouser_id— share creation was anonymous with no auth required. There was no ownership tracking, meaning shares couldn't be associated with their creator. More critically, the architecture didn't explicitly separate token-based share access from session state, making it fragile if downstream code introduced owner-session checks.Solution:
models.py— Addeduser_id(nullable FK →users.id) andownerrelationship toSharedSnippetshare.py—POST /share/now requires authentication viaDepends(get_current_user)and storescurrent_user.id;GET /share/{token}remains completely public — no auth dependency at all, ensuring share links work regardless of whether the owner is logged inschemas.py— Addeduser_idfield toShareRecordso API consumers know who created the sharetests/test_share.py— Rewrote with 4 tests:test_create_share_requires_auth— unauthenticated POST returns 401test_create_and_fetch_share— full happy path with authenticated creationtest_share_accessible_after_owner_logout— key test: create share with auth, then fetch it without any auth headers → proves access is independent of owner sessiontest_expired_share_returns_404— unchanged expiry behaviorRelated Issue
Fixes #545
Type of change
Checklist
mainpytest -vand all tests passfeat/fix/docs/test: short descriptionTest evidence