Skip to content

Commit

Permalink
admin user overrides mentorconfig lock
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronshiel committed Aug 19, 2024
1 parent 831cacc commit 580a4ef
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
9 changes: 6 additions & 3 deletions client/src/components/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import parseMentor, {
defaultMentorInfo,
} from "components/my-mentor-card/mentor-info";
import NavBar from "components/nav-bar";
import { canEditContent, launchMentor } from "helpers";
import { canEditContent, isAdmin, launchMentor } from "helpers";
import {
QuestionEdits,
useWithReviewAnswerState,
Expand All @@ -57,6 +57,7 @@ import { trainMentor } from "api";
import { useWithConfig } from "store/slices/config/useWithConfig";
import { BuildMentorTooltip } from "./build-mentor-tooltip";
import { MentorConfig } from "types-gql";
import { useAppSelector } from "store/hooks";

const useStyles = makeStyles({ name: { HomePage } })((theme: Theme) => ({
toolbar: {
Expand Down Expand Up @@ -155,7 +156,9 @@ function HomePage(props: {
const mentorConfig: MentorConfig | undefined = getData(
(m) => m.data?.mentorConfig
);
const lockedToConfig: boolean = getData((m) => m.data?.lockedToConfig);
const user = useAppSelector((state) => state.login.user);
const lockedToConfig: boolean =
!isAdmin(user) && getData((m) => m.data?.lockedToConfig);
const defaultMentor = props.user.defaultMentor._id;
const { classes } = useStyles();
const [showSetupAlert, setShowSetupAlert] = useState(true);
Expand Down Expand Up @@ -532,7 +535,7 @@ function HomePage(props: {
{name}
</MenuItem>
))}
{mentorConfig?.lockedToSubjects ? undefined : (
{lockedToConfig && mentorConfig?.lockedToSubjects ? undefined : (
<MenuItem
key={"add-subject"}
data-cy={"add-subject"}
Expand Down
10 changes: 7 additions & 3 deletions client/src/components/nav-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ import { useWithLogin } from "store/slices/login/useWithLogin";
import useActiveMentor from "store/slices/mentor/useActiveMentor";
import withLocation from "wrap-with-location";
import { Mentor, UploadTask } from "types";
import { canEditContent, launchMentor } from "helpers";
import { canEditContent, isAdmin, launchMentor } from "helpers";
import {
areAllTasksDone,
isATaskCancelled,
} from "hooks/graphql/upload-status-helpers";
import { useWithImportStatus } from "hooks/graphql/use-with-import-status";
import ImportInProgressDialog from "./import-export/import-in-progress";
import { useAppSelector } from "store/hooks";

const useStyles = makeStyles({ name: { Login } })((theme: Theme) => ({
toolbar: {
Expand Down Expand Up @@ -320,7 +321,8 @@ export function NavBar(props: {
} = props;
const { getData } = useActiveMentor();
const mentor: Mentor | undefined = getData((state) => state.data);

const user = useAppSelector((state) => state.login.user);
const lockedToConfig = mentor?.lockedToConfig && !isAdmin(user);
const importStatus = useWithImportStatus();
const { importTask } = importStatus;
const numUploadsInProgress =
Expand Down Expand Up @@ -403,7 +405,9 @@ export function NavBar(props: {
>
<Toolbar />
<NavMenu
mentorSubjectsLocked={Boolean(mentor?.mentorConfig?.lockedToSubjects)}
mentorSubjectsLocked={Boolean(
lockedToConfig && mentor?.mentorConfig?.lockedToSubjects
)}
classes={classes}
mentorId={props.mentorId}
onNav={onNav}
Expand Down
6 changes: 6 additions & 0 deletions client/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,9 @@ export function isDateWithinLastMonth(date: string): boolean {
const diffDays = Math.ceil(diff / (1000 * 3600 * 24));
return diffDays < 30;
}

export function isAdmin(user?: User): boolean {
return (
user?.userRole === UserRole.ADMIN || user?.userRole === UserRole.SUPER_ADMIN
);
}
23 changes: 17 additions & 6 deletions client/src/hooks/graphql/use-with-setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import {
} from "types";
import { LoadingError } from "./loading-reducer";
import { useWithConfig } from "store/slices/config/useWithConfig";
import { getValueIfKeyExists, isAnswerComplete, urlBuild } from "helpers";
import {
getValueIfKeyExists,
isAdmin,
isAnswerComplete,
urlBuild,
} from "helpers";
import { useMentorEdits } from "store/slices/mentor/useMentorEdits";
import useActiveMentor from "store/slices/mentor/useActiveMentor";
import useQuestions from "store/slices/questions/useQuestions";
Expand Down Expand Up @@ -194,11 +199,17 @@ export function useWithSetup(
requiredSubjects,
isSetupComplete,
});
const mentorSubjectsLocked = mentor.mentorConfig?.lockedToSubjects;
const user = useAppSelector((state) => state.login.user);
const lockedToConfig = !isAdmin(user) && mentor.lockedToConfig;
const mentorSubjectsLocked =
lockedToConfig && mentor.mentorConfig?.lockedToSubjects;
const mentorPrivacyLocked =
mentor.mentorConfig?.publiclyVisible !== undefined ||
mentor.mentorConfig?.orgPermissions.length;
const mentorTypeLocked = mentor.mentorConfig?.mentorType;
lockedToConfig &&
(mentor.mentorConfig?.publiclyVisible !== undefined ||
mentor.mentorConfig?.orgPermissions.length);
const mentorTypeLocked = lockedToConfig && mentor.mentorConfig?.mentorType;
const disabledMyGoalSlide =
lockedToConfig && mentor.mentorConfig?.disableMyGoalSlide;
const status: SetupStep[] = [
{ type: SetupStepType.WELCOME, complete: true },
{ type: SetupStepType.MENTOR_INFO, complete: isMentorInfoDone },
Expand All @@ -208,7 +219,7 @@ export function useWithSetup(
...(mentorPrivacyLocked
? []
: [{ type: SetupStepType.MENTOR_PRIVACY, complete: true }]),
...(mentor.mentorConfig?.disableMyGoalSlide
...(disabledMyGoalSlide
? []
: [
{ type: SetupStepType.MENTOR_GOAL, complete: Boolean(mentor.goal) },
Expand Down

0 comments on commit 580a4ef

Please sign in to comment.