diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 4c18542ba..36c10837e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -69,6 +69,11 @@ "type": "npm", "script": "lint", "problemMatcher": [] + }, + { + "type": "npm", + "script": "release", + "problemMatcher": [] } ] } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 8755e90b0..40171cfc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,79 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [5.3.0](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/compare/v5.2.3...v5.3.0) (2019-08-22) + + +### Bug Fixes + +* **allocations:** fix behaviour of "active" dbTable-filter ([b694a09](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/b694a09)) +* **course list:** show complete registration span ([754d6ca](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/754d6ca)), closes [#446](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/issues/446) +* **home:** fix hlint and other minor bugs ([839251e](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/839251e)) + + +### Features + +* **allocations:** add info page for allocations ([689b85a](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/689b85a)) +* **allocations:** show table of all allocations ([d621e61](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/d621e61)) +* **allocations:** show table of course applications ([f5da3be](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/f5da3be)) +* **home:** allow users to define exam warning time ([d23e222](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/d23e222)), closes [#445](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/issues/445) +* **home:** clean up homepage ([a6e2f64](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/a6e2f64)) + + + +### [5.2.3](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/compare/v5.2.2...v5.2.3) (2019-08-22) + + +### Bug Fixes + +* **csv exam import:** ignore unchanged noshow and voided ([a346524](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/a346524)) + + + +### [5.2.2](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/compare/v5.2.1...v5.2.2) (2019-08-22) + + + +### [5.2.1](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/compare/v5.2.0...v5.2.1) (2019-08-21) + + +### Bug Fixes + +* **csv upload exams:** allow ambiguous harmless study fields ([7d2937c](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/7d2937c)) + + + +## [5.2.0](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/compare/v5.1.0...v5.2.0) (2019-08-21) + + +### Bug Fixes + +* **csv import:** csv import preview help text adjusted ([b7321df](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/b7321df)) +* **csv import:** fix spelling and expand help text ([2c57a77](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/2c57a77)) +* **exam import:** inactive registered features may be selected ([3c4172c](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/3c4172c)) +* **routes:** change ex to sheet ([9d9ead9](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/9d9ead9)) +* **sheet list:** do not show icons for inaccessible items ([0bb9a0f](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/0bb9a0f)), closes [#421](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/issues/421) + + +### Features + +* **csv import:** add explanation text ([6d0a4c1](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/6d0a4c1)) + + + +## [5.1.0](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/compare/v5.0.2...v5.1.0) (2019-08-19) + + +### Features + +* **allocations:** add application form(s) ([ef625cd](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/ef625cd)) +* **allocations:** add registration form ([c5b18fc](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/c5b18fc)) +* **allocations:** implement application interface ([4dcc82a](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/4dcc82a)) +* **allocations:** link allocations from home ([c759364](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/c759364)) +* **allocations:** set up routes ([c2df01c](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/commit/c2df01c)) + + + ### [5.0.2](https://gitlab.cip.ifi.lmu.de/jost/UniWorX/compare/v5.0.1...v5.0.2) (2019-08-13) diff --git a/config/settings.yml b/config/settings.yml index bcd9cabcb..9d787ed7f 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -119,5 +119,6 @@ user-defaults: date-format: "%d.%m.%Y" time-format: "%R" download-files: false + warning-days: 1209600 instance-id: "_env:INSTANCE_ID:instance" diff --git a/frontend/src/services/util-registry/util-registry.js b/frontend/src/services/util-registry/util-registry.js index d96d7a4b3..c6e866adf 100644 --- a/frontend/src/services/util-registry/util-registry.js +++ b/frontend/src/services/util-registry/util-registry.js @@ -1,4 +1,4 @@ -const DEBUG_MODE = /localhost/.test(window.location.href) && 0; +const DEBUG_MODE = /localhost/.test(window.location.href) ? 2 : 0; export class UtilRegistry { diff --git a/frontend/src/utils/form/interactive-fieldset.js b/frontend/src/utils/form/interactive-fieldset.js index 5d24ee9c2..9c080e04f 100644 --- a/frontend/src/utils/form/interactive-fieldset.js +++ b/frontend/src/utils/form/interactive-fieldset.js @@ -16,6 +16,7 @@ export class InteractiveFieldset { conditionalValue; target; childInputs; + negated; constructor(element) { if (!element) { @@ -43,11 +44,13 @@ export class InteractiveFieldset { } // param conditionalValue - if (!this._element.dataset.conditionalValue && !this._isCheckbox()) { + if (!('conditionalValue' in this._element.dataset) && !this._isCheckbox()) { throw new Error('Interactive Fieldset needs a conditional value!'); } this.conditionalValue = this._element.dataset.conditionalValue; + this.negated = 'conditionalNegated' in this._element.dataset; + this.target = this._element.closest(INTERACTIVE_FIELDSET_UTIL_TARGET_SELECTOR); if (!this.target || this._element.matches(INTERACTIVE_FIELDSET_UTIL_TARGET_SELECTOR)) { this.target = this._element; @@ -88,11 +91,19 @@ export class InteractiveFieldset { } _matchesConditionalValue() { + var matches; + if (this._isCheckbox()) { - return this.conditionalInput.checked === true; + matches = this.conditionalInput.checked === true; + } else { + matches = this.conditionalInput.value === this.conditionalValue; } - return this.conditionalInput.value === this.conditionalValue; + if (this.negated) { + return !matches; + } else { + return matches; + } } _isCheckbox() { diff --git a/frontend/src/utils/form/interactive-fieldset.md b/frontend/src/utils/form/interactive-fieldset.md index 323c26e55..f98fdb0f4 100644 --- a/frontend/src/utils/form/interactive-fieldset.md +++ b/frontend/src/utils/form/interactive-fieldset.md @@ -8,6 +8,8 @@ Shows/hides inputs based on value of particular input Selector for the input that this fieldset watches for changes - `data-conditional-value: string`\ The value the conditional input needs to be set to for this fieldset to be shown. Can be omitted if conditionalInput is a checkbox +- `data-conditional-negated`\ + If present, negates the match on `data-conditional-value` ## Example usage: ### example with text input diff --git a/frontend/src/utils/inputs/inputs.scss b/frontend/src/utils/inputs/inputs.scss index 643902d08..ae81b82d4 100644 --- a/frontend/src/utils/inputs/inputs.scss +++ b/frontend/src/utils/inputs/inputs.scss @@ -9,11 +9,9 @@ grid-gap: 5px; justify-content: flex-start; align-items: flex-start; - padding: 4px 0; - border-left: 2px solid transparent; - + .form-group { - margin-top: 7px; + + .form-group, + .form-section-legend, + .form-section-notification { + margin-top: 11px; } + .form-section-title { diff --git a/messages/uniworx/de.msg b/messages/uniworx/de.msg index 547092e46..256f2a000 100644 --- a/messages/uniworx/de.msg +++ b/messages/uniworx/de.msg @@ -30,6 +30,7 @@ Aborted: Abgebrochen Remarks: Hinweise Registered: Angemeldet RegisteredSince: Angemeldet seit +Registration: Anmeldung RegisterFrom: Anmeldungen von RegisterTo: Anmeldungen bis DeRegUntil: Abmeldungen bis @@ -127,7 +128,7 @@ CourseShorthand: Kürzel CourseShorthandUnique: Muss innerhalb Institut und Semester eindeutig sein CourseSemester: Semester CourseSchool: Institut -CourseSchoolShort: Fach +CourseSchoolShort: Institut CourseSecretTip: Anmeldung zum Kurs erfordert Eingabe des Passworts, sofern gesetzt CourseSecretFormat: beliebige Zeichenkette CourseRegisterFromTip: Ohne Datum ist KEINE eigenständige Anmeldung von Studierenden möglich @@ -170,6 +171,18 @@ CourseApplicationInstructionsRegistration: Anweisungen zur Anmeldung CourseApplicationTemplateApplication: Bewerbungsvorlage(n) CourseApplicationTemplateRegistration: Anmeldungsvorlage(n) CourseApplicationTemplateArchiveName tid@TermId ssh@SchoolId csh@CourseShorthand: #{foldCase (termToText (unTermKey tid))}-#{foldedCase (unSchoolKey ssh)}-#{foldedCase csh}-bewerbungsvorlagen +CourseApplication: Bewerbung + +CourseApplicationExists: Sie haben sich bereits für diesen Kurs beworben +CourseApplicationInvalidAction: Angegeben Aktion kann nicht durchgeführt werden +CourseApplicationCreated csh@CourseShorthand: Erfolgreich zu #{csh} beworben +CourseApplicationEdited csh@CourseShorthand: Bewerbung zu #{csh} erfolgreich angepasst +CourseApplicationNotEdited csh@CourseShorthand: Bewerbung zu #{csh} hat sich nicht verändert +CourseApplicationRated: Bewertung erfolgreich angepasst +CourseApplicationRatingDeleted: Bewertung erfolgreich entfernt +CourseApplicationDeleted csh@CourseShorthand: Bewerbung zu #{csh} erfolgreich zurückgezogen + +CourseApplicationTitle displayName@Text csh@CourseShorthand: Bewerbung für #{csh}: #{displayName} CourseApplicationText: Text-Bewerbung CourseApplicationFollowInstructions: Beachten Sie die Anweisungen zur Bewerbung! @@ -178,11 +191,13 @@ CourseRegistrationFollowInstructions: Beachten Sie die Anweisungen zur Anmeldung CourseApplicationFile: Bewerbung CourseApplicationFiles: Bewerbungsdatei(en) -CourseApplicationArchive: Zip-Archiv der Bewerbungsdatei(en) +CourseApplicationArchive: Zip-Archiv der Bewerbungsdatei(en) CourseRegistrationFile: Datei zur Anmeldung CourseRegistrationFiles: Datei(en) zur Anmeldung CourseRegistrationArchive: Zip-Archiv der Datei(en) zur Anmeldung CourseApplicationNoFiles: Keine Datei(en) +CourseApplicationFilesNeedReupload: Bewerbungsdateien müssen neu hochgeladen werden, wann immer die Bewerbung angepasst wird +CourseRegistrationFilesNeedReupload: Dateien zur Anmeldung müssen neu hochgeladen werden, wann immer die Anmeldung angepasst wird CourseApplicationDeleteToEdit: Um Ihre Bewerbung zu editieren müssen Sie sie zunächst zurückziehen und sich erneut bewerben. CourseRegistrationDeleteToEdit: Um Ihre Anmeldungsdaten zu editieren müssen Sie sich zunächst ab- und dann erneut anmelden. @@ -212,6 +227,8 @@ CourseAllocationCapacityMayNotBeChanged: Kapazität eines Kurses, der an einer Z CourseLecturerRightsIdentical: Alle Sorten von Kursverwalter haben identische Rechte. +School: Institut + NoSuchTerm tid@TermId: Semester #{tid} gibt es nicht. NoSuchSchool ssh@SchoolId: Institut #{ssh} gibt es nicht. NoSuchCourseShorthand csh@CourseShorthand: Kein Kurs mit Kürzel #{csh} bekannt. @@ -332,7 +349,7 @@ MaterialArchiveName tid@TermId ssh@SchoolId csh@CourseShorthand materialName@Mat Unauthorized: Sie haben hierfür keine explizite Berechtigung. UnauthorizedAnd l@Text r@Text: (#{l} UND #{r}) UnauthorizedOr l@Text r@Text: (#{l} ODER #{r}) -UnauthorizedNot i@Text: (NICHT #{i}) +UnauthorizedNot r@Text: (NICHT #{r}) UnauthorizedNoToken: Ihrer Anfrage war kein Authorisierungs-Token beigefügt. UnauthorizedTokenExpired: Ihr Authorisierungs-Token ist abgelaufen. UnauthorizedTokenNotStarted: Ihr Authorisierungs-Token ist noch nicht gültig. @@ -345,13 +362,16 @@ UnauthorizedSchoolAdmin: Sie sind nicht als Administrator für dieses Institut e UnauthorizedAdminEscalation: Sie sind nicht Administrator für alle Institute, für die dieser Nutzer Administrator oder Veranstalter ist. UnauthorizedSchoolLecturer: Sie sind nicht als Veranstalter für dieses Institut eingetragen. UnauthorizedLecturer: Sie sind nicht als Veranstalter für diese Veranstaltung eingetragen. +UnauthorizedAllocationLecturer: Sie sind nicht als Veranstalter für eine Veranstaltung dieser Zentralanmeldung eingetragen. UnauthorizedCorrector: Sie sind nicht als Korrektor für diese Veranstaltung eingetragen. UnauthorizedSheetCorrector: Sie sind nicht als Korrektor für dieses Übungsblatt eingetragen. UnauthorizedCorrectorAny: Sie sind nicht als Korrektor für eine Veranstaltung eingetragen. UnauthorizedRegistered: Sie sind nicht als Teilnehmer für diese Veranstaltung registriert. +UnauthorizedAllocationRegistered: Sie sind nicht als Teilnehmer für diese Zentralanmeldung registriert. UnauthorizedExamResult: Sie haben keine Ergebnisse in dieser Prüfung. UnauthorizedParticipant: Angegebener Benutzer ist nicht als Teilnehmer dieser Veranstaltung registriert. UnauthorizedCourseTime: Dieses Kurs erlaubt momentan keine Anmeldungen. +UnauthorizedAllocationRegisterTime: Diese Zentralanmeldung erlaubt momentan keine Bewerbungen. UnauthorizedSheetTime: Dieses Übungsblatt ist momentan nicht freigegeben. UnauthorizedApplicationTime: Diese Bewerbung ist momentan nicht freigegeben. UnauthorizedMaterialTime: Dieses Material ist momentan nicht freigegeben. @@ -369,7 +389,7 @@ MaterialFree: Kursmaterialien ohne Anmeldung zugänglich UnauthorizedWrite: Sie haben hierfür keine Schreibberechtigung UnauthorizedSystemMessageTime: Diese Systemnachricht ist noch nicht oder nicht mehr einsehbar. UnauthorizedSystemMessageAuth: Diese Systemnachricht ist nur für angemeldete Benutzer einsehbar. -UnsupportedAuthPredicate authTagT@Text shownRoute@String: "#{authTagT}" wurde auf eine Route angewandt, die dies nicht unterstützt: #{shownRoute} +UnsupportedAuthPredicate authTagT@Text shownRoute@Text: „#{authTagT}“ wurde auf eine Route angewandt, die dies nicht unterstützt: „#{shownRoute}“ UnauthorizedDisabledTag authTag@AuthTag: Authorisierungsprädikat "#{toPathPiece authTag}" ist für Ihre Sitzung nicht aktiv UnknownAuthPredicate tag@String: Authorisierungsprädikat "#{tag}" ist dem System nicht bekannt UnauthorizedRedirect: Die angeforderte Seite existiert nicht oder Sie haben keine Berechtigung, die angeforderte Seite zu sehen. @@ -433,7 +453,7 @@ NotificationSettingsHeading displayName@Text: Benachrichtigungs-Einstellungen f TokensLastReset: Tokens zuletzt invalidiert TokensResetSuccess: Authorisierungs-Tokens invalidiert -HomeOpenCourses: Kurse mit offener Registrierung +HomeOpenAllocations: Offene Zentralanmeldungen HomeUpcomingSheets: Anstehende Übungsblätter HomeUpcomingExams: Bevorstehende Prüfungen @@ -576,7 +596,7 @@ MultiSinkException name@Text error@Text: In Abgabe #{name} ist ein Fehler aufget NoTableContent: Kein Tabelleninhalt NoUpcomingSheetDeadlines: Keine anstehenden Übungsblätter -NoUpcomingExams: In den nächsten 14 Tagen gibt es keine Prüfung mit offener Registrierung in Ihren Kursen +NoUpcomingExams difftime@Text: In den nächsten #{difftime} gibt es keine Prüfungen oder ablaufende Prüfungsanmeldungen in Ihren Kursen AdminHeading: Administration AdminUserHeading: Benutzeradministration @@ -602,6 +622,8 @@ DateFormat: Datumsformat TimeFormat: Uhrzeitformat DownloadFiles: Dateien automatisch herunterladen DownloadFilesTip: Wenn gesetzt werden Dateien von Abgaben und Übungsblättern automatisch als Download behandelt, ansonsten ist das Verhalten browserabhängig (es können z.B. PDFs im Browser geöffnet werden). +WarningDays: Fristen-Vorschau +WarningDaysTip: Wie viele Tage im Voraus sollen Fristen von Klausuren etc. auf Ihrer Startseite angezeigt werden? NotificationSettings: Erwünschte Benachrichtigungen FormNotifications: Benachrichtigungen FormBehaviour: Verhalten @@ -933,6 +955,8 @@ ErrorCryptoIdMismatch: Verschlüsselte Id der Abgabe passte nicht zu anderen Dat InvalidRoute: Konnte URL nicht interpretieren +MenuOpenCourses: Kurse mit offener Registrierung +MenuOpenAllocations: Aktive Zentralanmeldungen MenuHome: Aktuell MenuInformation: Informationen MenuImpressum: Impressum @@ -944,10 +968,12 @@ MenuHelp: Hilfe MenuProfile: Anpassen MenuLogin: Login MenuLogout: Logout +MenuAllocationList: Zentralanmeldungen MenuCourseList: Kurse MenuCourseMembers: Kursteilnehmer MenuCourseAddMembers: Kursteilnehmer hinzufügen MenuCourseCommunication: Kursmitteilung +MenuCourseApplications: Bewerbungen MenuTermShow: Semester MenuSubmissionDelete: Abgabe löschen MenuUsers: Benutzer @@ -1000,6 +1026,7 @@ MenuExamEdit: Bearbeiten MenuExamUsers: Teilnehmer MenuExamAddMembers: Prüfungsteilnehmer hinzufügen MenuLecturerInvite: Dozenten hinzufügen +MenuAllocationInfo: Hinweise zum Ablauf einer Zentralanmeldung AuthPredsInfo: Um eigene Veranstaltungen aus Sicht der Teilnehmer anzusehen, können Veranstalter und Korrektoren hier die Prüfung ihrer erweiterten Berechtigungen temporär deaktivieren. Abgewählte Prädikate schlagen immer fehl. Abgewählte Prädikate werden also nicht geprüft um Zugriffe zu gewähren, welche andernfalls nicht erlaubt wären. Diese Einstellungen gelten nur temporär bis Ihre Sitzung abgelaufen ist, d.h. bis ihr Browser-Cookie abgelaufen ist. Durch Abwahl von Prädikaten kann man sich höchstens temporär aussperren. AuthPredsActive: Aktive Authorisierungsprädikate @@ -1014,8 +1041,10 @@ AuthTagLecturer: Nutzer ist Dozent AuthTagCorrector: Nutzer ist Korrektor AuthTagTutor: Nutzer ist Tutor AuthTagTime: Zeitliche Einschränkungen sind erfüllt +AuthTagStaffTime: Zeitliche Einschränkungen für Lehrbeteiligte sind erfüllt AuthTagAllocationTime: Zeitliche Einschränkungen durch Zentralanmeldung sind erfüllt AuthTagCourseRegistered: Nutzer ist Kursteilnehmer +AuthTagAllocationRegistered: Nutzer nimmt an der Zentralanmeldung teil AuthTagTutorialRegistered: Nutzer ist Tutoriumsteilnehmer AuthTagExamRegistered: Nutzer ist Prüfungsteilnehmer AuthTagExamResult: Nutzer hat Prüfungsergebnisse @@ -1353,11 +1382,12 @@ BtnCsvImport: CSV-Datei importieren BtnCsvImportConfirm: CSV-Import abschließen CsvImportNotConfigured: CSV-Import nicht vorgesehen -CsvImportConfirmationHeading: CSV-Import abschließen -CsvImportConfirmationTip: Durch den CSV-Import würden die unten aufgeführten Änderungen vorgenommen. Bitte überprüfen Sie diese zunächst sorgfältig. +CsvImportConfirmationHeading: CSV-Import Vorschau (noch keine Änderungen importiert) +CsvImportConfirmationTip: Es wurden noch keine Änderungen übernommen! Durch den CSV-Import könnten die unten aufgeführten Änderungen vorgenommen werden. Wählen Sie jetzt die gewünschten Änderungen aus, bevor Sie den CSV-Import abschließen. CsvImportUnnecessary: Durch den CSV-Import würden keine Änderungen vorgenommen werden CsvImportSuccessful n@Int: CSV-Import erfolgreich, es #{pluralDE n "wurde eine Aktion" (mappend (mappend "wurden " (toMessage n)) " Aktionen")} durchgeführt CsvImportAborted: CSV-Import abgebrochen +CsvImportExplanationLabel: Hinweise zum CSV-Import Proportion c@Text of@Text prop@Rational: #{c}/#{of} (#{rationalToFixed2 (100 * prop)}%) @@ -1445,3 +1475,61 @@ MailSubjectSchoolLecturerInvitation school@SchoolName: Einladung zum Dozent für MailSchoolLecturerInviteHeading school@SchoolName: Einladung zum Dozent für „#{school}“ SchoolLecturerInviteExplanation: Sie wurden eingeladen, Dozent für ein Institut zu sein. Sie können, nachdem Sie die Einladung annehmen, eigenständig neue Kurse anlegen. SchoolLecturerInvitationAccepted school@SchoolName: Einladung zum Dozent für „#{school}“ angenommen + +AllocationActive: Aktiv +AllocationName: Name +AllocationTitle termText@Text ssh'@SchoolShorthand allocation@AllocationName: #{termText} - #{ssh'}: #{allocation} +AllocationShortTitle termText@Text ssh'@SchoolShorthand ash@AllocationShorthand: #{termText} - #{ssh'} - #{ash} +AllocationDescription: Beschreibung +AllocationStaffRegisterFrom: Eintragung der Kurse ab +AllocationStaffRegister: Eintragung der Kurse +AllocationRegisterFrom: Bewerbung ab +AllocationRegister: Bewerbung +AllocationRegisterClosed: Die Zentralanmeldung ist aktuell geschlossen. +AllocationRegisterOpensIn difftime@Text: Die Zentralanmeldung öffnet voraussichtlich in #{difftime} +AllocationStaffAllocationFrom: Bewertung der Bewerbungen ab +AllocationStaffAllocation: Bewerbungsbewertung +AllocationProcess: Platzvergabe +AllocationNoApplication: Keine Bewerbung +AllocationPriority: Priorität +AllocationPriorityTip: Kurse, denen Sie eine höhere Priorität zuteilen, werden bei der Platzvergabe präferiert. +AllocationPriorityRelative: Die absoluten Prioritäts-Werte sind bedeutungslos, es wird nur jeweils betrachtet ob ein Kurs höhere Priorität hat als ein anderer. +AllocationTotalCoursesNegative: Gewünschte Kursanzahl muss größer null sein +AllocationTotalCourses: Gewünschte Anzahl von Kursen +AllocationTotalCoursesTip: Sie werden im Laufe dieser Zentralanmeldung maximal so vielen Kursen zugeteilt, wie Sie hier angeben +AllocationRegistered: Teilnahme an der Zentralanmeldung erfolgreich registriert +AllocationRegistrationEdited: Einstellungen zur Teilnahme an der Zentralanmeldung erfolgreich angepasst +BtnAllocationRegister: Teilnahme registrieren +BtnAllocationRegistrationEdit: Teilnahme anpassen +AllocationParticipation: Teilnahme an der Zentralanmeldung +AllocationParticipationLoginFirst: Um an der Zentralanmeldung teilzunehmen, loggen Sie sich bitte zunächst ein. +AllocationCourses: Kurse dieser Zentralanmeldung +AllocationData: Organisatorisches +AllocationCoursePriority i@Natural: #{i}. Wahl +AllocationCourseNoApplication: Keine Bewerbung +BtnAllocationApply: Bewerben +BtnAllocationApplicationEdit: Bewerbung ersetzen +BtnAllocationApplicationRetract: Bewerbung zurückziehen +BtnAllocationApplicationRate: Bewerbung bewerten +ApplicationPriority: Priorität +ApplicationVeto: Veto +ApplicationVetoTip: Bewerber mit Veto werden garantiert nicht dem Kurs zugeteilt +ApplicationRatingPoints: Bewertung +ApplicationRatingPointsTip: Bewerber mit 5.0 werden garantiert nicht dem Kurs zugeteilt +ApplicationRatingComment: Kommentar +ApplicationRatingCommentVisibleTip: Feedback an den Bewerbers +ApplicationRatingCommentInvisibleTip: Dient zunächst nur als Notiz für Kursverwalter + +AllocationSchoolShort: Institut +Allocation: Zentralanmeldung +AllocationRegisterTo: Anmeldungen bis + +AllocationListTitle: Zentralanmeldungen + +CourseApplicationsListTitle: Bewerbungen +CourseApplicationId: Bewerbungsnummer +CourseApplicationRatingPoints: Bewertung +CourseApplicationVeto: Veto + +UserDisplayName: Voller Name +UserMatriculation: Matrikelnummer \ No newline at end of file diff --git a/models/allocations b/models/allocations index f7522696f..0fac2cfee 100644 --- a/models/allocations +++ b/models/allocations @@ -1,12 +1,10 @@ Allocation -- attributes with prefix staff- affect lecturers only, but are invisble to students - name (CI Text) - shorthand (CI Text) -- practical shorthand + name AllocationName + shorthand AllocationShorthand -- practical shorthand term TermId school SchoolId -- school that manages this central allocation, not necessarily school of courses description Html Maybe -- description for prospective students staffDescription Html Maybe -- description seen by prospective lecturers only - linkExternal Text Maybe -- arbitrary user-defined url for external course page - capacity Int Maybe -- number of allowed enrolements, if restricte staffRegisterFrom UTCTime Maybe -- lectureres may register courses staffRegisterTo UTCTime Maybe -- course registration stops -- staffDeregisterUntil not needed: staff may make arbitrary changes until staffRegisterTo, always frozen afterwards @@ -17,7 +15,6 @@ Allocation -- attributes with prefix staff- affect lecturers only, but are invis registerFrom UTCTime Maybe -- student applications allowed from a given day onwwards or prohibited registerTo UTCTime Maybe -- student applications may be prohibited from a given date onwards -- deregisterUntil not needed: students may withdraw applicants until registerTo, but never after. Also see overrideDeregister - registerSecret Text Maybe -- student application maybe protected by a simple common passphrase -- overrides registerByStaffFrom UTCTime Maybe -- lecturers may directly enrol/disenrol students after a given date or prohibited registerByStaffTo UTCTime Maybe @@ -26,6 +23,7 @@ Allocation -- attributes with prefix staff- affect lecturers only, but are invis -- overrideVisible not needed, since courses are always visible TermSchoolAllocationShort term school shorthand -- shorthand must be unique within school and semester TermSchoolAllocationName term school name -- name must be unique within school and semester + deriving Show AllocationCourse allocation AllocationId @@ -41,7 +39,6 @@ AllocationUser AllocationDeregister -- self-inflicted user-deregistrations from an allocated course user UserId - allocation AllocationId Maybe course CourseId Maybe time UTCTime reason Text Maybe -- if this deregistration was done by proxy (e.g. the lecturer pressed the button) diff --git a/models/courses b/models/courses index bcbdf4979..dd1099e55 100644 --- a/models/courses +++ b/models/courses @@ -76,11 +76,13 @@ CourseApplication user UserId field StudyFeaturesId Maybe -- associated degree course, user-defined; required for communicating grades text Text Maybe -- free text entered by user + ratingVeto Bool default=false ratingPoints ExamGrade Maybe ratingComment Text Maybe allocation AllocationId Maybe allocationPriority Natural Maybe time UTCTime default=now() + ratingTime UTCTime Maybe CourseApplicationFile application CourseApplicationId file FileId diff --git a/models/users b/models/users index 33a92adf1..155970f60 100644 --- a/models/users +++ b/models/users @@ -11,11 +11,11 @@ User json -- Each Uni2work user has a corresponding row in this table; create ident (CI Text) -- Case-insensitive user-identifier authentication AuthenticationMode -- 'AuthLDAP' or ('AuthPWHash'+password-hash) lastAuthentication UTCTime Maybe -- last login date - tokensIssuedAfter UTCTime Maybe -- do not accept bearer tokens issued before this time (accept all tokens if null) - matrikelnummer Text Maybe -- optional immatriculation-string; usually a number, but not always (e.g. lecturers, pupils, guests,...) + tokensIssuedAfter UTCTime Maybe -- do not accept bearer tokens issued before this time (accept all tokens if null) + matrikelnummer UserMatriculation Maybe -- optional immatriculation-string; usually a number, but not always (e.g. lecturers, pupils, guests,...) email (CI Text) -- Case-insensitive eMail address - displayName Text -- we only show LDAP-DisplayName, and highlight LDAP-Surname within (appended if not contained) - surname Text -- Display user names always through 'nameWidget displayName surname' + displayName UserDisplayName -- we only show LDAP-DisplayName, and highlight LDAP-Surname within (appended if not contained) + surname UserSurname -- Display user names always through 'nameWidget displayName surname' firstName Text -- For export in tables, pre-split firstName from displayName title Text Maybe -- For upcoming name customisation maxFavourites Int default=12 -- max number of rows with this userId in table "CourseFavourite"; for convenience links; user-defined @@ -23,12 +23,13 @@ User json -- Each Uni2work user has a corresponding row in this table; create dateTimeFormat DateTimeFormat "default='%a %d %b %Y %R'" -- preferred Date+Time display format for user; user-defined dateFormat DateTimeFormat "default='%d.%m.%Y'" -- preferred Date-only display format for user; user-defined timeFormat DateTimeFormat "default='%R'" -- preferred Time-only display format for user; user-defined - downloadFiles Bool default=false -- Should files be opened in browser or downloaded? (users often oblivious that their browser has a setting for this) + downloadFiles Bool default=false -- Should files be opened in browser or downloaded? (users often oblivious that their browser has a setting for this) mailLanguages MailLanguages "default='[]'::jsonb" -- Preferred language for eMail; i18n not yet implemented; user-defined - notificationSettings NotificationSettings -- Bit-array for which events email notifications are requested by user; user-defined - UniqueAuthentication ident -- Column 'ident' can be used as a row-key in this table - UniqueEmail email -- Column 'email' can be used as a row-key in this table - deriving Show Eq Generic -- Haskell-specific settings for runtime-value representing a row in memory + notificationSettings NotificationSettings -- Bit-array for which events email notifications are requested by user; user-defined + warningDays NominalDiffTime default=1209600 -- timedistance to pending deadlines for homepage infos + UniqueAuthentication ident -- Column 'ident' can be used as a row-key in this table + UniqueEmail email -- Column 'email' can be used as a row-key in this table + deriving Show Eq Generic -- Haskell-specific settings for runtime-value representing a row in memory UserAdmin -- Each row in this table grants school-specific administrator-rights to a specific user user UserId school SchoolId diff --git a/package-lock.json b/package-lock.json index fd81f5701..b10d2da20 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "uni2work", - "version": "5.0.2", + "version": "5.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 3946b8a27..d67a557eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "uni2work", - "version": "5.0.2", + "version": "5.3.0", "description": "", "keywords": [], "author": "", diff --git a/package.yaml b/package.yaml index 53e8c4d5e..ac24edf65 100644 --- a/package.yaml +++ b/package.yaml @@ -1,5 +1,5 @@ name: uniworx -version: 5.0.2 +version: 5.3.0 dependencies: # Due to a bug in GHC 8.0.1, we block its usage diff --git a/routes b/routes index 54f0fc5c5..88099df1a 100644 --- a/routes +++ b/routes @@ -61,6 +61,7 @@ /info InfoR GET !free /info/lecturer InfoLecturerR GET !lecturer /info/data DataProtR GET !free +/info/allocation InfoAllocationR GET !free /impressum ImpressumR GET !free /version VersionR GET !free @@ -80,6 +81,13 @@ /school SchoolListR GET !development /school/#SchoolId SchoolShowR GET !development +/allocation/ AllocationListR GET !free +/allocation/#TermId/#SchoolId/#AllocationShorthand AllocationR: + / AShowR GET !free + /register ARegisterR POST !time + /course/#CryptoUUIDCourse/apply AApplyR POST !timeANDallocation-registered + /application/#CryptoFileNameCourseApplication AApplicationR GET POST !timeANDself !lecturerANDstaff-time !selfANDread + -- For Pattern Synonyms see Foundation /course/ CourseListR GET !free @@ -100,11 +108,11 @@ /notes CNotesR GET POST !corrector -- THIS route is used to check for overall course corrector access! /subs CCorrectionsR GET POST /subs/assigned CAssignR GET POST - /ex SheetListR GET !course-registered !materials !corrector - /ex/new SheetNewR GET POST - /ex/current SheetCurrentR GET !course-registered !materials !corrector - /ex/unassigned SheetOldUnassignedR GET - /ex/#SheetName SheetR: + /sheet SheetListR GET !course-registered !materials !corrector + /sheet/new SheetNewR GET POST + /sheet/current SheetCurrentR GET !course-registered !materials !corrector + /sheet/unassigned SheetOldUnassignedR GET + /sheet/#SheetName SheetR: /show SShowR GET !timeANDcourse-registered !timeANDmaterials !corrector !timeANDtutor /show/download SArchiveR GET !timeANDcourse-registered !timeANDmaterials !corrector !timeANDtutor /edit SEditR GET POST @@ -154,6 +162,7 @@ /users/new EAddUserR GET POST /users/invite EInviteR GET POST /register ERegisterR POST !timeANDcourse-registeredAND¬exam-registered !timeANDexam-registeredAND¬exam-result + /apps CApplicationsR GET POST /apps/#CryptoFileNameCourseApplication CourseApplicationR: /files CAFilesR GET !self !lecturerANDtime diff --git a/src/Application.hs b/src/Application.hs index 7291fda1c..fe1bc98ff 100644 --- a/src/Application.hs +++ b/src/Application.hs @@ -64,10 +64,6 @@ import qualified Yesod.Core.Types as Yesod (Logger(..)) import qualified Data.HashMap.Strict as HashMap -import Utils.Lens - -import Data.Proxy - import qualified Data.Aeson as Aeson import System.Exit @@ -112,6 +108,7 @@ import Handler.CryptoIDDispatch import Handler.SystemMessage import Handler.Health import Handler.Exam +import Handler.Allocation -- This line actually creates our YesodDispatch instance. It is the second half diff --git a/src/Auth/LDAP.hs b/src/Auth/LDAP.hs index 26026dfee..406a3a2d4 100644 --- a/src/Auth/LDAP.hs +++ b/src/Auth/LDAP.hs @@ -10,7 +10,6 @@ module Auth.LDAP ) where import Import.NoFoundation hiding (userEmail, userDisplayName) -import Control.Lens import Network.Connection import Data.CaseInsensitive (CI) diff --git a/src/Colonnade/Instances.hs b/src/Colonnade/Instances.hs new file mode 100644 index 000000000..d47902515 --- /dev/null +++ b/src/Colonnade/Instances.hs @@ -0,0 +1,19 @@ +{-# OPTIONS_GHC -fno-warn-orphans #-} + +module Colonnade.Instances + ( + ) where + +import ClassyPrelude + +import Control.Lens.Indexed (FunctorWithIndex(imap)) + +import Colonnade.Encode (Colonnade(..), OneColonnade(..)) + +instance Functor h => FunctorWithIndex (Maybe a) (Colonnade h a) where + imap f (Colonnade ones) = Colonnade $ dimapColonnade' <$> ones + where + dimapColonnade' OneColonnade{..} = OneColonnade + { oneColonnadeEncode = \x -> f (Just x) $ oneColonnadeEncode x + , oneColonnadeHead = f Nothing <$> oneColonnadeHead + } diff --git a/src/Crypto/Hash/Instances.hs b/src/Crypto/Hash/Instances.hs new file mode 100644 index 000000000..66228a69e --- /dev/null +++ b/src/Crypto/Hash/Instances.hs @@ -0,0 +1,22 @@ +{-# OPTIONS_GHC -fno-warn-orphans #-} + +module Crypto.Hash.Instances + () where + +import ClassyPrelude + +import Crypto.Hash + +import Database.Persist +import Database.Persist.Sql + +import Data.ByteArray (convert) + + +instance HashAlgorithm hash => PersistField (Digest hash) where + toPersistValue = PersistByteString . convert + fromPersistValue (PersistByteString bs) = maybe (Left "Could not convert Digest from ByteString") Right $ digestFromByteString bs + fromPersistValue _ = Left "Digest values must be converted from PersistByteString" + +instance HashAlgorithm hash => PersistFieldSql (Digest hash) where + sqlType _ = SqlBlob diff --git a/src/CryptoID.hs b/src/CryptoID.hs index 915ad5de0..9263ca308 100644 --- a/src/CryptoID.hs +++ b/src/CryptoID.hs @@ -49,6 +49,7 @@ decCryptoIDs [ ''SubmissionId , ''ExamPartId , ''AllocationId , ''CourseApplicationId + , ''CourseId ] -- CryptoIDNamespace (CI FilePath) SubmissionId ~ "Submission" diff --git a/src/Data/CryptoID/Instances.hs b/src/Data/CryptoID/Instances.hs index 3e842dd6a..bc66cb874 100644 --- a/src/Data/CryptoID/Instances.hs +++ b/src/Data/CryptoID/Instances.hs @@ -13,8 +13,24 @@ import ClassyPrelude import Data.CaseInsensitive (CI) import qualified Data.CaseInsensitive as CI -instance {-# OVERLAPS #-} ToMarkup s => ToMarkup (CID.CryptoID c (CI s)) where - toMarkup = toMarkup . CI.foldedCase . CID.ciphertext +import Web.PathPieces +import Data.Aeson (ToJSON(..), ToJSONKey(..), ToJSONKeyFunction(..)) + instance ToMarkup s => ToMarkup (CID.CryptoID c s) where toMarkup = toMarkup . CID.ciphertext + +instance {-# OVERLAPS #-} ToMarkup s => ToMarkup (CID.CryptoID c (CI s)) where + toMarkup = toMarkup . CI.foldedCase . CID.ciphertext + +instance {-# OVERLAPS #-} ToJSON s => ToJSON (CID.CryptoID c (CI s)) where + toJSON = toJSON . CI.foldedCase . CID.ciphertext + +instance {-# OVERLAPS #-} (ToJSON s, ToJSONKey s) => ToJSONKey (CID.CryptoID c (CI s)) where + toJSONKey = case toJSONKey of + ToJSONKeyText toT toE -> ToJSONKeyText (toT . CI.foldedCase . CID.ciphertext) (toE . CI.foldedCase . CID.ciphertext) + ToJSONKeyValue toV toE -> ToJSONKeyValue (toV . CI.foldedCase . CID.ciphertext) (toE . CI.foldedCase . CID.ciphertext) + +instance {-# OVERLAPS #-} (PathPiece s, CI.FoldCase s) => PathPiece (CID.CryptoID c (CI s)) where + toPathPiece = toPathPiece . CI.foldedCase . CID.ciphertext + fromPathPiece = fmap (CID.CryptoID . CI.mk) . fromPathPiece diff --git a/src/Data/Time/Clock/Instances.hs b/src/Data/Time/Clock/Instances.hs index b9721ab7d..9629800d1 100644 --- a/src/Data/Time/Clock/Instances.hs +++ b/src/Data/Time/Clock/Instances.hs @@ -6,17 +6,27 @@ module Data.Time.Clock.Instances import ClassyPrelude -import Data.Time.Clock +import Database.Persist.Sql + +import Data.Proxy import Data.Binary (Binary) import qualified Data.Binary as Binary +import Data.Time.Clock import Data.Time.Calendar.Instances () instance Hashable DiffTime where hashWithSalt s = hashWithSalt s . toRational +instance PersistField NominalDiffTime where + toPersistValue = toPersistValue . toRational + fromPersistValue = fmap fromRational . fromPersistValue + +instance PersistFieldSql NominalDiffTime where + sqlType _ = sqlType (Proxy @Rational) + deriving instance Generic UTCTime instance Hashable UTCTime @@ -25,5 +35,5 @@ instance Hashable UTCTime instance Binary DiffTime where get = fromRational <$> Binary.get put = Binary.put . toRational - + instance Binary UTCTime diff --git a/src/Data/Void/Instances.hs b/src/Data/Void/Instances.hs new file mode 100644 index 000000000..a59e0cd39 --- /dev/null +++ b/src/Data/Void/Instances.hs @@ -0,0 +1,12 @@ +{-# OPTIONS_GHC -fno-warn-orphans #-} +module Data.Void.Instances + ( + ) where + +import ClassyPrelude.Yesod +import Data.Void + +instance ToContent Void where + toContent = absurd +instance ToTypedContent Void where + toTypedContent = absurd diff --git a/src/Database/Esqueleto/Utils.hs b/src/Database/Esqueleto/Utils.hs index 5a032a6de..74bfbb7d6 100644 --- a/src/Database/Esqueleto/Utils.hs +++ b/src/Database/Esqueleto/Utils.hs @@ -15,10 +15,14 @@ module Database.Esqueleto.Utils , orderByOrd, orderByEnum , lower, ciEq , selectExists + , SqlHashable + , sha256 + , maybe + , SqlProject(..) ) where -import ClassyPrelude.Yesod hiding (isInfixOf, any, all, or, and, isJust) +import ClassyPrelude.Yesod hiding (isInfixOf, any, all, or, and, isJust, maybe) import Data.Universe import qualified Data.Set as Set import qualified Data.List as List @@ -27,6 +31,11 @@ import qualified Database.Esqueleto as E import qualified Database.Esqueleto.Internal.Sql as E import Database.Esqueleto.Utils.TH +import qualified Data.Text.Lazy as Lazy (Text) +import qualified Data.ByteString.Lazy as Lazy (ByteString) + +import Crypto.Hash (Digest, SHA256) + {-# ANN any ("HLint: ignore Use any" :: String) #-} {-# ANN all ("HLint: ignore Use all" :: String) #-} @@ -153,21 +162,17 @@ mkExistsFilter query row criterias | otherwise = any (E.exists . query row) $ Set.toList criterias -- | Combine several filters, using logical or -anyFilter :: (Foldable f) - => f (t -> Set.Set Text-> E.SqlExpr (E.Value Bool)) - -> t - -> Set.Set Text - -> E.SqlExpr (E.Value Bool) +anyFilter :: Foldable f + => f (t -> cs -> E.SqlExpr (E.Value Bool)) + -> (t -> cs -> E.SqlExpr (E.Value Bool)) anyFilter fltrs needle criterias = F.foldr aux false fltrs where aux fltr acc = fltr needle criterias E.||. acc -- | Combine several filters, using logical and -allFilter :: (Foldable f) - => f (t -> Set.Set Text-> E.SqlExpr (E.Value Bool)) - -> t - -> Set.Set Text - -> E.SqlExpr (E.Value Bool) +allFilter :: Foldable f + => f (t -> cs -> E.SqlExpr (E.Value Bool)) + -> (t -> cs -> E.SqlExpr (E.Value Bool)) allFilter fltrs needle criterias = F.foldr aux true fltrs where aux fltr acc = fltr needle criterias E.&&. acc @@ -199,3 +204,41 @@ selectExists query = do case res of [E.Value b] -> return b _other -> error "SELECT EXISTS ... returned zero or more than one rows" + + +class SqlHashable a +instance SqlHashable Text +instance SqlHashable ByteString +instance SqlHashable Lazy.Text +instance SqlHashable Lazy.ByteString + + +sha256 :: SqlHashable a => E.SqlExpr (E.Value a) -> E.SqlExpr (E.Value (Digest SHA256)) +sha256 = E.unsafeSqlFunction "digest" . (, E.val "sha256" :: E.SqlExpr (E.Value Text)) + + +maybe :: (PersistField a, PersistField b) + => E.SqlExpr (E.Value b) + -> (E.SqlExpr (E.Value a) -> E.SqlExpr (E.Value b)) + -> E.SqlExpr (E.Value (Maybe a)) + -> E.SqlExpr (E.Value b) +maybe onNothing onJust val = E.case_ + [ E.when_ + (E.not_ $ E.isNothing val) + E.then_ + (onJust $ E.veryUnsafeCoerceSqlExprValue val) + ] + (E.else_ onNothing) + + +class (PersistEntity entity, PersistField value) => SqlProject entity value entity' value' | entity value entity' -> value', entity value value' -> entity' where + sqlProject :: E.SqlExpr entity' -> EntityField entity value -> E.SqlExpr (E.Value value') + unSqlProject :: forall p1 p2. p1 entity -> p2 entity' -> value -> value' + +instance (PersistEntity val, PersistField typ) => SqlProject val typ (E.Entity val) typ where + sqlProject = (E.^.) + unSqlProject _ _ = id + +instance (PersistEntity val, PersistField typ) => SqlProject val typ (Maybe (E.Entity val)) (Maybe typ) where + sqlProject = (E.?.) + unSqlProject _ _ = Just diff --git a/src/Foundation.hs b/src/Foundation.hs index d1e2e9892..9748f0b47 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -65,7 +65,6 @@ import Control.Monad.Memo.Class (MonadMemo(..), for4) import qualified Control.Monad.Catch as C import Handler.Utils.StudyFeatures -import Utils.Lens import Utils.Form import Utils.Sheet import Utils.SystemMessage @@ -152,6 +151,7 @@ deriving instance Generic MaterialR deriving instance Generic TutorialR deriving instance Generic ExamR deriving instance Generic CourseApplicationR +deriving instance Generic AllocationR deriving instance Generic (Route UniWorX) -- | Convenient Type Synonyms: @@ -261,6 +261,8 @@ instance RenderMessage UniWorX Int64 where renderMessage f ls = renderMessage f ls . tshow instance RenderMessage UniWorX Integer where renderMessage f ls = renderMessage f ls . tshow +instance RenderMessage UniWorX Natural where + renderMessage f ls = renderMessage f ls . tshow instance HasResolution a => RenderMessage UniWorX (Fixed a) where renderMessage f ls = renderMessage f ls . showFixed True @@ -281,8 +283,12 @@ instance RenderMessage UniWorX MsgLanguage where where mr = renderMessage foundation ls -instance RenderMessage UniWorX (UnsupportedAuthPredicate (Route UniWorX)) where - renderMessage f ls (UnsupportedAuthPredicate tag route) = renderMessage f ls $ MsgUnsupportedAuthPredicate tag (show route) +instance RenderMessage UniWorX (UnsupportedAuthPredicate AuthTag (Route UniWorX)) where + renderMessage f ls (UnsupportedAuthPredicate tag route) = mr . MsgUnsupportedAuthPredicate (mr tag) $ Text.intercalate "/" pieces + where + mr :: forall msg. RenderMessage UniWorX msg => msg -> Text + mr = renderMessage f ls + (pieces, _) = renderRoute route embedRenderMessage ''UniWorX ''MessageStatus ("Message" <>) embedRenderMessage ''UniWorX ''NotificationTrigger $ ("NotificationTrigger" <>) . concat . drop 1 . splitCamel @@ -362,6 +368,11 @@ instance RenderMessage UniWorX a => RenderMessage UniWorX (ExamResult' a) where mr :: RenderMessage UniWorX msg => msg -> Text mr = renderMessage foundation ls +instance RenderMessage UniWorX (Either ExamPassed ExamGrade) where + renderMessage foundation ls = either mr mr + where + mr :: RenderMessage UniWorX msg => msg -> Text + mr = renderMessage foundation ls -- ToMessage instances for converting raw numbers to Text (no internationalization) @@ -371,6 +382,8 @@ instance ToMessage Int64 where toMessage = tshow instance ToMessage Integer where toMessage = tshow +instance ToMessage Natural where + toMessage = tshow instance HasResolution a => ToMessage (Fixed a) where toMessage = toMessage . showFixed True @@ -600,6 +613,17 @@ tagAccessPredicate AuthAdmin = APDB $ \mAuthId route _ -> case route of E.&&. course E.^. CourseShorthand E.==. E.val csh guardMExceptT isAdmin (unauthorizedI MsgUnauthorizedSchoolAdmin) return Authorized + -- Allocations: access only to school admins + AllocationR tid ssh ash _ -> $cachedHereBinary (mAuthId, tid, ssh, ash) . exceptT return return $ do + authId <- maybeExceptT AuthenticationRequired $ return mAuthId + isAdmin <- lift . E.selectExists . E.from $ \(allocation `E.InnerJoin` userAdmin) -> do + E.on $ allocation E.^. AllocationSchool E.==. userAdmin E.^. UserAdminSchool + E.where_ $ userAdmin E.^. UserAdminUser E.==. E.val authId + E.&&. allocation E.^. AllocationTerm E.==. E.val tid + E.&&. allocation E.^. AllocationSchool E.==. E.val ssh + E.&&. allocation E.^. AllocationShorthand E.==. E.val ash + guardMExceptT isAdmin (unauthorizedI MsgUnauthorizedSchoolAdmin) + return Authorized -- other routes: access to any admin is granted here _other -> $cachedHereBinary mAuthId . exceptT return return $ do authId <- maybeExceptT AuthenticationRequired $ return mAuthId @@ -641,6 +665,34 @@ tagAccessPredicate AuthLecturer = APDB $ \mAuthId route _ -> case route of E.&&. course E.^. CourseShorthand E.==. E.val csh guardMExceptT isLecturer (unauthorizedI MsgUnauthorizedLecturer) return Authorized + AllocationR tid ssh ash (AApplicationR cID) -> $cachedHereBinary (mAuthId, tid, ssh, ash, cID) . exceptT return return $ do + authId <- maybeExceptT AuthenticationRequired $ return mAuthId + appId <- catchIfMExceptT (const $ unauthorizedI MsgUnauthorizedLecturer) (const True :: CryptoIDError -> Bool) $ decrypt cID + isLecturer <- lift . E.selectExists . E.from $ \(courseApplication `E.InnerJoin` allocation `E.InnerJoin` allocationCourse `E.InnerJoin` course `E.InnerJoin` lecturer) -> do + E.on $ course E.^. CourseId E.==. lecturer E.^. LecturerCourse + E.on $ course E.^. CourseId E.==. allocationCourse E.^. AllocationCourseCourse + E.on $ allocation E.^. AllocationId E.==. allocationCourse E.^. AllocationCourseAllocation + E.on $ courseApplication E.^. CourseApplicationAllocation E.==. E.just (allocation E.^. AllocationId) + E.&&. courseApplication E.^. CourseApplicationCourse E.==. course E.^. CourseId + E.where_ $ lecturer E.^. LecturerUser E.==. E.val authId + E.&&. allocation E.^. AllocationTerm E.==. E.val tid + E.&&. allocation E.^. AllocationSchool E.==. E.val ssh + E.&&. allocation E.^. AllocationShorthand E.==. E.val ash + E.&&. courseApplication E.^. CourseApplicationId E.==. E.val appId + guardMExceptT isLecturer (unauthorizedI MsgUnauthorizedLecturer) + return Authorized + AllocationR tid ssh ash _ -> $cachedHereBinary (mAuthId, tid, ssh, ash) . exceptT return return $ do + authId <- maybeExceptT AuthenticationRequired $ return mAuthId + isLecturer <- lift . E.selectExists . E.from $ \(allocation `E.InnerJoin` allocationCourse `E.InnerJoin` course `E.InnerJoin` lecturer) -> do + E.on $ course E.^. CourseId E.==. lecturer E.^. LecturerCourse + E.on $ course E.^. CourseId E.==. allocationCourse E.^. AllocationCourseCourse + E.on $ allocation E.^. AllocationId E.==. allocationCourse E.^. AllocationCourseAllocation + E.where_ $ lecturer E.^. LecturerUser E.==. E.val authId + E.&&. allocation E.^. AllocationTerm E.==. E.val tid + E.&&. allocation E.^. AllocationSchool E.==. E.val ssh + E.&&. allocation E.^. AllocationShorthand E.==. E.val ash + guardMExceptT isLecturer (unauthorizedI MsgUnauthorizedAllocationLecturer) + return Authorized -- lecturer for any school will do _ -> $cachedHereBinary mAuthId . exceptT return return $ do authId <- maybeExceptT AuthenticationRequired $ return mAuthId @@ -711,9 +763,7 @@ tagAccessPredicate AuthTime = APDB $ \mAuthId route _ -> case route of guard $ NTop (Just cTime) <= NTop allocationStaffAllocationTo return Authorized - - - + CExamR tid ssh csh examn subRoute -> maybeT (unauthorizedI MsgUnauthorizedExamTime) $ do course <- $cachedHereBinary (tid, ssh, csh) . MaybeT . getKeyBy $ TermSchoolCourseShort tid ssh csh Entity eId Exam{..} <- $cachedHereBinary (course, examn) . MaybeT . getBy $ UniqueExam course examn @@ -823,8 +873,16 @@ tagAccessPredicate AuthTime = APDB $ \mAuthId route _ -> case route of return Authorized _other -> unauthorizedI MsgUnauthorizedCourseTime + AllocationR tid ssh ash _ -> maybeT (unauthorizedI MsgUnauthorizedAllocationRegisterTime) $ do + -- Checks `registerFrom` and `registerTo`, override as further routes become available + now <- liftIO getCurrentTime + Entity _ Allocation{..} <- MaybeT . $cachedHereBinary (tid, ssh, ash) . getBy $ TermSchoolAllocationShort tid ssh ash + guard $ NTop allocationRegisterFrom <= NTop (Just now) + guard $ NTop (Just now) <= NTop allocationRegisterTo + return Authorized + MessageR cID -> maybeT (unauthorizedI MsgUnauthorizedSystemMessageTime) $ do - smId <- decrypt cID + smId <- catchIfMaybeT (const True :: CryptoIDError -> Bool) $ decrypt cID SystemMessage{systemMessageFrom, systemMessageTo} <- $cachedHereBinary smId . MaybeT $ get smId cTime <- (NTop . Just) <$> liftIO getCurrentTime guard $ NTop systemMessageFrom <= cTime @@ -832,6 +890,16 @@ tagAccessPredicate AuthTime = APDB $ \mAuthId route _ -> case route of return Authorized r -> $unsupportedAuthPredicate AuthTime r +tagAccessPredicate AuthStaffTime = APDB $ \_ route _ -> case route of + AllocationR tid ssh ash _ -> maybeT (unauthorizedI MsgUnauthorizedAllocationRegisterTime) $ do + -- Checks `registerFrom` and `registerTo`, override as further routes become available + now <- liftIO getCurrentTime + Entity _ Allocation{..} <- MaybeT . $cachedHereBinary (tid, ssh, ash) . getBy $ TermSchoolAllocationShort tid ssh ash + guard $ NTop allocationStaffAllocationFrom <= NTop (Just now) + guard $ NTop (Just now) <= NTop allocationStaffAllocationTo + return Authorized + + r -> $unsupportedAuthPredicate AuthStaffTime r tagAccessPredicate AuthAllocationTime = APDB $ \mAuthId route _ -> case route of CourseR tid ssh csh CRegisterR -> do now <- liftIO getCurrentTime @@ -969,12 +1037,20 @@ tagAccessPredicate AuthExamResult = APDB $ \mAuthId route _ -> case route of guardMExceptT hasResult (unauthorizedI MsgUnauthorizedExamResult) return Authorized r -> $unsupportedAuthPredicate AuthExamRegistered r +tagAccessPredicate AuthAllocationRegistered = APDB $ \mAuthId route _ -> case route of + AllocationR tid ssh ash _ -> maybeT (unauthorizedI MsgUnauthorizedAllocationRegistered) $ do + uid <- hoistMaybe mAuthId + aId <- MaybeT . $cachedHereBinary (tid, ssh, ash) . getKeyBy $ TermSchoolAllocationShort tid ssh ash + void . MaybeT . $cachedHereBinary (uid, aId) . getKeyBy $ UniqueAllocationUser aId uid + return Authorized + r -> $unsupportedAuthPredicate AuthAllocationRegistered r tagAccessPredicate AuthParticipant = APDB $ \_ route _ -> case route of CourseR tid ssh csh (CUserR cID) -> exceptT return return $ do + cTime <- liftIO getCurrentTime let authorizedIfExists f = do [E.Value ok] <- lift . E.select . return . E.exists $ E.from f whenExceptT ok Authorized - participant <- decrypt cID + participant <- catchIfMExceptT (const $ unauthorizedI MsgUnauthorizedParticipant) (const True :: CryptoIDError -> Bool) $ decrypt cID -- participant is currently registered $cachedHereBinary (participant, tid, ssh, csh) . authorizedIfExists $ \(course `E.InnerJoin` courseParticipant) -> do E.on $ course E.^. CourseId E.==. courseParticipant E.^. CourseParticipantCourse @@ -1030,6 +1106,17 @@ tagAccessPredicate AuthParticipant = APDB $ \_ route _ -> case route of E.&&. course E.^. CourseTerm E.==. E.val tid E.&&. course E.^. CourseSchool E.==. E.val ssh E.&&. course E.^. CourseShorthand E.==. E.val csh + -- participant is applicant for this course + $cachedHereBinary (participant, tid, ssh, csh) . authorizedIfExists $ \((course `E.InnerJoin` courseApplication) `E.LeftOuterJoin` allocation) -> do + E.on $ allocation E.?. AllocationId E.==. courseApplication E.^. CourseApplicationAllocation + E.on $ course E.^. CourseId E.==. courseApplication E.^. CourseApplicationCourse + E.where_ $ courseApplication E.^. CourseApplicationUser E.==. E.val participant + E.&&. course E.^. CourseTerm E.==. E.val tid + E.&&. course E.^. CourseSchool E.==. E.val ssh + E.&&. course E.^. CourseShorthand E.==. E.val csh + E.where_ $ E.maybe E.true (E.maybe E.false $ \f -> f E.<=. E.val cTime) (allocation E.?. AllocationStaffAllocationFrom) + E.&&. E.maybe E.true (E.maybe E.true $ \t -> t E.>=. E.val cTime) (allocation E.?. AllocationStaffAllocationTo) + unauthorizedI MsgUnauthorizedParticipant r -> $unsupportedAuthPredicate AuthParticipant r tagAccessPredicate AuthCapacity = APDB $ \_ route _ -> case route of @@ -1105,20 +1192,25 @@ tagAccessPredicate AuthCorrectorSubmissions = APDB $ \_ route _ -> case route of return Authorized r -> $unsupportedAuthPredicate AuthCorrectorSubmissions r tagAccessPredicate AuthSelf = APDB $ \mAuthId route _ -> exceptT return return $ do - referencedUser <- case route of - AdminUserR cID -> decrypt cID - AdminUserDeleteR cID -> decrypt cID - AdminHijackUserR cID -> decrypt cID - UserNotificationR cID -> decrypt cID - UserPasswordR cID -> decrypt cID - CourseR _ _ _ (CUserR cID) -> decrypt cID + referencedUser' <- case route of + AdminUserR cID -> return $ Left cID + AdminUserDeleteR cID -> return $ Left cID + AdminHijackUserR cID -> return $ Left cID + UserNotificationR cID -> return $ Left cID + UserPasswordR cID -> return $ Left cID + CourseR _ _ _ (CUserR cID) -> return $ Left cID CApplicationR _ _ _ cID _ -> do - appId <- decrypt cID - application <- $cachedHereBinary appId . lift $ get appId - case application of - Nothing -> throwError =<< unauthorizedI MsgUnauthorizedSelf - Just CourseApplication{..} -> return courseApplicationUser + appId <- catchIfMExceptT (const $ unauthorizedI MsgUnauthorizedSelf) (const True :: CryptoIDError -> Bool) $ decrypt cID + CourseApplication{..} <- maybeMExceptT (unauthorizedI MsgUnauthorizedSelf) . $cachedHereBinary appId $ get appId + return $ Right courseApplicationUser + AllocationR _ _ _ (AApplicationR cID) -> do + appId <- catchIfMExceptT (const $ unauthorizedI MsgUnauthorizedSelf) (const True :: CryptoIDError -> Bool) $ decrypt cID + CourseApplication{..} <- maybeMExceptT (unauthorizedI MsgUnauthorizedSelf) . $cachedHereBinary appId $ get appId + return $ Right courseApplicationUser _other -> throwError =<< $unsupportedAuthPredicate AuthSelf route + referencedUser <- case referencedUser' of + Right uid -> return uid + Left cID -> catchIfMExceptT (const $ unauthorizedI MsgUnauthorizedSelf) (const True :: CryptoIDError -> Bool) $ decrypt cID case mAuthId of Just uid | uid == referencedUser -> return Authorized @@ -1133,7 +1225,7 @@ tagAccessPredicate AuthIsLDAP = APDB $ \_ route _ -> exceptT return return $ do UserPasswordR cID -> return cID CourseR _ _ _ (CUserR cID) -> return cID _other -> throwError =<< $unsupportedAuthPredicate AuthIsLDAP route - referencedUser' <- decrypt referencedUser + referencedUser' <- catchIfMExceptT (const $ unauthorizedI MsgUnauthorizedSelf) (const True :: CryptoIDError -> Bool) $ decrypt referencedUser maybeTMExceptT (unauthorizedI MsgUnauthorizedLDAP) $ do User{..} <- MaybeT $ get referencedUser' guard $ userAuthentication == AuthLDAP @@ -1147,14 +1239,14 @@ tagAccessPredicate AuthIsPWHash = APDB $ \_ route _ -> exceptT return return $ d UserPasswordR cID -> return cID CourseR _ _ _ (CUserR cID) -> return cID _other -> throwError =<< $unsupportedAuthPredicate AuthIsPWHash route - referencedUser' <- decrypt referencedUser + referencedUser' <- catchIfMExceptT (const $ unauthorizedI MsgUnauthorizedSelf) (const True :: CryptoIDError -> Bool) $ decrypt referencedUser maybeTMExceptT (unauthorizedI MsgUnauthorizedPWHash) $ do User{..} <- MaybeT $ get referencedUser' guard $ is _AuthPWHash userAuthentication return Authorized tagAccessPredicate AuthAuthentication = APDB $ \mAuthId route _ -> case route of MessageR cID -> maybeT (unauthorizedI MsgUnauthorizedSystemMessageAuth) $ do - smId <- decrypt cID + smId <- catchIfMaybeT (const True :: CryptoIDError -> Bool) $ decrypt cID SystemMessage{..} <- $cachedHereBinary smId . MaybeT $ get smId let isAuthenticated = isJust mAuthId guard $ not systemMessageAuthenticatedOnly || isAuthenticated @@ -1636,6 +1728,7 @@ instance YesodBreadcrumbs UniWorX where breadcrumb InfoR = return ("Information" , Nothing) breadcrumb InfoLecturerR = return ("Veranstalter" , Just InfoR) breadcrumb DataProtR = return ("Datenschutz" , Just InfoR) + breadcrumb InfoAllocationR = return ("Zentralanmeldungen", Just InfoR) breadcrumb ImpressumR = return ("Impressum" , Just InfoR) breadcrumb VersionR = return ("Versionsgeschichte", Just InfoR) @@ -1659,6 +1752,13 @@ instance YesodBreadcrumbs UniWorX where breadcrumb (TermSchoolCourseListR tid ssh) = return (original $ unSchoolKey ssh, Just $ TermCourseListR tid) + breadcrumb AllocationListR = return ("Zentralanmeldungen", Just HomeR) + breadcrumb (AllocationR tid ssh ash AShowR) = do + mr <- getMessageRender + Entity _ Allocation{allocationName} <- runDB . getBy404 $ TermSchoolAllocationShort tid ssh ash + return ([st|#{allocationName} (#{mr (ShortTermIdentifier (unTermKey tid))}, #{original (unSchoolKey ssh)})|], Just $ AllocationListR) + breadcrumb (AllocationR tid ssh ash (AApplicationR _)) = return ("Bewerbung", Just $ AllocationR tid ssh ash AShowR) + breadcrumb CourseListR = return ("Kurse" , Nothing) breadcrumb CourseNewR = return ("Neu" , Just CourseListR) breadcrumb (CourseR tid ssh csh CShowR) = return (original csh, Just $ TermSchoolCourseListR tid ssh) @@ -1681,6 +1781,8 @@ instance YesodBreadcrumbs UniWorX where breadcrumb (CourseR tid ssh csh CExamListR) = return ("Prüfungen", Just $ CourseR tid ssh csh CShowR) breadcrumb (CourseR tid ssh csh CExamNewR) = return ("Anlegen", Just $ CourseR tid ssh csh CExamListR) + breadcrumb (CourseR tid ssh csh CApplicationsR) = return ("Bewerbungen", Just $ CourseR tid ssh csh CShowR) + breadcrumb (CExamR tid ssh csh examn EShowR) = return (original examn, Just $ CourseR tid ssh csh CExamListR) breadcrumb (CExamR tid ssh csh examn EEditR) = return ("Bearbeiten", Just $ CExamR tid ssh csh examn EShowR) breadcrumb (CExamR tid ssh csh examn EUsersR) = return ("Teilnehmer", Just $ CExamR tid ssh csh examn EShowR) @@ -1875,35 +1977,19 @@ pageActions (HomeR) = , menuItemModal = False , menuItemAccessCallback' = return True } - , MenuItem + , MenuItem { menuItemType = PageActionPrime - , menuItemLabel = MsgAdminHeading - , menuItemIcon = Just "screwdriver" - , menuItemRoute = SomeRoute AdminR - , menuItemModal = False - , menuItemAccessCallback' = return True - } - , MenuItem - { menuItemType = PageActionPrime - , menuItemLabel = MsgAdminFeaturesHeading + , menuItemLabel = MsgMenuOpenCourses , menuItemIcon = Nothing - , menuItemRoute = SomeRoute AdminFeaturesR + , menuItemRoute = SomeRoute (CourseListR, [("courses-openregistration", "True")]) , menuItemModal = False , menuItemAccessCallback' = return True } , MenuItem { menuItemType = PageActionPrime - , menuItemLabel = MsgMenuMessageList + , menuItemLabel = MsgMenuOpenAllocations , menuItemIcon = Nothing - , menuItemRoute = SomeRoute MessageListR - , menuItemModal = False - , menuItemAccessCallback' = return True - } - , MenuItem - { menuItemType = PageActionPrime - , menuItemLabel = MsgMenuAdminErrMsg - , menuItemIcon = Nothing - , menuItemRoute = SomeRoute AdminErrMsgR + , menuItemRoute = SomeRoute (AllocationListR, [("allocations-active", "True")]) , menuItemModal = False , menuItemAccessCallback' = return True } @@ -1927,20 +2013,12 @@ pageActions (AdminR) = } , MenuItem { menuItemType = PageActionPrime - , menuItemLabel = MsgErrMsgHeading + , menuItemLabel = MsgMenuAdminErrMsg , menuItemIcon = Nothing , menuItemRoute = SomeRoute AdminErrMsgR , menuItemModal = False , menuItemAccessCallback' = return True } - , MenuItem - { menuItemType = PageActionPrime - , menuItemLabel = MsgMenuUsers - , menuItemIcon = Nothing - , menuItemRoute = SomeRoute UsersR - , menuItemModal = False - , menuItemAccessCallback' = return True - } , MenuItem { menuItemType = PageActionSecondary , menuItemLabel = MsgMenuAdminTest @@ -2079,7 +2157,7 @@ pageActions (TermCourseListR tid) = ] pageActions (TermSchoolCourseListR _tid _ssh) = [ MenuItem - { menuItemType = PageActionPrime + { menuItemType = PageActionPrime , menuItemLabel = MsgMenuCourseNew , menuItemIcon = Just "book" , menuItemRoute = SomeRoute CourseNewR @@ -2087,6 +2165,16 @@ pageActions (TermSchoolCourseListR _tid _ssh) = , menuItemAccessCallback' = return True } ] +pageActions (AllocationR _tid _ssh _ash AShowR) = + [ MenuItem + { menuItemType = PageActionPrime + , menuItemLabel = MsgMenuAllocationInfo + , menuItemIcon = Nothing + , menuItemRoute = SomeRoute InfoAllocationR + , menuItemModal = True + , menuItemAccessCallback' = return True + } + ] pageActions (CourseListR) = [ MenuItem { menuItemType = PageActionPrime @@ -2096,6 +2184,14 @@ pageActions (CourseListR) = , menuItemModal = False , menuItemAccessCallback' = return True } + , MenuItem + { menuItemType = PageActionPrime + , menuItemLabel = MsgMenuAllocationList + , menuItemIcon = Nothing + , menuItemRoute = SomeRoute AllocationListR + , menuItemModal = False + , menuItemAccessCallback' = return True + } ] pageActions (CourseNewR) = [ MenuItem @@ -2174,6 +2270,28 @@ pageActions (CourseR tid ssh csh CShowR) = anyM examNames $ examAccess . E.unValue in runDB $ lecturerAccess `or2M` existsVisible } + , MenuItem + { menuItemType = PageActionSecondary + , menuItemLabel = MsgMenuCourseApplications + , menuItemIcon = Nothing + , menuItemRoute = SomeRoute $ CourseR tid ssh csh CApplicationsR + , menuItemModal = False + , menuItemAccessCallback' = + let courseWhere course = course <$ do + E.where_ $ course E.^. CourseTerm E.==. E.val tid + E.&&. course E.^. CourseSchool E.==. E.val ssh + E.&&. course E.^. CourseShorthand E.==. E.val csh + existsApplications = E.selectExists . E.from $ \(course `E.InnerJoin` courseApplication) -> do + E.on $ course E.^. CourseId E.==. courseApplication E.^. CourseApplicationCourse + void $ courseWhere course + courseApplications = fmap (any E.unValue) . E.select . E.from $ \course -> do + void $ courseWhere course + return $ course E.^. CourseApplicationsRequired + courseAllocation = E.selectExists . E.from $ \(course `E.InnerJoin` allocationCourse) -> do + E.on $ course E.^. CourseId E.==. allocationCourse E.^. AllocationCourseCourse + void $ courseWhere course + in runDB $ courseAllocation `or2M` courseApplications `or2M` existsApplications + } , MenuItem { menuItemType = PageActionSecondary , menuItemLabel = MsgMenuCourseMembers @@ -2940,6 +3058,7 @@ upsertCampusUser ldapData Creds{..} = do , userDateFormat = userDefaultDateFormat , userTimeFormat = userDefaultTimeFormat , userDownloadFiles = userDefaultDownloadFiles + , userWarningDays = userDefaultWarningDays , userNotificationSettings = def , userMailLanguages = def , userTokensIssuedAfter = Nothing diff --git a/src/Handler/Admin.hs b/src/Handler/Admin.hs index 27fc5c809..db6096bec 100644 --- a/src/Handler/Admin.hs +++ b/src/Handler/Admin.hs @@ -8,8 +8,6 @@ import Data.Aeson.Encode.Pretty (encodePrettyToTextBuilder) import Control.Monad.Trans.Except import Control.Monad.Trans.Writer (mapWriterT) -import Utils.Lens - -- import Data.Time import Data.Char (isDigit) import qualified Data.Text as Text @@ -21,7 +19,7 @@ import qualified Data.Map as Map import Database.Persist.Sql (fromSqlKey) import qualified Database.Esqueleto as E -import Database.Esqueleto.Utils as E +import Database.Esqueleto.Utils (mkExactFilter, mkContainsFilter) import Handler.Utils.Table.Cells import qualified Handler.Utils.TermCandidates as Candidates diff --git a/src/Handler/Allocation.hs b/src/Handler/Allocation.hs new file mode 100644 index 000000000..3cb35e7cc --- /dev/null +++ b/src/Handler/Allocation.hs @@ -0,0 +1,9 @@ +module Handler.Allocation + ( module Handler.Allocation + ) where + +import Handler.Allocation.Info as Handler.Allocation +import Handler.Allocation.Show as Handler.Allocation +import Handler.Allocation.Application as Handler.Allocation +import Handler.Allocation.Register as Handler.Allocation +import Handler.Allocation.List as Handler.Allocation diff --git a/src/Handler/Allocation/Application.hs b/src/Handler/Allocation/Application.hs new file mode 100644 index 000000000..2cf732df8 --- /dev/null +++ b/src/Handler/Allocation/Application.hs @@ -0,0 +1,442 @@ +module Handler.Allocation.Application + ( AllocationApplicationButton(..) + , ApplicationFormView(..) + , ApplicationForm(..) + , ApplicationFormMode(..) + , ApplicationFormException(..) + , applicationForm + , postAApplyR + , getAApplicationR, postAApplicationR + ) where + +import Import hiding (hash) + +import Handler.Utils +import qualified Data.Text as Text +import qualified Data.Set as Set + +import qualified Database.Esqueleto as E +import qualified Database.Esqueleto.Utils as E + +import qualified Data.Conduit.List as C + +import Crypto.Hash (hash) + +import Control.Monad.Trans.State (execStateT) +import Control.Monad.State.Class (modify) + + +data AllocationApplicationButton = BtnAllocationApply + | BtnAllocationApplicationEdit + | BtnAllocationApplicationRetract + | BtnAllocationApplicationRate + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic, Typeable) +instance Universe AllocationApplicationButton +instance Finite AllocationApplicationButton + +nullaryPathPiece ''AllocationApplicationButton $ camelToPathPiece' 1 +embedRenderMessage ''UniWorX ''AllocationApplicationButton id +makePrisms ''AllocationApplicationButton + +instance Button UniWorX AllocationApplicationButton where + btnClasses BtnAllocationApplicationRetract = [BCIsButton, BCDanger] + btnClasses _ = [BCIsButton, BCPrimary] + + +data ApplicationFormView = ApplicationFormView + { afvPriority :: Maybe (FieldView UniWorX) + , afvForm :: [FieldView UniWorX] + , afvButtons :: ([AllocationApplicationButton], Widget) + } + +data ApplicationForm = ApplicationForm + { afPriority :: Maybe Natural + , afField :: Maybe StudyFeaturesId + , afText :: Maybe Text + , afFiles :: Maybe (Source Handler File) + , afRatingVeto :: Bool + , afRatingPoints :: Maybe ExamGrade + , afRatingComment :: Maybe Text + , afAction :: AllocationApplicationButton + } + +data ApplicationFormMode = ApplicationFormMode + { afmApplicant :: Bool -- ^ Show priority + , afmApplicantEdit :: Bool -- ^ Allow editing text, files, priority (if shown) + , afmLecturer :: Bool -- ^ Allow editing rating + } + + +data ApplicationFormException = ApplicationFormNoApplication -- ^ Could not fill forced fields of application form with data from application + deriving (Eq, Ord, Read, Show, Generic, Typeable) +instance Exception ApplicationFormException + +applicationForm :: AllocationId + -> CourseId + -> UserId + -> ApplicationFormMode -- ^ Which parts of the shared form to display + -> Html -> MForm Handler (FormResult ApplicationForm, ApplicationFormView) +applicationForm aId cid uid ApplicationFormMode{..} csrf = do + (mApp, coursesNum, Course{..}, maxPrio) <- liftHandlerT . runDB $ do + mApplication <- listToMaybe <$> selectList [CourseApplicationAllocation ==. Just aId, CourseApplicationUser ==. uid, CourseApplicationCourse ==. cid] [LimitTo 1] + coursesNum <- fromIntegral <$> count [AllocationCourseAllocation ==. aId] + course <- getJust cid + [E.Value (fromMaybe 0 -> maxPrio)] <- E.select . E.from $ \courseApplication -> do + E.where_ $ courseApplication E.^. CourseApplicationCourse E.==. E.val cid + E.&&. courseApplication E.^. CourseApplicationUser E.==. E.val uid + E.&&. courseApplication E.^. CourseApplicationAllocation E.==. E.just (E.val aId) + E.&&. E.not_ (E.isNothing $ courseApplication E.^. CourseApplicationAllocationPriority) + return . E.joinV . E.max_ $ courseApplication E.^. CourseApplicationAllocationPriority + return (mApplication, coursesNum, course, maxPrio) + MsgRenderer mr <- getMsgRenderer + + let + oldPrio :: Maybe Natural + oldPrio = mApp >>= courseApplicationAllocationPriority . entityVal + + coursesNum' = succ maxPrio `max` coursesNum + + mkPrioOption :: Natural -> Option Natural + mkPrioOption i = Option + { optionDisplay = mr . MsgAllocationCoursePriority $ coursesNum' - i + , optionInternalValue = i + , optionExternalValue = tshow i + } + + prioOptions :: OptionList Natural + prioOptions = OptionList + { olOptions = sortOn (Down . optionInternalValue) . map mkPrioOption $ [0 .. pred coursesNum'] + , olReadExternal = readMay + } + prioField = selectField' (Just $ SomeMessage MsgAllocationCourseNoApplication) $ return prioOptions + + (prioRes, prioView) <- case (afmApplicant, afmApplicantEdit, mApp) of + (True , True , Nothing) + -> over _2 Just <$> mopt prioField (fslI MsgApplicationPriority) (Just $ oldPrio) + (True , True , Just _ ) + -> over (_1 . _FormSuccess) Just . over _2 Just <$> mreq prioField (fslI MsgApplicationPriority) oldPrio + (True , False, _ ) + -> over _2 Just <$> mforcedOpt prioField (fslI MsgApplicationPriority) oldPrio + (False, _ , Just _ ) + | is _Just oldPrio + -> pure (FormSuccess oldPrio, Nothing) + _other + -> throwM ApplicationFormNoApplication + + (fieldRes, fieldView') <- if + | afmApplicantEdit || afmLecturer + -> mreq (studyFeaturesFieldFor Nothing False [] $ Just uid) (fslI MsgCourseStudyFeature & setTooltip MsgCourseStudyFeatureTip) (courseApplicationField . entityVal <$> mApp) + | otherwise + -> mforced (studyFeaturesFieldFor Nothing True (maybeToList $ mApp >>= courseApplicationField . entityVal) $ Just uid) (fslI MsgCourseStudyFeature & setTooltip MsgCourseStudyFeatureTip) (mApp >>= courseApplicationField . entityVal) + + let textField' = convertField (Text.strip . unTextarea) Textarea textareaField + textFs + | is _Just courseApplicationsInstructions + = fslI MsgCourseApplicationText & setTooltip MsgCourseApplicationFollowInstructions + | otherwise + = fslI MsgCourseApplicationText + (textRes, textView) <- if + | not courseApplicationsText + -> pure (FormSuccess Nothing, Nothing) + | not afmApplicantEdit + -> over _2 Just <$> mforcedOpt textField' textFs (mApp >>= courseApplicationText . entityVal) + | otherwise + -> over _2 Just . over (_1 . _FormSuccess) (assertM $ not . Text.null) <$> mopt textField' textFs (Just $ mApp >>= courseApplicationText . entityVal) + + hasFiles <- for mApp $ \(Entity appId _) + -> fmap (not . null) . liftHandlerT . runDB $ selectKeysList [ CourseApplicationFileApplication ==. appId ] [ LimitTo 1 ] + appCID <- for mApp $ encrypt . entityKey + let appFilesInfo = (,) <$> hasFiles <*> appCID + + filesLinkView <- if + | fromMaybe False hasFiles || (isn't _NoUpload courseApplicationsFiles && not afmApplicantEdit) + -> let filesLinkField = Field{..} + where + fieldParse _ _ = return $ Right Nothing + fieldEnctype = mempty + fieldView theId _ attrs _ _ + = [whamlet| + $newline never + $case appFilesInfo + $of Just (True, appCID) + + _{MsgCourseApplicationFiles} + $of _ + + _{MsgCourseApplicationNoFiles} + |] + in Just . snd <$> mforced filesLinkField (fslI MsgCourseApplicationFiles) () + | otherwise + -> return Nothing + + filesWarningView <- if + | fromMaybe False hasFiles && isn't _NoUpload courseApplicationsFiles && afmApplicantEdit + -> fmap (Just . snd) . formMessage =<< messageIconI Info IconFileUpload MsgCourseApplicationFilesNeedReupload + | otherwise + -> return Nothing + + (filesRes, filesView) <- + let mkFs = bool MsgCourseApplicationFile MsgCourseApplicationArchive + in if + | not afmApplicantEdit || is _NoUpload courseApplicationsFiles + -> return $ (FormSuccess Nothing, Nothing) + | otherwise + -> fmap (over _2 $ Just . ($ [])) . aFormToForm $ fileUploadForm False (fslI . mkFs) courseApplicationsFiles + + (vetoRes, vetoView) <- if + | afmLecturer + -> over _2 Just <$> mpopt checkBoxField (fslI MsgApplicationVeto & setTooltip MsgApplicationVetoTip) (Just . fromMaybe False $ courseApplicationRatingVeto . entityVal <$> mApp) + | otherwise + -> return (FormSuccess . fromMaybe False $ courseApplicationRatingVeto . entityVal <$> mApp, Nothing) + + (pointsRes, pointsView) <- if + | afmLecturer + -> over _2 Just <$> mopt examGradeField (fslI MsgApplicationRatingPoints & setTooltip MsgApplicationRatingPointsTip) (fmap Just $ mApp >>= courseApplicationRatingPoints . entityVal) + | otherwise + -> return (FormSuccess $ courseApplicationRatingPoints . entityVal =<< mApp, Nothing) + + (commentRes, commentView) <- if + | afmLecturer + -> over _2 Just . over (_1 . _FormSuccess) (assertM $ not . Text.null) <$> mopt textField' (fslI MsgApplicationRatingComment & setTooltip (bool MsgApplicationRatingCommentInvisibleTip MsgApplicationRatingCommentVisibleTip courseApplicationsRatingsVisible)) (fmap Just $ mApp >>= courseApplicationRatingComment . entityVal) + | otherwise + -> return (FormSuccess $ courseApplicationRatingComment . entityVal =<< mApp, Nothing) + + let + buttons = catMaybes + [ guardOn (not afmApplicantEdit && is _Just mApp && afmLecturer) BtnAllocationApplicationRate + , guardOn ( afmApplicantEdit && is _Just mApp ) BtnAllocationApplicationEdit + , guardOn ( afmApplicantEdit && is _Nothing mApp ) BtnAllocationApply + , guardOn ( afmApplicantEdit && is _Just mApp ) BtnAllocationApplicationRetract + ] + (actionRes, buttonsView) <- buttonForm' buttons csrf + + return ( ApplicationForm + <$> prioRes + <*> fieldRes + <*> textRes + <*> filesRes + <*> vetoRes + <*> pointsRes + <*> commentRes + <*> actionRes + , ApplicationFormView + { afvPriority = prioView + , afvForm = catMaybes $ + [ Just fieldView' + , textView + , filesLinkView + , filesWarningView + ] ++ maybe [] (map Just) filesView ++ + [ vetoView + , pointsView + , commentView + ] + , afvButtons = (buttons, buttonsView) + } + ) + + + + +editApplicationR :: AllocationId + -> UserId + -> CourseId + -> Maybe CourseApplicationId + -> ApplicationFormMode + -> (AllocationApplicationButton -> Bool) + -> SomeRoute UniWorX + -> Handler (ApplicationFormView, Enctype) +editApplicationR aId uid cid mAppId afMode allowAction postAction = do + Course{..} <- runDB $ get404 cid + + ((appRes, appView), appEnc) <- runFormPost $ applicationForm aId cid uid afMode + + formResult appRes $ \ApplicationForm{..} -> do + if + | BtnAllocationApply <- afAction + , allowAction afAction + -> runDB $ do + haveOld <- exists [ CourseApplicationCourse ==. cid + , CourseApplicationUser ==. uid + , CourseApplicationAllocation ==. Just aId + ] + when haveOld $ + invalidArgsI [MsgCourseApplicationExists] + + now <- liftIO getCurrentTime + let rated = afRatingVeto || is _Just afRatingPoints + + appId <- insert CourseApplication + { courseApplicationCourse = cid + , courseApplicationUser = uid + , courseApplicationField = afField + , courseApplicationText = afText + , courseApplicationRatingVeto = afRatingVeto + , courseApplicationRatingPoints = afRatingPoints + , courseApplicationRatingComment = afRatingComment + , courseApplicationAllocation = Just aId + , courseApplicationAllocationPriority = afPriority + , courseApplicationTime = now + , courseApplicationRatingTime = guardOn rated now + } + let + sinkFile' file = do + fId <- insert file + insert_ $ CourseApplicationFile appId fId + forM_ afFiles $ \afFiles' -> + runConduit $ transPipe liftHandlerT afFiles' .| C.mapM_ sinkFile' + audit $ TransactionCourseApplicationEdit cid uid appId + addMessageI Success $ MsgCourseApplicationCreated courseShorthand + | is _BtnAllocationApplicationEdit afAction || is _BtnAllocationApplicationRate afAction + , allowAction afAction + , Just appId <- mAppId + -> runDB $ do + now <- liftIO getCurrentTime + + changes <- if + | afmApplicantEdit afMode -> do + oldFiles <- Set.fromList . map (courseApplicationFileFile . entityVal) <$> selectList [CourseApplicationFileApplication ==. appId] [] + changes <- flip execStateT oldFiles . forM_ afFiles $ \afFiles' -> + let sinkFile' file = do + oldFiles' <- lift . E.select . E.from $ \(courseApplicationFile `E.InnerJoin` file') -> do + E.on $ courseApplicationFile E.^. CourseApplicationFileFile E.==. file' E.^. FileId + E.where_ $ file' E.^. FileTitle E.==. E.val (fileTitle file) + E.&&. E.maybe + (E.val . is _Nothing $ fileContent file) + (\fc' -> maybe E.false (\fc -> E.sha256 fc' E.==. E.val (hash fc)) $ fileContent file) + (file' E.^. FileContent) + E.&&. file' E.^. FileId `E.in_` E.valList (Set.toList oldFiles) + return $ file' E.^. FileId + if + | [E.Value oldFileId] <- oldFiles' + -> modify $ Set.delete oldFileId + | otherwise + -> do + fId <- lift $ insert file + lift . insert_ $ CourseApplicationFile appId fId + modify $ Set.insert fId + in runConduit $ transPipe liftHandlerT afFiles' .| C.mapM_ sinkFile' + deleteCascadeWhere [ FileId <-. Set.toList (oldFiles `Set.intersection` changes) ] + return changes + | otherwise + -> return Set.empty + + oldApp <- get404 appId + let newApp = oldApp + { courseApplicationField = afField + , courseApplicationText = afText + , courseApplicationRatingVeto = afRatingVeto + , courseApplicationRatingPoints = afRatingPoints + , courseApplicationRatingComment = afRatingComment + , courseApplicationAllocation = Just aId + , courseApplicationAllocationPriority = afPriority + } + + newRating = any (\f -> f oldApp newApp) + [ (/=) `on` courseApplicationRatingVeto + , (/=) `on` courseApplicationRatingPoints + , (/=) `on` courseApplicationRatingComment + ] + hasRating = any ($ newApp) + [ courseApplicationRatingVeto + , is _Just . courseApplicationRatingPoints + ] + + appChanged = any (\f -> f oldApp newApp) + [ (/=) `on` courseApplicationField + , (/=) `on` courseApplicationText + , \_ _ -> not $ Set.null changes + ] + + newApp' = newApp + & bool id (set _courseApplicationRatingTime Nothing) appChanged + & bool id (set _courseApplicationRatingTime $ Just now) (newRating && hasRating) + & bool id (set _courseApplicationTime now) appChanged + replace appId newApp' + audit $ TransactionCourseApplicationEdit cid uid appId + + uncurry addMessageI =<< case (afmLecturer afMode, newRating, hasRating, appChanged) of + (_, False, _, True) -> return (Success, MsgCourseApplicationEdited courseShorthand) + (_, False, _, False) -> return (Info, MsgCourseApplicationNotEdited courseShorthand) + (True, True, True, _) -> return (Success, MsgCourseApplicationRated) + (True, True, False, _) -> return (Success, MsgCourseApplicationRatingDeleted) + (False, True, _, _) -> permissionDenied "rating changed without lecturer rights" + | is _BtnAllocationApplicationRetract afAction + , allowAction afAction + , Just appId <- mAppId + -> runDB $ do + deleteCascade appId + audit $ TransactionCourseApplicationDeleted cid uid appId + addMessageI Success $ MsgCourseApplicationDeleted courseShorthand + | otherwise + -> invalidArgsI [MsgCourseApplicationInvalidAction] + + redirect postAction + + return (appView, appEnc) + + +postAApplyR :: TermId -> SchoolId -> AllocationShorthand -> CryptoUUIDCourse -> Handler Void +postAApplyR tid ssh ash cID = do + uid <- requireAuthId + cid <- decrypt cID + (aId, Course{..}) <- runDB $ do + aId <- getKeyBy404 $ TermSchoolAllocationShort tid ssh ash + course <- get404 cid + return (aId, course) + + afmLecturer <- hasWriteAccessTo $ CourseR courseTerm courseSchool courseShorthand CEditR + + let afMode = ApplicationFormMode + { afmApplicant = True + , afmApplicantEdit = True + , afmLecturer + } + + void . editApplicationR aId uid cid Nothing afMode (== BtnAllocationApply) . SomeRoute $ AllocationR tid ssh ash AShowR :#: cID + + invalidArgs ["Application form required"] + + +getAApplicationR, postAApplicationR :: TermId -> SchoolId -> AllocationShorthand -> CryptoFileNameCourseApplication -> Handler Html +getAApplicationR = postAApplicationR +postAApplicationR tid ssh ash cID = do + uid <- requireAuthId + appId <- decrypt cID + (Entity aId Allocation{..}, Entity cid Course{..}, CourseApplication{..}, isAdmin, User{..}) <- runDB $ do + alloc <- getBy404 $ TermSchoolAllocationShort tid ssh ash + app <- get404 appId + Just course <- getEntity $ courseApplicationCourse app + Just appUser <- get $ courseApplicationUser app + isAdmin <- exists [UserAdminUser ==. uid, UserAdminSchool ==. alloc ^. _entityVal . _allocationSchool] + return (alloc, course, app, isAdmin, appUser) + + afmLecturer <- hasWriteAccessTo $ CourseR courseTerm courseSchool courseShorthand CEditR + afmApplicantEdit <- hasWriteAccessTo . AllocationR tid ssh ash $ AApplicationR cID + courseCID <- encrypt cid :: Handler CryptoUUIDCourse + + let afMode = ApplicationFormMode + { afmApplicant = uid == courseApplicationUser || isAdmin + , afmApplicantEdit + , afmLecturer + } + + (ApplicationFormView{..}, appEnc) <- editApplicationR aId uid cid (Just appId) afMode (/= BtnAllocationApply) $ if + | uid == courseApplicationUser + -> SomeRoute $ AllocationR tid ssh ash AShowR :#: courseCID + | otherwise + -> SomeRoute . AllocationR tid ssh ash $ AApplicationR cID + + let title = MsgCourseApplicationTitle userDisplayName courseShorthand + + siteLayoutMsg title $ do + setTitleI title + + wrapForm ((<> snd afvButtons) . renderFieldViews FormStandard . maybe id (:) afvPriority$ afvForm) FormSettings + { formMethod = POST + , formAction = Just . SomeRoute . AllocationR tid ssh ash $ AApplicationR cID + , formEncoding = appEnc + , formAttrs = [] + , formSubmit = FormNoSubmit + , formAnchor = Nothing :: Maybe Text + } diff --git a/src/Handler/Allocation/Info.hs b/src/Handler/Allocation/Info.hs new file mode 100644 index 000000000..f6aacf063 --- /dev/null +++ b/src/Handler/Allocation/Info.hs @@ -0,0 +1,13 @@ +module Handler.Allocation.Info + ( getInfoAllocationR + ) where + +import Import +import Handler.Utils + + +getInfoAllocationR :: Handler Html +getInfoAllocationR = + siteLayoutMsg MsgMenuAllocationInfo $ do + setTitleI MsgMenuAllocationInfo + $(i18nWidgetFile "allocation-info") diff --git a/src/Handler/Allocation/List.hs b/src/Handler/Allocation/List.hs new file mode 100644 index 000000000..38069fc4c --- /dev/null +++ b/src/Handler/Allocation/List.hs @@ -0,0 +1,89 @@ +module Handler.Allocation.List + ( getAllocationListR + ) where + +import Import + +import qualified Database.Esqueleto as E +import Handler.Utils.Table.Columns +import Handler.Utils.Table.Pagination + + +type AllocationTableExpr = E.SqlExpr (Entity Allocation) +type AllocationTableData = DBRow (Entity Allocation) + +allocationListIdent :: Text +allocationListIdent = "allocations" + +queryAllocation :: Getter AllocationTableExpr (E.SqlExpr (Entity Allocation)) +queryAllocation = id + +resultAllocation :: Lens' AllocationTableData (Entity Allocation) +resultAllocation = _dbrOutput + +allocationTermLink :: TermId -> SomeRoute UniWorX +allocationTermLink tid = SomeRoute (AllocationListR, [(dbFilterKey allocationListIdent "term", toPathPiece tid)]) + +allocationSchoolLink :: SchoolId -> SomeRoute UniWorX +allocationSchoolLink ssh = SomeRoute (AllocationListR, [(dbFilterKey allocationListIdent "school", toPathPiece ssh)]) + +allocationLink :: Allocation -> SomeRoute UniWorX +allocationLink Allocation{..} = SomeRoute $ AllocationR allocationTerm allocationSchool allocationShorthand AShowR + +getAllocationListR :: Handler Html +getAllocationListR = do + now <- liftIO getCurrentTime + let + dbtSQLQuery :: AllocationTableExpr -> E.SqlQuery _ + dbtSQLQuery = return + + dbtProj :: DBRow _ -> MaybeT (YesodDB UniWorX) AllocationTableData + dbtProj = return + + dbtRowKey = view $ queryAllocation . to (E.^. AllocationId) + + dbtColonnade :: Colonnade Sortable _ _ + dbtColonnade = mconcat + [ anchorColonnade (views (resultAllocation . _entityVal . _allocationTerm) allocationTermLink) $ colTermShort (resultAllocation . _entityVal . _allocationTerm) + , anchorColonnade (views (resultAllocation . _entityVal . _allocationSchool) allocationSchoolLink) $ colSchoolShort (resultAllocation . _entityVal . _allocationSchool) + , anchorColonnade (views (resultAllocation . _entityVal) allocationLink) $ colAllocationName (resultAllocation . _entityVal . _allocationName) + ] + + dbtSorting = mconcat + [ sortTerm $ queryAllocation . to (E.^. AllocationTerm) + , sortSchool $ queryAllocation . to (E.^. AllocationSchool) + , sortAllocationName $ queryAllocation . to (E.^. AllocationName) + ] + + dbtFilter = mconcat + [ fltrAllocationActive now queryAllocation + , fltrTerm $ queryAllocation . to (E.^. AllocationTerm) + , fltrSchool $ queryAllocation . to (E.^. AllocationSchool) + , fltrAllocation queryAllocation + ] + dbtFilterUI = mconcat + [ fltrAllocationActiveUI + , fltrTermUI + , fltrSchoolUI + , fltrAllocationUI + ] + + dbtStyle = def + { dbsFilterLayout = defaultDBSFilterLayout + } + dbtParams = def + + dbtCsvEncode = noCsvEncode + dbtCsvDecode = Nothing + + dbtIdent = allocationListIdent + + psValidator :: PSValidator _ _ + psValidator = def + & defaultSorting [SortDescBy "term", SortAscBy "school", SortAscBy "allocation"] + + table <- runDB $ dbTableWidget' psValidator DBTable{..} + + siteLayoutMsg MsgAllocationListTitle $ do + setTitleI MsgAllocationListTitle + table diff --git a/src/Handler/Allocation/Register.hs b/src/Handler/Allocation/Register.hs new file mode 100644 index 000000000..eb5e55255 --- /dev/null +++ b/src/Handler/Allocation/Register.hs @@ -0,0 +1,60 @@ +module Handler.Allocation.Register + ( AllocationRegisterForm(..) + , AllocationRegisterButton(..) + , allocationRegisterForm + , allocationUserToForm + , postARegisterR + ) where + +import Import + +import Handler.Utils.Form + +{-# ANN module ("HLint: ignore Use newtype instead of data"::String) #-} + + +data AllocationRegisterForm = AllocationRegisterForm + { arfTotalCourses :: Natural + } + +allocationRegisterForm :: Maybe AllocationRegisterForm -> AForm Handler AllocationRegisterForm +allocationRegisterForm template + = AllocationRegisterForm + <$> areq (posIntFieldI MsgAllocationTotalCoursesNegative) (fslI MsgAllocationTotalCourses & setTooltip MsgAllocationTotalCoursesTip) (arfTotalCourses <$> template <|> Just 1) + +allocationUserToForm :: AllocationUser -> AllocationRegisterForm +allocationUserToForm AllocationUser{..} = AllocationRegisterForm + { arfTotalCourses = allocationUserTotalCourses + } + +data AllocationRegisterButton = BtnAllocationRegister | BtnAllocationRegistrationEdit + deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic, Typeable) +instance Universe AllocationRegisterButton +instance Finite AllocationRegisterButton + +nullaryPathPiece ''AllocationRegisterButton $ camelToPathPiece' 1 +embedRenderMessage ''UniWorX ''AllocationRegisterButton id + +instance Button UniWorX AllocationRegisterButton where + btnClasses _ = [BCIsButton, BCPrimary] + +postARegisterR :: TermId -> SchoolId -> AllocationShorthand -> Handler Void +postARegisterR tid ssh ash = do + uid <- requireAuthId + + ((registerRes, _), _) <- runFormPost . renderAForm FormStandard $ allocationRegisterForm Nothing + formResult registerRes $ \AllocationRegisterForm{..} -> runDB $ do + aId <- getKeyBy404 $ TermSchoolAllocationShort tid ssh ash + isRegistered <- existsBy $ UniqueAllocationUser aId uid + void $ upsert AllocationUser + { allocationUserAllocation = aId + , allocationUserUser = uid + , allocationUserTotalCourses = arfTotalCourses + } + [ AllocationUserTotalCourses =. arfTotalCourses + ] + if + | isRegistered -> addMessageI Success MsgAllocationRegistrationEdited + | otherwise -> addMessageI Success MsgAllocationRegistered + + redirect $ AllocationR tid ssh ash AShowR :#: ("allocation-participation" :: Text) diff --git a/src/Handler/Allocation/Show.hs b/src/Handler/Allocation/Show.hs new file mode 100644 index 000000000..0cc4d455b --- /dev/null +++ b/src/Handler/Allocation/Show.hs @@ -0,0 +1,97 @@ +module Handler.Allocation.Show + ( getAShowR + ) where + +import Import +import Handler.Utils + +import Handler.Allocation.Register +import Handler.Allocation.Application + +import qualified Database.Esqueleto as E + + +getAShowR :: TermId -> SchoolId -> AllocationShorthand -> Handler Html +getAShowR tid ssh ash = do + muid <- maybeAuthId + now <- liftIO getCurrentTime + + let + resultCourse :: Simple Field1 a (Entity Course) => Lens' a (Entity Course) + resultCourse = _1 + resultCourseApplication :: Simple Field2 a (Maybe (Entity CourseApplication)) => Traversal' a (Entity CourseApplication) + resultCourseApplication = _2 . _Just + resultHasTemplate :: Simple Field3 a (E.Value Bool) => Lens' a Bool + resultHasTemplate = _3 . _Value + + (Entity aId Allocation{..}, courses, registration) <- runDB $ do + alloc@(Entity aId _) <- getBy404 $ TermSchoolAllocationShort tid ssh ash + + courses <- E.select . E.from $ \((allocationCourse `E.InnerJoin` course) `E.LeftOuterJoin` courseApplication) -> do + E.on $ courseApplication E.?. CourseApplicationCourse E.==. E.just (course E.^. CourseId) + E.&&. courseApplication E.?. CourseApplicationUser E.==. E.val muid + E.&&. courseApplication E.?. CourseApplicationAllocation E.==. E.just (E.just $ E.val aId) + E.on $ allocationCourse E.^. AllocationCourseCourse E.==. course E.^. CourseId + E.where_ $ allocationCourse E.^. AllocationCourseAllocation E.==. E.val aId + E.orderBy [E.asc $ course E.^. CourseName] + let hasTemplate = E.exists . E.from $ \courseAppInstructionFile -> + E.where_ $ courseAppInstructionFile E.^. CourseAppInstructionFileCourse E.==. course E.^. CourseId + return (course, courseApplication, hasTemplate) + + registration <- fmap join . for muid $ getBy . UniqueAllocationUser aId + + return (alloc, nubOn (view $ resultCourse . _entityKey) courses, registration) + + MsgRenderer mr <- getMsgRenderer + let title = MsgAllocationTitle (mr . ShortTermIdentifier $ unTermKey allocationTerm) (unSchoolKey allocationSchool) allocationName + shortTitle = MsgAllocationShortTitle (mr . ShortTermIdentifier $ unTermKey allocationTerm) (unSchoolKey allocationSchool) allocationShorthand + + staffInformation <- anyM courses $ \(view $ resultCourse . _entityVal -> Course{..}) -> + hasReadAccessTo $ CourseR courseTerm courseSchool courseShorthand CApplicationsR + mayRegister <- hasWriteAccessTo $ AllocationR tid ssh ash ARegisterR + (registerForm, registerEnctype) <- generateFormPost . renderAForm FormStandard . allocationRegisterForm $ allocationUserToForm . entityVal <$> registration + let + registerBtn = bool BtnAllocationRegister BtnAllocationRegistrationEdit $ is _Just registration + registerForm' = wrapForm' registerBtn registerForm FormSettings + { formMethod = POST + , formAction = Just . SomeRoute $ AllocationR tid ssh ash ARegisterR + , formEncoding = registerEnctype + , formAttrs = [] + , formSubmit = FormSubmit + , formAnchor = Nothing :: Maybe Text + } + + siteLayoutMsg title $ do + setTitleI shortTitle + + let courseWidgets = flip map courses $ \cEntry -> do + let Entity cid Course{..} = cEntry ^. resultCourse + hasApplicationTemplate = cEntry ^. resultHasTemplate + mApp = cEntry ^? resultCourseApplication + cID <- encrypt cid :: WidgetT UniWorX IO CryptoUUIDCourse + mayApply <- hasWriteAccessTo . AllocationR tid ssh ash $ AApplyR cID + isLecturer <- hasWriteAccessTo $ CourseR courseTerm courseSchool courseShorthand CEditR + mApplyFormView <- liftHandlerT . for muid $ \uid -> generateFormPost . applicationForm aId cid uid $ ApplicationFormMode True mayApply isLecturer + subRoute <- fmap (fromMaybe $ AApplyR cID) . for mApp $ \(Entity appId _) -> AApplicationR <$> encrypt appId + let mApplyFormView' = view _1 <$> mApplyFormView + overrideVisible = not mayApply && is _Just mApp + case mApplyFormView of + Just (_, appFormEnctype) + -> wrapForm $(widgetFile "allocation/show/course") FormSettings + { formMethod = POST + , formAction = Just . SomeRoute $ AllocationR tid ssh ash subRoute + , formEncoding = appFormEnctype + , formAttrs = [ ("class", "allocation-course") + ] + , formSubmit = FormNoSubmit + , formAnchor = Just cID + } + Nothing + -> let wdgt = $(widgetFile "allocation/show/course") + in [whamlet| +
+ ^{wdgt} + |] + let daysToRegistrationStart = assertM (>0) $ (`diffUTCTime` now) <$> allocationRegisterFrom + allocationInfoModal = modal [whamlet|_{MsgMenuAllocationInfo}|] $ Left $ SomeRoute InfoAllocationR + $(widgetFile "allocation/show") diff --git a/src/Handler/Corrections.hs b/src/Handler/Corrections.hs index 3e0a5a825..b366885d3 100644 --- a/src/Handler/Corrections.hs +++ b/src/Handler/Corrections.hs @@ -12,8 +12,6 @@ import Handler.Utils.SheetType import Handler.Utils.Delete -- import Handler.Utils.Zip -import Utils.Lens - import Data.List as List (nub, foldl, foldr) import Data.Set (Set) import qualified Data.Set as Set diff --git a/src/Handler/Course/Application.hs b/src/Handler/Course/Application.hs index 17fa5127b..998ff9670 100644 --- a/src/Handler/Course/Application.hs +++ b/src/Handler/Course/Application.hs @@ -1,12 +1,15 @@ module Handler.Course.Application ( getCAFilesR + , getCApplicationsR, postCApplicationsR ) where import Import import Handler.Utils +import Handler.Utils.Table.Columns import qualified Database.Esqueleto as E +import Database.Esqueleto.Utils.TH import System.FilePath (addExtension) @@ -35,3 +38,193 @@ getCAFilesR tid ssh csh cID = do return file serveSomeFiles archiveName $ fsSource .| C.map entityVal + + +type CourseApplicationsTableExpr = ( E.SqlExpr (Entity CourseApplication) + `E.InnerJoin` E.SqlExpr (Entity User) + ) + `E.LeftOuterJoin` E.SqlExpr (Maybe (Entity Allocation)) + `E.LeftOuterJoin` ( E.SqlExpr (Maybe (Entity StudyFeatures)) + `E.InnerJoin` E.SqlExpr (Maybe (Entity StudyTerms)) + `E.InnerJoin` E.SqlExpr (Maybe (Entity StudyDegree)) + ) +type CourseApplicationsTableData = DBRow ( Entity CourseApplication + , Entity User + , E.Value Bool -- hasFiles + , Maybe (Entity Allocation) + , Maybe (Entity StudyFeatures) + , Maybe (Entity StudyTerms) + , Maybe (Entity StudyDegree) + ) + +courseApplicationsIdent :: Text +courseApplicationsIdent = "applications" + +queryCourseApplication :: Getter CourseApplicationsTableExpr (E.SqlExpr (Entity CourseApplication)) +queryCourseApplication = to $ $(sqlIJproj 2 1) . $(sqlLOJproj 3 1) + +queryUser :: Getter CourseApplicationsTableExpr (E.SqlExpr (Entity User)) +queryUser = to $ $(sqlIJproj 2 2) . $(sqlLOJproj 3 1) + +queryHasFiles :: Getter CourseApplicationsTableExpr (E.SqlExpr (E.Value Bool)) +queryHasFiles = to $ hasFiles . $(sqlIJproj 2 1) . $(sqlLOJproj 3 1) + where + hasFiles appl = E.exists . E.from $ \courseApplicationFile -> + E.where_ $ courseApplicationFile E.^. CourseApplicationFileApplication E.==. appl E.^. CourseApplicationId + +queryAllocation :: Getter CourseApplicationsTableExpr (E.SqlExpr (Maybe (Entity Allocation))) +queryAllocation = to $(sqlLOJproj 3 2) + +queryStudyFeatures :: Getter CourseApplicationsTableExpr (E.SqlExpr (Maybe (Entity StudyFeatures))) +queryStudyFeatures = to $ $(sqlIJproj 3 1) . $(sqlLOJproj 3 3) + +queryStudyTerms :: Getter CourseApplicationsTableExpr (E.SqlExpr (Maybe (Entity StudyTerms))) +queryStudyTerms = to $ $(sqlIJproj 3 2) . $(sqlLOJproj 3 3) + +queryStudyDegree :: Getter CourseApplicationsTableExpr (E.SqlExpr (Maybe (Entity StudyDegree))) +queryStudyDegree = to $ $(sqlIJproj 3 3) . $(sqlLOJproj 3 3) + +resultCourseApplication :: Lens' CourseApplicationsTableData (Entity CourseApplication) +resultCourseApplication = _dbrOutput . _1 + +resultUser :: Lens' CourseApplicationsTableData (Entity User) +resultUser = _dbrOutput . _2 + +resultHasFiles :: Lens' CourseApplicationsTableData Bool +resultHasFiles = _dbrOutput . _3 . _Value + +resultAllocation :: Traversal' CourseApplicationsTableData (Entity Allocation) +resultAllocation = _dbrOutput . _4 . _Just + +resultStudyFeatures :: Traversal' CourseApplicationsTableData (Entity StudyFeatures) +resultStudyFeatures = _dbrOutput . _5 . _Just + +resultStudyTerms :: Traversal' CourseApplicationsTableData (Entity StudyTerms) +resultStudyTerms = _dbrOutput . _6 . _Just + +resultStudyDegree :: Traversal' CourseApplicationsTableData (Entity StudyDegree) +resultStudyDegree = _dbrOutput . _7 . _Just + +getCApplicationsR, postCApplicationsR :: TermId -> SchoolId -> CourseShorthand -> Handler Html +getCApplicationsR = postCApplicationsR +postCApplicationsR tid ssh csh = do + table <- runDB $ do + cid <- getKeyBy404 $ TermSchoolCourseShort tid ssh csh + + let + allocationLink :: Allocation -> SomeRoute UniWorX + allocationLink Allocation{..} = SomeRoute $ AllocationR allocationTerm allocationSchool allocationShorthand AShowR + + participantLink :: MonadCrypto m => UserId -> m (SomeRoute UniWorX) + participantLink uid = do + cID <- encrypt uid + return . SomeRoute . CourseR tid ssh csh $ CUserR cID + + dbtSQLQuery :: CourseApplicationsTableExpr -> E.SqlQuery _ + dbtSQLQuery = runReaderT $ do + courseApplication <- view queryCourseApplication + hasFiles <- view queryHasFiles + user <- view queryUser + allocation <- view queryAllocation + studyFeatures <- view queryStudyFeatures + studyTerms <- view queryStudyTerms + studyDegree <- view queryStudyDegree + + lift $ do + E.on $ studyDegree E.?. StudyDegreeId E.==. studyFeatures E.?. StudyFeaturesDegree + E.on $ studyTerms E.?. StudyTermsId E.==. studyFeatures E.?. StudyFeaturesField + E.on $ studyFeatures E.?. StudyFeaturesId E.==. courseApplication E.^. CourseApplicationField + E.on $ courseApplication E.^. CourseApplicationAllocation E.==. allocation E.?. AllocationId + E.on $ user E.^. UserId E.==. courseApplication E.^. CourseApplicationUser + E.where_ $ courseApplication E.^. CourseApplicationCourse E.==. E.val cid + + return (courseApplication, user, hasFiles, allocation, studyFeatures, studyTerms, studyDegree) + + dbtProj :: DBRow _ -> MaybeT (YesodDB UniWorX) CourseApplicationsTableData + dbtProj = runReaderT $ do + appId <- view $ resultCourseApplication . _entityKey + cID <- encrypt appId + + guardM . hasReadAccessTo $ CApplicationR tid ssh csh cID CAFilesR -- TODO: replace with CAShowR + + view id + + dbtRowKey = view $ queryCourseApplication . to (E.^. CourseApplicationId) + + dbtColonnade :: Colonnade Sortable _ _ + dbtColonnade = mconcat + [ emptyOpticColonnade (resultAllocation . _entityVal) $ \l -> anchorColonnade (views l allocationLink) $ colAllocationShorthand (l . _allocationShorthand) + , colApplicationId (resultCourseApplication . _entityKey) + , anchorColonnadeM (views (resultUser . _entityKey) participantLink) $ colUserDisplayName (resultUser . _entityVal . $(multifocusL 2) _userDisplayName _userSurname) + , colUserMatriculation (resultUser . _entityVal . _userMatrikelnummer) + , emptyOpticColonnade (resultStudyTerms . _entityVal) colStudyTerms + , emptyOpticColonnade (resultStudyDegree . _entityVal) colStudyDegree + , emptyOpticColonnade (resultStudyFeatures . _entityVal . _studyFeaturesSemester) colStudyFeaturesSemester + , colApplicationText (resultCourseApplication . _entityVal . _courseApplicationText) + , lmap ((tid, ssh, csh), ) $ colApplicationFiles ($(multifocusL 5) (_1 . _1) (_1 . _2) (_1 . _3) (_2 . resultCourseApplication . _entityKey) (_2 . resultHasFiles)) + , colApplicationVeto (resultCourseApplication . _entityVal . _courseApplicationRatingVeto) + , colApplicationRatingPoints (resultCourseApplication . _entityVal . _courseApplicationRatingPoints) + , colApplicationRatingComment (resultCourseApplication . _entityVal . _courseApplicationRatingComment) + ] + + dbtSorting = mconcat + [ sortAllocationShorthand $ queryAllocation . to (E.?. AllocationShorthand) + , sortUserName' $ $(multifocusG 2) (queryUser . to (E.^. UserDisplayName)) (queryUser . to (E.^. UserSurname)) + , sortUserMatriculation $ queryUser . to (E.^. UserMatrikelnummer) + , sortStudyTerms queryStudyTerms + , sortStudyDegree queryStudyDegree + , sortStudyFeaturesSemester $ queryStudyFeatures . to (E.?. StudyFeaturesSemester) + , sortApplicationText $ queryCourseApplication . to (E.^. CourseApplicationText) + , sortApplicationFiles queryHasFiles + , sortApplicationVeto $ queryCourseApplication . to (E.^. CourseApplicationRatingVeto) + , sortApplicationRatingPoints $ queryCourseApplication . to (E.^. CourseApplicationRatingPoints) + , sortApplicationRatingComment $ queryCourseApplication . to (E.^. CourseApplicationRatingComment) + ] + + dbtFilter = mconcat + [ fltrAllocation queryAllocation + , fltrUserName' $ queryUser . to (E.^. UserDisplayName) + , fltrUserMatriculation $ queryUser . to (E.^. UserMatrikelnummer) + , fltrStudyTerms queryStudyTerms + , fltrStudyDegree queryStudyDegree + , fltrStudyFeaturesSemester $ queryStudyFeatures . to (E.?. StudyFeaturesSemester) + , fltrApplicationText $ queryCourseApplication . to (E.^. CourseApplicationText) + , fltrApplicationFiles queryHasFiles + , fltrApplicationVeto $ queryCourseApplication . to (E.^. CourseApplicationRatingVeto) + , fltrApplicationRatingPoints $ queryCourseApplication . to (E.^. CourseApplicationRatingPoints) + , fltrApplicationRatingComment $ queryCourseApplication . to (E.^. CourseApplicationRatingComment) + ] + dbtFilterUI = mconcat + [ fltrAllocationUI + , fltrUserNameUI' + , fltrUserMatriculationUI + , fltrStudyTermsUI + , fltrStudyDegreeUI + , fltrStudyFeaturesSemesterUI + , fltrApplicationTextUI + , fltrApplicationFilesUI + , fltrApplicationVetoUI + , fltrApplicationRatingPointsUI + , fltrApplicationRatingCommentUI + ] + + dbtStyle = def + { dbsFilterLayout = defaultDBSFilterLayout + } + dbtParams = def + + dbtCsvEncode = noCsvEncode + dbtCsvDecode = Nothing + + dbtIdent = courseApplicationsIdent + + psValidator :: PSValidator _ _ + psValidator = def + + dbTableWidget' psValidator DBTable{..} + + let title = prependCourseTitle tid ssh csh MsgCourseApplicationsListTitle + + siteLayoutMsg title $ do + setTitleI title + table diff --git a/src/Handler/Course/Edit.hs b/src/Handler/Course/Edit.hs index cdedd90bb..ce9d0e422 100644 --- a/src/Handler/Course/Edit.hs +++ b/src/Handler/Course/Edit.hs @@ -5,7 +5,6 @@ module Handler.Course.Edit import Import -import Utils.Lens import Utils.Form import Handler.Utils import Handler.Utils.Invitations diff --git a/src/Handler/Course/LecturerInvite.hs b/src/Handler/Course/LecturerInvite.hs index 25086ff1b..7bc870396 100644 --- a/src/Handler/Course/LecturerInvite.hs +++ b/src/Handler/Course/LecturerInvite.hs @@ -8,7 +8,6 @@ module Handler.Course.LecturerInvite import Import -import Utils.Lens import Utils.Form import Handler.Utils.Invitations diff --git a/src/Handler/Course/List.hs b/src/Handler/Course/List.hs index 4a29f3851..4a8a63703 100644 --- a/src/Handler/Course/List.hs +++ b/src/Handler/Course/List.hs @@ -10,7 +10,6 @@ import Import import Data.Maybe (fromJust) -import Utils.Lens import Utils.Form -- import Utils.DB import Handler.Utils @@ -26,39 +25,39 @@ import qualified Database.Esqueleto.Utils as E -- NOTE: Outdated way to use dbTable; see ProfileDataR Handler for a more recent method. -type CourseTableData = DBRow (Entity Course, Int, Bool, Entity School, [Entity User]) +type CourseTableData = DBRow (Entity Course, Int, Bool, Entity School, [Entity User], Maybe (Entity Allocation)) colCourse :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a) colCourse = sortable (Just "course") (i18nCell MsgCourse) - $ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _, _) } -> + $ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _, _, _) } -> anchorCell (CourseR courseTerm courseSchool courseShorthand CShowR) [whamlet|_{courseName}|] colDescription :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a) colDescription = sortable Nothing mempty - $ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _, _) } -> + $ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _, _, _) } -> case courseDescription of Nothing -> mempty (Just descr) -> cell $ modal (toWidget $ hasComment True) (Right $ toWidget descr) colCShort :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a) colCShort = sortable (Just "cshort") (i18nCell MsgCourseShort) - $ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _, _) } -> + $ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _, _, _) } -> anchorCell (CourseR courseTerm courseSchool courseShorthand CShowR) [whamlet|_{courseShorthand}|] colTerm :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a) colTerm = sortable (Just "term") (i18nCell MsgTerm) - $ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _, _) } -> + $ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, _, _, _) } -> anchorCell (TermCourseListR courseTerm) [whamlet|#{courseTerm}|] colSchoolShort :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a) colSchoolShort = sortable (Just "schoolshort") (i18nCell MsgCourseSchoolShort) - $ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, Entity _ School{..}, _) } -> + $ \DBRow{ dbrOutput=(Entity _ Course{..}, _, _, Entity _ School{..}, _, _) } -> anchorCell (TermSchoolCourseListR courseTerm courseSchool) [whamlet|_{schoolShorthand}|] colRegistered :: IsDBTable m a => Colonnade Sortable CourseTableData (DBCell m a) colRegistered = sortable (Just "registered") (i18nCell MsgRegistered) - $ \DBRow{ dbrOutput=(_, _, registered, _, _) } -> tickmarkCell registered + $ \DBRow{ dbrOutput=(_, _, registered, _, _, _) } -> tickmarkCell registered type CourseTableExpr = E.SqlExpr (Entity Course) `E.InnerJoin` E.SqlExpr (Entity School) @@ -91,7 +90,9 @@ makeCourseTable whereClause colChoices psValidator = do dbtProj :: DBRow _ -> MaybeT (ReaderT SqlBackend (HandlerT UniWorX IO)) CourseTableData dbtProj = traverse $ \(course, E.Value participants, E.Value registered, school) -> do lecturerList <- lift $ E.select $ E.from $ lecturerQuery $ E.val $ entityKey course - return (course, participants, registered, school, lecturerList) + courseAlloc <- lift $ getBy (UniqueAllocationCourse $ entityKey course) + >>= traverse (getJustEntity . allocationCourseAllocation . entityVal) + return (course, participants, registered, school, lecturerList, courseAlloc) snd <$> dbTable psValidator DBTable { dbtSQLQuery , dbtRowKey = \(course `E.InnerJoin` _) -> course E.^. CourseId @@ -142,7 +143,22 @@ makeCourseTable whereClause colChoices psValidator = do Nothing -> E.val True Just b -> let regTo = course E.^. CourseRegisterTo regFrom = course E.^. CourseRegisterFrom - in (E.==.) (E.val b) $ (E.isNothing regTo E.||. E.val (Just now) E.<=. regTo) E.&&. E.val (Just now) E.>=. regFrom + courseOpen = E.maybe E.false (\f -> f E.<=. E.val now) regFrom + E.&&. E.maybe E.true (\t -> E.val now E.<=. t) regTo + alloc allocation = do + E.where_ . E.exists . E.from $ \allocationCourse -> + E.where_ $ allocationCourse E.^. AllocationCourseCourse E.==. course E.^. CourseId + return allocation + allocOpen allocation = ( E.maybe E.false (\f -> f E.<=. E.val now) (allocation E.^. AllocationRegisterFrom) + E.&&. E.maybe E.true (\t -> E.val now E.<=. t) (allocation E.^. AllocationRegisterTo) + ) + E.||. ( courseOpen + E.&&. E.maybe E.false (\f -> f E.<=. E.val now) (allocation E.^. AllocationRegisterByCourse) + ) + in (E.==. E.val b) $ ( courseOpen + E.&&. E.not_ (E.exists . void $ E.from alloc) + ) + E.||. E.exists (E.from $ E.where_ . allocOpen <=< alloc) ) , ( "registered", FilterColumn $ \tExpr criterion -> case getLast (criterion :: Last Bool) of Nothing -> E.val True :: E.SqlExpr (E.Value Bool) @@ -165,8 +181,8 @@ makeCourseTable whereClause colChoices psValidator = do ] , dbtStyle = def { dbsFilterLayout = defaultDBSFilterLayout - , dbsTemplate = DBSTCourse (_dbrOutput . _1) (_dbrOutput . _5) (_dbrOutput . _3) (_dbrOutput . _4) - -- ^ course ^ lecturer list ^ isRegistered ^ school + , dbsTemplate = DBSTCourse (_dbrOutput . _1) (_dbrOutput . _5) (_dbrOutput . _3) (_dbrOutput . _4) (_dbrOutput . _6 . _Just) + -- ^ course ^ lecturer list ^ isRegistered ^ school ^ allocation } , dbtParams = def , dbtIdent = "courses" :: Text diff --git a/src/Handler/Course/ParticipantInvite.hs b/src/Handler/Course/ParticipantInvite.hs index 292d0bf26..97b79e54c 100644 --- a/src/Handler/Course/ParticipantInvite.hs +++ b/src/Handler/Course/ParticipantInvite.hs @@ -8,7 +8,6 @@ module Handler.Course.ParticipantInvite import Import -import Utils.Lens import Utils.Form import Handler.Utils import Handler.Utils.Invitations diff --git a/src/Handler/Course/Register.hs b/src/Handler/Course/Register.hs index dbaaac8df..d134e31d1 100644 --- a/src/Handler/Course/Register.hs +++ b/src/Handler/Course/Register.hs @@ -7,7 +7,6 @@ module Handler.Course.Register import Import -import Utils.Lens import Handler.Utils import Data.Function ((&)) @@ -114,26 +113,26 @@ courseRegisterForm (Entity cid Course{..}) = liftHandlerT $ do let appFilesInfo = (,) <$> hasFiles <*> appCID filesMsg = bool MsgCourseRegistrationFiles MsgCourseApplicationFiles courseApplicationsRequired - if - | isn't _NoUpload courseApplicationsFiles || fromMaybe False hasFiles - -> let filesLinkField = Field{..} - where - fieldParse _ _ = return $ Right Nothing - fieldEnctype = mempty - fieldView theId _ attrs _ _ - = [whamlet| - $newline never - $case appFilesInfo - $of Just (True, appCID) - - _{filesMsg} - $of _ - - _{MsgCourseApplicationNoFiles} - |] - in void $ wforced filesLinkField (fslI filesMsg) Nothing - | otherwise - -> return () + when (isn't _NoUpload courseApplicationsFiles || fromMaybe False hasFiles) $ + let filesLinkField = Field{..} + where + fieldParse _ _ = return $ Right Nothing + fieldEnctype = mempty + fieldView theId _ attrs _ _ + = [whamlet| + $newline never + $case appFilesInfo + $of Just (True, appCID) + + _{filesMsg} + $of _ + + _{MsgCourseApplicationNoFiles} + |] + in void $ wforced filesLinkField (fslI filesMsg) Nothing + + when (fromMaybe False hasFiles && isn't _NoUpload courseApplicationsFiles) $ + wformMessage <=< messageIconI Info IconFileUpload $ bool MsgCourseRegistrationFilesNeedReupload MsgCourseApplicationFilesNeedReupload courseApplicationsRequired appFilesRes <- let mkFs | courseApplicationsRequired = bool MsgCourseApplicationFile MsgCourseApplicationArchive | otherwise = bool MsgCourseRegistrationFile MsgCourseRegistrationArchive @@ -177,7 +176,7 @@ postCRegisterR tid ssh csh = do = void <$> do appIds <- selectKeysList [ CourseApplicationAllocation ==. Nothing, CourseApplicationCourse ==. cid, CourseApplicationUser ==. uid ] [] appRes <- case appIds of - [] -> insertUnique $ CourseApplication cid uid crfStudyFeatures crfApplicationText Nothing Nothing Nothing Nothing cTime + [] -> insertUnique $ CourseApplication cid uid crfStudyFeatures crfApplicationText False Nothing Nothing Nothing Nothing cTime Nothing (prevId:ps) -> do forM_ ps $ \appId -> do deleteApplicationFiles appId @@ -218,8 +217,14 @@ postCRegisterR tid ssh csh = do Just _ -> addMessageIconI Success IconEnrolTrue MsgCourseRegisterOk BtnCourseDeregister -> runDB $ do deleteApplications - deleteBy $ UniqueParticipant uid cid - audit $ TransactionCourseParticipantDeleted cid uid + part <- getBy $ UniqueParticipant uid cid + forM_ part $ \(Entity partId CourseParticipant{..}) -> do + delete $ partId + audit $ TransactionCourseParticipantDeleted cid uid + + when courseParticipantAllocated $ do + now <- liftIO getCurrentTime + insert_ $ AllocationDeregister courseParticipantUser (Just courseParticipantCourse) now Nothing examRegistrations <- E.select . E.from $ \(examRegistration `E.InnerJoin` exam) -> do E.on $ examRegistration E.^. ExamRegistrationExam E.==. exam E.^. ExamId diff --git a/src/Handler/Course/Show.hs b/src/Handler/Course/Show.hs index 0eca71463..17125062d 100644 --- a/src/Handler/Course/Show.hs +++ b/src/Handler/Course/Show.hs @@ -12,7 +12,6 @@ import qualified Database.Esqueleto.Utils as E import Database.Esqueleto.Utils.TH import qualified Data.CaseInsensitive as CI -import Utils.Lens import qualified Data.Map as Map @@ -79,6 +78,10 @@ getCShowR tid ssh csh = do mRegTo <- traverse (formatTime SelFormatDateTime) $ courseRegisterTo course mDereg <- traverse (formatTime SelFormatDateTime) $ courseDeregisterUntil course mRegAt <- traverse (formatTime SelFormatDateTime) $ courseParticipantRegistration <$> registration + cID <- encrypt cid :: Handler CryptoUUIDCourse + mAllocation' <- for mAllocation $ \Allocation{..} -> (,) + <$> pure allocationName + <*> toTextUrl (AllocationR allocationTerm allocationSchool allocationShorthand AShowR :#: cID) regForm <- if | is _Just mbAid -> do (courseRegisterForm', regButton) <- courseRegisterForm (Entity cid course) diff --git a/src/Handler/Course/User.hs b/src/Handler/Course/User.hs index 798e23244..81ac54d5b 100644 --- a/src/Handler/Course/User.hs +++ b/src/Handler/Course/User.hs @@ -4,7 +4,6 @@ module Handler.Course.User import Import -import Utils.Lens import Utils.Form import Handler.Utils import Database.Esqueleto.Utils.TH diff --git a/src/Handler/Course/Users.hs b/src/Handler/Course/Users.hs index f0c0da708..0549a0745 100644 --- a/src/Handler/Course/Users.hs +++ b/src/Handler/Course/Users.hs @@ -9,7 +9,6 @@ module Handler.Course.Users import Import -import Utils.Lens import Utils.Form import Handler.Utils import Handler.Utils.Database diff --git a/src/Handler/CryptoIDDispatch.hs b/src/Handler/CryptoIDDispatch.hs index 54c2ec760..8a34cde8d 100644 --- a/src/Handler/CryptoIDDispatch.hs +++ b/src/Handler/CryptoIDDispatch.hs @@ -5,8 +5,6 @@ module Handler.CryptoIDDispatch import Import -import Data.Proxy - import qualified Data.Text as Text import Yesod.Core.Types (HandlerContents(..), ErrorResponse(..)) diff --git a/src/Handler/Exam/AddUser.hs b/src/Handler/Exam/AddUser.hs index f8e250831..7aafb58e2 100644 --- a/src/Handler/Exam/AddUser.hs +++ b/src/Handler/Exam/AddUser.hs @@ -8,8 +8,6 @@ import Handler.Exam.RegistrationInvite import Handler.Utils import Handler.Utils.Exam import Handler.Utils.Invitations - -import Utils.Lens import qualified Data.Set as Set diff --git a/src/Handler/Exam/CorrectorInvite.hs b/src/Handler/Exam/CorrectorInvite.hs index cc2882679..f8398487a 100644 --- a/src/Handler/Exam/CorrectorInvite.hs +++ b/src/Handler/Exam/CorrectorInvite.hs @@ -12,8 +12,6 @@ import Import import Handler.Utils.Invitations import Handler.Utils.Exam -import Utils.Lens - import Text.Hamlet (ihamlet) import Data.Aeson hiding (Result(..)) diff --git a/src/Handler/Exam/Edit.hs b/src/Handler/Exam/Edit.hs index 06abd7834..99bd12772 100644 --- a/src/Handler/Exam/Edit.hs +++ b/src/Handler/Exam/Edit.hs @@ -6,8 +6,6 @@ import Import import Handler.Exam.Form import Handler.Exam.CorrectorInvite -import Utils.Lens - import qualified Data.Set as Set import Handler.Utils diff --git a/src/Handler/Exam/Form.hs b/src/Handler/Exam/Form.hs index bcbde196b..503e066d4 100644 --- a/src/Handler/Exam/Form.hs +++ b/src/Handler/Exam/Form.hs @@ -8,8 +8,6 @@ module Handler.Exam.Form ) where import Import -import Utils.Lens hiding (parts) - import Handler.Exam.CorrectorInvite import Handler.Utils @@ -230,12 +228,12 @@ examPartsForm prev = wFormToAForm $ do examFormTemplate :: Entity Exam -> DB ExamForm examFormTemplate (Entity eId Exam{..}) = do - parts <- selectList [ ExamPartExam ==. eId ] [] + examParts <- selectList [ ExamPartExam ==. eId ] [] occurrences <- selectList [ ExamOccurrenceExam ==. eId ] [] correctors <- selectList [ ExamCorrectorExam ==. eId ] [] invitations <- map (\(email, InvDBDataExamCorrector) -> email) <$> sourceInvitationsList eId - parts' <- forM parts $ \(Entity pid part) -> (,) <$> encrypt pid <*> pure part + examParts' <- forM examParts $ \(Entity pid part) -> (,) <$> encrypt pid <*> pure part occurrences' <- forM occurrences $ \(Entity oid occ) -> (,) <$> encrypt oid <*> pure occ return ExamForm @@ -267,7 +265,7 @@ examFormTemplate (Entity eId Exam{..}) = do , eofDescription = examOccurrenceDescription } , efExamParts = Set.fromList $ do - (Just -> epfId, ExamPart{..}) <- parts' + (Just -> epfId, ExamPart{..}) <- examParts' return ExamPartForm { epfId , epfName = examPartName diff --git a/src/Handler/Exam/RegistrationInvite.hs b/src/Handler/Exam/RegistrationInvite.hs index 6ebcae157..2b41622b9 100644 --- a/src/Handler/Exam/RegistrationInvite.hs +++ b/src/Handler/Exam/RegistrationInvite.hs @@ -16,8 +16,6 @@ import Handler.Utils.Invitations import qualified Data.Set as Set import Text.Hamlet (ihamlet) - -import Utils.Lens import Data.Aeson hiding (Result(..)) diff --git a/src/Handler/Exam/Show.hs b/src/Handler/Exam/Show.hs index ad371d147..72c6058b4 100644 --- a/src/Handler/Exam/Show.hs +++ b/src/Handler/Exam/Show.hs @@ -5,8 +5,6 @@ module Handler.Exam.Show import Import import Handler.Exam.Register -import Utils.Lens hiding (parts) - import Data.Map ((!?)) import qualified Data.Map as Map @@ -24,7 +22,7 @@ getEShowR tid ssh csh examn = do cTime <- liftIO getCurrentTime mUid <- maybeAuthId - (Entity _ Exam{..}, parts, examVisible, (gradingVisible, gradingShown), (occurrenceAssignmentsVisible, occurrenceAssignmentsShown), results, result, occurrences, (registered, mayRegister), occurrenceNamesShown) <- runDB $ do + (Entity _ Exam{..}, examParts, examVisible, (gradingVisible, gradingShown), (occurrenceAssignmentsVisible, occurrenceAssignmentsShown), results, result, occurrences, (registered, mayRegister), occurrenceNamesShown) <- runDB $ do exam@(Entity eId Exam{..}) <- fetchExam tid ssh csh examn let examVisible = NTop (Just cTime) >= NTop examVisibleFrom @@ -35,12 +33,12 @@ getEShowR tid ssh csh examn = do let occurrenceAssignmentsVisible = NTop (Just cTime) >= NTop examPublishOccurrenceAssignments occurrenceAssignmentsShown <- or2M (return occurrenceAssignmentsVisible) . hasReadAccessTo $ CExamR tid ssh csh examn EEditR - parts <- selectList [ ExamPartExam ==. eId ] [ Asc ExamPartName ] + examParts <- selectList [ ExamPartExam ==. eId ] [ Asc ExamPartName ] resultsRaw <- for mUid $ \uid -> E.select . E.from $ \examPartResult -> do E.where_ $ examPartResult E.^. ExamPartResultUser E.==. E.val uid - E.&&. examPartResult E.^. ExamPartResultExamPart `E.in_` E.valList (map entityKey parts) + E.&&. examPartResult E.^. ExamPartResultExamPart `E.in_` E.valList (map entityKey examParts) return examPartResult let results = maybe Map.empty (\rs -> Map.fromList [ (examPartResultExamPart, res) | res@(Entity _ ExamPartResult{..}) <- rs ]) resultsRaw @@ -66,7 +64,7 @@ getEShowR tid ssh csh examn = do occurrenceNamesShown <- hasReadAccessTo $ CExamR tid ssh csh examn EEditR - return (exam, parts, examVisible, (gradingVisible, gradingShown), (occurrenceAssignmentsVisible, occurrenceAssignmentsShown), results, result, occurrences, (registered, mayRegister), occurrenceNamesShown) + return (exam, examParts, examVisible, (gradingVisible, gradingShown), (occurrenceAssignmentsVisible, occurrenceAssignmentsShown), results, result, occurrences, (registered, mayRegister), occurrenceNamesShown) let examTimes = all (\(Entity _ ExamOccurrence{..}, _) -> Just examOccurrenceStart == examStart && examOccurrenceEnd == examEnd) occurrences registerWidget diff --git a/src/Handler/Exam/Users.hs b/src/Handler/Exam/Users.hs index 35a8842a4..6bd06b1b5 100644 --- a/src/Handler/Exam/Users.hs +++ b/src/Handler/Exam/Users.hs @@ -6,7 +6,6 @@ module Handler.Exam.Users import Import -import Utils.Lens import Handler.Utils import Handler.Utils.Exam import Handler.Utils.Table.Columns @@ -16,18 +15,18 @@ import Handler.Utils.Csv import qualified Database.Esqueleto as E import qualified Database.Esqueleto.Utils as E import Database.Esqueleto.Utils.TH - + import qualified Data.Csv as Csv - + import Data.Map ((!)) import qualified Data.Map as Map import qualified Data.Set as Set - + import qualified Data.Text as Text import qualified Data.Text.Lens as Text - + import qualified Data.Conduit.List as C - + import qualified Data.CaseInsensitive as CI import Numeric.Lens (integral) @@ -109,7 +108,7 @@ data ExamUserTableCsv = ExamUserTableCsv , csvEUserExerciseNumPasses :: Maybe Int , csvEUserExercisePointsMax :: Maybe Points , csvEUserExerciseNumPassesMax :: Maybe Int - , csvEUserExamResult :: Maybe (Either ExamResultPassed ExamResultGrade) + , csvEUserExamResult :: Maybe ExamResultPassedGrade , csvEUserCourseNote :: Maybe Html } deriving (Generic) @@ -209,7 +208,7 @@ data ExamUserCsvAction } | ExamUserCsvSetResultData { examUserCsvActUser :: UserId - , examUserCsvActExamResult :: Maybe (Either ExamResultPassed ExamResultGrade) + , examUserCsvActExamResult :: Maybe ExamResultPassedGrade } | ExamUserCsvSetCourseNoteData { examUserCsvActUser :: UserId @@ -244,8 +243,8 @@ postEUsersR tid ssh csh examn = do showPasses = numSheetsPasses allBoni /= 0 showPoints = getSum (numSheetsPoints allBoni) /= 0 - resultView :: ExamResultGrade -> Either ExamResultPassed ExamResultGrade - resultView = bool (Left . over _examResult (view passingGrade)) Right examShowGrades + resultView :: ExamResultGrade -> ExamResultPassedGrade + resultView = fmap $ bool (Left . view passingGrade) Right examShowGrades let examUsersDBTable = DBTable{..} @@ -320,7 +319,7 @@ postEUsersR tid ssh csh examn = do criteria'' | ExamAttended (ExamPassed True) `Set.member` criteria = criteria' `Set.union` Set.fromList passed - | otherwise + | otherwise = criteria' in queryExamResult row E.?. ExamResultResult `E.in_` E.valList (Just <$> Set.toList criteria'') ) @@ -431,7 +430,7 @@ postEUsersR tid ssh csh examn = do ExamUserCsvCourseRegister -> DBCsvActionNew ExamUserCsvRegister -> DBCsvActionNew ExamUserCsvDeregister -> DBCsvActionMissing - _other -> DBCsvActionExisting + _other -> DBCsvActionExisting , dbtCsvExecuteActions = do C.mapM_ $ \case ExamUserCsvCourseRegisterData{..} -> do @@ -471,7 +470,7 @@ postEUsersR tid ssh csh examn = do deleteBy $ UniqueExamResult eid examUserCsvActUser audit $ TransactionExamResultDeleted eid examUserCsvActUser Just res -> do - let res' = either (over _examResult $ review passingGrade) id res + let res' = either (review passingGrade) id <$> res now <- liftIO getCurrentTime void $ upsertBy (UniqueExamResult eid examUserCsvActUser) @@ -496,7 +495,7 @@ postEUsersR tid ssh csh examn = do ExamUserCsvSetCourseNoteData{ examUserCsvActCourseNote = Just note, .. } -> do now <- liftIO getCurrentTime uid <- liftHandlerT requireAuthId - Entity nid _ <- upsert (CourseUserNote examCourse examUserCsvActUser note) [ CourseUserNoteNote =. note ] + Entity nid _ <- upsert (CourseUserNote examCourse examUserCsvActUser note) [ CourseUserNoteNote =. note ] insert_ $ CourseUserNoteEdit uid now nid return $ CExamR tid ssh csh examn EUsersR , dbtCsvRenderKey = \(registeredUserName -> registeredUserName') -> \case @@ -550,11 +549,7 @@ postEUsersR tid ssh csh examn = do $newline never ^{nameWidget userDisplayName userSurname} $maybe newResult <- examUserCsvActExamResult - $case newResult - $of Left pResult - , _{pResult} - $of Right gResult - , _{gResult} + , _{newResult} $nothing , _{MsgExamResultNone} |] @@ -579,12 +574,12 @@ postEUsersR tid ssh csh examn = do $newline never _{StudyDegreeTerm degree terms}, _{MsgStudyFeatureAge} #{studyFeaturesSemester} |] - + registeredUserName :: Map (E.Value ExamRegistrationId) ExamUserTableData -> ExamRegistrationId -> Widget registeredUserName existing (E.Value -> registration) = nameWidget userDisplayName userSurname where Entity _ User{..} = view resultUser $ existing ! registration - + guessUser :: ExamUserTableCsv -> DB (Bool, UserId) guessUser ExamUserTableCsv{..} = $cachedHereBinary (csvEUserMatriculation, csvEUserName, csvEUserSurname) $ do users <- E.select . E.from $ \user -> do @@ -617,30 +612,40 @@ postEUsersR tid ssh csh examn = do lookupStudyFeatures :: ExamUserTableCsv -> DB (Maybe StudyFeaturesId) lookupStudyFeatures csv@ExamUserTableCsv{..} = do uid <- view _2 <$> guessUser csv - studyFeatures <- E.select . E.from $ \(studyFeatures `E.InnerJoin` studyDegree `E.InnerJoin` studyTerms) -> do - E.on $ studyTerms E.^. StudyTermsId E.==. studyFeatures E.^. StudyFeaturesField - E.on $ studyDegree E.^. StudyDegreeId E.==. studyFeatures E.^. StudyFeaturesDegree - E.where_ . E.and $ catMaybes - [ do - field <- csvEUserField - return . E.or $ catMaybes - [ Just $ studyTerms E.^. StudyTermsName `E.ciEq` E.just (E.val field) - , Just $ studyTerms E.^. StudyTermsShorthand `E.ciEq` E.just (E.val field) - , (studyTerms E.^. StudyTermsKey E.==.) . E.val <$> readMay field - ] - , do - degree <- csvEUserDegree - return . E.or $ catMaybes - [ Just $ studyDegree E.^. StudyDegreeName `E.ciEq` E.just (E.val degree) - , Just $ studyDegree E.^. StudyDegreeShorthand `E.ciEq` E.just (E.val degree) - , (studyDegree E.^. StudyDegreeKey E.==.) . E.val <$> readMay degree - ] - , (studyFeatures E.^. StudyFeaturesSemester E.==.) . E.val <$> csvEUserSemester - ] - E.where_ $ studyFeatures E.^. StudyFeaturesUser E.==. E.val uid - E.&&. studyFeatures E.^. StudyFeaturesValid E.==. E.val True - E.limit 2 - return $ studyFeatures E.^. StudyFeaturesId + oldFeatures <- getBy $ UniqueParticipant uid examCourse + studyFeatures <- E.select . E.from $ \(studyFeatures `E.InnerJoin` studyDegree `E.InnerJoin` studyTerms) -> + E.distinctOnOrderBy [ E.asc (studyFeatures E.^. StudyFeaturesField) + , E.asc (studyFeatures E.^. StudyFeaturesDegree) + , E.asc (studyFeatures E.^. StudyFeaturesSemester)] $ do + E.on $ studyTerms E.^. StudyTermsId E.==. studyFeatures E.^. StudyFeaturesField + E.on $ studyDegree E.^. StudyDegreeId E.==. studyFeatures E.^. StudyFeaturesDegree + E.where_ . E.and $ catMaybes + [ do + field <- csvEUserField + return . E.or $ catMaybes + [ Just $ studyTerms E.^. StudyTermsName `E.ciEq` E.just (E.val field) + , Just $ studyTerms E.^. StudyTermsShorthand `E.ciEq` E.just (E.val field) + , (studyTerms E.^. StudyTermsKey E.==.) . E.val <$> readMay field + ] + , do + degree <- csvEUserDegree + return . E.or $ catMaybes + [ Just $ studyDegree E.^. StudyDegreeName `E.ciEq` E.just (E.val degree) + , Just $ studyDegree E.^. StudyDegreeShorthand `E.ciEq` E.just (E.val degree) + , (studyDegree E.^. StudyDegreeKey E.==.) . E.val <$> readMay degree + ] + , (studyFeatures E.^. StudyFeaturesSemester E.==.) . E.val <$> csvEUserSemester + ] + E.where_ $ studyFeatures E.^. StudyFeaturesUser E.==. E.val uid + let isActive = studyFeatures E.^. StudyFeaturesValid E.==. E.val True + isActiveOrPrevious = case oldFeatures of + Just (Entity _ CourseParticipant{courseParticipantField = Just sfid}) + -> isActive E.||. (E.val sfid E.==. studyFeatures E.^. StudyFeaturesId) + _ -> isActive + E.where_ isActiveOrPrevious -- either active studyFeature or the one previously associated with this course + E.orderBy [E.desc isActiveOrPrevious, E.asc (E.orderByOrd $ studyFeatures E.^. StudyFeaturesType)] + E.limit 2 -- we just need to know whether there is a unique one, none, or more than one + return $ studyFeatures E.^. StudyFeaturesId case studyFeatures of [E.Value fid] -> return $ Just fid _other @@ -648,6 +653,11 @@ postEUsersR tid ssh csh examn = do , is _Nothing csvEUserDegree , is _Nothing csvEUserSemester -> return Nothing + _other + | Just (Entity _ CourseParticipant{..}) <- oldFeatures + , Just sfid <- courseParticipantField + , E.Value sfid `elem` studyFeatures + -> return Nothing _other -> throwM ExamUserCsvExceptionNoMatchingStudyFeatures examUsersDBTableValidator = def & defaultSorting [SortAscBy "user-name"] diff --git a/src/Handler/Health.hs b/src/Handler/Health.hs index 36649a436..dad7ef747 100644 --- a/src/Handler/Health.hs +++ b/src/Handler/Health.hs @@ -5,8 +5,6 @@ import Import import qualified Data.Aeson.Encode.Pretty as Aeson import qualified Data.Text.Lazy.Builder as Builder -import Utils.Lens - import qualified Data.UUID as UUID import Data.Semigroup (Min(..), Max(..)) diff --git a/src/Handler/Home.hs b/src/Handler/Home.hs index b4d16ff10..30beb116a 100644 --- a/src/Handler/Home.hs +++ b/src/Handler/Home.hs @@ -2,7 +2,6 @@ module Handler.Home where import Import -import Utils.Lens import Handler.Utils import Handler.Utils.Table.Cells @@ -15,78 +14,16 @@ import qualified Database.Esqueleto.Utils as E getHomeR :: Handler Html getHomeR = do muid <- maybeAuthId - upcomingExamsWidget <- for muid $ runDB . homeUpcomingExams defaultLayout $ do setTitleI MsgHomeHeading - fromMaybe mempty upcomingExamsWidget - maybe mempty homeUpcomingSheets muid - homeOpenCourses + case muid of + Just uid -> do + homeUpcomingExams uid + homeUpcomingSheets uid + Nothing -> + $(i18nWidgetFile "unauth-home") -homeOpenCourses :: Widget -homeOpenCourses = do - cTime <- liftIO getCurrentTime - let tableData :: E.SqlExpr (Entity Course) - -> E.SqlQuery (E.SqlExpr (Entity Course)) - tableData course = do - E.where_ $ E.not_ (E.isNothing $ course E.^. CourseRegisterFrom) -- DO: do this with isAuthorized in dbtProj - E.&&. (course E.^. CourseRegisterFrom E.<=. E.val (Just cTime)) - E.&&. ( E.isNothing (course E.^. CourseRegisterTo) - E.||. course E.^. CourseRegisterTo E.>=. E.val (Just cTime) - ) - return course - - colonnade :: Colonnade Sortable (DBRow (Entity Course)) (DBCell (HandlerT UniWorX IO) ()) - colonnade = mconcat - [ -- dbRow - sortable (Just "term") (i18nCell MsgTerm) - $ \DBRow{ dbrOutput=Entity{entityVal = Course{..}} } -> - anchorCell (TermCourseListR courseTerm) [whamlet|#{courseTerm}|] - , sortable (Just "schoolshort") (i18nCell MsgCourseSchoolShort) - $ \DBRow{ dbrOutput=(Entity _ Course{..}) } -> - anchorCell (TermSchoolCourseListR courseTerm courseSchool) [whamlet|_{unSchoolKey courseSchool}|] - , sortable (Just "course") (i18nCell MsgCourse) $ \DBRow{ dbrOutput=Entity{entityVal = course} } -> do - let tid = courseTerm course - ssh = courseSchool course - csh = courseShorthand course - anchorCell (CourseR tid ssh csh CShowR) csh - , sortable (Just "deadline") (i18nCell MsgRegisterTo) $ \DBRow{ dbrOutput=Entity{entityVal = course} } -> - cell $ traverse (formatTime SelFormatDateTime) (courseRegisterTo course) >>= maybe mempty toWidget - ] - courseTable <- liftHandlerT . runDB $ dbTableWidget' def DBTable - { dbtSQLQuery = tableData - , dbtRowKey = (E.^. CourseId) - , dbtColonnade = colonnade - , dbtProj = return - , dbtSorting = Map.fromList - [ ( "term" - , SortColumn $ \course -> course E.^. CourseTerm - ) - , ( "schoolshort" - , SortColumn $ \course -> course E.^. CourseSchool - ) - , ( "course" - , SortColumn $ \course -> course E.^. CourseShorthand - ) - , ( "deadline" - , SortColumn $ \course -> course E.^. CourseRegisterTo - ) - ] - , dbtFilter = mempty {- [ ( "term" - , FilterColumn $ \(course `E.InnerJoin` _ `E.InnerJoin` _ ) tids -> if - | Set.null tids -> E.val True :: E.SqlExpr (E.Value Bool) - | otherwise -> course E.^. CourseTerm `E.in_` E.valList (Set.toList tids) - ) - ] -} - , dbtFilterUI = mempty - , dbtStyle = def - , dbtParams = def - , dbtIdent = "open-courses" :: Text - , dbtCsvEncode = noCsvEncode - , dbtCsvDecode = Nothing - } - $(widgetFile "home/openCourses") - homeUpcomingSheets :: UserId -> Widget homeUpcomingSheets uid = do cTime <- liftIO getCurrentTime @@ -189,134 +126,137 @@ homeUpcomingSheets uid = do $(widgetFile "home/upcomingSheets") - -homeUpcomingExams :: UserId -> DB Widget +homeUpcomingExams :: UserId -> Widget homeUpcomingExams uid = do now <- liftIO getCurrentTime - let fortnight = addWeeks 2 now - let -- code copied and slightly adapted from Handler.Course.getCShowR: - examDBTable = DBTable{..} - where - -- for ease of refactoring: - queryCourse = $(sqlIJproj 2 1) . $(sqlLOJproj 3 1) - queryExam = $(sqlIJproj 2 2) . $(sqlLOJproj 3 1) - lensCourse = _1 - lensExam = _2 - lensRegister = _3 . _Just - lensOccurrence = _4 . _Just + ((Any hasExams, examTable), warningDays) <- liftHandlerT . runDB $ do + User {userWarningDays} <- get404 uid + let fortnight = addUTCTime userWarningDays now + let -- code copied and slightly adapted from Handler.Course.getCShowR: + examDBTable = DBTable{..} + where + -- for ease of refactoring: + queryCourse = $(sqlIJproj 2 1) . $(sqlLOJproj 3 1) + queryExam = $(sqlIJproj 2 2) . $(sqlLOJproj 3 1) + lensCourse = _1 + lensExam = _2 + lensRegister = _3 . _Just + lensOccurrence = _4 . _Just - dbtSQLQuery ((course `E.InnerJoin` exam) `E.LeftOuterJoin` register `E.LeftOuterJoin` occurrence) = do - E.on $ register E.?. ExamRegistrationOccurrence E.==. E.just (occurrence E.?. ExamOccurrenceId) - E.on $ register E.?. ExamRegistrationExam E.==. E.just (exam E.^. ExamId) - E.&&. register E.?. ExamRegistrationUser E.==. E.just (E.val uid) - E.on $ course E.^. CourseId E.==. exam E.^. ExamCourse - E.where_ $ E.exists $ E.from $ \participant -> - E.where_ $ participant E.^. CourseParticipantUser E.==. E.val uid - E.&&. participant E.^. CourseParticipantCourse E.==. course E.^. CourseId - let regToWithinFortnight = exam E.^. ExamRegisterTo E.<=. E.just (E.val fortnight) - E.&&. exam E.^. ExamRegisterTo E.>=. E.just (E.val now) - E.&&. E.isNothing (register E.?. ExamRegistrationId) - startExamFortnight = exam E.^. ExamStart E.<=. E.just (E.val fortnight) - E.&&. exam E.^. ExamStart E.>=. E.just (E.val now) - E.&&. E.isJust (register E.?. ExamRegistrationId) - startOccurFortnight = occurrence E.?. ExamOccurrenceStart E.<=. E.just (E.val fortnight) - E.&&. occurrence E.?. ExamOccurrenceStart E.>=. E.just (E.val now) - E.&&. E.isJust (register E.?. ExamRegistrationId) - earliestOccurrence = E.sub_select $ E.from $ \occ -> do - E.where_ $ occ E.^. ExamOccurrenceExam E.==. exam E.^. ExamId - E.&&. occ E.^. ExamOccurrenceStart E.>=. E.val now - return $ E.min_ $ occ E.^. ExamOccurrenceStart - startEarliest = E.isNothing (occurrence E.?. ExamOccurrenceId) - E.&&. earliestOccurrence E.<=. E.just (E.val fortnight) - -- E.&&. earliestOccurrence E.>=. E.just (E.val now) - E.where_ $ regToWithinFortnight E.||. startExamFortnight E.||. startOccurFortnight E.||. startEarliest - return (course, exam, register, occurrence) - dbtRowKey = queryExam >>> (E.^. ExamId) - dbtProj r@DBRow{ dbrOutput } = do - let Entity _ Exam{..} = view lensExam dbrOutput - Entity _ Course{..} = view lensCourse dbrOutput - guardM . hasReadAccessTo $ CExamR courseTerm courseSchool courseShorthand examName EShowR -- check access rights - return r - dbtColonnade = dbColonnade $ mconcat - [ sortable (Just "term") (i18nCell MsgTerm) $ \DBRow{ dbrOutput = view lensCourse -> Entity _ Course{..} } -> - msgCell courseTerm - , sortable (Just "school") (i18nCell MsgCourseSchool) $ \DBRow{ dbrOutput = view lensCourse -> Entity _ Course{..} } -> - msgCell courseSchool - , sortable (Just "course") (i18nCell MsgCourse) $ \DBRow{ dbrOutput = view lensCourse -> Entity _ Course{..} } -> - anchorCell (CourseR courseTerm courseSchool courseShorthand CShowR) (toWgt courseShorthand) - -- continue here - , sortable (Just "name") (i18nCell MsgExamName) $ \DBRow{ dbrOutput } -> do - let Entity _ Exam{..} = view lensExam dbrOutput - Entity _ Course{..} = view lensCourse dbrOutput - indicatorCell <> anchorCell (CExamR courseTerm courseSchool courseShorthand examName EShowR) examName - , sortable (Just "register-from") (i18nCell MsgExamRegisterFrom) $ \DBRow { dbrOutput = view lensExam -> Entity _ Exam{..} } -> maybe mempty dateTimeCell examRegisterFrom - , sortable (Just "register-to") (i18nCell MsgExamRegisterTo) $ \DBRow { dbrOutput = view lensExam -> Entity _ Exam{..} } -> maybe mempty dateTimeCell examRegisterTo - , sortable (Just "time") (i18nCell MsgExamTime) $ \DBRow{ dbrOutput } -> - if | Just (Entity _ ExamOccurrence{..}) <- preview lensOccurrence dbrOutput - -> cell $ formatTimeRangeW SelFormatDateTime examOccurrenceStart examOccurrenceEnd - | Entity _ Exam{..} <- view lensExam dbrOutput - , Just start <- examStart -> cell $ formatTimeRangeW SelFormatDateTime start examEnd - | otherwise -> mempty - {- NOTE: We do not want thoughtless exam registrations, since many people click "register" and don't show up, causing logistic problems. - Hence we force them here to click twice. Maybe add a captcha where users have to distinguish pictures showing pink elephants and course lecturers. - , sortable Nothing mempty $ \DBRow{ dbrOutput } -> sqlCell $ do - let Entity eId Exam{..} = view lensExam dbrOutput - Entity _ Course{..} = view lensCourse dbrOutput - mayRegister <- (== Authorized) <$> evalAccessDB (CExamR courseTerm courseSchool courseShorthand examName ERegisterR) True - isRegistered <- existsBy $ UniqueExamRegistration eId uid - if - | mayRegister -> do - (examRegisterForm, examRegisterEnctype) <- liftHandlerT . generateFormPost . buttonForm' $ bool [BtnRegister] [BtnDeregister] isRegistered - return $ wrapForm examRegisterForm def - { formAction = Just . SomeRoute $ CExamR courseTerm courseSchool courseShorthand examName ERegisterR - , formEncoding = examRegisterEnctype - , formSubmit = FormNoSubmit - } - | isRegistered -> return [whamlet|_{MsgExamRegistered}|] - | otherwise -> return mempty - -} - , sortable (Just "registered") (i18nCell MsgExamRegistration ) $ \DBRow{ dbrOutput } -> sqlCell $ do - let Entity _ Exam{..} = view lensExam dbrOutput - Entity _ Course{..} = view lensCourse dbrOutput - mayRegister <- (== Authorized) <$> evalAccessDB (CExamR courseTerm courseSchool courseShorthand examName ERegisterR) True - let isRegistered = has lensRegister dbrOutput - label = bool MsgExamNotRegistered MsgExamRegistered isRegistered - examUrl = CExamR courseTerm courseSchool courseShorthand examName EShowR - if | mayRegister -> return $ simpleLinkI (SomeMessage label) examUrl - | otherwise -> return [whamlet|_{label}|] - , sortable (toNothingS "occurrence") (i18nCell MsgExamOccurrence) $ \DBRow{ dbrOutput } -> - if | Just (Entity _ ExamOccurrence{..}) <- preview lensOccurrence dbrOutput - -> textCell examOccurrenceRoom - | otherwise -> mempty - ] - dbtSorting = Map.fromList - [ ("demo-both", SortColumn $ queryCourse &&& queryExam >>> (\(_course,exam)-> exam E.^. ExamName)) - , ("term", SortColumn $ queryCourse >>> (E.^. CourseTerm )) - , ("school", SortColumn $ queryCourse >>> (E.^. CourseSchool )) - , ("course", SortColumn $ queryCourse >>> (E.^. CourseShorthand )) - , ("name", SortColumn $ queryExam >>> (E.^. ExamName )) - , ("time", SortColumn $ queryExam >>> (E.^. ExamStart )) - , ("register-from", SortColumn $ queryExam >>> (E.^. ExamRegisterFrom )) - , ("register-to", SortColumn $ queryExam >>> (E.^. ExamRegisterTo )) - , ("visible", SortColumn $ queryExam >>> (E.^. ExamVisibleFrom )) - , ("registered", SortColumn $ queryExam >>> (\exam -> - E.exists $ E.from $ \registration -> do - E.where_ $ registration E.^. ExamRegistrationUser E.==. E.val uid - E.where_ $ registration E.^. ExamRegistrationExam E.==. exam E.^. ExamId - )) - ] - dbtFilter = Map.empty - dbtFilterUI = const mempty - dbtStyle = def - dbtParams = def - dbtIdent :: Text - dbtIdent = "exams" - dbtCsvEncode = noCsvEncode - dbtCsvDecode = Nothing + dbtSQLQuery ((course `E.InnerJoin` exam) `E.LeftOuterJoin` register `E.LeftOuterJoin` occurrence) = do + E.on $ register E.?. ExamRegistrationOccurrence E.==. E.just (occurrence E.?. ExamOccurrenceId) + E.on $ register E.?. ExamRegistrationExam E.==. E.just (exam E.^. ExamId) + E.&&. register E.?. ExamRegistrationUser E.==. E.just (E.val uid) + E.on $ course E.^. CourseId E.==. exam E.^. ExamCourse + E.where_ $ E.exists $ E.from $ \participant -> + E.where_ $ participant E.^. CourseParticipantUser E.==. E.val uid + E.&&. participant E.^. CourseParticipantCourse E.==. course E.^. CourseId + let regToWithinFortnight = exam E.^. ExamRegisterTo E.<=. E.just (E.val fortnight) + E.&&. exam E.^. ExamRegisterTo E.>=. E.just (E.val now) + E.&&. E.isNothing (register E.?. ExamRegistrationId) + startExamFortnight = exam E.^. ExamStart E.<=. E.just (E.val fortnight) + E.&&. exam E.^. ExamStart E.>=. E.just (E.val now) + E.&&. E.isJust (register E.?. ExamRegistrationId) + startOccurFortnight = occurrence E.?. ExamOccurrenceStart E.<=. E.just (E.val fortnight) + E.&&. occurrence E.?. ExamOccurrenceStart E.>=. E.just (E.val now) + E.&&. E.isJust (register E.?. ExamRegistrationId) + earliestOccurrence = E.sub_select $ E.from $ \occ -> do + E.where_ $ occ E.^. ExamOccurrenceExam E.==. exam E.^. ExamId + E.&&. occ E.^. ExamOccurrenceStart E.>=. E.val now + return $ E.min_ $ occ E.^. ExamOccurrenceStart + startEarliest = E.isNothing (occurrence E.?. ExamOccurrenceId) + E.&&. earliestOccurrence E.<=. E.just (E.val fortnight) + -- E.&&. earliestOccurrence E.>=. E.just (E.val now) + E.where_ $ regToWithinFortnight E.||. startExamFortnight E.||. startOccurFortnight E.||. startEarliest + return (course, exam, register, occurrence) + dbtRowKey = queryExam >>> (E.^. ExamId) + dbtProj r@DBRow{ dbrOutput } = do + let Entity _ Exam{..} = view lensExam dbrOutput + Entity _ Course{..} = view lensCourse dbrOutput + guardM . hasReadAccessTo $ CExamR courseTerm courseSchool courseShorthand examName EShowR -- check access rights + return r + dbtColonnade = dbColonnade $ mconcat + [ sortable (Just "term") (i18nCell MsgTerm) $ \DBRow{ dbrOutput = view lensCourse -> Entity _ Course{..} } -> + msgCell courseTerm + , sortable (Just "school") (i18nCell MsgCourseSchool) $ \DBRow{ dbrOutput = view lensCourse -> Entity _ Course{..} } -> + msgCell courseSchool + , sortable (Just "course") (i18nCell MsgCourse) $ \DBRow{ dbrOutput = view lensCourse -> Entity _ Course{..} } -> + anchorCell (CourseR courseTerm courseSchool courseShorthand CShowR) (toWgt courseShorthand) + -- continue here + , sortable (Just "name") (i18nCell MsgExamName) $ \DBRow{ dbrOutput } -> do + let Entity _ Exam{..} = view lensExam dbrOutput + Entity _ Course{..} = view lensCourse dbrOutput + indicatorCell <> anchorCell (CExamR courseTerm courseSchool courseShorthand examName EShowR) examName + , sortable (Just "register-from") (i18nCell MsgExamRegisterFrom) $ \DBRow { dbrOutput = view lensExam -> Entity _ Exam{..} } -> maybe mempty dateTimeCell examRegisterFrom + , sortable (Just "register-to") (i18nCell MsgExamRegisterTo) $ \DBRow { dbrOutput = view lensExam -> Entity _ Exam{..} } -> maybe mempty dateTimeCell examRegisterTo + , sortable (Just "time") (i18nCell MsgExamTime) $ \DBRow{ dbrOutput } -> + if | Just (Entity _ ExamOccurrence{..}) <- preview lensOccurrence dbrOutput + -> cell $ formatTimeRangeW SelFormatDateTime examOccurrenceStart examOccurrenceEnd + | Entity _ Exam{..} <- view lensExam dbrOutput + , Just start <- examStart -> cell $ formatTimeRangeW SelFormatDateTime start examEnd + | otherwise -> mempty + {- NOTE: We do not want thoughtless exam registrations, since many people click "register" and don't show up, causing logistic problems. + Hence we force them here to click twice. Maybe add a captcha where users have to distinguish pictures showing pink elephants and course lecturers. + , sortable Nothing mempty $ \DBRow{ dbrOutput } -> sqlCell $ do + let Entity eId Exam{..} = view lensExam dbrOutput + Entity _ Course{..} = view lensCourse dbrOutput + mayRegister <- (== Authorized) <$> evalAccessDB (CExamR courseTerm courseSchool courseShorthand examName ERegisterR) True + isRegistered <- existsBy $ UniqueExamRegistration eId uid + if + | mayRegister -> do + (examRegisterForm, examRegisterEnctype) <- liftHandlerT . generateFormPost . buttonForm' $ bool [BtnRegister] [BtnDeregister] isRegistered + return $ wrapForm examRegisterForm def + { formAction = Just . SomeRoute $ CExamR courseTerm courseSchool courseShorthand examName ERegisterR + , formEncoding = examRegisterEnctype + , formSubmit = FormNoSubmit + } + | isRegistered -> return [whamlet|_{MsgExamRegistered}|] + | otherwise -> return mempty + -} + , sortable (Just "registered") (i18nCell MsgExamRegistration ) $ \DBRow{ dbrOutput } -> sqlCell $ do + let Entity _ Exam{..} = view lensExam dbrOutput + Entity _ Course{..} = view lensCourse dbrOutput + mayRegister <- (== Authorized) <$> evalAccessDB (CExamR courseTerm courseSchool courseShorthand examName ERegisterR) True + let isRegistered = has lensRegister dbrOutput + label = bool MsgExamNotRegistered MsgExamRegistered isRegistered + examUrl = CExamR courseTerm courseSchool courseShorthand examName EShowR + if | mayRegister -> return $ simpleLinkI (SomeMessage label) examUrl + | otherwise -> return [whamlet|_{label}|] + , sortable (toNothingS "occurrence") (i18nCell MsgExamOccurrence) $ \DBRow{ dbrOutput } -> + if | Just (Entity _ ExamOccurrence{..}) <- preview lensOccurrence dbrOutput + -> textCell examOccurrenceRoom + | otherwise -> mempty + ] + dbtSorting = Map.fromList + [ ("demo-both", SortColumn $ queryCourse &&& queryExam >>> (\(_course,exam)-> exam E.^. ExamName)) + , ("term", SortColumn $ queryCourse >>> (E.^. CourseTerm )) + , ("school", SortColumn $ queryCourse >>> (E.^. CourseSchool )) + , ("course", SortColumn $ queryCourse >>> (E.^. CourseShorthand )) + , ("name", SortColumn $ queryExam >>> (E.^. ExamName )) + , ("time", SortColumn $ queryExam >>> (E.^. ExamStart )) + , ("register-from", SortColumn $ queryExam >>> (E.^. ExamRegisterFrom )) + , ("register-to", SortColumn $ queryExam >>> (E.^. ExamRegisterTo )) + , ("visible", SortColumn $ queryExam >>> (E.^. ExamVisibleFrom )) + , ("registered", SortColumn $ queryExam >>> (\exam -> + E.exists $ E.from $ \registration -> do + E.where_ $ registration E.^. ExamRegistrationUser E.==. E.val uid + E.where_ $ registration E.^. ExamRegistrationExam E.==. exam E.^. ExamId + )) + ] + dbtFilter = Map.empty + dbtFilterUI = const mempty + dbtStyle = def + dbtParams = def + dbtIdent :: Text + dbtIdent = "exams" + dbtCsvEncode = noCsvEncode + dbtCsvDecode = Nothing - examDBTableValidator = def - & defaultSorting [SortAscBy "time"] - (Any hasExams, examTable) <- dbTable examDBTableValidator examDBTable - return $(widgetFile "home/upcomingExams") + examDBTableValidator = def + & defaultSorting [SortAscBy "time"] + + (, userWarningDays) <$> dbTable examDBTableValidator examDBTable + + $(widgetFile "home/upcomingExams") diff --git a/src/Handler/Material.hs b/src/Handler/Material.hs index d0abf6824..025b0c9bc 100644 --- a/src/Handler/Material.hs +++ b/src/Handler/Material.hs @@ -14,7 +14,6 @@ import qualified Data.Conduit.List as C import qualified Database.Esqueleto as E import Database.Esqueleto.Utils.TH -import Utils.Lens import Utils.Form import Handler.Utils import Handler.Utils.Delete diff --git a/src/Handler/Profile.hs b/src/Handler/Profile.hs index e871575dc..11b9728a3 100644 --- a/src/Handler/Profile.hs +++ b/src/Handler/Profile.hs @@ -5,7 +5,6 @@ import Import import Handler.Utils import Handler.Utils.Table.Cells -import Utils.Lens -- import Colonnade hiding (fromMaybe, singleton) -- import Yesod.Colonnade import Data.Monoid (Any(..)) @@ -25,6 +24,7 @@ data SettingsForm = SettingsForm , stgDate :: DateTimeFormat , stgTime :: DateTimeFormat , stgDownloadFiles :: Bool + , stgWarningDays :: NominalDiffTime , stgNotificationSettings :: NotificationSettings } @@ -51,6 +51,9 @@ makeSettingForm template html = do <*> apopt checkBoxField (fslI MsgDownloadFiles & setTooltip MsgDownloadFilesTip ) (stgDownloadFiles <$> template) + <*> areq daysField (fslI MsgWarningDays + & setTooltip MsgWarningDaysTip + ) (stgWarningDays <$> template) <* aformSection MsgFormNotifications <*> notificationForm (stgNotificationSettings <$> template) return (result, widget) -- no validation required here @@ -182,6 +185,7 @@ postProfileR = do , stgTime = userTimeFormat , stgDownloadFiles = userDownloadFiles , stgNotificationSettings = userNotificationSettings + , stgWarningDays = userWarningDays } ((res,formWidget), formEnctype) <- runFormPost . identifyForm ProfileSettings $ makeSettingForm settingsTemplate @@ -193,6 +197,7 @@ postProfileR = do , UserDateFormat =. stgDate , UserTimeFormat =. stgTime , UserDownloadFiles =. stgDownloadFiles + , UserWarningDays =. stgWarningDays , UserNotificationSettings =. stgNotificationSettings ] when (stgMaxFavourties < userMaxFavourites) $ do diff --git a/src/Handler/Sheet.hs b/src/Handler/Sheet.hs index 4a5cccef9..5ee6ba68f 100644 --- a/src/Handler/Sheet.hs +++ b/src/Handler/Sheet.hs @@ -49,11 +49,6 @@ import Data.Map (Map, (!)) import Data.Monoid (Any(..)) --- import Control.Lens -import Utils.Lens - ---import qualified Data.Aeson as Aeson - import Control.Monad.Random.Class (MonadRandom(..)) import Utils.Sql @@ -186,7 +181,7 @@ getSheetListR tid ssh csh = do let hasSFT :: (E.Value Bool, E.Value Bool, E.Value Bool, E.Value Bool) -> [SheetFileType] hasSFT (E.Value hasExercise, E.Value hasHint, E.Value hasSolution, E.Value hasMarking) - = [ sft | sft <- [minBound..maxBound] + = [ sft | sft <- universeF , sft /= SheetExercise || hasExercise , sft /= SheetHint || hasHint , sft /= SheetSolution || hasSolution @@ -204,7 +199,7 @@ getSheetListR tid ssh csh = do E.where_ $ sheet E.^. SheetCourse E.==. E.val cid sheetFilter :: SheetName -> DB Bool - sheetFilter sheetName = (== Authorized) <$> evalAccessDB (CSheetR tid ssh csh sheetName SShowR) False + sheetFilter sheetName = hasReadAccessTo $ CSheetR tid ssh csh sheetName SShowR sheetCol = widgetColonnade . mconcat $ [ -- dbRow , @@ -220,9 +215,9 @@ getSheetListR tid ssh csh = do | let existingSFTs = hasSFT existFiles , sft <- [minBound..maxBound] , let link = CSheetR tid ssh csh sheetName $ SZipR sft - , let icn = toWidget $ sheetFile2markup sft + , let icn = toWgt $ sheetFile2markup sft , let icnCell = if sft `elem` existingSFTs - then linkEmptyCell link icn + then linkEitherCell link (icn, [whamlet| |]) else spacerCell ] id & cellAttrs <>~ [("class","list--inline list--space-separated")] , sortable (Just "submission-since") (i18nCell MsgSheetActiveFrom) @@ -726,7 +721,7 @@ correctorForm shid = wFormToAForm $ do -- when (not (Map.null loads) && applyDefaultLoads) $ -- Alert Message -- addMessageI Warning MsgCorrectorsDefaulted when (not (Map.null loads) && applyDefaultLoads) $ -- Alert Notification - wformMessage =<< messageI Warning MsgCorrectorsDefaulted + wformMessage =<< messageIconI Warning IconNoCorrectors MsgCorrectorsDefaulted let diff --git a/src/Handler/Submission.hs b/src/Handler/Submission.hs index 0d2268d24..1d14a8d9f 100644 --- a/src/Handler/Submission.hs +++ b/src/Handler/Submission.hs @@ -6,8 +6,6 @@ import Import import Jobs -import Utils.Lens - -- import Yesod.Form.Bootstrap3 import Handler.Utils diff --git a/src/Handler/SystemMessage.hs b/src/Handler/SystemMessage.hs index ae1c7f757..b2c7ef90f 100644 --- a/src/Handler/SystemMessage.hs +++ b/src/Handler/SystemMessage.hs @@ -11,8 +11,6 @@ import qualified Data.List.NonEmpty as NonEmpty import Handler.Utils import Handler.Utils.Table.Cells -import Utils.Lens - import qualified Database.Esqueleto as E -- htmlField' moved to Handler.Utils.Form/Fields diff --git a/src/Handler/Term.hs b/src/Handler/Term.hs index 8d67d8e5c..26cba329a 100644 --- a/src/Handler/Term.hs +++ b/src/Handler/Term.hs @@ -5,8 +5,6 @@ import Handler.Utils import Handler.Utils.Table.Cells import qualified Data.Map as Map -import Utils.Lens - import qualified Database.Esqueleto as E import qualified Data.Set as Set diff --git a/src/Handler/Tutorial.hs b/src/Handler/Tutorial.hs index 5232dad17..ae2c26ea0 100644 --- a/src/Handler/Tutorial.hs +++ b/src/Handler/Tutorial.hs @@ -25,8 +25,6 @@ import qualified Data.CaseInsensitive as CI import qualified Data.Text as Text -import Utils.Lens - import Data.Aeson hiding (Result(..)) import Text.Hamlet (ihamlet) diff --git a/src/Handler/Tutorial/Users.hs b/src/Handler/Tutorial/Users.hs index 3650755d5..34046f452 100644 --- a/src/Handler/Tutorial/Users.hs +++ b/src/Handler/Tutorial/Users.hs @@ -4,7 +4,6 @@ module Handler.Tutorial.Users import Import -import Utils.Lens import Utils.Form -- import Utils.DB import Handler.Utils diff --git a/src/Handler/Users.hs b/src/Handler/Users.hs index 59f5837c9..a8df63296 100644 --- a/src/Handler/Users.hs +++ b/src/Handler/Users.hs @@ -13,8 +13,6 @@ import Handler.Utils.Invitations import qualified Auth.LDAP as Auth -import Utils.Lens - import qualified Data.CaseInsensitive as CI import qualified Data.Set as Set diff --git a/src/Handler/Utils.hs b/src/Handler/Utils.hs index 65e701eed..21f140921 100644 --- a/src/Handler/Utils.hs +++ b/src/Handler/Utils.hs @@ -4,8 +4,6 @@ module Handler.Utils import Import -import Utils.Lens - import qualified Data.Text as T import qualified Data.Text.Encoding as T import Data.Map ((!)) @@ -15,10 +13,6 @@ import Data.CaseInsensitive (original) -- import qualified Data.CaseInsensitive as CI import qualified Data.Conduit.List as Conduit -import Language.Haskell.TH -import Language.Haskell.TH.Syntax (qRunIO) --- import Language.Haskell.TH.Datatype - import Text.Hamlet (shamletFile) import Handler.Utils.DateTime as Handler.Utils @@ -32,12 +26,9 @@ import Handler.Utils.Rating as Handler.Utils hiding (extractRatings) import Handler.Utils.Sheet as Handler.Utils import Handler.Utils.Mail as Handler.Utils import Handler.Utils.ContentDisposition as Handler.Utils +import Handler.Utils.I18n as Handler.Utils -import System.Directory (listDirectory) -import System.FilePath.Posix (takeBaseName, takeFileName) - -import qualified Data.List as List -import qualified Data.List.NonEmpty as NonEmpty +import System.FilePath.Posix (takeFileName) import Control.Monad.Logger @@ -218,36 +209,6 @@ warnTermDays tid timeNames = do forM_ outoflecture $ warnI MsgDayIsOutOfLecture forM_ outoftermdays $ warnI MsgDayIsOutOfTerm --- | Add language dependent template files --- --- For large files which are translated as a whole. --- --- Argument musst be a directory under @/templates@, --- which contains a file for each language, --- eg. @imprint@ for choosing between --- @/templates/imprint/de.hamlet@, @/templates/imprint/de-at.hamlet@, --- and @/templates/imprint/en.hamlet@ --- --- Dependency detection cannot work properly (no `addDependentFile`-equivalent --- for directories) --- @$ stack clean@ is required so new translations show up -i18nWidgetFile :: FilePath -> Q Exp -i18nWidgetFile basename = do - -- Construct list of available translations (@de@, @en@, ...) at compile time - let i18nDirectory = "templates" "i18n" basename - availableFiles <- qRunIO $ listDirectory i18nDirectory - let availableTranslations = sortWith (NTop . flip List.elemIndex (NonEmpty.toList appLanguages)) . List.nub $ pack . takeBaseName <$> availableFiles - availableTranslations' <- maybe (fail $ "‘" <> i18nDirectory <> "’ is empty") return $ NonEmpty.nonEmpty availableTranslations - - -- Dispatch to correct language (depending on user settings via `selectLanguage`) at run time - ws <- newName "ws" -- Name for dispatch function - letE - [ funD ws $ [ clause [litP $ stringL l] (normalB . widgetFile $ "i18n" basename l) [] - | l <- unpack <$> NonEmpty.toList availableTranslations' -- One function definition for every available language - ] ++ [ clause [wildP] (normalB [e| error "selectLanguage returned an invalid translation" |]) [] ] -- Fallback mostly there so compiler does not complain about non-exhaustive pattern match - ] [e|selectLanguage availableTranslations' >>= $(varE ws)|] - - -- | return a value only if the current user ist authorized for a given route guardAuthorizedFor :: ( HandlerSite h ~ UniWorX, MonadHandler h, MonadLogger h diff --git a/src/Handler/Utils/Communication.hs b/src/Handler/Utils/Communication.hs index 7ee1f815a..2e2ef88c8 100644 --- a/src/Handler/Utils/Communication.hs +++ b/src/Handler/Utils/Communication.hs @@ -9,7 +9,6 @@ module Handler.Utils.Communication import Import import Handler.Utils -import Utils.Lens import Jobs.Queue import Control.Monad.Trans.Reader (mapReaderT) diff --git a/src/Handler/Utils/ContentDisposition.hs b/src/Handler/Utils/ContentDisposition.hs index 7be2bd81b..b353d1bb3 100644 --- a/src/Handler/Utils/ContentDisposition.hs +++ b/src/Handler/Utils/ContentDisposition.hs @@ -5,8 +5,6 @@ module Handler.Utils.ContentDisposition import Import -import Utils.Lens - -- | Check whether the user's preference for files is inline-viewing or downloading downloadFiles :: (MonadHandler m, HandlerSite m ~ UniWorX) => m Bool downloadFiles = do diff --git a/src/Handler/Utils/DateTime.hs b/src/Handler/Utils/DateTime.hs index 8bb33a222..56553ce38 100644 --- a/src/Handler/Utils/DateTime.hs +++ b/src/Handler/Utils/DateTime.hs @@ -16,8 +16,6 @@ module Handler.Utils.DateTime import Import -import Utils.Lens - import Data.Time.Zones import qualified Data.Time.Zones as TZ diff --git a/src/Handler/Utils/Delete.hs b/src/Handler/Utils/Delete.hs index 149ab8285..8a268ac2c 100644 --- a/src/Handler/Utils/Delete.hs +++ b/src/Handler/Utils/Delete.hs @@ -17,8 +17,6 @@ module Handler.Utils.Delete import Import import Handler.Utils.Form -import Utils.Lens - import qualified Data.Text as Text import qualified Data.Set as Set diff --git a/src/Handler/Utils/Exam.hs b/src/Handler/Utils/Exam.hs index 3f53325a8..5cdd6fd29 100644 --- a/src/Handler/Utils/Exam.hs +++ b/src/Handler/Utils/Exam.hs @@ -12,8 +12,6 @@ import qualified Database.Esqueleto.Utils as E import qualified Database.Esqueleto.Internal.Sql as E import Database.Esqueleto.Utils.TH -import Utils.Lens - import qualified Data.Conduit.List as C import qualified Data.Map as Map diff --git a/src/Handler/Utils/Form.hs b/src/Handler/Utils/Form.hs index ac2aab479..878dd4813 100644 --- a/src/Handler/Utils/Form.hs +++ b/src/Handler/Utils/Form.hs @@ -40,13 +40,9 @@ import Control.Monad.Error.Class (MonadError(..)) import Data.Either (partitionEithers) -import Utils.Lens - import Data.Aeson (eitherDecodeStrict') import Data.Aeson.Text (encodeToLazyText) -import Data.Proxy - import qualified Text.Email.Validate as Email import Yesod.Core.Types (FileInfo(..)) diff --git a/src/Handler/Utils/Form/MassInput.hs b/src/Handler/Utils/Form/MassInput.hs index c8a869514..7e2131ae3 100644 --- a/src/Handler/Utils/Form/MassInput.hs +++ b/src/Handler/Utils/Form/MassInput.hs @@ -17,7 +17,6 @@ module Handler.Utils.Form.MassInput import Import import Utils.Form -import Utils.Lens import Handler.Utils.Form.MassInput.Liveliness import Handler.Utils.Form.MassInput.TH diff --git a/src/Handler/Utils/Form/Occurrences.hs b/src/Handler/Utils/Form/Occurrences.hs index 753868a9e..ced9c3c0b 100644 --- a/src/Handler/Utils/Form/Occurrences.hs +++ b/src/Handler/Utils/Form/Occurrences.hs @@ -10,8 +10,6 @@ import qualified Data.Set as Set import Data.Map ((!)) import qualified Data.Map as Map -import Utils.Lens - data OccurrenceScheduleKind = ScheduleKindWeekly deriving (Eq, Ord, Enum, Bounded, Read, Show, Generic, Typeable) diff --git a/src/Handler/Utils/I18n.hs b/src/Handler/Utils/I18n.hs new file mode 100644 index 000000000..1119191d2 --- /dev/null +++ b/src/Handler/Utils/I18n.hs @@ -0,0 +1,43 @@ +module Handler.Utils.I18n + where + +import Import + +import Language.Haskell.TH +import Language.Haskell.TH.Syntax (qRunIO) + +import qualified Data.List as List +import qualified Data.List.NonEmpty as NonEmpty + +import System.Directory (listDirectory) +import System.FilePath.Posix (takeBaseName) + + +-- | Add language dependent template files +-- +-- For large files which are translated as a whole. +-- +-- Argument musst be a directory under @/templates@, +-- which contains a file for each language, +-- eg. @imprint@ for choosing between +-- @/templates/imprint/de.hamlet@, @/templates/imprint/de-at.hamlet@, +-- and @/templates/imprint/en.hamlet@ +-- +-- Dependency detection cannot work properly (no `addDependentFile`-equivalent +-- for directories) +-- @$ stack clean@ is required so new translations show up +i18nWidgetFile :: FilePath -> Q Exp +i18nWidgetFile basename = do + -- Construct list of available translations (@de@, @en@, ...) at compile time + let i18nDirectory = "templates" "i18n" basename + availableFiles <- qRunIO $ listDirectory i18nDirectory + let availableTranslations = sortWith (NTop . flip List.elemIndex (NonEmpty.toList appLanguages)) . List.nub $ pack . takeBaseName <$> availableFiles + availableTranslations' <- maybe (fail $ "‘" <> i18nDirectory <> "’ is empty") return $ NonEmpty.nonEmpty availableTranslations + + -- Dispatch to correct language (depending on user settings via `selectLanguage`) at run time + ws <- newName "ws" -- Name for dispatch function + letE + [ funD ws $ [ clause [litP $ stringL l] (normalB . widgetFile $ "i18n" basename l) [] + | l <- unpack <$> NonEmpty.toList availableTranslations' -- One function definition for every available language + ] ++ [ clause [wildP] (normalB [e| error "selectLanguage returned an invalid translation" |]) [] ] -- Fallback mostly there so compiler does not complain about non-exhaustive pattern match + ] [e|selectLanguage availableTranslations' >>= $(varE ws)|] \ No newline at end of file diff --git a/src/Handler/Utils/Invitations.hs b/src/Handler/Utils/Invitations.hs index a4ab660d2..94740d96c 100644 --- a/src/Handler/Utils/Invitations.hs +++ b/src/Handler/Utils/Invitations.hs @@ -16,7 +16,6 @@ module Handler.Utils.Invitations ) where import Import -import Utils.Lens import Utils.Form import Jobs.Queue diff --git a/src/Handler/Utils/Mail.hs b/src/Handler/Utils/Mail.hs index 0548d341c..e370676d5 100644 --- a/src/Handler/Utils/Mail.hs +++ b/src/Handler/Utils/Mail.hs @@ -7,8 +7,6 @@ module Handler.Utils.Mail import Import -import Utils.Lens - import qualified Data.CaseInsensitive as CI import qualified Data.ByteString.Lazy as LBS diff --git a/src/Handler/Utils/Rating.hs b/src/Handler/Utils/Rating.hs index 472e49950..5549766dc 100644 --- a/src/Handler/Utils/Rating.hs +++ b/src/Handler/Utils/Rating.hs @@ -39,8 +39,6 @@ import qualified Database.Esqueleto as E import qualified Data.Conduit.List as Conduit -import Utils.Lens - instance HasResolution prec => Pretty (Fixed prec) where pretty = pretty . show diff --git a/src/Handler/Utils/SheetType.hs b/src/Handler/Utils/SheetType.hs index a4cd057b3..494729793 100644 --- a/src/Handler/Utils/SheetType.hs +++ b/src/Handler/Utils/SheetType.hs @@ -5,7 +5,6 @@ module Handler.Utils.SheetType import Import import Data.Monoid (Sum(..)) -import Utils.Lens addBonusToPoints :: SheetTypeSummary -> SheetTypeSummary addBonusToPoints sts = diff --git a/src/Handler/Utils/Submission.hs b/src/Handler/Utils/Submission.hs index bcda2d83c..b048177d3 100644 --- a/src/Handler/Utils/Submission.hs +++ b/src/Handler/Utils/Submission.hs @@ -15,8 +15,6 @@ import Import hiding (joinPath) import Jobs.Queue import Yesod.Core.Types (HandlerContents(..), ErrorResponse(..)) -import Utils.Lens - import Control.Monad.State as State (StateT) import Control.Monad.State.Class as State import Control.Monad.Writer (MonadWriter(..), execWriterT, execWriter) diff --git a/src/Handler/Utils/Table.hs b/src/Handler/Utils/Table.hs index 2acaf2a6a..626fa7e11 100644 --- a/src/Handler/Utils/Table.hs +++ b/src/Handler/Utils/Table.hs @@ -2,7 +2,6 @@ module Handler.Utils.Table where -- General Utilities for Tables import Import -import Data.Profunctor import Control.Monad.Except @@ -51,10 +50,12 @@ headedRowSelector toExternal fromExternal attrs colonnade tdata = do externalIds <- mapM (lift . toExternal) tdata let - checkbox extId = Field parse view UrlEncoded + checkbox extId = Field{..} where - parse [] _ = return $ Right Nothing - parse optlist _ = runExceptT $ do + fieldEnctype = UrlEncoded + + fieldParse [] _ = return $ Right Nothing + fieldParse optlist _ = runExceptT $ do extIds <- maybe (throwError "Error parsing values") return $ mapM fromPathPiece optlist case () of _ | extId `elem` extIds @@ -62,11 +63,11 @@ headedRowSelector toExternal fromExternal attrs colonnade tdata = do | otherwise -> return Nothing - view _ name attributes val _ = + fieldView theId name attributes val _ = -- TODO: move this to a *.hamlet file [whamlet|
#{messageContent}|] + , fvInput = [whamlet| + $newline never +
+
+ #{messageContent} + |] }) + where + defaultIcon = case messageStatus of + Success -> "check-circle" + Info -> "info-circle" + Warning -> "exclamation-circle" + Error -> "exclamation-triangle" --------------------- -- Form evaluation -- @@ -1007,6 +1038,29 @@ mforced Field{..} FieldSettings{..} val = do } ) +mforcedOpt :: MonadHandler m + => Field m a + -> FieldSettings (HandlerSite m) + -> Maybe a + -> MForm m (FormResult (Maybe a), FieldView (HandlerSite m)) +mforcedOpt Field{..} FieldSettings{..} mVal = do + tell fieldEnctype + name <- maybe newFormIdent return fsName + theId <- lift $ maybe newIdent return fsId + mr <- getMessageRender + let fsAttrs' = fsAttrs <> [("disabled", "")] + return ( FormSuccess mVal + , FieldView + { fvLabel = toHtml $ mr fsLabel + , fvTooltip = toHtml <$> fmap mr fsTooltip + , fvId = theId + , fvInput = fieldView theId name fsAttrs' (maybe (Left "") Right mVal) False + , fvErrors = Nothing + , fvRequired = False + } + ) + + aforced :: (RenderMessage site FormMessage, HandlerSite m ~ site, MonadHandler m) => Field m a -> FieldSettings site -> a -> AForm m a aforced field settings val = formToAForm $ over _2 pure <$> mforced field settings val diff --git a/src/Utils/Icon.hs b/src/Utils/Icon.hs index a7f6ceeae..23aa34f6e 100644 --- a/src/Utils/Icon.hs +++ b/src/Utils/Icon.hs @@ -47,6 +47,7 @@ data Icon | IconCommentFalse | IconLink | IconFileDownload + | IconFileUpload | IconFileZip | IconFileCSV | IconSFTQuestion -- for SheetFileType only @@ -57,6 +58,9 @@ data Icon | IconRegisterTemplate | IconApplyTrue | IconApplyFalse + | IconNoCorrectors + | IconApplicationVeto + | IconApplicationFiles deriving (Eq, Ord, Enum, Bounded, Show, Read) iconText :: Icon -> Text @@ -78,6 +82,7 @@ iconText = \case IconCommentFalse -> "comment-slash" -- comment-alt-slash is not available for free IconLink -> "link" IconFileDownload -> "file-download" + IconFileUpload -> "file-upload" IconFileZip -> "file-archive" IconFileCSV -> "file-csv" IconSFTQuestion -> "question-circle" -- for SheetFileType only, should all be round (similar) @@ -88,6 +93,9 @@ iconText = \case IconRegisterTemplate -> "file-alt" IconApplyTrue -> "file-alt" IconApplyFalse -> "trash" + IconNoCorrectors -> "user-slash" + IconApplicationVeto -> "times" + IconApplicationFiles -> "file-alt" instance Universe Icon instance Finite Icon diff --git a/src/Utils/Lens.hs b/src/Utils/Lens.hs index 4c015f185..8f1cc1357 100644 --- a/src/Utils/Lens.hs +++ b/src/Utils/Lens.hs @@ -3,13 +3,18 @@ module Utils.Lens ( module Utils.Lens ) where -import ClassyPrelude.Yesod hiding (HasHttpManager(..)) -import qualified ClassyPrelude.Yesod as Yesod (HasHttpManager(..)) +import Import.NoModel import Model +import qualified ClassyPrelude.Yesod as Yesod (HasHttpManager(..)) -import Control.Lens as Utils.Lens hiding ((<.>), universe, snoc) +import Control.Lens as Utils.Lens + hiding ( (<.>) + , universe + , cons, uncons, snoc, unsnoc, (<|) + , Index, index, (<.) + ) import Control.Lens.Extras as Utils.Lens (is) -import Utils.Lens.TH as Utils.Lens (makeLenses_, makeClassyFor_) +import Utils.Lens.TH as Utils.Lens import Data.Set.Lens as Utils.Lens import Yesod.Core.Types (HandlerContents(..), ErrorResponse(..)) @@ -42,6 +47,8 @@ _SchoolId = iso unSchoolKey SchoolKey ----------------------------------- -- Lens Definitions for our Types +makeClassyFor_ ''Term + -- makeLenses_ ''Course makeClassyFor_ ''Course @@ -154,6 +161,10 @@ makePrisms ''AuthenticationMode makeLenses_ ''CourseUserNote +makeLenses_ ''CourseApplication + +makeLenses_ ''Allocation + -- makeClassy_ ''Load diff --git a/src/Utils/Lens/TH.hs b/src/Utils/Lens/TH.hs index 701c87b76..0042fb308 100644 --- a/src/Utils/Lens/TH.hs +++ b/src/Utils/Lens/TH.hs @@ -1,10 +1,17 @@ -module Utils.Lens.TH where +module Utils.Lens.TH + ( makeLenses_, makeClassyFor_ + , multifocusG, multifocusL + ) where -import ClassyPrelude (Maybe(..), (<>)) +import ClassyPrelude import Control.Lens import Control.Lens.Internal.FieldTH import Language.Haskell.TH +import Numeric.Natural + +import Data.Foldable (Foldable(foldl)) + -- import Control.Lens.Misc {- NOTE: The code for lensRules_ and makeLenses_ was stolen from package lens-misc-0.0.2.0, @@ -65,3 +72,47 @@ makeClassyFor_ recName = makeFieldOptics (classyRulesFor_ clNamer) recName clNamer :: ClassyNamer -- clNamer _ = Just (clsName, funName) -- for newer versions >= 4.17 clNamer _ = Just (mkName clsName, mkName funName) + +multifocusG :: Natural -> ExpQ +multifocusG = multifocusOptic + [e|to . view|] + (\s a -> [t|Getting $(a) $(s) $(a)|]) + (\s a -> [t|Getter $(s) $(a)|]) + (\doGet _doSet -> [e|to $(doGet)|]) + +multifocusL :: Natural -> ExpQ +multifocusL = multifocusOptic + [e|cloneLens|] + (\s a -> [t|ALens' $(s) $(a)|]) + (\s a -> [t|Lens' $(s) $(a)|]) + (\doGet doSet -> [e|lens $(doGet) $(doSet)|]) + + +multifocusOptic :: _ -> _ -> _ -> _ -> Natural -> ExpQ +multifocusOptic _ _ _ _ 0 = [e|united|] +multifocusOptic doClone _ _ _ 1 = doClone +multifocusOptic doClone alensT lensT lens' (fromIntegral -> n) = do + ll <- newName "l" + ls <- replicateM n $ newName "l" + s <- newName "s" + xs <- replicateM n $ newName "x" + + tS <- newName "s" + tXs <- replicateM n $ newName "x" :: Q [Name] + + let tup = foldl (\t x -> [t|$(t) $(varT x)|]) (tupleT (length tXs)) tXs + mkL x = alensT (varT tS) (varT x) + + letE + [ sigD ll $ foldr (\x t -> [t|$(mkL x) -> $(t)|]) (lensT (varT tS) tup) tXs + , funD ll + [ clause + (map (viewP doClone . varP) ls) + (normalB $ lens' + (lamE [varP s] . tupE . flip map ls $ \l -> [e| $(varE s) ^. $(varE l) |]) + (lamE [varP s, tupP $ map varP xs] . foldr (\(x, l) x' -> [e|$(x') & $(varE l) .~ $(varE x)|]) (varE s) $ zip xs ls) + ) + [] + ] + ] + (varE ll) diff --git a/src/Utils/Message.hs b/src/Utils/Message.hs index d72d065bf..908848873 100644 --- a/src/Utils/Message.hs +++ b/src/Utils/Message.hs @@ -6,6 +6,7 @@ module Utils.Message , addMessage, addMessageI, addMessageIHamlet, addMessageFile, addMessageWidget , statusToUrgencyClass , Message(..) + , messageIconI , messageI, messageIHamlet, messageFile, messageWidget ) where @@ -140,6 +141,11 @@ messageI messageStatus msg = do let messageIcon = Nothing return Message{..} +messageIconI :: (MonadHandler m, RenderMessage (HandlerSite m) msg) => MessageStatus -> Icon -> msg -> m Message +messageIconI messageStatus (Just -> messageIcon) msg = do + messageContent <- toHtml . ($ msg) <$> getMessageRender + return Message{..} + addMessageIHamlet :: ( MonadHandler m , RenderMessage (HandlerSite m) msg , HandlerSite m ~ site diff --git a/src/Utils/Sql.hs b/src/Utils/Sql.hs index aae593c05..b0aa13ef2 100644 --- a/src/Utils/Sql.hs +++ b/src/Utils/Sql.hs @@ -23,7 +23,7 @@ setSerializable act = setSerializable' (0 :: Integer) let delay :: NominalDiffTime delay = 1e-3 * 2 ^ logBackoff - $logWarnS "Sql" $ tshow (delay, e) + $logDebugS "Sql" $ tshow (delay, e) transactionUndo threadDelay . round $ delay * 1e6 setSerializable' (succ logBackoff) diff --git a/stack.yaml b/stack.yaml index f9f48a935..0a748ab91 100644 --- a/stack.yaml +++ b/stack.yaml @@ -11,11 +11,11 @@ packages: - . extra-deps: - - git: https://github.com/pngwjpgh/zip-stream.git + - git: https://github.com/uni2work/zip-stream.git commit: 9272bbed000928d500febad1cdc98d1da29d399e - - git: https://github.com/pngwjpgh/encoding.git + - git: https://github.com/uni2work/encoding.git commit: 67bb87ceff53f0178c988dd4e15eeb2daee92b84 - - git: https://github.com/pngwjpgh/memcached-binary.git + - git: https://github.com/uni2work/memcached-binary.git commit: b5461747e7be226d3b67daebc3c9aefe8a4490ad - colonnade-1.2.0 diff --git a/stack.yaml.lock b/stack.yaml.lock index cb8c9d974..45c694d00 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -10,13 +10,13 @@ packages: sha256: 2cab90bba4d15bf6a17e3cb8e50bc8708c1091de503dd4e91d3954240e89f37b name: zip-stream version: 0.1.0.1 - git: https://github.com/pngwjpgh/zip-stream.git + git: https://github.com/uni2work/zip-stream.git pantry-tree: size: 657 sha256: d1626bbc3fb88a48ce9c5c37199f8cbf426be6410740891d76a8343de4f3c109 commit: 9272bbed000928d500febad1cdc98d1da29d399e original: - git: https://github.com/pngwjpgh/zip-stream.git + git: https://github.com/uni2work/zip-stream.git commit: 9272bbed000928d500febad1cdc98d1da29d399e - completed: cabal-file: @@ -24,13 +24,13 @@ packages: sha256: 88537113b855381b8d70da2442ae644dc979ad6b32aaaec2ebf55306764c8f1a name: encoding version: 0.8.2 - git: https://github.com/pngwjpgh/encoding.git + git: https://github.com/uni2work/encoding.git pantry-tree: size: 5668 sha256: 57160d758802aba6a0d2cc88c53f2f0bb60df7d5e6822938351618b7eca0beab commit: 67bb87ceff53f0178c988dd4e15eeb2daee92b84 original: - git: https://github.com/pngwjpgh/encoding.git + git: https://github.com/uni2work/encoding.git commit: 67bb87ceff53f0178c988dd4e15eeb2daee92b84 - completed: cabal-file: @@ -38,13 +38,13 @@ packages: sha256: 7b25a0ef819e8a01b485d6d0865baa3445faa826ffb3876c94109dd2469ffbd3 name: memcached-binary version: 0.2.0 - git: https://github.com/pngwjpgh/memcached-binary.git + git: https://github.com/uni2work/memcached-binary.git pantry-tree: size: 1170 sha256: c466f91129410bae1f53e25aec4026f6984ce2dff0ada4516e2548048aba549a commit: b5461747e7be226d3b67daebc3c9aefe8a4490ad original: - git: https://github.com/pngwjpgh/memcached-binary.git + git: https://github.com/uni2work/memcached-binary.git commit: b5461747e7be226d3b67daebc3c9aefe8a4490ad - completed: hackage: colonnade-1.2.0@sha256:5620e999a68a394abfe157da6302dd6d8ce8a89b527ea9c294519efd7c4edb2c,2092 diff --git a/templates/allocation/show.hamlet b/templates/allocation/show.hamlet new file mode 100644 index 000000000..29024f2e4 --- /dev/null +++ b/templates/allocation/show.hamlet @@ -0,0 +1,83 @@ +$newline never +
+ $#

