Skip to content

Commit 7179501

Browse files
authored
Merge pull request #412 from CodeForPhilly/309-393-test-combined-prs
Test unauthenticated users access on the website
2 parents c027b8e + 82eed3c commit 7179501

38 files changed

+1150
-343
lines changed

CHANGELOG.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
- **Conditional PDF Access Based on Authentication** (2025-01-XX)
12+
- Logged-in users see "View PDF" button that opens PDF viewer in new tab
13+
- Non-logged-in users see "Download PDF" button that directly downloads the file
14+
- Backend: Added `upload_file_guid` field to risk/source API responses
15+
- Frontend: Conditional rendering based on Redux authentication state
16+
- Fallback GUID extraction from URL if backend field is missing
17+
18+
**Backend Changes:**
19+
20+
*File: `server/api/views/risk/views_riskWithSources.py`*
21+
```python
22+
# Added to source_info dictionary in 3 locations (lines ~138, ~252, ~359):
23+
source_info = {
24+
'filename': filename,
25+
'title': getattr(embedding, 'title', None),
26+
'publication': getattr(embedding, 'publication', ''),
27+
'text': getattr(embedding, 'text', ''),
28+
'rule_type': medrule.rule_type,
29+
'history_type': medrule.history_type,
30+
'upload_fileid': getattr(embedding, 'upload_file_id', None),
31+
'page': getattr(embedding, 'page_num', None),
32+
'link_url': self._build_pdf_link(embedding),
33+
'upload_file_guid': str(embedding.upload_file.guid) if embedding.upload_file else None # NEW
34+
}
35+
```
36+
37+
**Frontend Changes:**
38+
39+
*File: `frontend/src/pages/PatientManager/PatientManager.tsx`*
40+
```typescript
41+
// Added imports:
42+
import { useSelector } from "react-redux";
43+
import { RootState } from "../../services/actions/types";
44+
45+
// Added hook to get auth state:
46+
const { isAuthenticated } = useSelector((state: RootState) => state.auth);
47+
48+
// Passed to PatientSummary:
49+
<PatientSummary
50+
// ... existing props
51+
isAuthenticated={isAuthenticated}
52+
/>
53+
```
54+
55+
*File: `frontend/src/pages/PatientManager/PatientSummary.tsx`*
56+
```typescript
57+
// Updated interface:
58+
interface PatientSummaryProps {
59+
// ... existing props
60+
isAuthenticated?: boolean; // NEW
61+
}
62+
63+
// Updated SourceItem type:
64+
type SourceItem = {
65+
// ... existing fields
66+
upload_file_guid?: string | null; // NEW
67+
};
68+
69+
// Added helper function:
70+
const extractGuidFromUrl = (url: string): string | null => {
71+
try {
72+
const urlObj = new URL(url, window.location.origin);
73+
return urlObj.searchParams.get('guid');
74+
} catch {
75+
return null;
76+
}
77+
};
78+
79+
// Updated component:
80+
const PatientSummary = ({
81+
// ... existing props
82+
isAuthenticated = false, // NEW
83+
}: PatientSummaryProps) => {
84+
const baseURL = import.meta.env.VITE_API_BASE_URL || ''; // NEW
85+
86+
// Updated MedicationItem props:
87+
const MedicationItem = ({
88+
// ... existing props
89+
isAuthenticated, // NEW
90+
baseURL, // NEW
91+
}: {
92+
// ... existing types
93+
isAuthenticated: boolean; // NEW
94+
baseURL: string; // NEW
95+
}) => {
96+
97+
// Updated MedicationTier props:
98+
const MedicationTier = ({
99+
// ... existing props
100+
isAuthenticated, // NEW
101+
baseURL, // NEW
102+
}: {
103+
// ... existing types
104+
isAuthenticated: boolean; // NEW
105+
baseURL: string; // NEW
106+
}) => (
107+
// ... passes to MedicationItem
108+
<MedicationItem
109+
// ... existing props
110+
isAuthenticated={isAuthenticated}
111+
baseURL={baseURL}
112+
/>
113+
);
114+
115+
// Conditional button rendering:
116+
{s.link_url && (() => {
117+
const guid = s.upload_file_guid || extractGuidFromUrl(s.link_url);
118+
if (!guid) return null;
119+
120+
return isAuthenticated ? (
121+
<a
122+
href={s.link_url}
123+
target="_blank"
124+
rel="noopener noreferrer"
125+
className="ml-2 px-2 py-1 text-xs bg-blue-100 text-blue-700 rounded hover:bg-blue-200 transition-colors"
126+
>
127+
View PDF
128+
</a>
129+
) : (
130+
<a
131+
href={`${baseURL}/v1/api/uploadFile/${guid}`}
132+
download
133+
className="ml-2 px-2 py-1 text-xs bg-green-100 text-green-700 rounded hover:bg-green-200 transition-colors"
134+
>
135+
Download PDF
136+
</a>
137+
);
138+
})()}
139+
140+
// Updated all MedicationTier calls to pass new props:
141+
<MedicationTier
142+
// ... existing props
143+
isAuthenticated={isAuthenticated}
144+
baseURL={baseURL}
145+
/>
146+
```
147+
148+
### Fixed
149+
- **URL Route Case Consistency** (2025-01-XX)
150+
- Fixed case mismatch between backend URL generation (`/drugsummary`) and frontend route (`/drugSummary`)
151+
- Updated all references to use consistent camelCase `/drugSummary` route
152+
- Affected files: `views_riskWithSources.py`, `Layout_V2_Sidebar.tsx`, `Layout_V2_Header.tsx`, `FileRow.tsx`
153+
154+
- **Protected Route Authentication Flow** (2025-01-XX)
155+
- Fixed blank page issue when opening protected routes in new tab
156+
- `ProtectedRoute` now waits for authentication check to complete before redirecting
157+
- Added `useAuth()` hook to `Layout_V2_Main` to trigger auth verification
158+
159+
### Changed
160+
- **PatientSummary Component** (2025-01-XX)
161+
- Now receives `isAuthenticated` prop from Redux state
162+
- Props passed through component hierarchy: `PatientManager``PatientSummary``MedicationTier``MedicationItem`
163+
- Added `baseURL` constant for API endpoint construction
164+
165+
## [Previous versions would go here]

0 commit comments

Comments
 (0)