Example #1
0
 public function __invoke(ChangeParentTaskCommand $command)
 {
     $task = $this->repository->taskOfId(TaskId::generate($command->id()));
     if (!$task instanceof Task) {
         throw new TaskDoesNotExistException();
     }
     if (null !== ($parentId = $command->parentId())) {
         $parentId = TaskId::generate($parentId);
         if ($task->id()->equals($parentId)) {
             throw new TaskAndTaskParentCannotBeTheSameException();
         }
         $parent = $this->repository->taskOfId($parentId);
         if (!$parent instanceof Task) {
             throw new TaskParentDoesNotExistException();
         }
         if (!$task->projectId()->equals($parent->projectId())) {
             throw new TaskParentCannotBelongToOtherProjectException();
         }
     }
     $project = $this->projectRepository->projectOfId($task->projectId());
     $organization = $this->organizationRepository->organizationOfId($project->organizationId());
     if (!$organization->isOrganizationMember(UserId::generate($command->changerId()))) {
         throw new UnauthorizedTaskActionException();
     }
     $task->changeParent(!isset($parent) ? null : $parent->id());
     $this->repository->persist($task);
 }
Example #2
0
 public function __invoke(CreateTaskCommand $command)
 {
     if (null !== ($id = $command->taskId())) {
         $task = $this->repository->taskOfId(TaskId::generate($id));
         if ($command->parentId() === $command->taskId()) {
             throw new TaskAndTaskParentCannotBeTheSameException();
         }
         if ($task instanceof Task) {
             throw new TaskAlreadyExistsException();
         }
     }
     $project = $this->projectRepository->projectOfId(ProjectId::generate($command->projectId()));
     if (!$project instanceof Project) {
         throw new ProjectDoesNotExistException();
     }
     $organization = $this->organizationRepository->organizationOfId($project->organizationId());
     $creatorId = UserId::generate($command->creatorId());
     $assigneeId = UserId::generate($command->assigneeId());
     if (!$organization->isOrganizationMember($creatorId) || !$organization->isOrganizationMember($assigneeId)) {
         throw new UnauthorizedTaskActionException();
     }
     if (null !== ($parentId = $command->parentId())) {
         $parent = $this->repository->taskOfId(TaskId::generate($parentId));
         if (!$parent instanceof Task) {
             throw new TaskParentDoesNotExistException();
         }
     }
     $task = new Task(TaskId::generate($id), new TaskTitle($command->title()), $command->description(), $organization->organizationMember($creatorId)->id(), $organization->organizationMember($assigneeId)->id(), new TaskPriority($command->priority()), $project->id(), TaskId::generate($parentId));
     $this->repository->persist($task);
 }
Example #3
0
 function it_does_not_edit_a_task_because_task_edition_is_not_allowed(EditTaskCommand $command, TaskRepository $repository, Task $task, ProjectRepository $projectRepository, OrganizationRepository $organizationRepository, ProjectId $projectId, Project $project, OrganizationId $organizationId, Organization $organization)
 {
     $command->id()->shouldBeCalled()->willReturn('task-id');
     $repository->taskOfId(TaskId::generate('task-id'))->shouldBeCalled()->willReturn($task);
     $task->projectId()->shouldBeCalled()->willReturn($projectId);
     $projectRepository->projectOfId($projectId)->shouldBeCalled()->willReturn($project);
     $project->organizationId()->shouldBeCalled()->willReturn($organizationId);
     $organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
     $command->editorId()->shouldBeCalled()->willReturn('editor-id');
     $organization->isOrganizationMember(UserId::generate('editor-id'))->shouldBeCalled()->willReturn(false);
     $this->shouldThrow(UnauthorizedTaskActionException::class)->during__invoke($command);
 }
Example #4
0
 public function __invoke(EditTaskCommand $command)
 {
     $task = $this->repository->taskOfId(TaskId::generate($command->id()));
     if (!$task instanceof Task) {
         throw new TaskDoesNotExistException();
     }
     $project = $this->projectRepository->projectOfId($task->projectId());
     $organization = $this->organizationRepository->organizationOfId($project->organizationId());
     if (!$organization->isOrganizationMember(UserId::generate($command->editorId()))) {
         throw new UnauthorizedTaskActionException();
     }
     $task->edit(new TaskTitle($command->title()), $command->description());
     $this->repository->persist($task);
 }
 public function __invoke(ChangeTaskPriorityCommand $command)
 {
     $task = $this->taskRepository->taskOfId(TaskId::generate($command->id()));
     if (!$task instanceof Task) {
         throw new TaskDoesNotExistException();
     }
     $project = $this->projectRepository->projectOfId($task->projectId());
     $organization = $this->organizationRepository->organizationOfId($project->organizationId());
     if (!$organization->isOrganizationMember(UserId::generate($command->editorId()))) {
         throw new UnauthorizedTaskActionException();
     }
     $task->changePriority(new TaskPriority($command->priority()));
     $this->taskRepository->persist($task);
 }
