From bf7b25ca9e9d11df94b91f7483ee339cefd3e0c9 Mon Sep 17 00:00:00 2001 From: Sarah Vaupel Date: Fri, 11 Jun 2021 11:59:02 +0200 Subject: [PATCH] feat(exams): do form validation --- .../categories/courses/exam/exam/de-de-formal.msg | 6 +++++- .../uniworx/categories/courses/exam/exam/en-eu.msg | 6 +++++- src/Handler/Exam/Form.hs | 12 ++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/messages/uniworx/categories/courses/exam/exam/de-de-formal.msg b/messages/uniworx/categories/courses/exam/exam/de-de-formal.msg index 4ea047217..baac78f3f 100644 --- a/messages/uniworx/categories/courses/exam/exam/de-de-formal.msg +++ b/messages/uniworx/categories/courses/exam/exam/de-de-formal.msg @@ -324,4 +324,8 @@ ExamAuthorshipStatementUseCustomDefinitionTip: Soll anstatt der institutsweit vo ExamAuthorshipStatementUseCustomDefinitionDisabledTip: Für dieses Institut ist die institutsweite Vorgabe als Erklärung zu verwenden. Benutzerdefinierte Erklärungen sind nicht gestattet. ExamAuthorshipStatementCustom: Benutzerdefinierte 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. \ No newline at end of file +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. \ No newline at end of file diff --git a/messages/uniworx/categories/courses/exam/exam/en-eu.msg b/messages/uniworx/categories/courses/exam/exam/en-eu.msg index 385a1e44e..ab41c986a 100644 --- a/messages/uniworx/categories/courses/exam/exam/en-eu.msg +++ b/messages/uniworx/categories/courses/exam/exam/en-eu.msg @@ -322,4 +322,8 @@ ExamAuthorshipStatementUseCustomDefinitionTip: Should a custom Statement of Auth ExamAuthorshipStatementUseCustomDefinitionDisabledTip: This school dictates that the school-wide Statement of Authorship must be used. Custom statements are prohibited. ExamAuthorshipStatementCustom: Custom 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. \ No newline at end of file +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. \ No newline at end of file diff --git a/src/Handler/Exam/Form.hs b/src/Handler/Exam/Form.hs index 1f8ed214e..4391a7ed6 100644 --- a/src/Handler/Exam/Form.hs +++ b/src/Handler/Exam/Form.hs @@ -558,10 +558,14 @@ validateExam cId oldExam = do warnValidation MsgExamModeSchoolDiscouraged . not $ evalExamModeDNF schoolExamDiscouragedModes efExamMode - -- TODO: form validation of examAuthorshipStatement wrt school settings - -- - if mode is none, the statement must be `Nothing` - -- - if mode is required, the statement must be `Just x` - -- - if the school has a definition and disallows other, the statement must match the school definition + case schoolSheetExamAuthorshipStatementMode of + SchoolAuthorshipStatementModeNone -> guardValidation MsgExamAuthorshipStatementMustBeEmpty $ is _Nothing efAuthorshipStatement + SchoolAuthorshipStatementModeRequired -> guardValidation MsgExamAuthorshipStatementMustBeNonEmpty $ is _Just efAuthorshipStatement + _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) $ guardValidation MsgExamStaffRequired $ isn't _Nothing efStaff