diff --git a/apps/app/src/paths/AssignmentViewer.tsx b/apps/app/src/paths/AssignmentViewer.tsx index d0c5e07a6..f769f81af 100644 --- a/apps/app/src/paths/AssignmentViewer.tsx +++ b/apps/app/src/paths/AssignmentViewer.tsx @@ -8,7 +8,17 @@ import { import { DoenetViewer } from "@doenet/doenetml-iframe"; -import { Box, Button, Grid, GridItem, Text, Tooltip } from "@chakra-ui/react"; +import { + Alert, + AlertDescription, + AlertIcon, + Box, + Button, + Grid, + GridItem, + Text, + Tooltip, +} from "@chakra-ui/react"; import axios, { AxiosError } from "axios"; import { EnterClassCode, @@ -256,6 +266,10 @@ export function AssignmentViewer() { throw Error("User should have been defined"); } + const isAnonymous = user.isAnonymous === true; + const anonymousBannerHeight = "40px"; + const headerHeight = isAnonymous ? "120px" : "80px"; + const [attemptNumber, setAttemptNumber] = useState( loaderData.attemptNumber, ); @@ -565,8 +579,6 @@ export function AssignmentViewer() { const baseUrl = window.location.protocol + "//" + window.location.host; const doenetViewerUrl = `${baseUrl}/activityViewer`; - const headerHeight = "80px"; - let viewer: ReactElement; if (loaderData.type === "singleDoc") { const maxAttempts = assignment.assignmentInfo?.maxAttempts ?? 0; @@ -698,6 +710,25 @@ export function AssignmentViewer() { + {isAnonymous && ( + + + + + You are logged in as an anonymous user. Your work is saved in this + browser only and may be lost if you clear your browser data. + + + + )} + { + const code = Date.now().toString(); + const instructorEmail = `test${code}@doenet.org`; + cy.loginAsTestUser({ + isAuthor: true, + email: instructorEmail, + firstNames: "Instructor", + lastNames: "One", + }); + + let classCode: number | null = null; + + cy.createContent({ + name: "Test Assignment", + contentType: "singleDoc", + doenetML: `

Hello world

`, + }).then((contentId) => { + cy.createAssignment({ + contentId, + closedOn: DateTime.now().plus({ days: 7 }).toISO(), + }).then(({ classCode: cc }) => { + classCode = cc; + }); + }); + + // Anonymous user sees the banner + cy.loginAsTestUser({ isAnonymous: true }); + + cy.then(() => { + cy.visit(`/code/${classCode}`); + cy.get('[data-test="Anonymous User Banner"]').should("be.visible"); + cy.contains("anonymous user").should("be.visible"); + }); + + // Non-anonymous user does not see the banner + cy.loginAsTestUser({ + email: instructorEmail, + firstNames: "Instructor", + lastNames: "One", + }); + + cy.then(() => { + cy.visit(`/code/${classCode}`); + cy.get('[data-test="Anonymous User Banner"]').should("not.exist"); + }); + }, + ); });