feat(exams): do form validation

This commit is contained in:
Sarah Vaupel 2021-06-11 11:59:02 +02:00 committed by Gregor Kleen
parent fe5111c25f
commit bf7b25ca9e
3 changed files with 18 additions and 6 deletions

View File

@ -325,3 +325,7 @@ ExamAuthorshipStatementUseCustomDefinitionDisabledTip: Für dieses Institut ist
ExamAuthorshipStatementCustom: Benutzerdefinierte Eigenständigkeitserklärung ExamAuthorshipStatementCustom: Benutzerdefinierte Eigenständigkeitserklärung
ExamAuthorshipStatementContent: Eigenständigkeitserklärung ExamAuthorshipStatementContent: Eigenständigkeitserklärung
ExamAuthorshipStatementAllowOtherFalseTip: Für dieses Institut ist die institutsweit vorgegebene Eigenständigkeitserklärung für prüfungsrelevante Übungsblätter zu verwenden. Benutzerdefinierte Erklärungen sind nicht gestattet. ExamAuthorshipStatementAllowOtherFalseTip: Für dieses Institut ist die institutsweit vorgegebene Eigenständigkeitserklärung für prüfungsrelevante Übungsblätter zu verwenden. Benutzerdefinierte Erklärungen sind nicht gestattet.
ExamAuthorshipStatementMustBeEmpty: Es darf keine Eigenständigkeitserklärung für prüfungsrelevante Übungsblätter angegeben werden.
ExamAuthorshipStatementMustBeNonEmpty: Es muss eine nicht-leere Eigenständigkeitserklärung für prüfungsrelevante Übungsblätter angegeben werden.
ExamAuthorshipStatementMustMatchSchoolDefinition: Die angegebene Eigenständigkeitserklärung für prüfungsrelevante Übungsblätter muss der Vorgabe des Instituts entsprechen.

View File

@ -323,3 +323,7 @@ ExamAuthorshipStatementUseCustomDefinitionDisabledTip: This school dictates that
ExamAuthorshipStatementCustom: Custom Statement of Authorship ExamAuthorshipStatementCustom: Custom Statement of Authorship
ExamAuthorshipStatementContent: Statement of Authorship ExamAuthorshipStatementContent: Statement of Authorship
ExamAuthorshipStatementAllowOtherFalseTip: The settings of this school dictate that the school-wide Statement of Authorship for exam-related sheets must be used. Custom statements are prohibited. ExamAuthorshipStatementAllowOtherFalseTip: The settings of this school dictate that the school-wide Statement of Authorship for exam-related sheets must be used. Custom statements are prohibited.
ExamAuthorshipStatementMustBeEmpty: No Statement of Authorship for exam-related sheets may be given.
ExamAuthorshipStatementMustBeNonEmpty: A non-empty Statement of Authorship for exam-related sheets must be given.
ExamAuthorshipStatementMustMatchSchoolDefinition: The given Statement of Authorship for exam-related sheets must match the school-wide Statement of Authorship.

View File

@ -558,10 +558,14 @@ validateExam cId oldExam = do
warnValidation MsgExamModeSchoolDiscouraged . not $ evalExamModeDNF schoolExamDiscouragedModes efExamMode warnValidation MsgExamModeSchoolDiscouraged . not $ evalExamModeDNF schoolExamDiscouragedModes efExamMode
-- TODO: form validation of examAuthorshipStatement wrt school settings case schoolSheetExamAuthorshipStatementMode of
-- - if mode is none, the statement must be `Nothing` SchoolAuthorshipStatementModeNone -> guardValidation MsgExamAuthorshipStatementMustBeEmpty $ is _Nothing efAuthorshipStatement
-- - if mode is required, the statement must be `Just x` SchoolAuthorshipStatementModeRequired -> guardValidation MsgExamAuthorshipStatementMustBeNonEmpty $ is _Just efAuthorshipStatement
-- - if the school has a definition and disallows other, the statement must match the school definition _otherwise -> return ()
whenIsJust efAuthorshipStatement $ \statementContent -> do
mSchoolAuthorshipStatement <- lift $ maybe (pure Nothing) getEntity schoolSheetExamAuthorshipStatementDefinition
guardValidation MsgExamAuthorshipStatementMustBeNonEmpty $ schoolSheetExamAuthorshipStatementMode == SchoolAuthorshipStatementModeRequired && statementContent /= mempty
guardValidation MsgExamAuthorshipStatementMustMatchSchoolDefinition $ not schoolSheetExamAuthorshipStatementAllowOther && Just statementContent == (authorshipStatementDefinitionContent . entityVal <$> mSchoolAuthorshipStatement)
unless (has (_Just . _entityVal . _examStaff . _Nothing) oldExam) $ unless (has (_Just . _entityVal . _examStaff . _Nothing) oldExam) $
guardValidation MsgExamStaffRequired $ isn't _Nothing efStaff guardValidation MsgExamStaffRequired $ isn't _Nothing efStaff