/**
  * Execute the action
  *
  * @access public
  * @param  array   $data   Event data dictionary
  * @return bool            True if the action was executed or false when not executed
  */
 public function doAction(array $data)
 {
     if ($data['column_id'] == $this->getParam('column_id')) {
         $this->task->update(array('id' => $data['task_id'], 'owner_id' => $this->acl->getUserId()), false);
         return true;
     }
     return false;
 }
 public function testExecute()
 {
     $action = new Action\TaskAssignCurrentUser(1, new Task($this->registry), new Acl($this->registry));
     $action->setParam('column_id', 2);
     $_SESSION = array('user' => array('id' => 5));
     // We create a task in the first column
     $t = new Task($this->registry);
     $p = new Project($this->registry);
     $a = new Acl($this->registry);
     $this->assertEquals(5, $a->getUserId());
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
     // We create an event to move the task to the 2nd column
     $event = array('project_id' => 1, 'task_id' => 1, 'column_id' => 2);
     // Our event should be executed
     $this->assertTrue($action->execute($event));
     // Our task should be assigned to the user 5 (from the session)
     $task = $t->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(1, $task['id']);
     $this->assertEquals(5, $task['owner_id']);
 }
示例#3
0
 /**
  * Display the template show task (common between different actions)
  *
  * @access protected
  * @param  array  $task               Task data
  * @param  array  $comment_form       Comment form data
  * @param  array  $description_form   Description form data
  * @param  array  $comment_edit_form  Comment edit form data
  */
 protected function showTask(array $task, array $comment_form = array(), array $description_form = array(), array $comment_edit_form = array())
 {
     if (empty($comment_form)) {
         $comment_form = array('values' => array('task_id' => $task['id'], 'user_id' => $this->acl->getUserId()), 'errors' => array());
     }
     if (empty($description_form)) {
         $description_form = array('values' => array('id' => $task['id']), 'errors' => array());
     }
     if (empty($comment_edit_form)) {
         $comment_edit_form = array('values' => array('id' => 0), 'errors' => array());
     } else {
         $hide_comment_form = true;
     }
     $this->response->html($this->template->layout('task_show', array('hide_comment_form' => isset($hide_comment_form), 'comment_edit_form' => $comment_edit_form, 'comment_form' => $comment_form, 'description_form' => $description_form, 'comments' => $this->comment->getAll($task['id']), 'task' => $task, 'columns_list' => $this->board->getColumnsList($task['project_id']), 'colors_list' => $this->task->getColors(), 'menu' => 'tasks', 'title' => $task['title'])));
 }
示例#4
0
 public function testExtend()
 {
     $acl = new Acl($this->container);
     $this->assertFalse($acl->isProjectManagerAction('plop', 'show'));
     $acl->extend('project_manager_acl', array('plop' => '*'));
     $this->assertTrue($acl->isProjectManagerAction('plop', 'show'));
     $this->assertTrue($acl->isProjectManagerAction('swimlane', 'index'));
 }
示例#5
0
 public function testPageAccessNotMember()
 {
     $acl = new Acl($this->container);
     $p = new Project($this->container);
     $pp = new ProjectPermission($this->container);
     $u = new User($this->container);
     // We create our user
     $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
     // We create a project and set our user as member
     $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
     $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
     $this->assertFalse($pp->isMember(1, 2));
     $this->assertFalse($pp->isManager(1, 2));
     $session = new Session();
     $session['user'] = array('id' => 2, 'is_admin' => false);
     $this->assertFalse($acl->isAllowed('board', 'show', 2));
     $this->assertFalse($acl->isAllowed('board', 'show', 1));
     $this->assertFalse($acl->isAllowed('task', 'show', 1));
     $this->assertFalse($acl->isAllowed('task', 'update', 1));
     $this->assertFalse($acl->isAllowed('project', 'show', 1));
     $this->assertFalse($acl->isAllowed('config', 'application', 1));
     $this->assertFalse($acl->isAllowed('project', 'users', 1));
     $this->assertFalse($acl->isAllowed('task', 'remove', 1));
     $this->assertTrue($acl->isAllowed('app', 'index', 1));
 }
