copy teams from logged-in user for new projects (#3599)
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"ext-mbstring": "*",
|
"ext-mbstring": "*",
|
||||||
"ext-pdo": "*",
|
"ext-pdo": "*",
|
||||||
|
"ext-tokenizer": "*",
|
||||||
"ext-xml": "*",
|
"ext-xml": "*",
|
||||||
"ext-xsl": "*",
|
"ext-xsl": "*",
|
||||||
"ext-zip": "*",
|
"ext-zip": "*",
|
||||||
|
|||||||
499
composer.lock
generated
499
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -423,4 +423,11 @@ class SystemConfiguration implements SystemBundleConfiguration
|
|||||||
{
|
{
|
||||||
return (bool) $this->find('theme.tags_create');
|
return (bool) $this->find('theme.tags_create');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========== Projects ==========
|
||||||
|
|
||||||
|
public function isProjectCopyTeamsOnCreate(): bool
|
||||||
|
{
|
||||||
|
return $this->find('project.copy_teams_on_create') === true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ use App\Repository\ProjectRepository;
|
|||||||
use App\Repository\Query\ActivityQuery;
|
use App\Repository\Query\ActivityQuery;
|
||||||
use App\Repository\Query\ProjectQuery;
|
use App\Repository\Query\ProjectQuery;
|
||||||
use App\Repository\TeamRepository;
|
use App\Repository\TeamRepository;
|
||||||
|
use App\Utils\Context;
|
||||||
use Pagerfanta\Pagerfanta;
|
use Pagerfanta\Pagerfanta;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
@@ -166,7 +167,7 @@ final class ProjectController extends AbstractController
|
|||||||
|
|
||||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
||||||
try {
|
try {
|
||||||
$this->projectService->saveNewProject($project);
|
$this->projectService->saveNewProject($project, new Context($this->getUser()));
|
||||||
$this->flashSuccess('action.update.success');
|
$this->flashSuccess('action.update.success');
|
||||||
|
|
||||||
return $this->redirectToRoute('project_details', ['id' => $project->getId()]);
|
return $this->redirectToRoute('project_details', ['id' => $project->getId()]);
|
||||||
|
|||||||
@@ -533,6 +533,11 @@ final class SystemConfigurationController extends AbstractController
|
|||||||
->setName('project.choice_pattern')
|
->setName('project.choice_pattern')
|
||||||
->setLabel('choice_pattern')
|
->setLabel('choice_pattern')
|
||||||
->setType(ProjectTypePatternType::class),
|
->setType(ProjectTypePatternType::class),
|
||||||
|
(new Configuration())
|
||||||
|
->setName('project.copy_teams_on_create')
|
||||||
|
->setLabel('copy_teams_on_create')
|
||||||
|
->setType(YesNoType::class)
|
||||||
|
->setTranslationDomain('system-configuration'),
|
||||||
]),
|
]),
|
||||||
(new SystemConfigurationModel('activity'))
|
(new SystemConfigurationModel('activity'))
|
||||||
->setConfiguration([
|
->setConfiguration([
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ class Configuration implements ConfigurationInterface
|
|||||||
->append($this->getLdapNode())
|
->append($this->getLdapNode())
|
||||||
->append($this->getSamlNode())
|
->append($this->getSamlNode())
|
||||||
->append($this->getQuickEntryNode())
|
->append($this->getQuickEntryNode())
|
||||||
|
->append($this->getProjectNode())
|
||||||
->end()
|
->end()
|
||||||
->end();
|
->end();
|
||||||
|
|
||||||
@@ -100,6 +101,24 @@ class Configuration implements ConfigurationInterface
|
|||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getProjectNode()
|
||||||
|
{
|
||||||
|
$builder = new TreeBuilder('project');
|
||||||
|
/** @var ArrayNodeDefinition $node */
|
||||||
|
$node = $builder->getRootNode();
|
||||||
|
|
||||||
|
$node
|
||||||
|
->addDefaultsIfNotSet()
|
||||||
|
->children()
|
||||||
|
->booleanNode('copy_teams_on_create')
|
||||||
|
->defaultValue(false)
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
;
|
||||||
|
|
||||||
|
return $node;
|
||||||
|
}
|
||||||
|
|
||||||
private function getTimesheetNode(): ArrayNodeDefinition
|
private function getTimesheetNode(): ArrayNodeDefinition
|
||||||
{
|
{
|
||||||
$builder = new TreeBuilder('timesheet');
|
$builder = new TreeBuilder('timesheet');
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
namespace App\Project;
|
namespace App\Project;
|
||||||
|
|
||||||
|
use App\Configuration\SystemConfiguration;
|
||||||
use App\Entity\Customer;
|
use App\Entity\Customer;
|
||||||
use App\Entity\Project;
|
use App\Entity\Project;
|
||||||
use App\Event\ProjectCreateEvent;
|
use App\Event\ProjectCreateEvent;
|
||||||
@@ -18,6 +19,7 @@ use App\Event\ProjectMetaDefinitionEvent;
|
|||||||
use App\Event\ProjectUpdatePostEvent;
|
use App\Event\ProjectUpdatePostEvent;
|
||||||
use App\Event\ProjectUpdatePreEvent;
|
use App\Event\ProjectUpdatePreEvent;
|
||||||
use App\Repository\ProjectRepository;
|
use App\Repository\ProjectRepository;
|
||||||
|
use App\Utils\Context;
|
||||||
use App\Validator\ValidationFailedException;
|
use App\Validator\ValidationFailedException;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
@@ -28,21 +30,18 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|||||||
*/
|
*/
|
||||||
class ProjectService
|
class ProjectService
|
||||||
{
|
{
|
||||||
/**
|
private $configuration;
|
||||||
* @var ProjectRepository
|
|
||||||
*/
|
|
||||||
private $repository;
|
private $repository;
|
||||||
/**
|
|
||||||
* @var EventDispatcherInterface
|
|
||||||
*/
|
|
||||||
private $dispatcher;
|
private $dispatcher;
|
||||||
/**
|
|
||||||
* @var ValidatorInterface
|
|
||||||
*/
|
|
||||||
private $validator;
|
private $validator;
|
||||||
|
|
||||||
public function __construct(ProjectRepository $projectRepository, EventDispatcherInterface $dispatcher, ValidatorInterface $validator)
|
public function __construct(
|
||||||
{
|
SystemConfiguration $configuration,
|
||||||
|
ProjectRepository $projectRepository,
|
||||||
|
EventDispatcherInterface $dispatcher,
|
||||||
|
ValidatorInterface $validator
|
||||||
|
) {
|
||||||
|
$this->configuration = $configuration;
|
||||||
$this->repository = $projectRepository;
|
$this->repository = $projectRepository;
|
||||||
$this->dispatcher = $dispatcher;
|
$this->dispatcher = $dispatcher;
|
||||||
$this->validator = $validator;
|
$this->validator = $validator;
|
||||||
@@ -62,7 +61,7 @@ class ProjectService
|
|||||||
return $project;
|
return $project;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveNewProject(Project $project): Project
|
public function saveNewProject(Project $project, ?Context $context = null): Project
|
||||||
{
|
{
|
||||||
if (null !== $project->getId()) {
|
if (null !== $project->getId()) {
|
||||||
throw new InvalidArgumentException('Cannot create project, already persisted');
|
throw new InvalidArgumentException('Cannot create project, already persisted');
|
||||||
@@ -70,6 +69,13 @@ class ProjectService
|
|||||||
|
|
||||||
$this->validateProject($project);
|
$this->validateProject($project);
|
||||||
|
|
||||||
|
if ($context !== null && $this->configuration->isProjectCopyTeamsOnCreate()) {
|
||||||
|
foreach ($context->getUser()->getTeams() as $team) {
|
||||||
|
$project->addTeam($team);
|
||||||
|
$team->addProject($project);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->dispatcher->dispatch(new ProjectCreatePreEvent($project));
|
$this->dispatcher->dispatch(new ProjectCreatePreEvent($project));
|
||||||
$this->repository->saveProject($project);
|
$this->repository->saveProject($project);
|
||||||
$this->dispatcher->dispatch(new ProjectCreatePostEvent($project));
|
$this->dispatcher->dispatch(new ProjectCreatePostEvent($project));
|
||||||
|
|||||||
27
src/Utils/Context.php
Normal file
27
src/Utils/Context.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?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\Utils;
|
||||||
|
|
||||||
|
use App\Entity\User;
|
||||||
|
|
||||||
|
final class Context
|
||||||
|
{
|
||||||
|
private $user;
|
||||||
|
|
||||||
|
public function __construct(User $user)
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUser(): User
|
||||||
|
{
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -469,6 +469,9 @@ class ConfigurationTest extends TestCase
|
|||||||
'recent_activity_weeks' => null,
|
'recent_activity_weeks' => null,
|
||||||
'minimum_rows' => 3,
|
'minimum_rows' => 3,
|
||||||
],
|
],
|
||||||
|
'project' => [
|
||||||
|
'copy_teams_on_create' => false,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->assertConfig($this->getMinConfig(), $fullDefaultConfig);
|
$this->assertConfig($this->getMinConfig(), $fullDefaultConfig);
|
||||||
|
|||||||
@@ -9,8 +9,11 @@
|
|||||||
|
|
||||||
namespace App\Tests\Project;
|
namespace App\Tests\Project;
|
||||||
|
|
||||||
|
use App\Configuration\SystemConfiguration;
|
||||||
use App\Entity\Customer;
|
use App\Entity\Customer;
|
||||||
use App\Entity\Project;
|
use App\Entity\Project;
|
||||||
|
use App\Entity\Team;
|
||||||
|
use App\Entity\User;
|
||||||
use App\Event\ProjectCreateEvent;
|
use App\Event\ProjectCreateEvent;
|
||||||
use App\Event\ProjectCreatePostEvent;
|
use App\Event\ProjectCreatePostEvent;
|
||||||
use App\Event\ProjectCreatePreEvent;
|
use App\Event\ProjectCreatePreEvent;
|
||||||
@@ -19,6 +22,7 @@ use App\Event\ProjectUpdatePostEvent;
|
|||||||
use App\Event\ProjectUpdatePreEvent;
|
use App\Event\ProjectUpdatePreEvent;
|
||||||
use App\Project\ProjectService;
|
use App\Project\ProjectService;
|
||||||
use App\Repository\ProjectRepository;
|
use App\Repository\ProjectRepository;
|
||||||
|
use App\Utils\Context;
|
||||||
use App\Validator\ValidationFailedException;
|
use App\Validator\ValidationFailedException;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
@@ -34,11 +38,9 @@ class ProjectServiceTest extends TestCase
|
|||||||
private function getSut(
|
private function getSut(
|
||||||
?EventDispatcherInterface $dispatcher = null,
|
?EventDispatcherInterface $dispatcher = null,
|
||||||
?ValidatorInterface $validator = null,
|
?ValidatorInterface $validator = null,
|
||||||
?ProjectRepository $repository = null
|
bool $copyTeamsOnCreate = false
|
||||||
): ProjectService {
|
): ProjectService {
|
||||||
if ($repository === null) {
|
|
||||||
$repository = $this->createMock(ProjectRepository::class);
|
$repository = $this->createMock(ProjectRepository::class);
|
||||||
}
|
|
||||||
|
|
||||||
if ($dispatcher === null) {
|
if ($dispatcher === null) {
|
||||||
$dispatcher = $this->createMock(EventDispatcherInterface::class);
|
$dispatcher = $this->createMock(EventDispatcherInterface::class);
|
||||||
@@ -49,7 +51,10 @@ class ProjectServiceTest extends TestCase
|
|||||||
$validator->method('validate')->willReturn(new ConstraintViolationList());
|
$validator->method('validate')->willReturn(new ConstraintViolationList());
|
||||||
}
|
}
|
||||||
|
|
||||||
$service = new ProjectService($repository, $dispatcher, $validator);
|
$configuration = $this->createMock(SystemConfiguration::class);
|
||||||
|
$configuration->method('isProjectCopyTeamsOnCreate')->willReturn($copyTeamsOnCreate);
|
||||||
|
|
||||||
|
$service = new ProjectService($configuration, $repository, $dispatcher, $validator);
|
||||||
|
|
||||||
return $service;
|
return $service;
|
||||||
}
|
}
|
||||||
@@ -64,7 +69,7 @@ class ProjectServiceTest extends TestCase
|
|||||||
$this->expectException(\InvalidArgumentException::class);
|
$this->expectException(\InvalidArgumentException::class);
|
||||||
$this->expectExceptionMessage('Cannot create project, already persisted');
|
$this->expectExceptionMessage('Cannot create project, already persisted');
|
||||||
|
|
||||||
$sut->saveNewProject($project);
|
$sut->saveNewProject($project, new Context(new User()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSaveNewProjectHasValidationError()
|
public function testSaveNewProjectHasValidationError()
|
||||||
@@ -80,7 +85,7 @@ class ProjectServiceTest extends TestCase
|
|||||||
$this->expectException(ValidationFailedException::class);
|
$this->expectException(ValidationFailedException::class);
|
||||||
$this->expectExceptionMessage('Validation Failed');
|
$this->expectExceptionMessage('Validation Failed');
|
||||||
|
|
||||||
$sut->saveNewProject(new Project());
|
$sut->saveNewProject(new Project(), new Context(new User()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateDispatchesEvents()
|
public function testUpdateDispatchesEvents()
|
||||||
@@ -141,7 +146,26 @@ class ProjectServiceTest extends TestCase
|
|||||||
$sut = $this->getSut($dispatcher);
|
$sut = $this->getSut($dispatcher);
|
||||||
|
|
||||||
$project = new Project();
|
$project = new Project();
|
||||||
$sut->saveNewProject($project);
|
$sut->saveNewProject($project, new Context(new User()));
|
||||||
|
self::assertCount(0, $project->getTeams());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateNewProjectCopiesTeam()
|
||||||
|
{
|
||||||
|
$dispatcher = $this->createMock(EventDispatcherInterface::class);
|
||||||
|
|
||||||
|
$sut = $this->getSut($dispatcher, null, true);
|
||||||
|
|
||||||
|
$team1 = new Team();
|
||||||
|
$team2 = new Team();
|
||||||
|
|
||||||
|
$user = new User();
|
||||||
|
$user->addTeam($team1);
|
||||||
|
$user->addTeam($team2);
|
||||||
|
|
||||||
|
$project = new Project();
|
||||||
|
$sut->saveNewProject($project, new Context($user));
|
||||||
|
self::assertCount(2, $project->getTeams());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateNewProjectWithoutCustomer()
|
public function testCreateNewProjectWithoutCustomer()
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ abstract class BaseFormTypeQueryTest extends TestCase
|
|||||||
$team = new Team();
|
$team = new Team();
|
||||||
self::assertInstanceOf(BaseFormTypeQuery::class, $sut->addTeam($team));
|
self::assertInstanceOf(BaseFormTypeQuery::class, $sut->addTeam($team));
|
||||||
self::assertCount(1, $sut->getTeams());
|
self::assertCount(1, $sut->getTeams());
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
self::assertSame($team, $sut->getTeams()[0]);
|
self::assertSame($team, $sut->getTeams()[0]);
|
||||||
|
|
||||||
self::assertInstanceOf(BaseFormTypeQuery::class, $sut->setTeams([]));
|
self::assertInstanceOf(BaseFormTypeQuery::class, $sut->setTeams([]));
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ class BaseQueryTest extends TestCase
|
|||||||
$team = new Team();
|
$team = new Team();
|
||||||
self::assertInstanceOf(BaseQuery::class, $sut->setTeams([$team]));
|
self::assertInstanceOf(BaseQuery::class, $sut->setTeams([$team]));
|
||||||
self::assertEquals(1, \count($sut->getTeams()));
|
self::assertEquals(1, \count($sut->getTeams()));
|
||||||
|
/* @phpstan-ignore-next-line */
|
||||||
self::assertSame($team, $sut->getTeams()[0]);
|
self::assertSame($team, $sut->getTeams()[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -318,6 +318,10 @@
|
|||||||
<source>label.calendar.title_pattern</source>
|
<source>label.calendar.title_pattern</source>
|
||||||
<target>Darstellung der Titel von Kalendereinträgen</target>
|
<target>Darstellung der Titel von Kalendereinträgen</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
<trans-unit id="MXasdfgbpD7" resname="label.copy_teams_on_create" approved="yes">
|
||||||
|
<source>label.copy_teams_on_create</source>
|
||||||
|
<target>Übernehme Teams beim Erstellen neuer Einträge vom angemeldeten Benutzer</target>
|
||||||
|
</trans-unit>
|
||||||
</body>
|
</body>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
|||||||
@@ -318,6 +318,10 @@
|
|||||||
<source>label.calendar.title_pattern</source>
|
<source>label.calendar.title_pattern</source>
|
||||||
<target>Display of the titles of calendar entries</target>
|
<target>Display of the titles of calendar entries</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
<trans-unit id="MXasdfgbpD7" resname="label.copy_teams_on_create" approved="yes">
|
||||||
|
<source>label.copy_teams_on_create</source>
|
||||||
|
<target>Take over teams from the logged-in user when creating new entries</target>
|
||||||
|
</trans-unit>
|
||||||
</body>
|
</body>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
|||||||
Reference in New Issue
Block a user