Skip to content

Commit

Permalink
Fixes 346 (#1269)
Browse files Browse the repository at this point in the history
* Update course progress placeholder texts

* Include course module completion date in the csv

* Don't render the glossary in the hero section

* System test fixes

* Typo fix
  • Loading branch information
nygrenh authored May 6, 2024
1 parent 0f3c0b5 commit d946ebf
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,27 @@ const parseCitation = (data: string) => {
return converted
}

const parseText = (content: string | undefined | StringWithHTML, terms: Term[]) => {
const parseText = (
content: string | undefined | StringWithHTML,
terms: Term[],
options: { glossary: boolean } = { glossary: true },
) => {
const sanitizedHTML = sanitizeCourseMaterialHtml(content)
const { count, converted: parsedLatex } = convertToLatex(sanitizedHTML)
const parsedCitation = parseCitation(parsedLatex)
const parsedGlossary = parseGlossary(parsedCitation, terms ?? [])

const hasCitationsOrGlossary = parsedLatex !== parsedGlossary
let parsedText = parsedCitation
let hasCitationsOrGlossary = false

return { count, parsedText: parsedGlossary, hasCitationsOrGlossary }
if (options.glossary) {
parsedText = parseGlossary(parsedCitation, terms ?? [])
}

hasCitationsOrGlossary = parsedLatex !== parsedText

// Sanitation always needs to be the last step because otherwise we might accidentally introduce injection attacks with our custom parsing and modifications to the string
parsedText = sanitizeCourseMaterialHtml(parsedText)
return { count, parsedText, hasCitationsOrGlossary }
}

export { parseText }
10 changes: 8 additions & 2 deletions services/course-material/src/components/HeroSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,15 @@ const HeroSection: React.FC<React.PropsWithChildren<React.PropsWithChildren<Card
<span className="chapter">{label}</span>
<h1
className={INCLUDE_THIS_HEADING_IN_HEADINGS_NAVIGATION_CLASS}
dangerouslySetInnerHTML={{ __html: parseText(title, terms).parsedText }}
dangerouslySetInnerHTML={{
__html: parseText(title, terms, { glossary: false }).parsedText,
}}
/>
<span
dangerouslySetInnerHTML={{
__html: parseText(subtitle, terms, { glossary: false }).parsedText,
}}
/>
<span dangerouslySetInnerHTML={{ __html: parseText(subtitle, terms).parsedText }} />
</TextBox>
</div>
)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ pub struct CourseModuleCompletionWithRegistrationInfo {
pub registered: bool,
/// ID of the user for the completion.
pub user_id: Uuid,
// When the user completed the course
pub completion_date: DateTime<Utc>,
}

/// Gets summaries for all completions on the given course instance.
Expand All @@ -218,7 +220,8 @@ SELECT completions.completion_registration_attempt_date,
completions.passed,
completions.prerequisite_modules_completed,
(registered.id IS NOT NULL) AS "registered!",
completions.user_id
completions.user_id,
completions.completion_date
FROM course_module_completions completions
LEFT JOIN course_module_completion_registered_to_study_registries registered ON (
completions.id = registered.course_module_completion_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ where
let module_name = module.name.as_deref().unwrap_or("default_module");
headers.push(format!("{module_name}_grade"));
headers.push(format!("{module_name}_registered"));
headers.push(format!("{module_name}_completion_date"));
}

// write rows
Expand Down Expand Up @@ -100,6 +101,11 @@ where
.map(|cm| cm.registered.to_string())
.unwrap_or_default();
csv_row.push(registered);
csv_row.push(
user_completion
.map(|uc| uc.completion_date.to_rfc3339())
.unwrap_or_default(),
)
}
// To avoid confusion with some people potentially not understanding that '-' means not completed,
// we'll skip the users that don't have any completions from any modules. The confusion is less likely in cases where there are more than one module, and only in those cases the teachers would see the '-' entries in this file.
Expand Down
4 changes: 2 additions & 2 deletions shared-module/src/locales/en/cms.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"congratulations-explanation": "This block is placed in the course material where you wish to show the student congratulations when they have completed the course. For courses that have been configured for receiving ECTS, it will also provide a link to a page where they can register their completion to Open University.",
"congratulations-placeholder": "Congratulations placeholder",
"course-instance-enrollment-condition": "Student has enrolled to any of the following course instances:",
"course-progress-placeholder": "Chapter progress placeholder",
"course-progress-placeholder-explanation": "This block is placed on the course material where you wish to show the course progress.",
"course-progress-placeholder": "Course progress placeholder",
"course-progress-placeholder-explanation": "This block is placed on the course material where you wish to show to the user their current progress and how many points they have gotten from the whole course.",
"default": "Default",
"default-question": "Insert question here",
"delete": "Delete",
Expand Down
2 changes: 1 addition & 1 deletion shared-module/src/locales/fi/cms.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"congratulations-placeholder": "Onnittelulohko",
"course-instance-enrollment-condition": "Opiskelija on ilmoittautunut johonkin seuraavista kurssitoteutuksista:",
"course-progress-placeholder": "Kurssin edistyminen lohko",
"course-progress-placeholder-explanation": "Tämä lohko sijoitetaan kurssimateriaaliin, johon haluat näyttää kurssin edistymisen.",
"course-progress-placeholder-explanation": "Tämä lohko sijoitetaan kurssimateriaaliin, johon haluat näyttää käyttäjälle hänen nykyisen edistymisensä ja pistetilanteensa koko kurssilta.",
"default": "Oletus",
"default-question": "Lisää kysymys tähän",
"delete": "Poista",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ test("Manually adding completions works", async ({ page, headless }, testInfo) =
])

const completionsCsvContents = await downloadToString(download)
expect(completionsCsvContents).toContain("user_id,first_name,last_name,email")
expect(completionsCsvContents).toContain("[email protected],4,false,-,,-,")
expect(completionsCsvContents).toContain("[email protected],4,false,pass,false,-,")
expect(completionsCsvContents).toContain(
"user_id,first_name,last_name,email,default_module_grade,default_module_registered,default_module_completion_date",
)
expect(completionsCsvContents).toMatch(
/[^, ]*-[^, ]*-[^, ]*-[^, ]*-[^, ].*,user_2@example\.com,4,false,[^, ]*T[^, ]*,-,,,-,,/,
)
expect(completionsCsvContents).toMatch(
/[^, ]*-[^, ]*-[^, ]*-[^, ]*-[^, ].*,user_3@example\.com,4,false,[^, ]*T[^, ]*,pass,false,[^, ]*T[^, ]*/,
)
})
2 changes: 2 additions & 0 deletions system-tests/src/tests/user-research-consent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ test("Research consent form is visible on login, if not yet answered", async ({
waitForTheseToBeVisibleAndStable: [page.getByText("Regarding research done on courses")],
})
await page.getByRole("button", { name: "Save" }).click()
await page.getByText("Operation successful").waitFor()

//Login again and check research consent form doesn't show again when already answered.
await page.getByRole("button", { name: "Open menu" }).click()
Expand Down Expand Up @@ -84,6 +85,7 @@ test("Research consent form is visible on login, if not yet answered", async ({

await page.getByLabel("I do not want to participate in the educational research.").check()
await page.getByRole("button", { name: "Save" }).click()
await page.getByText("Operation successful").waitFor()
await page.getByRole("button", { name: "Edit" }).click()
expect(
await page
Expand Down

0 comments on commit d946ebf

Please sign in to comment.