Skip to content

Commit

Permalink
admin user overrides mentorconfig lock (#318)
Browse files Browse the repository at this point in the history
* admin user overrides mentorconfig lock

---------

Co-authored-by: aaronshiel <[email protected]>
  • Loading branch information
aaronshiel and aaronshiel authored Aug 19, 2024
1 parent 831cacc commit 2c9086a
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Build the docker-compose stack
run: docker-compose up -d
run: docker compose up -d
- name: Check running containers
run: docker ps
- name: Cypress run tests
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DOCKER_IMAGE?=mentor-admin
TEST_E2E_DOCKER_COMPOSE=docker-compose
TEST_E2E_DOCKER_COMPOSE=docker compose
TEST_E2E_IMAGE_SNAPSHOTS_PATH?=cypress/snapshots
TEST_E2E_DOCKER_IMAGE_SNAPSHOTS_PATH?=/app/$(TEST_E2E_IMAGE_SNAPSHOTS_PATH)
TEST_E2E_HOST_IMAGE_SNAPSHOTS_PATH?=$(PWD)/cypress/$(TEST_E2E_IMAGE_SNAPSHOTS_PATH)
Expand Down
2 changes: 1 addition & 1 deletion client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ clean:

.PHONY: develop
develop: node_modules/gatsby
npx gatsby develop -p 80
npx gatsby develop -p 8000

.PHONY: pretty
pretty:
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/config/mentor-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function MentorItem(props: {
<FormControlLabel
control={
<IconButton
data-cy="launch-mentor"
data-cy={`launch-mentor-${mentor._id}`}
size="small"
onClick={() =>
launchMentor(
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/config/mentor-panel-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function MentorPanelItem(props: {
<FormControlLabel
control={
<IconButton
data-cy="launch-mentor-panel"
data-cy={`launch-mentor-panel-${mentorPanel.mentors.join("-")}`}
size="small"
onClick={() =>
launchMentorPanel(
Expand Down
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 @@ -92,6 +97,7 @@ export function useWithSetup(
undefined,
0
);
const user = useAppSelector((state) => state.login.user);

const mentor: Mentor = getData((state) => state.data);
useQuestions(
Expand Down Expand Up @@ -194,11 +200,16 @@ export function useWithSetup(
requiredSubjects,
isSetupComplete,
});
const mentorSubjectsLocked = mentor.mentorConfig?.lockedToSubjects;
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
2 changes: 1 addition & 1 deletion cypress/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export default defineConfig({
setupNodeEvents(on, config) {
return require("./cypress/plugins/index.ts")(on, config);
},
baseUrl: "http://localhost:80",
baseUrl: "http://localhost:8000",
},
});
20 changes: 16 additions & 4 deletions cypress/cypress/e2e/config.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ describe("config screen", () => {
cy.get('[data-cy=toggle-active] [type="checkbox"]').should(
"be.checked"
);
cy.get("[data-cy=launch-mentor]").trigger("mouseover").click();
cy.get("[data-cy=launch-mentor-62aa503082f27ce347bdc7f4]")
.should("exist")
.should("be.enabled");
});
});
});
Expand Down Expand Up @@ -323,7 +325,9 @@ describe("config screen", () => {
cy.get('[data-cy=toggle-featured] [type="checkbox"]').should(
"not.be.checked"
);
cy.get("[data-cy=launch-mentor]").trigger("mouseover").click();
cy.get("[data-cy=launch-mentor-62b4f62482f27ce347ba02e2]")
.should("exist")
.should("be.enabled");
});
});
});
Expand Down Expand Up @@ -381,7 +385,11 @@ describe("config screen", () => {
cy.get('[data-cy=toggle-active] [type="checkbox"]').should(
"be.checked"
);
cy.get("[data-cy=launch-mentor-panel]").trigger("mouseover").click();
cy.get(
"[data-cy=launch-mentor-panel-62b4f62482f27ce347ba02e2-62aa503082f27ce347bdc7f4-62aa503082f27ce347bdc7f8]"
)
.should("exist")
.should("be.enabled");
});
});
});
Expand Down Expand Up @@ -434,7 +442,11 @@ describe("config screen", () => {
cy.get('[data-cy=toggle-featured] [type="checkbox"]').should(
"not.be.checked"
);
cy.get("[data-cy=launch-mentor-panel]").trigger("mouseover").click();
cy.get(
"[data-cy=launch-mentor-panel-62b4f62482f27ce347ba02e2-62aa503082f27ce347bdc7f4-62aa503082f27ce347bdc7f8]"
)
.should("exist")
.should("be.enabled");
});
});
});
Expand Down
2 changes: 2 additions & 0 deletions cypress/cypress/e2e/home.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,7 @@ describe("My Mentor Page", () => {
cyMockDefault(cy, {
mentor: {
...clintWithConfig,
lockedToConfig: true,
mentorConfig: {
...clintWithConfig.mentorConfig,
lockedToSubjects: true,
Expand All @@ -1203,6 +1204,7 @@ describe("My Mentor Page", () => {
cyMockDefault(cy, {
mentor: {
...clintWithConfig,
lockedToConfig: true,
mentorConfig: {
...clintWithConfig.mentorConfig,
lockedToSubjects: true,
Expand Down
6 changes: 2 additions & 4 deletions cypress/cypress/e2e/setup.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1292,10 +1292,7 @@ describe("Setup", () => {
.get("[data-cy=nav-btn-avatar]")
.should("have.css", "backgroundColor", "rgb(255, 0, 0)");
cy.contains("1 / 3");
cy.getSettled("[data-cy=record-btn]", { retries: 4 })
.trigger("mouseover")
.click();
// go to record
cy.getSettled("[data-cy=record-btn]", { delay: 1000 }).click();
cy.location("pathname").then(($el) =>
assert($el.replace("/admin", ""), "/record")
);
Expand Down Expand Up @@ -1446,6 +1443,7 @@ describe("Setup", () => {
it("Record required subject slide considers answer as complete if upload in progress", () => {
const videoWithConfigAndUnansweredQ: Mentor = {
...completeMentor(videoMentor),
lockedToConfig: true,
mentorConfig: mentorConfig,
name: "helo",
firstName: "world",
Expand Down
1 change: 1 addition & 0 deletions cypress/cypress/fixtures/recording/video_mentors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,6 @@ export const mentorConfig: MentorConfig = {
};
export const videoMentorWithConfig: Mentor = {
...videoMentor,
lockedToConfig: true,
mentorConfig,
};
1 change: 1 addition & 0 deletions cypress/cypress/support/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export interface Mentor {
isPrivate: boolean;
isArchived: boolean;
isAdvanced: boolean;
lockedToConfig?: boolean;
defaultSubject?: Subject;
mentorConfig?: MentorConfig;
numAnswersComplete: number;
Expand Down

0 comments on commit 2c9086a

Please sign in to comment.