added team permissions (#996)
This commit is contained in:
@@ -26,12 +26,12 @@ class ActivityControllerTest extends ControllerBaseTest
|
||||
public function testIsSecure()
|
||||
{
|
||||
$this->assertUrlIsSecured('/admin/activity/');
|
||||
$this->assertUrlIsSecuredForRole(User::ROLE_TEAMLEAD, '/admin/activity/');
|
||||
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/admin/activity/');
|
||||
}
|
||||
|
||||
public function testIndexAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
$this->assertAccessIsGranted($client, '/admin/activity/');
|
||||
$this->assertHasDataTable($client);
|
||||
}
|
||||
|
||||
@@ -9,13 +9,16 @@
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Tests\DataFixtures\CustomerFixtures;
|
||||
use App\Tests\DataFixtures\TeamFixtures;
|
||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||
use App\Tests\Mocks\CustomerTestMetaFieldSubscriberMock;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Symfony\Component\DomCrawler\Field\ChoiceFormField;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
@@ -25,12 +28,12 @@ class CustomerControllerTest extends ControllerBaseTest
|
||||
public function testIsSecure()
|
||||
{
|
||||
$this->assertUrlIsSecured('/admin/customer/');
|
||||
$this->assertUrlIsSecuredForRole(User::ROLE_TEAMLEAD, '/admin/customer/');
|
||||
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/admin/customer/');
|
||||
}
|
||||
|
||||
public function testIndexAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
$this->assertAccessIsGranted($client, '/admin/customer/');
|
||||
$this->assertHasDataTable($client);
|
||||
}
|
||||
@@ -111,6 +114,39 @@ class CustomerControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals('Test Customer 2', $editForm->get('customer_edit_form[name]')->getValue());
|
||||
}
|
||||
|
||||
public function testTeamPermissionAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
/** @var Customer $customer */
|
||||
$customer = $em->getRepository(Customer::class)->find(1);
|
||||
self::assertEquals(0, $customer->getTeams()->count());
|
||||
|
||||
$fixture = new TeamFixtures();
|
||||
$fixture->setAmount(2);
|
||||
$fixture->setAddCustomer(false);
|
||||
$this->importFixture($em, $fixture);
|
||||
|
||||
$this->assertAccessIsGranted($client, '/admin/customer/1/permissions');
|
||||
$form = $client->getCrawler()->filter('form[name=customer_team_permission_form]')->form();
|
||||
/** @var ChoiceFormField $team1 */
|
||||
$team1 = $form->get('customer_team_permission_form[teams][0]');
|
||||
$team1->tick();
|
||||
/** @var ChoiceFormField $team2 */
|
||||
$team2 = $form->get('customer_team_permission_form[teams][1]');
|
||||
$team2->tick();
|
||||
|
||||
$client->submit($form);
|
||||
$this->assertIsRedirect($client, $this->createUrl('/admin/customer/'));
|
||||
$client->followRedirect();
|
||||
$this->assertHasDataTable($client);
|
||||
|
||||
/** @var Customer $customer */
|
||||
$customer = $em->getRepository(Customer::class)->find(1);
|
||||
self::assertEquals(2, $customer->getTeams()->count());
|
||||
}
|
||||
|
||||
public function testDeleteAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
|
||||
@@ -12,8 +12,10 @@ namespace App\Tests\Controller;
|
||||
use App\DataFixtures\UserFixtures;
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserPreference;
|
||||
use App\Tests\DataFixtures\TeamFixtures;
|
||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||
use Symfony\Bundle\FrameworkBundle\Client;
|
||||
use Symfony\Component\DomCrawler\Field\ChoiceFormField;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
||||
|
||||
/**
|
||||
@@ -95,7 +97,7 @@ class ProfileControllerTest extends ControllerBaseTest
|
||||
|
||||
return [
|
||||
[User::ROLE_USER, UserFixtures::USERNAME_USER, ['#settings', '#password', '#api-token']],
|
||||
[User::ROLE_SUPER_ADMIN, UserFixtures::USERNAME_SUPER_ADMIN, array_merge($userTabs, ['#roles'])],
|
||||
[User::ROLE_SUPER_ADMIN, UserFixtures::USERNAME_SUPER_ADMIN, array_merge($userTabs, ['#teams', '#roles'])],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -315,6 +317,52 @@ class ProfileControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals(['ROLE_TEAMLEAD', 'ROLE_SUPER_ADMIN', 'ROLE_USER'], $user->getRoles());
|
||||
}
|
||||
|
||||
public function testTeamsActionIsSecured()
|
||||
{
|
||||
$this->assertUrlIsSecured('/profile/' . UserFixtures::USERNAME_USER . '/teams');
|
||||
$this->assertUrlIsSecuredForRole(User::ROLE_TEAMLEAD, '/profile/' . UserFixtures::USERNAME_USER . '/teams');
|
||||
}
|
||||
|
||||
public function testTeamsAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->getUserByRole($em, User::ROLE_USER);
|
||||
|
||||
$fixture = new TeamFixtures();
|
||||
$fixture->setAmount(3);
|
||||
$fixture->setAddCustomer(true);
|
||||
$fixture->setAddUser(false);
|
||||
$fixture->addUserToIgnore($user);
|
||||
$this->importFixture($em, $fixture);
|
||||
|
||||
$this->request($client, '/profile/' . UserFixtures::USERNAME_USER . '/teams');
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->getUserByRole($em, User::ROLE_USER);
|
||||
$this->assertEquals([], $user->getTeams()->toArray());
|
||||
|
||||
$form = $client->getCrawler()->filter('form[name=user_teams]')->form();
|
||||
/** @var ChoiceFormField $team */
|
||||
$team = $form->get('user_teams[teams][0]');
|
||||
$team->tick();
|
||||
|
||||
$client->submit($form);
|
||||
|
||||
$this->assertIsRedirect($client, $this->createUrl('/profile/' . urlencode(UserFixtures::USERNAME_USER) . '/teams'));
|
||||
$client->followRedirect();
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$this->assertHasFlashSuccess($client);
|
||||
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
$user = $this->getUserByRole($em, User::ROLE_USER);
|
||||
|
||||
$this->assertEquals(1, $user->getTeams()->count());
|
||||
}
|
||||
|
||||
public function getPreferencesTestData()
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -14,9 +14,11 @@ use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Tests\DataFixtures\CustomerFixtures;
|
||||
use App\Tests\DataFixtures\ProjectFixtures;
|
||||
use App\Tests\DataFixtures\TeamFixtures;
|
||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||
use App\Tests\Mocks\ProjectTestMetaFieldSubscriberMock;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Symfony\Component\DomCrawler\Field\ChoiceFormField;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
@@ -26,12 +28,12 @@ class ProjectControllerTest extends ControllerBaseTest
|
||||
public function testIsSecure()
|
||||
{
|
||||
$this->assertUrlIsSecured('/admin/project/');
|
||||
$this->assertUrlIsSecuredForRole(User::ROLE_TEAMLEAD, '/admin/project/');
|
||||
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/admin/project/');
|
||||
}
|
||||
|
||||
public function testIndexAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
$this->assertAccessIsGranted($client, '/admin/project/');
|
||||
$this->assertHasDataTable($client);
|
||||
}
|
||||
@@ -135,6 +137,39 @@ class ProjectControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals('Test 2', $editForm->get('project_edit_form[name]')->getValue());
|
||||
}
|
||||
|
||||
public function testTeamPermissionAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
/** @var Project $project */
|
||||
$project = $em->getRepository(Project::class)->find(1);
|
||||
self::assertEquals(0, $project->getTeams()->count());
|
||||
|
||||
$fixture = new TeamFixtures();
|
||||
$fixture->setAmount(2);
|
||||
$fixture->setAddCustomer(false);
|
||||
$this->importFixture($em, $fixture);
|
||||
|
||||
$this->assertAccessIsGranted($client, '/admin/project/1/permissions');
|
||||
$form = $client->getCrawler()->filter('form[name=project_team_permission_form]')->form();
|
||||
/** @var ChoiceFormField $team1 */
|
||||
$team1 = $form->get('project_team_permission_form[teams][0]');
|
||||
$team1->tick();
|
||||
/** @var ChoiceFormField $team2 */
|
||||
$team2 = $form->get('project_team_permission_form[teams][1]');
|
||||
$team2->tick();
|
||||
|
||||
$client->submit($form);
|
||||
$this->assertIsRedirect($client, $this->createUrl('/admin/project/'));
|
||||
$client->followRedirect();
|
||||
$this->assertHasDataTable($client);
|
||||
|
||||
/** @var Project $project */
|
||||
$project = $em->getRepository(Project::class)->find(1);
|
||||
self::assertEquals(2, $project->getTeams()->count());
|
||||
}
|
||||
|
||||
public function testDeleteAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
|
||||
155
tests/Controller/TeamControllerTest.php
Normal file
155
tests/Controller/TeamControllerTest.php
Normal file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\Team;
|
||||
use App\Entity\User;
|
||||
use App\Tests\DataFixtures\TeamFixtures;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Symfony\Bundle\FrameworkBundle\Client;
|
||||
use Symfony\Component\DomCrawler\Field\ChoiceFormField;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
class TeamControllerTest extends ControllerBaseTest
|
||||
{
|
||||
public function testIsSecure()
|
||||
{
|
||||
$this->assertUrlIsSecured('/admin/teams/');
|
||||
$this->assertUrlIsSecuredForRole(User::ROLE_TEAMLEAD, '/admin/teams/');
|
||||
}
|
||||
|
||||
public function testIndexAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
$fixture = new TeamFixtures();
|
||||
$fixture->setAmount(5);
|
||||
$this->importFixture($em, $fixture);
|
||||
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/admin/teams/');
|
||||
$this->assertPageActions($client, ['create' => $this->createUrl('/admin/teams/create')]);
|
||||
$this->assertHasDataTable($client);
|
||||
$this->assertDataTableRowCount($client, 'datatable_admin_teams', 5);
|
||||
}
|
||||
|
||||
public function testCreateAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/admin/teams/create');
|
||||
$form = $client->getCrawler()->filter('form[name=team_edit_form]')->form();
|
||||
|
||||
$editForm = $client->getCrawler()->filter('form[name=team_edit_form]')->form();
|
||||
$this->assertEquals('', $editForm->get('team_edit_form[name]')->getValue());
|
||||
$this->assertEquals('5', $editForm->get('team_edit_form[teamlead]')->getValue());
|
||||
|
||||
$client->submit($form, [
|
||||
'team_edit_form' => [
|
||||
'name' => 'Test Team',
|
||||
]
|
||||
]);
|
||||
$this->assertIsRedirect($client, $this->createUrl('/admin/teams/1/edit'));
|
||||
$client->followRedirect();
|
||||
$this->assertHasFlashSuccess($client);
|
||||
$this->assertHasCustomerAndProjectPermissionBoxes($client);
|
||||
}
|
||||
|
||||
protected function assertHasCustomerAndProjectPermissionBoxes(Client $client)
|
||||
{
|
||||
$content = $client->getResponse()->getContent();
|
||||
$this->assertStringContainsString('Grant access to customers', $content);
|
||||
$this->assertStringContainsString('Grant access to projects', $content);
|
||||
$this->assertEquals(1, $client->getCrawler()->filter('form[name=team_customer_form]')->count());
|
||||
$this->assertEquals(1, $client->getCrawler()->filter('form[name=team_project_form]')->count());
|
||||
}
|
||||
|
||||
public function testEditAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
$fixture = new TeamFixtures();
|
||||
$fixture->setAmount(2);
|
||||
$this->importFixture($em, $fixture);
|
||||
|
||||
$this->assertAccessIsGranted($client, '/admin/teams/1/edit');
|
||||
$form = $client->getCrawler()->filter('form[name=team_edit_form]')->form();
|
||||
$this->assertNotEmpty($form->get('team_edit_form[name]')->getValue());
|
||||
$client->submit($form, [
|
||||
'team_edit_form' => [
|
||||
'name' => 'Test Team 2'
|
||||
]
|
||||
]);
|
||||
$this->assertIsRedirect($client, $this->createUrl('/admin/teams/1/edit'));
|
||||
$client->followRedirect();
|
||||
$editForm = $client->getCrawler()->filter('form[name=team_edit_form]')->form();
|
||||
$this->assertEquals('Test Team 2', $editForm->get('team_edit_form[name]')->getValue());
|
||||
}
|
||||
|
||||
public function testEditCustomerAccessAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
|
||||
/** @var EntityManager $em */
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
$fixture = new TeamFixtures();
|
||||
$fixture->setAmount(2);
|
||||
$fixture->setAddCustomer(false);
|
||||
$this->importFixture($em, $fixture);
|
||||
|
||||
$team = $em->getRepository(Team::class)->find(1);
|
||||
self::assertEquals(0, count($team->getCustomers()));
|
||||
|
||||
$this->assertAccessIsGranted($client, '/admin/teams/1/edit');
|
||||
$form = $client->getCrawler()->filter('form[name=team_customer_form]')->form();
|
||||
|
||||
/** @var ChoiceFormField $customer */
|
||||
$customer = $form->get('team_customer_form[customers][0]');
|
||||
$customer->tick();
|
||||
|
||||
$client->submit($form);
|
||||
$this->assertIsRedirect($client, $this->createUrl('/admin/teams/1/edit'));
|
||||
|
||||
$team = $em->getRepository(Team::class)->find(1);
|
||||
self::assertEquals(1, count($team->getCustomers()));
|
||||
}
|
||||
|
||||
public function testEditProjectAccessAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
|
||||
/** @var EntityManager $em */
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
$fixture = new TeamFixtures();
|
||||
$fixture->setAmount(2);
|
||||
$fixture->setAddCustomer(false);
|
||||
$this->importFixture($em, $fixture);
|
||||
|
||||
$team = $em->getRepository(Team::class)->find(1);
|
||||
self::assertEquals(0, count($team->getProjects()));
|
||||
|
||||
$this->assertAccessIsGranted($client, '/admin/teams/1/edit');
|
||||
$form = $client->getCrawler()->filter('form[name=team_project_form]')->form();
|
||||
|
||||
/** @var ChoiceFormField $customer */
|
||||
$customer = $form->get('team_project_form[projects]');
|
||||
$customer->select([1]);
|
||||
|
||||
$client->submit($form);
|
||||
$this->assertIsRedirect($client, $this->createUrl('/admin/teams/1/edit'));
|
||||
|
||||
$team = $em->getRepository(Team::class)->find(1);
|
||||
self::assertEquals(1, count($team->getProjects()));
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,8 @@ class TimesheetTeamControllerTest extends ControllerBaseTest
|
||||
|
||||
public function testIndexActionWithQuery()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
// Switching the user is not allowed for TEAMLEADs but ONLLY for admin and super-admins
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$start = new \DateTime('first day of this month');
|
||||
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
@@ -118,7 +119,7 @@ class TimesheetTeamControllerTest extends ControllerBaseTest
|
||||
|
||||
public function testCreateAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$this->request($client, '/team/timesheet/create');
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
@@ -160,7 +161,7 @@ class TimesheetTeamControllerTest extends ControllerBaseTest
|
||||
$fixture->setStartDate('2017-05-01');
|
||||
$this->importFixture($em, $fixture);
|
||||
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$this->request($client, '/team/timesheet/1/edit');
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
@@ -52,7 +52,7 @@ class UserControllerTest extends ControllerBaseTest
|
||||
$this->assertIsRedirect($client, $this->createUrl('/profile/' . urlencode($username) . '/edit'));
|
||||
$client->followRedirect();
|
||||
|
||||
$expectedTabs = ['#settings', '#password', '#api-token', '#roles'];
|
||||
$expectedTabs = ['#settings', '#password', '#api-token', '#teams', '#roles'];
|
||||
|
||||
$tabs = $client->getCrawler()->filter('div.nav-tabs-custom ul.nav-tabs li');
|
||||
$this->assertEquals(count($expectedTabs), $tabs->count());
|
||||
@@ -210,6 +210,6 @@ class UserControllerTest extends ControllerBaseTest
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/admin/user/permissions');
|
||||
$this->assertHasDataTable($client);
|
||||
$this->assertDataTableRowCount($client, 'datatable_user_admin_permissions', 69);
|
||||
$this->assertDataTableRowCount($client, 'datatable_user_admin_permissions', 84);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user