From a852dccd8b74b67ba4c8ddf29c65333a38c1dd6d Mon Sep 17 00:00:00 2001 From: tp_dhu Date: Mon, 17 Feb 2025 01:21:16 +0000 Subject: [PATCH] - added interface - for CRUD, ensures all methods are present and aligned. - added trait for checking authorisation with redirect stored in session to return - shows which controllers requires auth, adds check function --- app/controllers/AttachmentController.php | 6 +----- app/controllers/KBController.php | 9 ++------ app/controllers/TagController.php | 23 ++++++++++++++------ app/controllers/TicketController.php | 14 ++++++------ app/controllers/UserController.php | 27 +++++++++++++++++------- app/interfaces/CRUD.php | 25 ++++++++++++++++++++++ app/traits/RequiresAuth.php | 13 ++++++++++++ 7 files changed, 84 insertions(+), 33 deletions(-) create mode 100644 app/interfaces/CRUD.php create mode 100644 app/traits/RequiresAuth.php diff --git a/app/controllers/AttachmentController.php b/app/controllers/AttachmentController.php index a0f934d..3aabb48 100644 --- a/app/controllers/AttachmentController.php +++ b/app/controllers/AttachmentController.php @@ -2,11 +2,7 @@ class AttachmentController { - private function check_access($f3){ - if(!$f3->exists('SESSION.user')){ - $f3->reroute('/login'); - } - } + use RequiresAuth; // list attachments public function index($f3){ diff --git a/app/controllers/KBController.php b/app/controllers/KBController.php index 0090ea2..180f07f 100644 --- a/app/controllers/KBController.php +++ b/app/controllers/KBController.php @@ -1,13 +1,8 @@ exists('SESSION.user')){ - // $f3->set('SESSION.error', 'You don\'t have permission for this ticket.'); - $f3->reroute('/login'); - } - } + use RequiresAuth; public function index($f3){ diff --git a/app/controllers/TagController.php b/app/controllers/TagController.php index 3a774cb..6c1411f 100644 --- a/app/controllers/TagController.php +++ b/app/controllers/TagController.php @@ -1,12 +1,8 @@ exists('SESSION.user')){ - $f3->reroute('/login'); - } - } + use RequiresAuth; /** * List all tags @@ -40,5 +36,20 @@ class TagController { $db->exec('INSERT IGNORE INTO tags (name, color) VALUES (?, ?)', [$name, $color]); $f3->reroute('/tags'); } + + public function view($f3) + { + + } + + public function editForm($f3) + { + + } + + public function update($f3) + { + + } } \ No newline at end of file diff --git a/app/controllers/TicketController.php b/app/controllers/TicketController.php index 06596de..ae8cbb7 100644 --- a/app/controllers/TicketController.php +++ b/app/controllers/TicketController.php @@ -1,6 +1,8 @@ check_access($f3); @@ -41,6 +44,7 @@ class TicketController { } // show create form + // TODO_PROJECTS: dropdown to associate ticket with project public function createForm($f3){ $this->check_access($f3); $f3->set('content', '../ui/views/ticket/create.html'); @@ -92,6 +96,7 @@ class TicketController { // show edit form // including custom forms + // TODO_PROJECTS: allow reasssigning or removing a project association public function editForm($f3){ $this->check_access($f3); @@ -207,12 +212,7 @@ class TicketController { $f3->reroute('/ticket/' . $parent_id); } - protected function check_access($f3){ - if(!$f3->exists('SESSION.user')){ - // $f3->set('SESSION.error', 'You don\'t have permission for this ticket.'); - $f3->reroute('/login'); - } - } + protected function get_ticket_check_edit_permission($f3){ diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index e17a6c4..b893882 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -1,16 +1,11 @@ get('SESSION.user'); - if(!$current_user || $current_user['role_name'] !== 'admin'){ - $f3->reroute('/login'); - } - } - public function index($f3){ $this->check_access($f3); @@ -59,4 +54,20 @@ class UserController { [$new_username, $user_id]); $f3->reroute('/users'); } + + public function createForm($f3) + { + + } + + public function create($f3) + { + + } + + public function view($f3) + { + + } + } \ No newline at end of file diff --git a/app/interfaces/CRUD.php b/app/interfaces/CRUD.php new file mode 100644 index 0000000..740fea4 --- /dev/null +++ b/app/interfaces/CRUD.php @@ -0,0 +1,25 @@ +exists('SESSION.user')){ + // $f3->set('SESSION.error', 'You don\'t have permission for this ticket.'); + $f3->set('SESSION.redirect', $f3->get('PATH')); + $f3->reroute('/login'); + } + } + +} \ No newline at end of file