RemoveUserFromGroup.php 1013 Bytes
Newer Older
Jacob Priddy's avatar
Jacob Priddy committed
1
2
3
4
<?php

namespace Source\UseCases\GroupUser\RemoveUserFromGroup;

Jacob Priddy's avatar
Jacob Priddy committed
5
use Source\Authorization\Authorizer;
Jacob Priddy's avatar
Jacob Priddy committed
6
7
8
9
10
11
12
13
14
use Source\Gateways\GroupUser\GroupUserRepository;

class RemoveUserFromGroup implements RemoveUserFromGroupUseCase
{
    /**
     * @var \Source\Gateways\GroupUser\GroupUserRepository
     */
    protected GroupUserRepository $repository;

Jacob Priddy's avatar
Jacob Priddy committed
15
16
17
18
19
20
    /**
     * @var \Source\Authorization\Authorizer
     */
    protected Authorizer $authorizer;

    public function __construct(Authorizer $authorizer, GroupUserRepository $repository)
Jacob Priddy's avatar
Jacob Priddy committed
21
22
    {
        $this->repository = $repository;
Jacob Priddy's avatar
Jacob Priddy committed
23
        $this->authorizer = $authorizer;
Jacob Priddy's avatar
Jacob Priddy committed
24
25
26
27
28
29
30
    }

    /**
     * @inheritDoc
     */
    public function removeUserFromGroup(string $userId, string $groupId, Presenter $presenter): void
    {
Jacob Priddy's avatar
Jacob Priddy committed
31
32
        $this->authorizer->protectAdminRights($userId, $groupId);

Jacob Priddy's avatar
Jacob Priddy committed
33
34
35
36
37
38
39
        $this->repository->removeUserFromGroup($userId, $groupId);

        $responseModel = new ResponseModel('Success');

        $presenter->present($responseModel);
    }
}