Example #6
0
 public function __invoke(ReassignTaskCommand $command)
 {
     $task = $this->taskRepository->taskOfId(TaskId::generate($command->id()));
     if (!$task instanceof Task) {
         throw new TaskDoesNotExistException();
     }
     $project = $this->projectRepository->projectOfId($task->projectId());
     $organization = $this->organizationRepository->organizationOfId($project->organizationId());
     $newAssigneeId = UserId::generate($command->assigneeId());
     if (!$organization->isOrganizationMember(UserId::generate($command->editorId())) || !$organization->isOrganizationMember($newAssigneeId)) {
         throw new UnauthorizedTaskActionException();
     }
     $task->reassign($organization->organizationMember($newAssigneeId)->id());
     $this->taskRepository->persist($task);
 }
 function it_does_not_change_parent_task_because_task_action_is_not_allowed(ChangeParentTaskCommand $command, TaskRepository $repository, Task $task, TaskId $taskId, Task $parent, ProjectId $projectId, ProjectRepository $projectRepository, Project $project, OrganizationRepository $organizationRepository, Organization $organization, OrganizationId $organizationId)
 {
     $command->id()->shouldBeCalled()->willReturn('task-id');
     $repository->taskOfId(TaskId::generate('task-id'))->shouldBeCalled()->willReturn($task);
     $command->parentId()->shouldBeCalled()->willReturn('parent-id');
     $task->id()->shouldBeCalled()->willReturn($taskId);
     $taskId->equals(TaskId::generate('parent-id'))->shouldBeCalled()->willReturn(false);
     $repository->taskOfId(TaskId::generate('parent-id'))->shouldBeCalled()->willReturn($parent);
     $task->projectId()->shouldBeCalled()->willReturn($projectId);
     $parent->projectId()->shouldBeCalled()->willReturn($projectId);
     $projectId->equals($projectId)->shouldBeCalled()->willReturn(true);
     $projectRepository->projectOfId($projectId)->shouldBeCalled()->willReturn($project);
     $project->organizationId()->shouldBeCalled()->willReturn($organizationId);
     $organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
     $command->changerId()->shouldBeCalled()->willReturn('changer-id');
     $organization->isOrganizationMember(UserId::generate('changer-id'))->shouldBeCalled()->willReturn(false);
     $this->shouldThrow(UnauthorizedTaskActionException::class)->during__invoke($command);
 }
 public function taskOfId(TaskId $id)
 {
     return $this->find($id->id());
 }
Example #9
0
 function it_does_not_create_a_task_because_parent_task_does_not_exist(CreateTaskCommand $command, TaskRepository $repository, ProjectRepository $projectRepository, OrganizationRepository $organizationRepository, Project $project, OrganizationId $organizationId, Organization $organization)
 {
     $command->projectId()->shouldBeCalled()->willReturn('project-id');
     $command->taskId()->shouldBeCalled()->willReturn('task-id');
     $command->parentId()->shouldBeCalled()->willReturn('parent-id');
     $repository->taskOfId(TaskId::generate('task-id'))->shouldBeCalled()->willReturn(null);
     $projectRepository->projectOfId(ProjectId::generate('project-id'))->shouldBeCalled()->willReturn($project);
     $project->organizationId()->shouldBeCalled()->willReturn($organizationId);
     $organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
     $command->creatorId()->shouldBeCalled()->willReturn('creator-id');
     $command->assigneeId()->shouldBeCalled()->willReturn('assignee-id');
     $organization->isOrganizationMember(UserId::generate('creator-id'))->shouldBeCalled()->willReturn(true);
     $organization->isOrganizationMember(UserId::generate('assignee-id'))->shouldBeCalled()->willReturn(true);
     $repository->taskOfId(TaskId::generate('parent-id'))->shouldBeCalled()->willReturn(null);
     $this->shouldThrow(TaskParentDoesNotExistException::class)->during__invoke($command);
 }
Example #10
0
 public function convertToPHPValue($value, AbstractPlatform $platform) : TaskId
 {
     return TaskId::generate($value);
 }
Example #11
0
 function let(TaskId $taskId, TaskTitle $title, MemberId $creator, MemberId $assignee, TaskPriority $priority, ProjectId $projectId)
 {
     $taskId->id()->willReturn('task-id');
     $this->beConstructedWith($taskId, $title, 'Description', $creator, $assignee, $priority, $projectId);
 }