copy teams from logged-in user for new projects (#3599)
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace App\Project;
|
||||
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Event\ProjectCreateEvent;
|
||||
@@ -18,6 +19,7 @@ use App\Event\ProjectMetaDefinitionEvent;
|
||||
use App\Event\ProjectUpdatePostEvent;
|
||||
use App\Event\ProjectUpdatePreEvent;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Utils\Context;
|
||||
use App\Validator\ValidationFailedException;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
@@ -28,21 +30,18 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
*/
|
||||
class ProjectService
|
||||
{
|
||||
/**
|
||||
* @var ProjectRepository
|
||||
*/
|
||||
private $configuration;
|
||||
private $repository;
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
private $dispatcher;
|
||||
/**
|
||||
* @var ValidatorInterface
|
||||
*/
|
||||
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->dispatcher = $dispatcher;
|
||||
$this->validator = $validator;
|
||||
@@ -62,7 +61,7 @@ class ProjectService
|
||||
return $project;
|
||||
}
|
||||
|
||||
public function saveNewProject(Project $project): Project
|
||||
public function saveNewProject(Project $project, ?Context $context = null): Project
|
||||
{
|
||||
if (null !== $project->getId()) {
|
||||
throw new InvalidArgumentException('Cannot create project, already persisted');
|
||||
@@ -70,6 +69,13 @@ class ProjectService
|
||||
|
||||
$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->repository->saveProject($project);
|
||||
$this->dispatcher->dispatch(new ProjectCreatePostEvent($project));
|
||||
|
||||
Reference in New Issue
Block a user