From 05b361f1288fa93e272e11eb2e3cc3e6ec5e830a Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Fri, 23 Nov 2018 00:08:07 +0100 Subject: [dozmod] Add LDAP filter submodule --- modules-available/dozmod/lang/de/messages.json | 7 ++ modules-available/dozmod/lang/de/module.json | 1 + modules-available/dozmod/lang/de/permissions.json | 2 + .../dozmod/lang/de/template-tags.json | 8 ++ modules-available/dozmod/lang/en/messages.json | 6 ++ modules-available/dozmod/lang/en/module.json | 1 + modules-available/dozmod/lang/en/permissions.json | 2 + .../dozmod/lang/en/template-tags.json | 8 ++ modules-available/dozmod/page.inc.php | 3 +- modules-available/dozmod/pages/ldapfilters.inc.php | 119 +++++++++++++++++++++ .../dozmod/permissions/permissions.json | 6 ++ .../dozmod/templates/ldapfilter-add.html | 39 +++++++ .../dozmod/templates/ldapfilters.html | 72 +++++++++++++ 13 files changed, 273 insertions(+), 1 deletion(-) create mode 100644 modules-available/dozmod/pages/ldapfilters.inc.php create mode 100644 modules-available/dozmod/templates/ldapfilter-add.html create mode 100644 modules-available/dozmod/templates/ldapfilters.html diff --git a/modules-available/dozmod/lang/de/messages.json b/modules-available/dozmod/lang/de/messages.json index 60c37927..47912ae1 100644 --- a/modules-available/dozmod/lang/de/messages.json +++ b/modules-available/dozmod/lang/de/messages.json @@ -3,6 +3,13 @@ "delete-images": "L\u00f6schung: {{0}}", "dozmod-error": "Fehler bei der Kommunikation mit dem bwLehrpool-Suite server: {{0}}", "images-pending-delete-exist": "Zur L\u00f6schung markierte VM-Versionen: {{0}}", + "ldap-filter-created": "LDAP Filter wurde erfolgreich erstellt", + "ldap-filter-deleted": "LDAP Filter wurde erfolgreich gel\u00f6scht", + "ldap-invalid-filter-id": "Ung\u00fcltige LDAP Filter ID", + "ldap-filter-id-missing": "Fehlende LDAP Filter ID", + "ldap-filter-insert-failed": "LDAP filter konnte der Datenbank nicht hinzugef\u00fcgt werden", + "ldap-filter-save-missing-information": "Es fehlen LDAP Filter Informationen", + "ldap-filter-saved": "LDAP Filter wurde erfolgreich gespeichert", "mail-config-saved": "Mail-Konfiguration gespeichert", "no-expired-images": "Keine Abgelaufenen VM-Versionen", "nothing-submitted": "Es wurde nichts \u00fcbermittelt", diff --git a/modules-available/dozmod/lang/de/module.json b/modules-available/dozmod/lang/de/module.json index c9acd4ee..4a5e0249 100644 --- a/modules-available/dozmod/lang/de/module.json +++ b/modules-available/dozmod/lang/de/module.json @@ -3,6 +3,7 @@ "page_title": "Verwalten der bwLehrpool-Suite", "submenu_actionlog": "Aktions-Log", "submenu_expiredimages": "Abgelaufene VM-Versionen", + "submenu_ldapfilters": "LDAP Filter", "submenu_mailconfig": "Email-Konfiguration", "submenu_runtimeconfig": "Limits und Standardwerte", "submenu_templates": "Textbausteine f\u00fcr E-Mails", diff --git a/modules-available/dozmod/lang/de/permissions.json b/modules-available/dozmod/lang/de/permissions.json index df913265..ad099d37 100644 --- a/modules-available/dozmod/lang/de/permissions.json +++ b/modules-available/dozmod/lang/de/permissions.json @@ -1,6 +1,8 @@ { "actionlog.view": "Aktions-Log einsehen.", "expiredimages.delete": "Zur L\u00f6schung vorgemerkete Abbilder l\u00f6schen.", + "ldapfilters.save": "LDAP Filter speichern.", + "ldapfilters.view": "LDAP Filter einsehen.", "mailconfig.save": "\u00c4nderungen an der SMTP-Konfiguration zum Versenden von Mails speichern.", "runtimeconfig.save": "\u00c4nderungen an der Laufzeit-Konfiguration speichern.", "templates.reset": "E-Mail Templates zur\u00fccksetzen.", diff --git a/modules-available/dozmod/lang/de/template-tags.json b/modules-available/dozmod/lang/de/template-tags.json index 84f6e0de..7fbeda37 100644 --- a/modules-available/dozmod/lang/de/template-tags.json +++ b/modules-available/dozmod/lang/de/template-tags.json @@ -35,6 +35,14 @@ "lang_lastEditor": "Zuletzt bearbeitet von", "lang_lastLogin": "Letzte Anmeldung", "lang_latestVersion": "Neuste Version", + "lang_ldapFilterAdd": "LDAP Filter Hinzuf\u00fcgen", + "lang_ldapFilterAttribute": "Attribut", + "lang_ldapFilterDeleteConfirmation": "Willst du diesen LDAP Filter wirklich L\u00f6schen.", + "lang_ldapFilterDescription": "Dies sind die Filter, die ein Benutzer in der bwLehrpool-Suite Veranstaltungen hinzuf\u00fcgen kann.", + "lang_ldapFilterEdit": "LDAP Filter bearbeiten", + "lang_ldapFilterName": "Filtername", + "lang_ldapfilters": "LDAP Filter", + "lang_ldapFilterValue": "Wert", "lang_lecture": "Veranstaltung", "lang_lecturePermissionAdmin": "Administration", "lang_lecturePermissionEdit": "Bearbeiten", diff --git a/modules-available/dozmod/lang/en/messages.json b/modules-available/dozmod/lang/en/messages.json index 6d7ea0ac..4d914406 100644 --- a/modules-available/dozmod/lang/en/messages.json +++ b/modules-available/dozmod/lang/en/messages.json @@ -3,6 +3,12 @@ "delete-images": "Delete: {{0}}", "dozmod-error": "Error communicating with the bwLehrpool-Suite server: {{0}}", "images-pending-delete-exist": "VMs marked for deletion: {{0}}", + "ldap-filter-created": "LDAP filter was successfully created", + "ldap-filter-deleted": "LDAP filter successfully deleted", + "ldap-invalid-filter-id": "Invalid LDAP filter id", + "ldap-filter-id-missing": "LDAP filter id was missing", + "ldap-filter-insert-failed": "LDAP filter could not be inserted into the database", + "ldap-filter-save-missing-information": "LDAP filter informations were missing", "mail-config-saved": "Mail config saved", "no-expired-images": "No expired VMs", "nothing-submitted": "There was nothing submitted", diff --git a/modules-available/dozmod/lang/en/module.json b/modules-available/dozmod/lang/en/module.json index b7a04762..c2b4439d 100644 --- a/modules-available/dozmod/lang/en/module.json +++ b/modules-available/dozmod/lang/en/module.json @@ -3,6 +3,7 @@ "page_title": "Manage the bwLehrpool-Suite", "submenu_actionlog": "action log", "submenu_expiredimages": "Expired VM versions", + "submenu_ldapfilters": "LDAP filters", "submenu_mailconfig": "email configuration", "submenu_runtimeconfig": "limits and defaults", "submenu_templates": "templates", diff --git a/modules-available/dozmod/lang/en/permissions.json b/modules-available/dozmod/lang/en/permissions.json index 0827c8d2..797f7c2f 100644 --- a/modules-available/dozmod/lang/en/permissions.json +++ b/modules-available/dozmod/lang/en/permissions.json @@ -1,6 +1,8 @@ { "actionlog.view": "View action log.", "expiredimages.delete": "Delete images marked for deletion.", + "ldapfilters.save": "Save LDAP filter.", + "ldapfilters.view": "View LDAP filters. ", "mailconfig.save": "Save SMTP configuration for sending mails.", "runtimeconfig.save": "Save limits and defaults of a runtime configuration.", "templates.reset": "Reset email templates.", diff --git a/modules-available/dozmod/lang/en/template-tags.json b/modules-available/dozmod/lang/en/template-tags.json index 3ee95e8c..4f9ab877 100644 --- a/modules-available/dozmod/lang/en/template-tags.json +++ b/modules-available/dozmod/lang/en/template-tags.json @@ -35,6 +35,14 @@ "lang_lastEditor": "Edited by", "lang_lastLogin": "Last login", "lang_latestVersion": "latest version", + "lang_ldapFilterAdd": "Add LDAP filter", + "lang_ldapFilterAttribute": "Attribute", + "lang_ldapFilterDeleteConfirmation": "Do you really want to delete this LDAP filter.", + "lang_ldapFilterDescription": "These are the LDAP filters that can be applied to lectures in the bwLehrpool-Suite.", + "lang_ldapFilterEdit": "Edit LDAP filter", + "lang_ldapFilterName": "Filter name", + "lang_ldapfilters": "LDAP filters", + "lang_ldapFilterValue": "Value", "lang_lecture": "Lecture", "lang_lecturePermissionAdmin": "Administrate", "lang_lecturePermissionEdit": "Edit", diff --git a/modules-available/dozmod/page.inc.php b/modules-available/dozmod/page.inc.php index a8e0da0e..47110dd0 100644 --- a/modules-available/dozmod/page.inc.php +++ b/modules-available/dozmod/page.inc.php @@ -5,7 +5,7 @@ class Page_DozMod extends Page /** @var bool true if we have a proper subpage */ private $haveSubPage = false; - private $validSections = ['expiredimages', 'mailconfig', 'templates', 'runtimeconfig', 'users', 'actionlog']; + private $validSections = ['expiredimages', 'mailconfig', 'templates', 'runtimeconfig', 'users', 'actionlog', 'ldapfilters']; private $section; @@ -60,6 +60,7 @@ class Page_DozMod extends Page Dictionary::translate('submenu_runtimeconfig', true); Dictionary::translate('submenu_users', true); Dictionary::translate('submenu_actionlog', true); + Dictionary::translate('submenu_ldapfilters', true); */ /* add sub-menus */ diff --git a/modules-available/dozmod/pages/ldapfilters.inc.php b/modules-available/dozmod/pages/ldapfilters.inc.php new file mode 100644 index 00000000..6b5ce2dc --- /dev/null +++ b/modules-available/dozmod/pages/ldapfilters.inc.php @@ -0,0 +1,119 @@ + $ldapfilters, + 'hasEditPermission' => User::hasPermission('ldapfilters.save') + ); + + Render::addTemplate('ldapfilters', $data); + } else if (self::$show === 'edit') { + $filterid = Request::get('filterid', false, 'int'); + + if ($filterid === false) { + Render::addTemplate('ldapfilter-add', array( + 'filterid' => 0 + )); + } else { + $ldapfilter = Database::queryFirst("SELECT * FROM sat.ldapfilter WHERE filterid=:id", array( 'id' => $filterid)); + + $data = array( + 'filterid' => $filterid, + 'filtername' => $ldapfilter['filtername'], + 'attribute' => $ldapfilter['attribute'], + 'value' => $ldapfilter['value'] + ); + Render::addTemplate('ldapfilter-add', $data); + } + } + } + + private function deleteLdapFilter() { + User::assertPermission('ldapfilters.save'); + $filterid = Request::post('filterid', false, 'int'); + if ($filterid === false) { + Message::addError('ldap-filter-id-missing'); + return; + } + $res = Database::exec("DELETE FROM sat.ldapfilter WHERE filterid=:id", array('id' => $filterid)); + if ($res !== 1) { + Message::addWarning('ldap-invalid-filter-id', $filterid); + } else { + Message::addSuccess('ldap-filter-deleted'); + } + } + + private function saveLdapFilter() { + $filterid = Request::post('filterid', '', 'int'); + $filtername = Request::post('filtername', false, 'string'); + $filterattribute = Request::post('attribute', false, 'string'); + $filtervalue = Request::post('value', false, 'string'); + + if ($filtername === false || $filterattribute === false || $filtervalue === false) { + Message::addError('ldap-filter-save-missing-information'); + return; + } + + if ($filterid === 0) { + // Insert filter in the db. + $res = Database::exec("INSERT INTO sat.ldapfilter (filtername, attribute, value) VALUES (:filtername, :attribute, :value)", array( + 'filtername' => $filtername, + 'attribute' => $filterattribute, + 'value' => $filtervalue + )); + + if ($res !== 1) { + Message::addError('ldap-filter-insert-failed'); + } else { + Message::addSuccess('ldap-filter-created'); + } + + } else { + // Update filter in the db. + $res = Database::exec("UPDATE sat.ldapfilter SET filtername=:filtername, attribute=:attribute, value=:value WHERE filterid=:filterid", array( + 'filterid' => $filterid, + 'filtername' => $filtername, + 'attribute' => $filterattribute, + 'value' => $filtervalue + )); + + if ($res !== 1) { + Message::addError('ldap-filter-insert-failed'); + } else { + Message::addSuccess('ldap-filter-created'); + } + + } + Util::redirect("?do=dozmod§ion=ldapfilters"); + } + + public static function doAjax() + { + + } + +} \ No newline at end of file diff --git a/modules-available/dozmod/permissions/permissions.json b/modules-available/dozmod/permissions/permissions.json index b9c82107..dc5a46ed 100644 --- a/modules-available/dozmod/permissions/permissions.json +++ b/modules-available/dozmod/permissions/permissions.json @@ -5,6 +5,12 @@ "actionlog.view": { "location-aware": false }, + "ldapfilters.view": { + "location-aware": false + }, + "ldapfilters.save": { + "location-aware": false + }, "mailconfig.save": { "location-aware": false }, diff --git a/modules-available/dozmod/templates/ldapfilter-add.html b/modules-available/dozmod/templates/ldapfilter-add.html new file mode 100644 index 00000000..c74fbcda --- /dev/null +++ b/modules-available/dozmod/templates/ldapfilter-add.html @@ -0,0 +1,39 @@ +

{{lang_ldapfilters}}

+ +
+
+ {{lang_ldapFilterEdit}} +
+
+ +

{{lang_ldapFilterDescription}}

+
+ + + +
+ + +
+
+ + +
+
+ + +
+ +
+ {{lang_cancel}} + +
+
+
+
+ + diff --git a/modules-available/dozmod/templates/ldapfilters.html b/modules-available/dozmod/templates/ldapfilters.html new file mode 100644 index 00000000..49ecc222 --- /dev/null +++ b/modules-available/dozmod/templates/ldapfilters.html @@ -0,0 +1,72 @@ +

{{lang_ldapfilters}}

+ + + + + + + {{#hasEditPermission}} + + + {{/hasEditPermission}} + + + + {{#ldapfilters}} + + + + + {{#hasEditPermission}} + + + {{/hasEditPermission}} + + {{/ldapfilters}} + +
{{lang_ldapFilterName}}{{lang_ldapFilterAttribute}}{{lang_ldapFilterValue}}{{lang_edit}}{{lang_delete}}
{{filtername}}{{attribute}}{{value}} + + + + + +
+ +{{#hasEditPermission}} +
+ + + {{lang_ldapFilterAdd}} + +
+{{/hasEditPermission}} + +
+ + + +
+ + -- cgit v1.2.3-55-g7522