-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Builds out roles + role-specific landing UX + tighten up auth guards (#…
…455) * feat: adding role to session, will be needed for lots of features * fix: refactor types into src/types/auth.ts * fix: move type to auth.ts types * fix: refactor trpc auth guard name + add two more * feat: migration to build out roles in db + one rename of auth guard * Add UserType enum and refactor hasMinimumRole * Do not display staff link on frontend unless user role is case manager or admin * Fix typescript types * Move UserType enum to auth types, only let Paras see Assigned link * feat: navitems are role-based, sorry page added, front-end error handling of 401 * feat: auth guards + type fix in trpc.ts * feat: all roles land on correct page + paras can see their tasks * Specify UNAUTHORIZED as error * Add specs to test authentication of each of case_maanger router endpoints * Only paras and up can upload files * Only allow case managers to access iep router routes, and add two api endpoint tests * Add tests for authenticated access to para controller routes * Add some specs to student router endpoints for controlled access * Finish adding specs to student router * fix: remove 401 hook as it doesn't work with all routes * feat: link accounts to compass app when they first log in if they were pre-added by case manager or admin * fix: some auth guards were wrong, removed a test. * Tweak misleading test * fix: migration collision * fix: type check --------- Co-authored-by: Vincent Shuali <vincent.shuali@gmail.com>
- Loading branch information
1 parent
637cbc2
commit 3c95751
Showing
33 changed files
with
784 additions
and
163 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,14 @@ | ||
-- Step 1: Drop the existing check constraint if it exists | ||
ALTER TABLE "public"."user" DROP CONSTRAINT IF EXISTS user_role_check; | ||
|
||
-- Step 3: Update existing roles | ||
UPDATE "public"."user" SET role = 'case_manager' WHERE role = 'admin'; | ||
UPDATE "public"."user" SET role = 'para' WHERE role = 'staff'; | ||
|
||
-- Step 2: Add the new check constraint with the updated roles | ||
ALTER TABLE "public"."user" ADD CONSTRAINT user_role_check | ||
CHECK (role = ANY (ARRAY['user'::text, 'para'::text, 'case_manager'::text, 'admin'::text])); | ||
|
||
|
||
-- Step 4: Add a comment to the table explaining the role values | ||
COMMENT ON COLUMN "public"."user".role IS 'User role: user, para, case_manager, or admin'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
@@ -1,17 +1,24 @@ | ||
import test from "ava"; | ||
import { getTestServer } from "@/backend/tests"; | ||
import { UserType } from "@/types/auth"; | ||
|
||
test("getPostgresInfo", async (t) => { | ||
const { trpc } = await getTestServer(t, { authenticateAs: "admin" }); | ||
const { trpc } = await getTestServer(t, { authenticateAs: UserType.Admin }); | ||
|
||
const postgresInfo = await trpc.admin.getPostgresInfo.query(); | ||
t.true(postgresInfo.includes("PostgreSQL")); | ||
}); | ||
|
||
test("getPostgresInfo (throws if not admin)", async (t) => { | ||
const { trpc } = await getTestServer(t, { authenticateAs: "para" }); | ||
const { trpc } = await getTestServer(t, { authenticateAs: UserType.Para }); | ||
|
||
await t.throwsAsync(async () => { | ||
const error = await t.throwsAsync(async () => { | ||
await trpc.admin.getPostgresInfo.query(); | ||
}); | ||
|
||
t.is( | ||
error?.message, | ||
"UNAUTHORIZED", | ||
"Expected an 'unauthorized' error message" | ||
); | ||
}); |
This file contains 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.