+ $# _{MsgAllocationData} +
+ $maybe desc <- allocationDescription +
+ _{MsgAllocationDescription} +
+ #{desc} + $maybe fromT <- allocationStaffRegisterFrom +
+ $maybe _ <- allocationStaffRegisterTo + _{MsgAllocationStaffRegister} + $nothing + _{MsgAllocationStaffRegisterFrom} +
+ ^{formatTimeRangeW SelFormatDateTime fromT allocationStaffRegisterTo} + $maybe fromT <- allocationRegisterFrom +
+ $maybe _ <- allocationRegisterTo + _{MsgAllocationRegister} + $nothing + _{MsgAllocationRegisterFrom} +
+ ^{formatTimeRangeW SelFormatDateTime fromT allocationRegisterTo} + $if staffInformation + $maybe fromT <- allocationStaffAllocationFrom +
+ $maybe _ <- allocationStaffAllocationTo + _{MsgAllocationStaffAllocation} + $nothing + _{MsgAllocationStaffAllocationFrom} +
+ ^{formatTimeRangeW SelFormatDateTime fromT allocationStaffAllocationTo} + + $# TODO show datetime of automatic allocation + $# + $#
+ $# _{MsgAllocationProcess} + $#
+ $# ^{formatTimeRangeW SelFormatDateTime fromT allocationProcess} + $# + +
+

