Archived
1
0

Changes of the last few months including restructuring system from using only ranks to permissions

This commit is contained in:
Marcel
2018-12-26 18:19:28 +01:00
parent 72f3434803
commit 1a1ac17ecf
38 changed files with 845 additions and 361 deletions

View File

@@ -1,7 +1,7 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Projects extends CI_Controller
class Projects extends MY_Controller
{
public function __construct()
@@ -13,7 +13,7 @@
public function index()
{
if (!isset($_SESSION['user']) || empty($_SESSION['user']) || $_SESSION['user']['rank'] < 9) redirect(base_url('login'));
$this->neededPermission('projects.view');
$entries = $this->ProjectsModel->getEntries('all');
$categories = $this->ProjectsModel->getCategories('all');
@@ -25,12 +25,17 @@
public function edit($id = NULL)
{
if (!isset($_SESSION['user']) || empty($_SESSION['user']) || $_SESSION['user']['rank'] < 9) redirect(base_url('login'));
$this->neededPermission('projects.create');
$edit = $id === NULL ? false : true;
$content = null;
$projectCategories = [];
if ($edit) {
// TODO: Check if project is created by user or not
$this->neededPermission('projects.edit');
if ($this->ProjectsModel->checkIfExists($id)) {
$content = $this->ProjectsModel->getEntry($id);
$content = $this->ProjectsModel->mergeFullTranslationData($content)[0];
@@ -50,8 +55,16 @@
public function sendEdit()
{
header('Content-Type: application/json');
if (!isset($_SESSION['user']) || empty($_SESSION['user']) || $_SESSION['user']['rank'] < 9) {
echo json_encode(['success' => false, 'message' => 'Du hast nicht genügend Rechte, um Projekte zu erstellen bzw. bearbeiten.']);
if (!$this->hasPermission('projects.create')) {
echo json_encode(['success' => false, 'message' => 'Du hast nicht genügend Rechte, um Projekte zu erstellen.']);
exit;
}
$editingID = $this->input->post('editingID');
// TODO: Check if user is author of project
if($editingID !== '-1' && !$this->hasPermission('projects.edit')) {
echo json_encode(['success' => false, 'message' => 'Du hast nicht genügend Rechte, um Projekte zu bearbeiten.']);
exit;
}
@@ -83,7 +96,6 @@
$date = date('Y-m-d H:i:s', strtotime($this->input->post('date')));
$image = $this->input->post('image');
$editingID = $this->input->post('editingID');
if($editingID == '-1' && $this->ProjectsModel->checkIfNameExists($url)) {
echo json_encode(['success' => false, 'message' => 'Die angegebene URL ist bereits vergeben.']);
@@ -102,14 +114,17 @@
public function delete()
{
if (!isset($_SESSION['user']) || empty($_SESSION['user']) || $_SESSION['user']['rank'] < 9) redirect(base_url('login'));
// TODO: Check if user is author of project
$this->neededPermission('projects.delete');
$id = filter_input(INPUT_POST, "id");
$this->ProjectsModel->delete($id);
}
public function delete_category()
{
if (!isset($_SESSION['user']) || empty($_SESSION['user']) || $_SESSION['user']['rank'] < 9) redirect(base_url('login'));
$this->neededPermission('projects.deleteCategory');
$id = filter_input(INPUT_POST, "id");
$this->ProjectsModel->deleteCategory($id);
}