From b8fa0246803dab40cf57d40b45984c53046f2d55 Mon Sep 17 00:00:00 2001 From: "Dzial Techniczny WMW Projekt s.c" Date: Tue, 10 Dec 2019 11:34:53 +0100 Subject: Plugins directory and local modifications --- .../Group_assign/Model/TaskProjectMoveModel.php | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 plugins/Group_assign/Model/TaskProjectMoveModel.php (limited to 'plugins/Group_assign/Model/TaskProjectMoveModel.php') diff --git a/plugins/Group_assign/Model/TaskProjectMoveModel.php b/plugins/Group_assign/Model/TaskProjectMoveModel.php new file mode 100644 index 00000000..554d3330 --- /dev/null +++ b/plugins/Group_assign/Model/TaskProjectMoveModel.php @@ -0,0 +1,96 @@ +taskFinderModel->getById($task_id); + $values = $this->prepare($project_id, $swimlane_id, $column_id, $category_id, $owner_id, $task); + + $this->checkDestinationProjectValues($values); + $this->tagDuplicationModel->syncTaskTagsToAnotherProject($task_id, $project_id); + + // Check if the group is allowed for the destination project and unassign if not + $group_id = $this->db->table(TaskModel::TABLE)->eq('id', $task_id)->findOneColumn('owner_gp'); + if ($group_id > 0) { + $group_in_project = $this->db + ->table(ProjectGroupRoleModel::TABLE) + ->eq('project_id', $project_id) + ->eq('group_id', $group_id) + ->exists(); + if (!$group_in_project) { $this->db->table(TaskModel::TABLE)->eq('id', $task_id)->update(['owner_gp' => 0]); } + } + + // Check if the other assignees are allowed for the destination project and remove from ms group if not + $ms_id = $this->db->table(TaskModel::TABLE)->eq('id', $task_id)->findOneColumn('owner_ms'); + if ($ms_id > 0) { + $users_in_ms = $this->multiselectMemberModel->getMembers($ms_id); + foreach ($users_in_ms as $user) { + if (! $this->projectPermissionModel->isAssignable($project_id, $user['id'])) { + $this->multiselectMemberModel->removeUser($ms_id, $user['id']); + } + } + } + + + if ($this->db->table(TaskModel::TABLE)->eq('id', $task_id)->update($values)) { + $this->queueManager->push($this->taskEventJob->withParams($task_id, array(TaskModel::EVENT_MOVE_PROJECT), $values)); + } + + return true; + } + + /** + * Prepare new task values + * + * @access protected + * @param integer $project_id + * @param integer $swimlane_id + * @param integer $column_id + * @param integer $category_id + * @param integer $owner_id + * @param array $task + * @return array + */ + protected function prepare($project_id, $swimlane_id, $column_id, $category_id, $owner_id, array $task) + { + $values = array(); + $values['is_active'] = 1; + $values['project_id'] = $project_id; + $values['column_id'] = $column_id !== null ? $column_id : $task['column_id']; + $values['position'] = $this->taskFinderModel->countByColumnId($project_id, $values['column_id']) + 1; + $values['swimlane_id'] = $swimlane_id !== null ? $swimlane_id : $task['swimlane_id']; + $values['category_id'] = $category_id !== null ? $category_id : $task['category_id']; + $values['owner_id'] = $owner_id !== null ? $owner_id : $task['owner_id']; + $values['priority'] = $task['priority']; + return $values; + } +} -- cgit v1.2.3