+ _{MsgAllocationParticipation} + $if is _Nothing muid +

+ _{MsgAllocationParticipationLoginFirst} + $elseif mayRegister + $# existing registrations may also be edited in this case + ^{registerForm'} + $elseif is _Just registration + $# show existing registration even if it cannot be changed now + $maybe Entity _ AllocationUser{allocationUserTotalCourses} <- registration +

+
+ _{MsgAllocationTotalCourses} +
+ #{allocationUserTotalCourses} + $else + $# Provide helpful information for confused students who cannot register now + $maybe daysToOpen <- daysToRegistrationStart +

+ _{MsgAllocationRegisterOpensIn (formatDiffDays daysToOpen)} + $nothing +

+ _{MsgAllocationRegisterClosed} +

+ $# This redundant links prevents useless help requests from frantic users + ^{allocationInfoModal} + +$if not (null courseWidgets) +

+

+ _{MsgAllocationCourses} +
+

_{MsgAllocationPriorityTip} +

_{MsgAllocationPriorityRelative} +

+ $forall courseWgt <- courseWidgets + ^{courseWgt} diff --git a/templates/allocation/show.lucius b/templates/allocation/show.lucius new file mode 100644 index 000000000..7e2e4f406 --- /dev/null +++ b/templates/allocation/show.lucius @@ -0,0 +1,85 @@ +.allocation__label { + color: var(--color-fontsec); + font-style: italic; +} + +.allocation__courses { + margin-top: 20px; +} + +.allocation-course { + display: grid; + grid-template-columns: 140px 1fr; + grid-template-areas: + '. name ' + 'prio-label prio ' + 'instr-label instr ' + 'form-label form '; + + grid-gap: 5px 7px; + padding: 12px 10px; + + &:last-child { + padding: 12px 10px 0 10px; + } + + & + .allocation-course { + border-top: 1px solid var(--color-grey); + } + + + .allocation-course__priority { + grid-area: prio; + } + .allocation-course__priority-label { + grid-area: prio-label; + justify-self: end; + align-self: center; + text-align: right; + } + + .allocation-course__name { + grid-area: name; + + align-self: center; + + font-size: 1.2rem; + } + + .allocation-course__instructions { + grid-area: instr; + } + .allocation-course__instructions-label { + grid-area: instr-label; + justify-self: end; + text-align: right; + } + + .allocation-course__application { + grid-area: form; + } + .allocation-course__application-label { + grid-area: form-label; + justify-self: end; + text-align: right; + padding-top: 6px; + } +} + +@media (max-width: 426px) { + .allocation-course { + grid-template-columns: 1fr; + grid-template-areas: + 'name ' + 'prio-label ' + 'prio ' + 'instr-label' + 'instr ' + 'form-label ' + 'form '; + } + + .allocation-course__application-label { + padding-top: 0; + } +} diff --git a/templates/allocation/show/course.hamlet b/templates/allocation/show/course.hamlet new file mode 100644 index 000000000..53992eed4 --- /dev/null +++ b/templates/allocation/show/course.hamlet @@ -0,0 +1,27 @@ +$if is _Just muid +
+ _{MsgAllocationPriority} +
+ $maybe prioView <- mApplyFormView' >>= afvPriority + ^{fvInput prioView} + $nothing + _{MsgAllocationNoApplication} + + #{courseName} +$if hasApplicationTemplate || is _Just courseApplicationsInstructions +
+ _{MsgCourseApplicationInstructionsApplication} +
+ $maybe aInst <- courseApplicationsInstructions +

