public function testDuplicate()
 {
     $userModel = new User($this->container);
     $projectModel = new Project($this->container);
     $groupModel = new Group($this->container);
     $groupMemberModel = new GroupMember($this->container);
     $groupRoleModel = new ProjectGroupRole($this->container);
     $userRoleModel = new ProjectUserRole($this->container);
     $projectPermission = new ProjectPermission($this->container);
     $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1')));
     $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2')));
     $this->assertEquals(2, $userModel->create(array('username' => 'user 1', 'name' => 'User #1')));
     $this->assertEquals(3, $userModel->create(array('username' => 'user 2')));
     $this->assertEquals(4, $userModel->create(array('username' => 'user 3')));
     $this->assertEquals(5, $userModel->create(array('username' => 'user 4')));
     $this->assertEquals(6, $userModel->create(array('username' => 'user 5', 'name' => 'User #5')));
     $this->assertEquals(1, $groupModel->create('Group C'));
     $this->assertEquals(2, $groupModel->create('Group B'));
     $this->assertEquals(3, $groupModel->create('Group A'));
     $this->assertTrue($groupMemberModel->addUser(1, 4));
     $this->assertTrue($groupMemberModel->addUser(2, 5));
     $this->assertTrue($groupMemberModel->addUser(3, 3));
     $this->assertTrue($groupMemberModel->addUser(3, 2));
     $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER));
     $this->assertTrue($groupRoleModel->addGroup(1, 3, Role::PROJECT_MANAGER));
     $this->assertTrue($userRoleModel->addUser(1, 5, Role::PROJECT_MANAGER));
     $this->assertTrue($userRoleModel->addUser(1, 6, Role::PROJECT_MEMBER));
     $this->assertTrue($projectPermission->duplicate(1, 2));
     $this->assertCount(2, $userRoleModel->getUsers(2));
     $this->assertCount(3, $groupRoleModel->getUsers(2));
 }
 /**
  * Send overdue tasks
  *
  * @access public
  */
 public function sendOverdueTaskNotifications(InputInterface $input)
 {
     $tasks = $this->taskFinder->getOverdueTasks();
     if ($input->getOption('group')) {
         $user_tasks = array();
         $user_by_task = array();
         $projects = array();
         foreach ($this->groupByColumn($tasks, 'project_id') as $project_id => $project_tasks) {
             $users = $this->userNotification->getUsersWithNotificationEnabled($project_id);
             foreach ($users as $user) {
                 foreach ($project_tasks as $task) {
                     if ($this->userNotificationFilter->shouldReceiveNotification($user, array('task' => $task))) {
                         $user_tasks[$user['id']][] = $task;
                         $user_by_task[$user['id']][] = $user;
                         $projects[$user['id']][$task['project_id']] = $task['project_name'];
                     }
                 }
             }
         }
         if (!empty($user_tasks)) {
             $this->sendGroupUserOverdueTaskNotifications($user_tasks, $user_by_task, $projects);
         }
     } else {
         foreach ($this->groupByColumn($tasks, 'project_id') as $project_id => $project_tasks) {
             $users = $this->userNotification->getUsersWithNotificationEnabled($project_id);
             foreach ($users as $user) {
                 $this->sendUserOverdueTaskNotifications($user, $project_tasks);
             }
         }
     }
     if ($input->getOption('admin')) {
         $overdue_tasks = array();
         $projects = array();
         $project_managers = array();
         foreach ($this->groupByColumn($tasks, 'project_id') as $project_id => $project_tasks) {
             $users = $this->userNotification->getUsersWithNotificationEnabled($project_id);
             foreach ($project_tasks as $task) {
                 $managers = ProjectPermission::getManagers($task['project_id']);
                 $overdue_tasks[$project_id][] = $task;
                 $projects[$task['project_id']] = $task['project_name'];
                 $project_managers[$task['project_id']] = $managers;
             }
         }
         if (!empty($overdue_tasks)) {
             $this->sendOverdueTaskNotificationsToAdmin($overdue_tasks, $projects, $project_managers);
         }
     }
     return $tasks;
 }
예제 #3
0
 public function testMoveAnotherProjectWithForbiddenUser()
 {
     $td = new TaskDuplication($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($this->container);
     $pp = new ProjectPermission($this->container);
     $user = new User($this->container);
     // We create 2 projects
     $this->assertEquals(1, $p->create(array('name' => 'test1')));
     $this->assertEquals(2, $p->create(array('name' => 'test2')));
     // We create a new user for our project
     $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
     $this->assertTrue($pp->addMember(1, 2));
     $this->assertTrue($pp->addMember(2, 2));
     $this->assertTrue($pp->isUserAllowed(1, 2));
     $this->assertTrue($pp->isUserAllowed(2, 2));
     // We create a task
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 3)));
     // We move our task to the 2nd project
     $this->assertTrue($td->moveToProject(1, 2));
     // Check the values of the moved task
     $task = $tf->getById(1);
     $this->assertNotEmpty($task);
     $this->assertEquals(1, $task['position']);
     $this->assertEquals(0, $task['owner_id']);
     $this->assertEquals(2, $task['project_id']);
     $this->assertEquals(6, $task['column_id']);
 }
