lock exported timesheets (#798)
This commit is contained in:
@@ -23,10 +23,7 @@ use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
||||
*/
|
||||
class TimesheetVoterTest extends AbstractVoterTest
|
||||
{
|
||||
/**
|
||||
* @dataProvider getTestData
|
||||
*/
|
||||
public function testVote(User $user, $subject, $attribute, $result)
|
||||
protected function assertVote(User $user, $subject, $attribute, $result)
|
||||
{
|
||||
$token = new UsernamePasswordToken($user, 'foo', 'bar', $user->getRoles());
|
||||
$sut = $this->getVoter(TimesheetVoter::class, $user);
|
||||
@@ -34,6 +31,14 @@ class TimesheetVoterTest extends AbstractVoterTest
|
||||
$this->assertEquals($result, $sut->vote($token, $subject, [$attribute]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTestData
|
||||
*/
|
||||
public function testVote(User $user, $subject, $attribute, $result)
|
||||
{
|
||||
$this->assertVote($user, $subject, $attribute, $result);
|
||||
}
|
||||
|
||||
public function getTestData()
|
||||
{
|
||||
$user0 = $this->getUser(0, null);
|
||||
@@ -46,6 +51,10 @@ class TimesheetVoterTest extends AbstractVoterTest
|
||||
$timesheet2 = $this->getTimesheet($user2);
|
||||
$timesheet3 = $this->getTimesheet($user3);
|
||||
$timesheet4 = $this->getTimesheet($user4);
|
||||
$timesheet5 = $this->getTimesheet($user2);
|
||||
$timesheet5->setExported(true);
|
||||
$timesheet6 = $this->getTimesheet($user1);
|
||||
$timesheet6->getActivity()->setVisible(false);
|
||||
|
||||
$result = VoterInterface::ACCESS_GRANTED;
|
||||
$times = [
|
||||
@@ -78,6 +87,50 @@ class TimesheetVoterTest extends AbstractVoterTest
|
||||
}
|
||||
}
|
||||
|
||||
public function testSpecialCases()
|
||||
{
|
||||
$user1 = $this->getUser(1, User::ROLE_USER);
|
||||
$user2 = $this->getUser(2, User::ROLE_TEAMLEAD);
|
||||
$user3 = $this->getUser(3, User::ROLE_ADMIN);
|
||||
$user4 = $this->getUser(4, User::ROLE_SUPER_ADMIN);
|
||||
|
||||
// unknown attribute
|
||||
$timesheet = $this->getTimesheet($user3);
|
||||
$this->assertVote($user3, $timesheet, 'edit2', VoterInterface::ACCESS_ABSTAIN);
|
||||
|
||||
$timesheet = $this->getTimesheet($user2);
|
||||
$timesheet->setExported(true);
|
||||
// edit exported timesheet disallowed for teamleads
|
||||
$this->assertVote($user2, $timesheet, 'edit', VoterInterface::ACCESS_DENIED);
|
||||
$this->assertVote($user2, $timesheet, 'delete', VoterInterface::ACCESS_DENIED);
|
||||
// but allowed for admins
|
||||
$this->assertVote($user4, $timesheet, 'edit', VoterInterface::ACCESS_GRANTED);
|
||||
$this->assertVote($user4, $timesheet, 'delete', VoterInterface::ACCESS_GRANTED);
|
||||
|
||||
// hidden activities might not be started
|
||||
$timesheet = $this->getTimesheet($user1);
|
||||
$timesheet->getActivity()->setVisible(false);
|
||||
$this->assertVote($user2, $timesheet, 'start', VoterInterface::ACCESS_DENIED);
|
||||
|
||||
// hidden projects might not be started
|
||||
$timesheet = $this->getTimesheet($user1);
|
||||
$timesheet->getProject()->setVisible(false);
|
||||
$this->assertVote($user2, $timesheet, 'start', VoterInterface::ACCESS_DENIED);
|
||||
|
||||
// hidden customers might not be started
|
||||
$timesheet = $this->getTimesheet($user1);
|
||||
$timesheet->getProject()->getCustomer()->setVisible(false);
|
||||
$this->assertVote($user2, $timesheet, 'start', VoterInterface::ACCESS_DENIED);
|
||||
// cannot start timesheet without activity
|
||||
$timesheet = new Timesheet();
|
||||
$timesheet->setUser($user2)->setProject(new Project());
|
||||
$this->assertVote($user2, $timesheet, 'start', VoterInterface::ACCESS_DENIED);
|
||||
// cannot start timesheet without project
|
||||
$timesheet = new Timesheet();
|
||||
$timesheet->setUser($user2)->setActivity(new Activity());
|
||||
$this->assertVote($user2, $timesheet, 'start', VoterInterface::ACCESS_DENIED);
|
||||
}
|
||||
|
||||
protected function getTimesheet($user)
|
||||
{
|
||||
$timesheet = new Timesheet();
|
||||
|
||||
Reference in New Issue
Block a user