示例#1
0
 public function removeByUserId(UserId $userId)
 {
     $members = $this->toArray();
     foreach ($members as $member) {
         if ($userId->equals($member->userId())) {
             $this->remove($member);
             return;
         }
     }
     throw new CollectionElementAlreadyRemovedException();
 }
示例#2
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);
 }
示例#3
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);
 }
示例#4
0
 function it_does_not_add_user_when_the_user_already_exists(AddUserCommand $command, UserRepository $repository, User $user)
 {
     $command->userId()->shouldBeCalled()->willReturn('user-id');
     $repository->userOfId(UserId::generate('user-id'))->shouldBeCalled()->willReturn($user);
     $user->id()->shouldBeCalled()->willReturn(UserId::generate('user-id'));
     $this->shouldThrow(UserAlreadyExistsException::class)->during__invoke($command);
 }
示例#5
0
 public function __invoke(FilterProjectsQuery $query)
 {
     $organizations = $this->repository->query($this->specificationFactory->buildFilterableSpecification(UserId::generate($query->userId()), null === $query->organizationId() ? null : OrganizationId::generate($query->organizationId()), null === $query->name() ? null : new ProjectName($query->name()), $query->offset(), $query->limit()));
     return array_map(function (Project $organization) {
         $this->dataTransformer->write($organization);
         return $this->dataTransformer->read();
     }, $organizations);
 }
 function it_does_not_edits_an_organization_because_the_owner_does_not_authorized(EditOrganizationCommand $command, OrganizationRepository $repository, Organization $organization)
 {
     $command->id()->shouldBeCalled()->willReturn('organization-id');
     $repository->organizationOfId(OrganizationId::generate('organization-id'))->shouldBeCalled()->willReturn($organization);
     $command->userId()->shouldBeCalled()->willReturn('editor-id');
     $organization->isOwner(UserId::generate('editor-id'))->shouldBeCalled()->willReturn(false);
     $this->shouldThrow(UnauthorizedEditOrganizationException::class)->during__invoke($command);
 }
 function it_does_not_serialize_organization_member_because_it_does_not_exist(OrganizationMemberOfIdQuery $query, OrganizationRepository $repository, Organization $organization)
 {
     $query->organizationId()->shouldBeCalled()->willReturn('organization-id');
     $repository->organizationOfId(OrganizationId::generate('organization-id'))->shouldBeCalled()->willReturn($organization);
     $query->userId()->shouldBeCalled()->willReturn('user-id');
     $organization->isOrganizationMember(UserId::generate('user-id'))->shouldBeCalled()->willReturn(false);
     $this->shouldThrow(OrganizationMemberDoesNotExistException::class)->during__invoke($query);
 }
 function it_transform_organization_to_plain_dto(MemberDataTransformer $memberDataTransformer)
 {
     $userId = UserId::generate('user-id');
     $organization = new Organization(OrganizationId::generate('organization-id'), new OrganizationName('Organization name'), new Slug('Organization name'), $userId);
     $this->write($organization);
     $memberDataTransformer->write($organization->owner($userId))->shouldBeCalled();
     $memberDataTransformer->read()->shouldBeCalled()->willReturn(['id' => 'owner-id', 'created_on' => '2016-10-24', 'updated_on' => '2016-10-24', 'user_id' => 'user-id', 'organization' => [['id' => 'organization-id', 'name' => 'Organization name', 'slug' => 'organization-name', 'created_on' => '2016-10-24', 'updated_on' => '2016-10-24']]]);
     $this->read()->shouldReturn(['id' => 'organization-id', 'name' => 'Organization name', 'slug' => 'organization-name', 'created_on' => (new \DateTimeImmutable())->format('Y-m-d'), 'updated_on' => (new \DateTimeImmutable())->format('Y-m-d'), 'owners' => [['id' => 'owner-id', 'created_on' => '2016-10-24', 'updated_on' => '2016-10-24', 'user_id' => 'user-id', 'organization' => [['id' => 'organization-id', 'name' => 'Organization name', 'slug' => 'organization-name', 'created_on' => '2016-10-24', 'updated_on' => '2016-10-24']]]], 'organizationMembers' => []]);
 }
