Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
 function it_does_not_serialize_project_when_the_user_does_not_allowed(ProjectOfIdQuery $query, ProjectRepository $repository, Project $project, OrganizationId $organizationId, OrganizationRepository $organizationRepository, Organization $organization)
 {
     $query->projectId()->shouldBeCalled()->willReturn('project-id');
     $repository->projectOfId(ProjectId::generate('project-id'))->shouldBeCalled()->willReturn($project);
     $project->organizationId()->shouldBeCalled()->willReturn($organizationId);
     $organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
     $query->userId()->shouldBeCalled()->willReturn('user-id');
     $organization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(false);
     $this->shouldThrow(UnauthorizedProjectResourceException::class)->during__invoke($query);
 }
Exemplo n.º 3
0
 function it_does_not_allow_to_edit_project_if_editor_is_not_organization_owner(OrganizationRepository $organizationRepository, ProjectRepository $projectRepository, EditProjectCommand $command, Project $project, Organization $organization, OrganizationId $organizationId)
 {
     $command->id()->willReturn('project-id');
     $command->name()->willReturn('Project name');
     $command->slug()->willReturn(null);
     $command->editorId()->willReturn('editor-id');
     $projectRepository->projectOfId(ProjectId::generate('project-id'))->shouldBeCalled()->willReturn($project);
     $project->organizationId()->shouldBeCalled()->willReturn($organizationId);
     $organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
     $organization->isOwner(UserId::generate('editor-id'))->shouldBeCalled()->willReturn(false);
     $this->shouldThrow(UnauthorizedProjectActionException::class)->during__invoke($command);
 }
Exemplo n.º 4
0
 public function __invoke(EditProjectCommand $command)
 {
     $project = $this->repository->projectOfId(ProjectId::generate($command->id()));
     if (!$project instanceof Project) {
         throw new ProjectDoesNotExistException();
     }
     $organization = $this->organizationRepository->organizationOfId($project->organizationId());
     if (!$organization->isOwner(UserId::generate($command->editorId()))) {
         throw new UnauthorizedProjectActionException();
     }
     $project->edit(new ProjectName($command->name()), new Slug(null === $command->slug() ? $command->name() : $command->slug()));
     $this->repository->persist($project);
 }
Exemplo n.º 5
0
 public function __invoke(ProjectOfIdQuery $query)
 {
     $project = $this->repository->projectOfId(ProjectId::generate($query->projectId()));
     if (!$project instanceof Project) {
         throw new ProjectDoesNotExistException();
     }
     $organization = $this->organizationRepository->organizationOfId($project->organizationId());
     if (!$organization->isOrganizationMember(UserId::generate($query->userId()))) {
         throw new UnauthorizedProjectResourceException();
     }
     $this->dataTransformer->write($project);
     return $this->dataTransformer->read();
 }
Exemplo n.º 6
0
 public function __invoke(CreateProjectCommand $command)
 {
     $project = $this->projectRepository->projectOfId(ProjectId::generate($command->id()));
     if ($project instanceof Project) {
         throw new ProjectAlreadyExists($project->id());
     }
     $organizationId = OrganizationId::generate($command->organizationId());
     $organization = $this->organizationRepository->organizationOfId($organizationId);
     if (!$organization instanceof Organization) {
         throw new OrganizationDoesNotExistException();
     }
     if (!$organization->isOwner(UserId::generate($command->creatorId()))) {
         throw new UnauthorizedCreateProjectException();
     }
     $project = new Project(ProjectId::generate($command->id()), new ProjectName($command->name()), new Slug(null === $command->slug() ? $command->name() : $command->slug()), $organization->id());
     $this->projectRepository->persist($project);
 }
Exemplo n.º 7
0
 function let(ProjectId $projectId)
 {
     $projectId->id()->willReturn('project-id');
     $this->beConstructedWith($projectId);
 }
Exemplo n.º 8
0
 public function convertToPHPValue($value, AbstractPlatform $platform) : ProjectId
 {
     return ProjectId::generate($value);
 }
Exemplo n.º 9
0
 function let(ProjectId $projectId, ProjectName $projectName, Slug $projectSlug, OrganizationId $organizationId)
 {
     $projectId->id()->willReturn('project-id');
     $this->beConstructedWith($projectId, $projectName, $projectSlug, $organizationId);
 }
Exemplo n.º 10
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);
 }
Exemplo n.º 11
0
 public function __construct(ProjectId $projectId)
 {
     parent::__construct(sprintf('Project with id "%s" already exists', $projectId->id()));
 }
Exemplo n.º 12
0
 public function projectOfId(ProjectId $id)
 {
     return $this->find($id->id());
 }