Skip to content

Commit 8d236cc

Browse files
Merge pull request #98 from natalierobbins/feat/expanded-rbac
feat: Incorporate new RBAC rules
2 parents 637283d + 6516767 commit 8d236cc

File tree

25 files changed

+1716
-520
lines changed

25 files changed

+1716
-520
lines changed

client/src/pages/Signup/Signup.tsx

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,32 @@ export default function Signup() {
1212
lastName: '',
1313
email: '',
1414
phone: '',
15-
role: ''
15+
role: '',
16+
locationObjectId: ''
1617
});
1718
const [otp, setOtp] = useState('');
1819
const [otpSent, setOtpSent] = useState(false);
1920
const [errorMessage, setErrorMessage] = useState('');
2021
const [countdown, setCountdown] = useState(0);
22+
const [locations, setLocations] = useState<
23+
Array<{ _id: string; hubName: string }>
24+
>([]);
25+
26+
useEffect(() => {
27+
const fetchLocations = async () => {
28+
try {
29+
const response = await fetch('/api/v2/locations');
30+
if (response.ok) {
31+
const data = await response.json();
32+
console.log('Fetched locations:', data);
33+
setLocations(data.data);
34+
}
35+
} catch (error) {
36+
console.error('Failed to fetch locations:', error);
37+
}
38+
};
39+
fetchLocations();
40+
}, []);
2141

2242
useEffect(() => {
2343
let timer: string | number | NodeJS.Timeout | undefined;
@@ -124,16 +144,29 @@ export default function Signup() {
124144
onChange={handlePhoneChange}
125145
required
126146
/>
147+
<select
148+
name="locationObjectId"
149+
value={userData.locationObjectId}
150+
onChange={handleChange}
151+
required
152+
>
153+
<option value="">--Select Location--</option>
154+
{locations.map(location => (
155+
<option key={location._id} value={location._id}>
156+
{location.hubName}
157+
</option>
158+
))}
159+
</select>
127160
<select
128161
name="role"
129162
value={userData.role}
130163
onChange={handleChange}
131164
required
132165
>
133166
<option value="">--Select Role--</option>
134-
<option value="Volunteer">Volunteer</option>
135-
<option value="Manager">Manager</option>
136-
<option value="Admin">Admin</option>
167+
<option value="VOLUNTEER">VOLUNTEER</option>
168+
<option value="MANAGER">MANAGER</option>
169+
<option value="ADMIN">ADMIN</option>
137170
</select>
138171
<button onClick={sendOtp}>Send OTP</button>
139172
<p className="switch-auth">

server/src/database/seed/zod/__tests__/seed.zod.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ describe('Seed Type Validation Schemas', () => {
2727

2828
const result = createSeedSchema.safeParse(minimalData);
2929
expect(result.success).toBe(true);
30-
if (result.success) {
31-
expect(result.data.locationObjectId).toBe(validObjectId);
32-
expect(result.data.isFallback).toBe(false); // Should default to false
33-
}
3430
});
3531

3632
test('should validate with isFallback true', () => {

server/src/database/seed/zod/seed.base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ export const baseSeedSchema = z
1515
locationObjectId: z
1616
.string()
1717
.refine(Types.ObjectId.isValid, 'Invalid location objectId'),
18-
isFallback: z.boolean().optional().default(false) // Assume false unless otherwise specified
18+
isFallback: z.boolean().optional()
1919
})
2020
.meta({ model: Seed });

server/src/database/seed/zod/seed.validator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { baseSeedSchema } from './seed.base';
44
export const createSeedSchema = baseSeedSchema
55
.pick({
66
locationObjectId: true,
7-
isFallback: true
7+
isFallback: true // This marks `isFallback` as acceptable in the request body
88
})
99
.partial({
10-
isFallback: true // This marks `isFallback` as optional; defaults to false unless otherwise specified as declared in the base schema
10+
isFallback: true // This marks `isFallback` as optional
1111
})
1212
.strict()
1313
.meta({ model: Seed });

server/src/database/survey/mongoose/__tests__/survey.model.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import {
99
import { MongoMemoryServer } from 'mongodb-memory-server';
1010
import mongoose, { Types } from 'mongoose';
1111

12+
import { ROLES } from '../../../../permissions/constants';
1213
import Location from '../../../location/mongoose/location.model';
1314
import User from '../../../user/mongoose/user.model';
1415
import {
1516
HubType,
1617
LocationType,
17-
Role,
1818
SYSTEM_SURVEY_CODE
1919
} from '../../../utils/constants';
2020
import { errors } from '../../../utils/errors';
@@ -58,7 +58,7 @@ describe('Survey Model', () => {
5858
lastName: 'User',
5959
email: 'test@example.com',
6060
phone: '1234567890',
61-
role: Role.VOLUNTEER,
61+
role: ROLES.VOLUNTEER,
6262
approvalStatus: 'APPROVED',
6363
approvedByUserObjectId: new mongoose.Types.ObjectId(),
6464
locationObjectId: testLocation._id,

0 commit comments

Comments
 (0)