Skip to content

Commit

Permalink
feat: more fixes to not requireProfile on applicant pages
Browse files Browse the repository at this point in the history
  • Loading branch information
jackbravo committed Jun 28, 2024
1 parent 01d3c52 commit fb0be77
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/core/components/ApplicantComments/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function AplicantComments({
}: {
comments: CommentsArrayType;
applicantId: number;
profileId: string;
profileId: string | undefined;
}) {
return (
<Box sx={{ marginTop: 2, marginBottom: 2 }}>
Expand Down Expand Up @@ -83,7 +83,7 @@ function CommentItem({
}: {
comment: CommentItemType;
applicantId: number;
profileId: string;
profileId: string | undefined;
}) {
const [openDeleteModal, setOpenDeleteModal] = useState<boolean>(false);
const [openEditComment, setOpenEditComment] = useState<boolean>(false);
Expand Down
5 changes: 4 additions & 1 deletion app/models/authorization.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ type Actions = "create" | "view" | "edit" | "delete" | "edit.project";
type Resources = "applicant" | "project";

export function checkPermission(
principal: string | number,
principal: string | number | undefined,
role: Roles,
action: Actions,
resourceType: Resources,
resource: any
) {
if (principal === undefined) {
return false;
}
const derivedRoles = getDerivedRoles(principal, resourceType, resource);
if (role == "ADMIN") {
return true;
Expand Down
12 changes: 6 additions & 6 deletions app/routes/applicants.$applicantId._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ import { getApplicantByEmail } from "~/models/applicant.server";
import { getCommentsApplicant } from "~/models/applicantComment.server";
import { checkPermission } from "~/models/authorization.server";
import type { Roles } from "~/models/authorization.server";
import { getProfileByUserId } from "~/models/profile.server";
import { getProjectsList } from "~/models/project.server";
import { requireProfile, requireUser } from "~/session.server";
import { requireUser } from "~/session.server";
import { validateNavigationRedirect } from "~/utils";

export function links() {
Expand Down Expand Up @@ -97,12 +98,11 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
throw new Response("Not Found", { status: 404 });
}

const profile = await requireProfile(request);
const profileId = profile.id;

const user = await requireUser(request);
const profile = await getProfileByUserId(user.id);

const canEditProject = checkPermission(
profile.id,
profile?.id,
user.role as Roles,
"edit.project",
"applicant",
Expand All @@ -114,7 +114,7 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
projects,
canEditProject,
applicantId: applicant.id,
profileId,
profileId: profile?.id,
comments,
});
};
Expand Down
2 changes: 1 addition & 1 deletion app/routes/applicationForm.$applicantId._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export default function FormPage() {
career in technology.
</Typography>
<ValidatedForm
name="applicantForm"
validator={validator}
//action="./createapplicant"
//TODO: Maybe this is not the correct approach
Expand Down Expand Up @@ -583,7 +584,6 @@ export default function FormPage() {
inputProps={{
min: startDate,
}}
disabled={startDate === getCurrentDate()}
/>
<LabeledTextField
label="How many hours a week could you provide"
Expand Down
8 changes: 4 additions & 4 deletions app/routes/applicationForm.$applicantId.createapplicant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { validator } from "./applicationForm.$applicantId._index";
import type { ActionFunction } from "@remix-run/server-runtime";
import { redirect } from "@remix-run/server-runtime";
import { createApplicant } from "~/models/applicant.server";
import { requireProfile } from "~/session.server";
import { requireUser } from "~/session.server";

const parseDate = (dateString: string): Date => {
const [year, month, day] = dateString.split("-");
Expand All @@ -11,9 +11,9 @@ const parseDate = (dateString: string): Date => {

export const action: ActionFunction = async ({ request }) => {
const result = await validator.validate(await request.formData());
const profile = await requireProfile(request);
const user = await requireUser(request);

const email = profile?.email;
const email = user?.email;
const personalEmail =
(result?.data?.personalEmail as string) ?? "DefaultPersonalEmailValue";
const fullName = (result?.data?.fullName as string) ?? "DefaultFullNameValue";
Expand Down Expand Up @@ -71,7 +71,7 @@ export const action: ActionFunction = async ({ request }) => {
(result?.data?.wizelinePrograms as string) ??
"DefaultWizelineProgramsValue";
const comments = (result?.data?.comments as string) ?? "DefaultCommentsValue";
const avatarApplicant = profile?.avatarUrl as string;
const avatarApplicant = user?.avatarUrl as string;

if (!result) {
throw new Response("Error", {
Expand Down

0 comments on commit fb0be77

Please sign in to comment.