示例#9
0
 public function __invoke(AddUserCommand $command)
 {
     $userId = UserId::generate($command->userId());
     $user = $this->repository->userOfId($userId);
     if ($user instanceof User) {
         throw new UserAlreadyExistsException($user->id());
     }
     $this->repository->persist(new User($userId));
 }
 function it_does_not_add_organization_member_to_organization_because_it_is_not_allowed(AddOrganizationMemberToOrganizationCommand $command, OrganizationRepository $repository, Organization $organization)
 {
     $organizationId = OrganizationId::generate('organization-id');
     $command->organizationId()->shouldBeCalled()->willReturn('organization-id');
     $repository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization);
     $command->adderId()->shouldBeCalled()->willReturn('adder-id');
     $organization->isOwner(UserId::generate('adder-id'))->shouldBeCalled()->willReturn(false);
     $this->shouldThrow(UnauthorizedOrganizationActionException::class)->during__invoke($command);
 }
示例#11
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);
 }
 public function __invoke(AddOrganizationMemberToOrganizationCommand $command)
 {
     $organization = $this->repository->organizationOfId(OrganizationId::generate($command->organizationId()));
     if (!$organization instanceof Organization) {
         throw new OrganizationDoesNotExistException();
     }
     if (!$organization->isOwner(UserId::generate($command->adderId()))) {
         throw new UnauthorizedOrganizationActionException();
     }
     $organization->addOrganizationMember(UserId::generate($command->userId()));
     $this->repository->persist($organization);
 }
示例#13
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);
 }
 function it_does_not_allow_changing_priority_if_editor_is_not_organization_organizationMember(OrganizationRepository $organizationRepository, ProjectRepository $projectRepository, TaskRepository $taskRepository, ChangeTaskPriorityCommand $command, Task $task, Project $project, ProjectId $projectId, OrganizationId $organizationId, Organization $organization)
 {
     $command->id()->shouldBeCalled()->willReturn('task-id');
     $command->editorId()->shouldBeCalled()->willReturn('editor-id');
     $taskRepository->taskOfId(Argument::type(TaskId::class))->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);
     $organization->isOrganizationMember(UserId::generate('editor-id'))->shouldBeCalled()->willReturn(false);
     $this->shouldThrow(UnauthorizedTaskActionException::class)->during('__invoke', [$command]);
 }
示例#15
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);
 }
示例#16
0
 public function __invoke(EditOrganizationCommand $command)
 {
     $organization = $this->repository->organizationOfId(OrganizationId::generate($command->id()));
     if (!$organization instanceof Organization) {
         throw new OrganizationDoesNotExistException();
     }
     if (!$organization->isOwner(UserId::generate($command->userId()))) {
         throw new UnauthorizedEditOrganizationException();
     }
     $organization->edit(new OrganizationName($command->name()), new Slug(null === $command->slug() ? $command->name() : $command->slug()));
     $this->repository->persist($organization);
 }
示例#17
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);
 }
示例#18
0
 public function __invoke(OwnerOfIdQuery $query)
 {
     $organization = $this->repository->organizationOfId(OrganizationId::generate($query->organizationId()));
     if (!$organization instanceof Organization) {
         throw new OrganizationDoesNotExistException();
     }
     $userId = UserId::generate($query->userId());
     if (!$organization->isOwner($userId)) {
         throw new OwnerDoesNotExistException($userId);
     }
     $this->dataTransformer->write($organization->owner($userId));
     return $this->dataTransformer->read();
 }
示例#19
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();
 }
