From dfaaabfc2a1e09b0623f76e017fbacfcc439e97a Mon Sep 17 00:00:00 2001 From: adisposkofh Date: Thu, 17 Sep 2026 18:05:24 +0200 Subject: [PATCH] implemented permissions controller, reworked news admin permissions into api call --- application/controllers/CisVue/Cms.php | 4 -- .../api/frontend/v1/OtherLvPlan.php | 2 +- .../api/frontend/v1/Permission.php | 61 +++++++++++++++++++ public/js/api/factory/permission.js | 28 +++++++++ .../NewsAdministration/NewsAdministration.js | 34 +++++++---- 5 files changed, 112 insertions(+), 17 deletions(-) create mode 100644 application/controllers/api/frontend/v1/Permission.php create mode 100644 public/js/api/factory/permission.js diff --git a/application/controllers/CisVue/Cms.php b/application/controllers/CisVue/Cms.php index 70a9f04a3..39a747b1b 100644 --- a/application/controllers/CisVue/Cms.php +++ b/application/controllers/CisVue/Cms.php @@ -101,10 +101,6 @@ class Cms extends Auth_Controller $this->load->view('CisRouterView/CisRouterView.php', [ 'viewData'=>$viewData, 'route' => 'NewsAdministration', - 'permissions' => [ - 'basis/news_r' => $this->permissionlib->isBerechtigt('basis/news', 's'), - 'basis/news_w' => $this->permissionlib->isBerechtigt('basis/news', 'suid'), - ], ]); } diff --git a/application/controllers/api/frontend/v1/OtherLvPlan.php b/application/controllers/api/frontend/v1/OtherLvPlan.php index 1807f0a4a..e6616cc99 100644 --- a/application/controllers/api/frontend/v1/OtherLvPlan.php +++ b/application/controllers/api/frontend/v1/OtherLvPlan.php @@ -1,6 +1,6 @@ . + */ + +if (!defined('BASEPATH')) + exit('No direct script access allowed'); + +class Permission extends FHCAPI_Controller +{ + + /** + * Object initialization + */ + public function __construct() + { + parent::__construct([ + 'getPermissions' => self::PERM_LOGGED, + ]); + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + /** + * retrieves permissions for auth user + * @access public + */ + public function getPermissions() + { + $permissionsParam = $this->input->post("permissions"); + if (!$permissionsParam || !is_array($permissionsParam)) { + $this->terminateWithError("Invalid parameter!"); + } + + $permissions = []; + foreach ($permissionsParam as $permission) { + $permissions[$permission] = $this->permissionlib->isBerechtigt($permission); + } + + $this->terminateWithSuccess($permissions); + } + + // ----------------------------------------------------------------------------------------------------------------- + // Private methods + +} + diff --git a/public/js/api/factory/permission.js b/public/js/api/factory/permission.js new file mode 100644 index 000000000..9c4e5405e --- /dev/null +++ b/public/js/api/factory/permission.js @@ -0,0 +1,28 @@ +/** + * Copyright (C) 2026 fhcomplete.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +export default { + getPermissions(permissions) { + return { + method: 'post', + url: '/api/frontend/v1/permission/getPermissions', + params: { + permissions, + }, + }; + }, +}; \ No newline at end of file diff --git a/public/js/components/Cis/Cms/NewsAdministration/NewsAdministration.js b/public/js/components/Cis/Cms/NewsAdministration/NewsAdministration.js index 3a368f148..6a1927f98 100644 --- a/public/js/components/Cis/Cms/NewsAdministration/NewsAdministration.js +++ b/public/js/components/Cis/Cms/NewsAdministration/NewsAdministration.js @@ -1,7 +1,9 @@ import NewsItemForm from './NewsItemForm.js'; import NewsItemPreview from './NewsItemPreview.js'; import NewsList from './NewsList.js'; + import ApiNewsAdministration from '../../../../api/factory/newsAdministration.js'; +import ApiPermission from '../../../../api/factory/permission.js'; export default { name: 'NewsAdministration', @@ -10,9 +12,6 @@ export default { NewsItemPreview, NewsList, }, - props: { - permissions: Object, - }, data() { return { isNewsFormShown: false, @@ -20,6 +19,8 @@ export default { editableNewsItem: null, newsPreview: null, newsFormCollapse: null, + hasBasisNewsTypRPermission: false, + hasBasisNewsTypWPermission: false, }; }, watch: { @@ -42,14 +43,6 @@ export default { }, }, }, - computed: { - hasBasisNewsTypRPermission() { - return this.permissions['basis/news_r'] || false; - }, - hasBasisNewsTypWPermission() { - return this.permissions['basis/news_w'] || false; - }, - }, methods: { async scrollToNewsForm() { await this.$nextTick(); @@ -138,11 +131,28 @@ export default { handlePreviewChange(preview) { this.newsPreview = preview; }, + async getPermissions() { + const permissionsResponse = await this.$api.call( + ApiPermission.getPermissions( + [ + "basis/news:r", + "basis/news:w", + ] + ) + ); + + if (permissionsResponse.meta.status === "success") { + this.hasBasisNewsTypRPermission = permissionsResponse.data["basis/news:r"]; + this.hasBasisNewsTypWPermission = permissionsResponse.data["basis/news:w"]; + } + }, }, - created() { + async created() { this.$p.loadCategory('ui').then(() => { this.phrasesLoaded = true; }); + + await this.getPermissions(); }, mounted() { this.newsFormCollapse = new bootstrap.Collapse(