diff --git a/application/controllers/api/frontend/v1/dashboard/Widget.php b/application/controllers/api/frontend/v1/dashboard/Widget.php index ac8c682e8..99865b6db 100644 --- a/application/controllers/api/frontend/v1/dashboard/Widget.php +++ b/application/controllers/api/frontend/v1/dashboard/Widget.php @@ -101,6 +101,9 @@ class Widget extends FHCAPI_Controller $tmpsetup = json_decode($widget->setup); $tmpsetup->file = absoluteJsImportUrl($tmpsetup->file); $widget->setup = $tmpsetup; + $widget->permitted = empty($widget->berechtigung_kurzbz) + || $this->permissionlib->isBerechtigt($widget->berechtigung_kurzbz); + return $widget; }, $widgets); diff --git a/public/js/components/Dashboard/Item.js b/public/js/components/Dashboard/Item.js index 160b34e91..eea92f1c9 100644 --- a/public/js/components/Dashboard/Item.js +++ b/public/js/components/Dashboard/Item.js @@ -1,5 +1,6 @@ import BsModal from "../Bootstrap/Modal.js"; import HeightTransition from "../Tranistion/HeightTransition.js"; +import MissingPermissionWidget from "../DashboardWidget/MissingPermission.js"; import { enableDragDropTouch } from "../../../../vendor/drag-drop-touch-js/dragdroptouch/dist/drag-drop-touch.esm.min.js"; @@ -112,6 +113,12 @@ export default { isPinned() { return this.place?.pinned ? true : false; }, + permitted() { + // widgets without a linked permission (or before the template loaded) + // are considered permitted; the backend sets permitted === false only + // when the user is missing the widget's required permission + return this.widgetTemplate?.permitted !== false; + }, ready() { return this.component && this.arguments !== null; } @@ -169,7 +176,11 @@ export default { && this.widgetTemplate.widget_id && this.widgetTemplate.arguments ) { - let component = (await import(this.widgetTemplate.setup.file)).default; + // render the "missing permission" screen instead of the actual + // widget when the user does not hold the widget's linked permission + let component = this.permitted + ? (await import(this.widgetTemplate.setup.file)).default + : MissingPermissionWidget; this.$options.components["widget" + this.widgetTemplate.widget_id] = component; this.component = "widget" + this.widgetTemplate.widget_id; this.arguments = { ...this.widgetTemplate.arguments, ...this.config }; @@ -269,7 +280,7 @@ export default { widget.permitted !== false); + }, hasAnyWidgets() { if (!this.widgets) return false; - if (!this.widgets.length && !this.hiddenWidgets?.length) + if (!this.availableWidgets.length && !this.hiddenWidgets?.length) return false; return true; } @@ -54,7 +58,7 @@ export default { diff --git a/public/js/components/DashboardWidget/MissingPermission.js b/public/js/components/DashboardWidget/MissingPermission.js new file mode 100644 index 000000000..ceaff5295 --- /dev/null +++ b/public/js/components/DashboardWidget/MissingPermission.js @@ -0,0 +1,21 @@ +import AbstractWidget from './Abstract.js'; + +/** + * Fallback screen rendered in place of a widget when the current user is missing + * the permission (berechtigung_kurzbz) linked to that widget. Used for widgets + * that are already on a user's dashboard but whose required permission the user + * no longer holds. + */ +export default { + mixins: [ + AbstractWidget + ], + created() { + this.$emit('setConfig', false); + }, + template: /*html*/` +
+ +

{{ $p.t('dashboard/widget_missing_permission') }}

+
` +} diff --git a/system/dbupdate_3.4.php b/system/dbupdate_3.4.php index 899a065ae..4a1b70d8c 100644 --- a/system/dbupdate_3.4.php +++ b/system/dbupdate_3.4.php @@ -103,6 +103,7 @@ require_once('dbupdate_3.4/76160_lvv_favorites.php'); require_once('dbupdate_3.4/77080_tabulator_presets_table.php'); require_once('dbupdate_3.4/78292_gehaltsanpassungtyp.php'); require_once('dbupdate_3.4/54225_reihungstest_ablauf_fuer_quereinsteiger.php'); +require_once('dbupdate_3.4/77757_widgets_berechtigungen.php'); require_once('dbupdate_3.4/77048_cis4_mitarbeiter_studstatus_widget.php'); // *** Pruefung und hinzufuegen der neuen Attribute und Tabellen diff --git a/system/dbupdate_3.4/77757_widgets_berechtigungen.php b/system/dbupdate_3.4/77757_widgets_berechtigungen.php new file mode 100644 index 000000000..da7fc7d0c --- /dev/null +++ b/system/dbupdate_3.4/77757_widgets_berechtigungen.php @@ -0,0 +1,57 @@ + system.tbl_berechtigung) +if ($result = @$db->db_query(" + SELECT 1 + FROM information_schema.columns + WHERE table_schema = 'dashboard' + AND table_name = 'tbl_widget' + AND column_name = 'berechtigung_kurzbz';")) +{ + if ($db->db_num_rows($result) == 0) + { + $qry = " + ALTER TABLE dashboard.tbl_widget + ADD COLUMN berechtigung_kurzbz VARCHAR(32) NULL; + + ALTER TABLE dashboard.tbl_widget + ADD CONSTRAINT tbl_widget_berechtigung_fk + FOREIGN KEY (berechtigung_kurzbz) + REFERENCES system.tbl_berechtigung (berechtigung_kurzbz) + ON UPDATE CASCADE ON DELETE SET NULL;"; + + if (!$db->db_query($qry)) + { + echo 'dashboard.tbl_widget: '.$db->db_last_error().'
'; + } + else + { + echo 'dashboard.tbl_widget: Spalte berechtigung_kurzbz (FK system.tbl_berechtigung) hinzugefuegt
'; + } + } +} diff --git a/system/phrasesupdate.php b/system/phrasesupdate.php index 8ba0f4368..99cbae061 100644 --- a/system/phrasesupdate.php +++ b/system/phrasesupdate.php @@ -49779,6 +49779,26 @@ array( ) ) ), + array( + 'app' => 'core', + 'category' => 'dashboard', + 'phrase' => 'widget_missing_permission', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'Ihnen fehlt die erforderliche Berechtigung, um dieses Widget anzuzeigen.', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'You do not have the permission required to display this widget.', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), // CIS4 phrases from legacy code end // FHC4 Phrases Abschlusspruefung array(