mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-10-12 15:04:04 +00:00
implemented permissions controller, reworked news admin permissions into api call
This commit is contained in:
@@ -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'),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2024 fhcomplete.org
|
||||
* 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
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
export default {
|
||||
getPermissions(permissions) {
|
||||
return {
|
||||
method: 'post',
|
||||
url: '/api/frontend/v1/permission/getPermissions',
|
||||
params: {
|
||||
permissions,
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user