+ #{aInst} + $if hasApplicationTemplate +

+ + #{iconRegisterTemplate} _{MsgCourseApplicationTemplateApplication} +$maybe ApplicationFormView{ ..} <- mApplyFormView' +

+ _{MsgCourseApplication} +
+ ^{renderFieldViews FormStandard afvForm} + ^{snd afvButtons} diff --git a/templates/course.hamlet b/templates/course.hamlet index 713f61e13..1372fd58d 100644 --- a/templates/course.hamlet +++ b/templates/course.hamlet @@ -64,9 +64,11 @@ $# $if NTop (Just 0) < NTop (courseCapacity course) #{participants} $maybe capacity <- courseCapacity course \ von #{capacity} - $maybe Allocation{allocationName} <- mAllocation + $maybe (name, url) <- mAllocation'
_{MsgCourseAllocation} -
#{allocationName} +
+ + #{name} $nothing $maybe regFrom <- mRegFrom
Anmeldezeitraum diff --git a/templates/default-layout.lucius b/templates/default-layout.lucius index b1db5eea7..b3b493fd5 100644 --- a/templates/default-layout.lucius +++ b/templates/default-layout.lucius @@ -180,11 +180,15 @@ h4 { } p { - margin: 10px 0; - } + margin: 0.5rem 0; - p:last-child { - margin: 10px 0 0; + &:last-child { + margin: 0.5rem 0 0; + + &:first-of-type { + margin: 0; + } + } } } @@ -478,6 +482,11 @@ ul.list--inline { } } +.list--icon-width li { + width: 1rem; + height: 1rem; +} + /* DEFINITION LIST */ .deflist { display: grid; @@ -546,6 +555,7 @@ section { &:last-child { border-bottom: none; + padding-bottom: 0px; } } @@ -564,32 +574,63 @@ section { border-radius: 3px; padding: 10px 20px 20px; margin: 40px 0; - color: var(--color-dark); box-shadow: 0 0 4px 2px inset currentColor; - padding-left: 20%; + padding-left: 100px; min-height: 100px; + max-width: 700px; + font-weight: 600; + vertical-align: center; + display: grid; + grid-column: 2; &::before { - content: 'i'; + font-family: "Font Awesome 5 Free"; + font-weight: 900; position: absolute; display: flex; left: 0; top: 0; height: 100%; - width: 20%; - font-size: 100px; + width: 100px; + font-size: 50px; align-items: center; justify-content: center; } + + .notification__content { + grid-column: 1; + align-self: center; + } } -.form-group__input > .notification { - margin: 0; +.form-section-notification { + display: grid; + grid-template-columns: 1fr 3fr; + grid-gap: 5px; + + .notification { + margin: 0; + } + + + .form-group, + .form-section-legend, + .form-section-notification { + margin-top: 11px; + } + + + .form-section-title { + margin-top: 40px; + } } @media (max-width: 768px) { + .form-section-notification { + grid-template-columns: 1fr; + margin-top: 17px; + } .notification { + grid-column: 1; + + max-width: none; padding-left: 40px; @@ -602,16 +643,20 @@ section { } } -.notification-danger { - color: #c51919 ; - - &::before { - content: '!'; - } +.notification-error { + color: var(--color-error) ; } -.notification__content { - color: var(--color-font); +.notification-warning { + color: var(--color-warning) ; +} + +.notification-info { + color: var(--color-lightblack) ; +} + +.notification-success { + color: var(--color-warning) ; } diff --git a/templates/exam-show.hamlet b/templates/exam-show.hamlet index d14dbcf52..6e12d555d 100644 --- a/templates/exam-show.hamlet +++ b/templates/exam-show.hamlet @@ -126,7 +126,7 @@ $if not (null occurrences) $maybe desc <- examOccurrenceDescription #{desc} -$if gradingShown && not (null parts) +$if gradingShown && not (null examParts)

_{MsgExamParts} @@ -139,7 +139,7 @@ $if gradingShown && not (null parts) _{MsgExamPartMaxPoints} _{MsgExamPartResultPoints} - $forall Entity partId ExamPart{examPartName, examPartWeight, examPartMaxPoints} <- parts + $forall Entity partId ExamPart{examPartName, examPartWeight, examPartMaxPoints} <- examParts #{examPartName} diff --git a/templates/home/openAllocations.hamlet b/templates/home/openAllocations.hamlet new file mode 100644 index 000000000..16c84d41a --- /dev/null +++ b/templates/home/openAllocations.hamlet @@ -0,0 +1,4 @@ +$newline never +
+

_{MsgHomeOpenAllocations} + ^{allocationTable} diff --git a/templates/home/openCourses.hamlet b/templates/home/openCourses.hamlet deleted file mode 100644 index 913275128..000000000 --- a/templates/home/openCourses.hamlet +++ /dev/null @@ -1,4 +0,0 @@ -$newline never -
-

_{MsgHomeOpenCourses} - ^{courseTable} diff --git a/templates/home/upcomingExams.hamlet b/templates/home/upcomingExams.hamlet index 1bb40bb09..29ee05df4 100644 --- a/templates/home/upcomingExams.hamlet +++ b/templates/home/upcomingExams.hamlet @@ -4,4 +4,4 @@ $newline never $if hasExams ^{examTable} $else - _{MsgNoUpcomingExams} + _{MsgNoUpcomingExams (formatDiffDays warningDays)} diff --git a/templates/i18n/allocation-info/de.hamlet b/templates/i18n/allocation-info/de.hamlet new file mode 100644 index 000000000..e1379d2c4 --- /dev/null +++ b/templates/i18n/allocation-info/de.hamlet @@ -0,0 +1,85 @@ +$newline text +
+

+ Jede Zentralanmeldung durchläuft + der Reihe nach folgende Phasen: +

+
+ _{MsgAllocationStaffRegister} +
+

+ Veranstalter können nur in diesem Zeitraum ihre Veranstaltungen + zur Zentralanmeldung hinzufügen oder entfernen. +

+ Pro Veranstaltung wird einzeln festgelegt, + ob Studierende einen Bewerbungstext und/oder Bewerbungsdateien + einreichen sollen. + Veranstalter stellen auch Anweisungen zur Bewerbung ein, + z.B. welchen Inhalt abzugebende Bewerbungsdateien enthalten sollen. +

+ Zur Zentralanmeldung eingetragene Kurse + erlauben während dem gesamten Ablauf + der Zentralanmeldung keine anderweitigen Kursanmeldung mehr, + auch nicht durch den Veranstalter selbst. + +

+ _{MsgAllocationRegister} +
+

+ Studierende können sich nur in diesem Zeitraum + auf Plätze in Kursen einer Zentralanmeldung bewerben. +

+ Bewerber können jedem Kurs der Zentralanmeldung eine Priorität + zuweisen, zwischen "dieser Kurs wäre meine erste Wahl" + und "diesen Kurs besuche ich auf keinen Fall". + Es kann auch mehreren Kursen die gleiche Priorität eingeräumt werden. +

+ Studierende können auch mehr als einen Platz + in verschiedenen Kursen einer Zentralanmeldung anfordern, + falls die Kurskapazitäten und/oder Dringlichkeit ausreichend sind. +

+ Bewerbungstexte und/oder Bewerbungsdateien + sind pro Kurs anzugeben, falls vom Veranstalter gefordert. + +

+ _{MsgAllocationStaffAllocation} +
+

+ Veranstalter können nur in diesem Zeitraum die + Bewerbungen einsehen und bewerten. + $#

+ $# Nur in manchen Zentralanmeldungen dürfen Veranstalter + $# Bewerber jetzt direkt ablehnen und/oder übernehmen. + $#

+ $# Veranstalter haben noch eine letzte Möglichkeit, + $# die Kurskapazität anzupassen. + +

+ _{MsgAllocationProcess} +
+

+ Die Plätze werden gemäß Studienfortschritt, Dringlichkeit + und der Bewertung durch den Veranstalter auf die Bewerber verteilt. +

+ Die Bewerber werden diekt in den jeweiligen Kursen angemeldet. + Eine Abmeldung durch Studierende ist nicht erlaubt. + Übernommene Bewerber, welche einen zugeteilten Platz + ohne Angabe eines triftigen Grundes nicht antreten, + werden in zukünftigen Zentralanmeldungen + unter Umständen benachteiligt. +

+ Veranstalter können frühestens nach der erfolgten Zuteilung + Teilnehmer selbst an-/abmelden + und ggf. Nachrücker für freigewordene Plätze anfordern. + +

+ Der Ablauf einer Zentralanmeldung kann unter Umständen noch variieren. + + Insbesondere: # + Fehlt in der Übersichtsseite einer Zentralanmeldung + die Angabe einer dieser Phasen, dann wurde der entsprechende Zeitraum + leider noch nicht festgelegt! +

+ Mehrere Zentralanmeldungen werden völlig unabhängig voneinander + abgewickelt. + diff --git a/templates/i18n/changelog/de.hamlet b/templates/i18n/changelog/de.hamlet index d32d6a27c..d2c436d00 100644 --- a/templates/i18n/changelog/de.hamlet +++ b/templates/i18n/changelog/de.hamlet @@ -1,5 +1,15 @@ $newline never

+
19.08.2019 +
+