예제 #4
0
 public function testCloneProjectWithUsers()
 {
     $p = new Project($this->container);
     $c = new Category($this->container);
     $pp = new ProjectPermission($this->container);
     $u = new User($this->container);
     $pd = new ProjectDuplication($this->container);
     $this->assertEquals(2, $u->create(array('username' => 'unittest1', 'password' => 'unittest')));
     $this->assertEquals(3, $u->create(array('username' => 'unittest2', 'password' => 'unittest')));
     $this->assertEquals(4, $u->create(array('username' => 'unittest3', 'password' => 'unittest')));
     $this->assertEquals(1, $p->create(array('name' => 'P1')));
     $this->assertTrue($pp->addMember(1, 2));
     $this->assertTrue($pp->addMember(1, 4));
     $this->assertTrue($pp->addManager(1, 3));
     $this->assertTrue($pp->isMember(1, 2));
     $this->assertTrue($pp->isMember(1, 3));
     $this->assertTrue($pp->isMember(1, 4));
     $this->assertFalse($pp->isManager(1, 2));
     $this->assertTrue($pp->isManager(1, 3));
     $this->assertFalse($pp->isManager(1, 4));
     $this->assertEquals(2, $pd->duplicate(1));
     $project = $p->getById(2);
     $this->assertNotEmpty($project);
     $this->assertEquals('P1 (Clone)', $project['name']);
     $this->assertEquals(3, count($pp->getMembers(2)));
     $this->assertTrue($pp->isMember(2, 2));
     $this->assertTrue($pp->isMember(2, 3));
     $this->assertTrue($pp->isMember(2, 4));
     $this->assertFalse($pp->isManager(2, 2));
     $this->assertTrue($pp->isManager(2, 3));
     $this->assertFalse($pp->isManager(2, 4));
 }
예제 #5
0
 public function testCommentCreatedWithUser()
 {
     $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithUser'));
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'foobar')));
     $tc = new TaskCreation($this->container);
     $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 355691, 'project_id' => 1)));
     $u = new User($this->container);
     $this->assertEquals(2, $u->create(array('username' => 'minicoders')));
     $pp = new ProjectPermission($this->container);
     $this->assertTrue($pp->addMember(1, 2));
     $g = new GitlabWebhook($this->container);
     $g->setProjectId(1);
     $this->assertNotFalse($g->parsePayload(json_decode(file_get_contents(__DIR__ . '/../fixtures/gitlab_comment_created.json'), true)));
 }
예제 #6
0
 public function testIssueAssigned()
 {
     $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, array($this, 'onIssueAssigned'));
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'foobar')));
     $tc = new TaskCreation($this->container);
     $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1)));
     $u = new User($this->container);
     $this->assertEquals(2, $u->create(array('username' => 'minicoders')));
     $pp = new ProjectPermission($this->container);
     $this->assertTrue($pp->addMember(1, 2));
     $g = new BitbucketWebhook($this->container);
     $g->setProjectId(1);
     $this->assertNotFalse($g->parsePayload('issue:updated', json_decode(file_get_contents(__DIR__ . '/../fixtures/bitbucket_issue_assigned.json'), true)));
     $this->assertNotEmpty($this->container['dispatcher']->getCalledListeners());
 }
예제 #7
0
 public function testIsProjectManagementAllowedForProjectManager()
 {
     $h = new User($this->container);
     $p = new Project($this->container);
     $pp = new ProjectPermission($this->container);
     $u = new UserModel($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 project member
     $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
     $this->assertTrue($pp->addManager(1, 2));
     $this->assertTrue($pp->isMember(1, 2));
     $this->assertTrue($pp->isManager(1, 2));
     // We fake a session for him
     $this->container['sessionStorage']->user = array('id' => 2, 'is_admin' => false, 'is_project_admin' => false);
     $this->assertTrue($h->isProjectManagementAllowed(1));
 }
예제 #8
0
 public function testSendNotifications()
 {
     $u = new User($this->container);
     $n = new UserNotification($this->container);
     $p = new Project($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $pp = new ProjectPermission($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'is_everybody_allowed' => 1)));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
     $this->assertTrue($u->update(array('id' => 1, 'email' => 'test@localhost')));
     $this->assertTrue($pp->isEverybodyAllowed(1));
     $n->saveSettings(1, array('notifications_enabled' => 1, 'notifications_filter' => UserNotificationFilter::FILTER_NONE, 'notification_types' => array('web' => 1, 'email' => 1)));
     $notifier = $this->getMockBuilder('Stdclass')->setMethods(array('notifyUser'))->getMock();
     $notifier->expects($this->exactly(2))->method('notifyUser');
     $this->container['userNotificationType']->expects($this->at(0))->method('getSelectedTypes')->will($this->returnValue(array('email', 'web')));
     $this->container['userNotificationType']->expects($this->at(1))->method('getType')->with($this->equalTo('email'))->will($this->returnValue($notifier));
     $this->container['userNotificationType']->expects($this->at(2))->method('getType')->with($this->equalTo('web'))->will($this->returnValue($notifier));
     $n->sendNotifications(Task::EVENT_CREATE, array('task' => $tf->getDetails(1)));
 }