示例#20
0
 function it_does_not_allow_to_reassign_when_editor_is_not_a_organization_organizationMember(OrganizationRepository $organizationRepository, ProjectRepository $projectRepository, TaskRepository $taskRepository, ReassignTaskCommand $command, Task $task, ProjectId $projectId, Project $project, OrganizationId $organizationId, Organization $organization)
 {
     $command->id()->shouldBeCalled()->willReturn('task-id');
     $command->assigneeId()->shouldBeCalled()->willReturn('new-assignee-id');
     $command->editorId()->shouldBeCalled()->willReturn('editor-id');
     $taskRepository->taskOfId(Argument::type(TaskId::class))->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);
     $organization->isOrganizationMember(UserId::generate('editor-id'))->shouldBeCalled()->willReturn(false);
     $this->shouldThrow(UnauthorizedTaskActionException::class)->during__invoke($command);
 }
示例#21
0
 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);
 }
示例#22
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);
 }
示例#23
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_creates_an_organization_without_slug(CreateOrganizationCommand $command, OrganizationRepository $repository, UserRepository $userRepository, User $user)
 {
     $userId = UserId::generate('user-id');
     $command->id()->shouldBeCalled()->willReturn('organization-id');
     $repository->organizationOfId(Argument::type(OrganizationId::class))->shouldBeCalled()->willReturn(null);
     $command->creatorId()->shouldBeCalled()->willReturn('user-id');
     $userRepository->userOfId($userId)->shouldBeCalled()->willReturn($user);
     $user->id()->shouldBeCalled()->willReturn($userId);
     $repository->organizationOfId(Argument::type(OrganizationId::class))->shouldBeCalled()->willReturn(null);
     $command->creatorId()->shouldBeCalled()->willReturn('user-id');
     $command->name()->shouldBeCalled()->willReturn('Organization name');
     $command->slug()->shouldBeCalled()->willReturn(null);
     $repository->persist(Argument::type(Organization::class))->shouldBeCalled();
     $this->__invoke($command);
 }
 function it_handles_task_priority_change(OrganizationRepository $organizationRepository, ProjectRepository $projectRepository, TaskRepository $taskRepository, ChangeTaskProgressCommand $command, Task $task, Project $project, ProjectId $projectId, OrganizationId $organizationId, Organization $organization)
 {
     $command->id()->shouldBeCalled()->willReturn('task-id');
     $command->progress()->shouldBeCalled()->willReturn('doing');
     $command->editorId()->shouldBeCalled()->willReturn('editor-id');
     $taskRepository->taskOfId(Argument::type(TaskId::class))->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);
     $organization->isOrganizationMember(UserId::generate('editor-id'))->shouldBeCalled()->willReturn(true);
     $task->changeProgress(Argument::type(TaskProgress::class))->shouldBeCalled();
     $taskRepository->persist(Argument::type(Task::class))->shouldBeCalled();
     $this->__invoke($command);
 }
示例#26
0
 public function __invoke(CreateOrganizationCommand $command)
 {
     if (null !== ($id = $command->id())) {
         $organization = $this->repository->organizationOfId(OrganizationId::generate($id));
         if ($organization instanceof Organization) {
             throw new OrganizationAlreadyExistsException();
         }
     }
     $user = $this->userRepository->userOfId(UserId::generate($command->creatorId()));
     if (!$user instanceof User) {
         throw new UserDoesNotExistException();
     }
     $organizationId = OrganizationId::generate($command->id());
     $organization = new Organization($organizationId, new OrganizationName($command->name()), new Slug(null === $command->slug() ? $command->name() : $command->slug()), $user->id());
     $this->repository->persist($organization);
 }
示例#27
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);
 }
示例#28
0
文件: UserSpec.php 项目: kreta/kreta
 function let(UserId $id)
 {
     $id->id()->willReturn('user-id');
     $this->beConstructedWith($id);
 }
 function it_should_return_message(UserId $userId)
 {
     $userId->id()->shouldBeCalled()->willReturn('user-id');
     $this->getMessage()->shouldReturn('Already exists a user with the "user-id" id');
 }
 public function __construct(UserId $userId)
 {
     parent::__construct(sprintf('The given %s user is already an owner', $userId->id()));
 }