forked from Probesys/bileto
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeamService.php
More file actions
66 lines (50 loc) · 1.9 KB
/
TeamService.php
File metadata and controls
66 lines (50 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
// This file is part of Bileto.
// Copyright 2022-2026 Probesys
// SPDX-License-Identifier: AGPL-3.0-or-later
namespace App\Service;
use App\Entity;
use App\Repository;
use App\Security;
class TeamService
{
public function __construct(
private Repository\OrganizationRepository $organizationRepository,
private Repository\TeamRepository $teamRepository,
private Repository\TeamAuthorizationRepository $teamAuthorizationRepository,
private Security\Authorizer $authorizer,
) {
}
public function addAgent(Entity\Team $team, Entity\User $agent): void
{
if (!$team->hasAgent($agent)) {
$team->addAgent($agent);
$this->teamRepository->save($team, true);
$this->authorizer->grantToTeam($agent, $team);
}
}
public function removeAgent(Entity\Team $team, Entity\User $agent): void
{
if ($team->hasAgent($agent)) {
$team->removeAgent($agent);
$this->teamRepository->save($team, true);
$this->authorizer->ungrantFromTeam($agent, $team);
}
}
public function createAuthorization(Entity\TeamAuthorization $teamAuthorization): void
{
$this->teamAuthorizationRepository->save($teamAuthorization, true);
$team = $teamAuthorization->getTeam();
$this->authorizer->grantTeamAuthorization($team, $teamAuthorization);
}
public function removeAuthorization(Entity\TeamAuthorization $teamAuthorization): void
{
$this->teamAuthorizationRepository->remove($teamAuthorization, true);
$team = $teamAuthorization->getTeam();
$organizations = $this->organizationRepository->findObsoleteSupervisedOrganizations($team);
foreach ($organizations as $organization) {
$organization->setResponsibleTeam(null);
}
$this->organizationRepository->save($organizations, true);
}
}