예제 #9
0
 public function testDuplicateMixedResults()
 {
     $p = new Project($this->container);
     $pp = new ProjectPermission($this->container);
     $a = new Action($this->container);
     $u = new User($this->container);
     $c = new Category($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'P1')));
     $this->assertEquals(2, $p->create(array('name' => 'P2')));
     $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
     $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 2)));
     $this->assertEquals(3, $c->create(array('name' => 'C1', 'project_id' => 2)));
     $this->assertEquals(2, $u->create(array('username' => 'unittest1')));
     $this->assertTrue($pp->addMember(1, 2));
     $this->assertEquals(1, $a->create(array('project_id' => 1, 'event_name' => Task::EVENT_CREATE_UPDATE, 'action_name' => 'TaskAssignSpecificUser', 'params' => array('column_id' => 1, 'user_id' => 2))));
     $action = $a->getById(1);
     $this->assertNotEmpty($action);
     $this->assertNotEmpty($action['params']);
     $this->assertEquals(2, $a->create(array('project_id' => 1, 'event_name' => Task::EVENT_CREATE_UPDATE, 'action_name' => 'TaskAssignCategoryColor', 'params' => array('color_id' => 'blue', 'category_id' => 1))));
     $action = $a->getById(2);
     $this->assertNotEmpty($action);
     $this->assertNotEmpty($action['params']);
     $this->assertEquals('category_id', $action['params'][1]['name']);
     $this->assertEquals(1, $action['params'][1]['value']);
     $actions = $a->getAllByProject(1);
     $this->assertNotEmpty($actions);
     $this->assertCount(2, $actions);
     $this->assertTrue($a->duplicate(1, 2));
     $actions = $a->getAllByProject(2);
     $this->assertNotEmpty($actions);
     $this->assertCount(1, $actions);
     $actions = $a->getAll();
     $this->assertNotEmpty($actions);
     $this->assertCount(3, $actions);
     $action = $a->getById($actions[2]['id']);
     $this->assertNotEmpty($action);
     $this->assertNotEmpty($action['params']);
     $this->assertEquals('color_id', $action['params'][0]['name']);
     $this->assertEquals('blue', $action['params'][0]['value']);
     $this->assertEquals('category_id', $action['params'][1]['name']);
     $this->assertEquals(3, $action['params'][1]['value']);
 }
예제 #10
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));
 }
예제 #11
0
 public function testGetAssignableUsersWithDisabledUsersAndEverybodyAllowed()
 {
     $projectModel = new Project($this->container);
     $projectPermission = new ProjectPermission($this->container);
     $userModel = new User($this->container);
     $userRoleModel = new ProjectUserRole($this->container);
     $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User1')));
     $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User2')));
     $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1', 'is_everybody_allowed' => 1)));
     $this->assertTrue($projectPermission->isEverybodyAllowed(1));
     $users = $userRoleModel->getAssignableUsers(1);
     $this->assertCount(3, $users);
     $this->assertEquals('admin', $users[1]);
     $this->assertEquals('User1', $users[2]);
     $this->assertEquals('User2', $users[3]);
     $this->assertTrue($userModel->disable(2));
     $users = $userRoleModel->getAssignableUsers(1);
     $this->assertCount(2, $users);
     $this->assertEquals('admin', $users[1]);
     $this->assertEquals('User2', $users[3]);
 }
예제 #12
0
 public function testUsersList()
 {
     $p = new Project($this->container);
     $pp = new ProjectPermission($this->container);
     $user = new User($this->container);
     $this->assertNotFalse($user->create(array('username' => 'unittest', 'password' => 'unittest')));
     // We create project
     $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
     // No restriction, we should have no body
     $this->assertEquals(array('Unassigned'), $pp->getMemberList(1));
     // We allow only the regular user
     $this->assertTrue($pp->addMember(1, 2));
     $this->assertEquals(array(0 => 'Unassigned', 2 => 'unittest'), $pp->getMemberList(1));
     // We allow the admin user
     $this->assertTrue($pp->addMember(1, 1));
     $this->assertEquals(array(0 => 'Unassigned', 1 => 'admin', 2 => 'unittest'), $pp->getMemberList(1));
     // We revoke only the regular user
     $this->assertTrue($pp->revokeMember(1, 2));
     $this->assertEquals(array(0 => 'Unassigned', 1 => 'admin'), $pp->getMemberList(1));
     // We revoke only the admin user, we should have everybody
     $this->assertTrue($pp->revokeMember(1, 1));
     $this->assertEquals(array(0 => 'Unassigned'), $pp->getMemberList(1));
 }