From 94a9f89416ea4e7d522439ee4773d3dad6cb2edc Mon Sep 17 00:00:00 2001 From: upstream Date: Fri, 2 Oct 2026 16:27:40 +0200 Subject: [PATCH] Upstream kanboard/kanboard state of the touched files before e6a5d284be --- app/Api/Procedure/BaseProcedure.php | 50 ++++++++ app/Api/Procedure/CommentProcedure.php | 113 ++++++++++++++++++ app/Api/Procedure/MeProcedure.php | 67 +++++++++++ app/Api/Procedure/ProjectProcedure.php | 152 +++++++++++++++++++++++++ 4 files changed, 382 insertions(+) create mode 100644 app/Api/Procedure/BaseProcedure.php create mode 100644 app/Api/Procedure/CommentProcedure.php create mode 100644 app/Api/Procedure/MeProcedure.php create mode 100644 app/Api/Procedure/ProjectProcedure.php diff --git a/app/Api/Procedure/BaseProcedure.php b/app/Api/Procedure/BaseProcedure.php new file mode 100644 index 0000000..aa00d0d --- /dev/null +++ b/app/Api/Procedure/BaseProcedure.php @@ -0,0 +1,50 @@ +container)->check($procedure); + UserAuthorization::getInstance($this->container)->check($this->getClassName(), $procedure); + } + + protected function filterValues(array $values) + { + foreach ($values as $key => $value) { + if (is_null($value)) { + unset($values[$key]); + } + } + + return $values; + } + + protected function filterUser($user) + { + return is_array($user) ? $this->userModel->removePrivateColumns($user) : $user; + } + + protected function filterUsers($users) + { + return is_array($users) ? array_map(array($this, 'filterUser'), $users) : $users; + } + + protected function getClassName() + { + $reflection = new ReflectionClass(get_called_class()); + return $reflection->getShortName(); + } +} diff --git a/app/Api/Procedure/CommentProcedure.php b/app/Api/Procedure/CommentProcedure.php new file mode 100644 index 0000000..3209924 --- /dev/null +++ b/app/Api/Procedure/CommentProcedure.php @@ -0,0 +1,113 @@ +container)->check($this->getClassName(), 'getComment', $comment_id); + return $this->commentModel->getById($comment_id); + } + + public function getAllComments($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllComments', $task_id); + $comments = $this->commentModel->getAll($task_id); + $filteredComments = []; + $userRole = $this->userSession->getRole(); + + foreach ($comments as $comment) { + if ($userRole === Role::APP_MANAGER && $comment['visibility'] === Role::APP_ADMIN) { + continue; + } + + if ($userRole === Role::APP_USER && $comment['visibility'] !== Role::APP_USER) { + continue; + } + + $filteredComments[] = $comment; + } + + return $filteredComments; + } + + public function removeComment($comment_id) + { + CommentAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeComment', $comment_id); + + if ($this->userSession->isLogged()) { + $loggedUserID = $this->userSession->getId(); + $comment = $this->commentModel->getById($comment_id); + if ($comment['user_id'] != $loggedUserID) { + return false; + } + } + + return $this->commentModel->remove($comment_id); + } + + public function createComment($task_id, $user_id, $content, $reference = '', $visibility = Role::APP_USER) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'createComment', $task_id); + + if ($this->userSession->isLogged()) { + $loggedUserID = $this->userSession->getId(); + if ($user_id != $loggedUserID) { + return false; + } + + $userRole = $this->userSession->getRole(); + if ($userRole === Role::APP_MANAGER && $visibility === Role::APP_ADMIN) { + return false; + } + + if ($userRole === Role::APP_USER && $visibility !== Role::APP_USER) { + return false; + } + } + + $values = array( + 'task_id' => $task_id, + 'user_id' => $user_id, + 'comment' => $content, + 'reference' => $reference, + 'visibility' => $visibility, + ); + + list($valid, ) = $this->commentValidator->validateCreation($values); + + return $valid ? $this->commentModel->create($values) : false; + } + + public function updateComment($id, $content) + { + CommentAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateComment', $id); + + if ($this->userSession->isLogged()) { + $loggedUserID = $this->userSession->getId(); + $comment = $this->commentModel->getById($id); + if ($comment['user_id'] != $loggedUserID) { + return false; + } + } + + $values = array( + 'id' => $id, + 'comment' => $content, + ); + + list($valid, ) = $this->commentValidator->validateModification($values); + return $valid && $this->commentModel->update($values); + } +} diff --git a/app/Api/Procedure/MeProcedure.php b/app/Api/Procedure/MeProcedure.php new file mode 100644 index 0000000..3ccba0e --- /dev/null +++ b/app/Api/Procedure/MeProcedure.php @@ -0,0 +1,67 @@ +userSession->getId(); + + return $this->taskListSubtaskAssigneeFormatter + ->withQuery($this->taskFinderModel->getUserQuery($userId)) + ->withUserId($userId) + ->format(); + } + + public function getMyActivityStream() + { + $project_ids = $this->projectPermissionModel->getActiveProjectIds($this->userSession->getId()); + return $this->helper->projectActivity->getProjectsEvents($project_ids, 100); + } + + public function createMyPrivateProject($name, $description = null) + { + if ($this->configModel->get('disable_private_project', 0) == 1) { + return false; + } + + $values = array( + 'name' => $name, + 'description' => $description, + 'is_private' => 1, + ); + + list($valid, ) = $this->projectValidator->validateCreation($values); + return $valid ? $this->projectModel->create($values, $this->userSession->getId(), true) : false; + } + + public function getMyProjectsList() + { + return (object) $this->projectUserRoleModel->getProjectsByUser($this->userSession->getId()); + } + + public function getMyOverdueTasks() + { + return $this->taskFinderModel->getOverdueTasksByUser($this->userSession->getId()); + } + + public function getMyProjects() + { + $project_ids = $this->projectPermissionModel->getActiveProjectIds($this->userSession->getId()); + $projects = $this->projectModel->getAllByIds($project_ids); + + return $this->projectsApiFormatter->withProjects($projects)->format(); + } +} diff --git a/app/Api/Procedure/ProjectProcedure.php b/app/Api/Procedure/ProjectProcedure.php new file mode 100644 index 0000000..6da00ae --- /dev/null +++ b/app/Api/Procedure/ProjectProcedure.php @@ -0,0 +1,152 @@ +container)->check($this->getClassName(), 'getProjectById', $project_id); + $project = $this->projectModel->getById($project_id); + return $this->projectApiFormatter->withProject($project)->format(); + } + + public function getProjectByName($name) + { + $project = $this->projectModel->getByName($name); + + if (empty($project)) { + return false; + } + + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getProjectByName', $project['id']); + return $this->projectApiFormatter->withProject($project)->format(); + } + + public function getProjectByIdentifier($identifier) + { + $project = $this->projectModel->getByIdentifier($identifier); + + if (empty($project)) { + return false; + } + + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getProjectByIdentifier', $project['id']); + return $this->projectApiFormatter->withProject($project)->format(); + } + + public function getProjectByEmail($email) + { + $project = $this->projectModel->getByEmail($email); + + if (empty($project)) { + return false; + } + + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getProjectByEmail', $project['id']); + return $this->projectApiFormatter->withProject($project)->format(); + } + + public function getAllProjects() + { + return $this->projectsApiFormatter->withProjects($this->projectModel->getAll())->format(); + } + + public function removeProject($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeProject', $project_id); + return $this->projectModel->remove($project_id); + } + + public function enableProject($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'enableProject', $project_id); + return $this->projectModel->enable($project_id); + } + + public function disableProject($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'disableProject', $project_id); + return $this->projectModel->disable($project_id); + } + + public function enableProjectPublicAccess($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'enableProjectPublicAccess', $project_id); + return $this->projectModel->enablePublicAccess($project_id); + } + + public function disableProjectPublicAccess($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'disableProjectPublicAccess', $project_id); + return $this->projectModel->disablePublicAccess($project_id); + } + + public function getProjectActivities(array $project_ids) + { + foreach ($project_ids as $project_id) { + ProjectAuthorization::getInstance($this->container) + ->check($this->getClassName(), 'getProjectActivities', $project_id); + } + + return $this->helper->projectActivity->getProjectsEvents($project_ids); + } + + public function getProjectActivity($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getProjectActivity', $project_id); + return $this->helper->projectActivity->getProjectEvents($project_id); + } + + public function createProject($name, $description = null, $owner_id = 0, $identifier = null, $start_date = null, $end_date = null, $priority_default = null, $priority_start = null, $priority_end = null, $email = null) + { + if ($owner_id === 0 && $this->userSession->isLogged()) { + $owner_id = $this->userSession->getId(); + } + + $values = $this->filterValues(array( + 'name' => $name, + 'description' => $description, + 'identifier' => $identifier, + 'start_date' => $start_date, + 'end_date' => $end_date, + 'priority_default' => $priority_default, + 'priority_start' => $priority_start, + 'priority_end' => $priority_end, + 'email' => $email, + )); + + list($valid, ) = $this->projectValidator->validateCreation($values); + return $valid ? $this->projectModel->create($values, $owner_id, $this->userSession->isLogged()) : false; + } + + public function updateProject($project_id, $name = null, $description = null, $owner_id = null, $identifier = null, $start_date = null, $end_date = null, $priority_default = null, $priority_start = null, $priority_end = null, $email = null) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateProject', $project_id); + + $values = $this->filterValues(array( + 'id' => $project_id, + 'name' => $name, + 'description' => $description, + 'owner_id' => $owner_id, + 'identifier' => $identifier, + 'start_date' => $start_date, + 'end_date' => $end_date, + 'priority_default' => $priority_default, + 'priority_start' => $priority_start, + 'priority_end' => $priority_end, + 'email' => $email, + )); + + list($valid, ) = $this->projectValidator->validateModification($values); + return $valid && $this->projectModel->update($values); + } +}