示例#6
0
 public function testIsPageAllowed()
 {
     $acl = new Acl($this->container);
     // Public access
     $_SESSION = array();
     $this->assertFalse($acl->isPageAccessAllowed('user', 'create'));
     $this->assertFalse($acl->isPageAccessAllowed('user', 'save'));
     $this->assertFalse($acl->isPageAccessAllowed('user', 'remove'));
     $this->assertFalse($acl->isPageAccessAllowed('user', 'confirm'));
     $this->assertFalse($acl->isPageAccessAllowed('app', 'index'));
     $this->assertFalse($acl->isPageAccessAllowed('user', 'index'));
     $this->assertTrue($acl->isPageAccessAllowed('user', 'login'));
     $this->assertTrue($acl->isPageAccessAllowed('user', 'check'));
     $this->assertTrue($acl->isPageAccessAllowed('webhook', 'task'));
     $this->assertTrue($acl->isPageAccessAllowed('board', 'readonly'));
     // Regular user
     $_SESSION = array('user' => array('is_admin' => false));
     $this->assertFalse($acl->isPageAccessAllowed('user', 'create'));
     $this->assertFalse($acl->isPageAccessAllowed('user', 'save'));
     $this->assertFalse($acl->isPageAccessAllowed('user', 'remove'));
     $this->assertFalse($acl->isPageAccessAllowed('user', 'confirm'));
     $this->assertTrue($acl->isPageAccessAllowed('app', 'index'));
     $this->assertFalse($acl->isPageAccessAllowed('user', 'index'));
     $this->assertTrue($acl->isPageAccessAllowed('user', 'login'));
     $this->assertTrue($acl->isPageAccessAllowed('user', 'check'));
     $this->assertTrue($acl->isPageAccessAllowed('webhook', 'task'));
     $this->assertTrue($acl->isPageAccessAllowed('board', 'readonly'));
     // Admin user
     $_SESSION = array('user' => array('is_admin' => true));
     $this->assertTrue($acl->isPageAccessAllowed('user', 'create'));
     $this->assertTrue($acl->isPageAccessAllowed('user', 'save'));
     $this->assertTrue($acl->isPageAccessAllowed('user', 'remove'));
     $this->assertTrue($acl->isPageAccessAllowed('user', 'confirm'));
     $this->assertTrue($acl->isPageAccessAllowed('app', 'index'));
     $this->assertTrue($acl->isPageAccessAllowed('user', 'index'));
     $this->assertTrue($acl->isPageAccessAllowed('user', 'login'));
     $this->assertTrue($acl->isPageAccessAllowed('user', 'check'));
     $this->assertTrue($acl->isPageAccessAllowed('task', 'add'));
     $this->assertTrue($acl->isPageAccessAllowed('board', 'readonly'));
 }
示例#7
0
 /**
  * Get all projects, optionaly fetch stats for each project and can check users permissions
  *
  * @access public
  * @param  bool       $fetch_stats          If true, return metrics about each projects
  * @param  bool       $check_permissions    If true, remove projects not allowed for the current user
  * @return array
  */
 public function getAll($fetch_stats = false, $check_permissions = false)
 {
     if (!$fetch_stats) {
         return $this->db->table(self::TABLE)->asc('name')->findAll();
     }
     $this->db->startTransaction();
     $projects = $this->db->table(self::TABLE)->asc('name')->findAll();
     $boardModel = new Board($this->db, $this->event);
     $taskModel = new Task($this->db, $this->event);
     $aclModel = new Acl($this->db, $this->event);
     foreach ($projects as $pkey => &$project) {
         if ($check_permissions && !$this->isUserAllowed($project['id'], $aclModel->getUserId())) {
             unset($projects[$pkey]);
         } else {
             $columns = $boardModel->getcolumns($project['id']);
             $project['nb_active_tasks'] = 0;
             foreach ($columns as &$column) {
                 $column['nb_active_tasks'] = $taskModel->countByColumnId($project['id'], $column['id']);
                 $project['nb_active_tasks'] += $column['nb_active_tasks'];
             }
             $project['columns'] = $columns;
             $project['nb_tasks'] = $taskModel->countByProjectId($project['id']);
             $project['nb_inactive_tasks'] = $project['nb_tasks'] - $project['nb_active_tasks'];
         }
     }
     $this->db->closeTransaction();
     return $projects;
 }