|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Circles - Bring cloud-users closer together. |
|
6
|
|
|
* |
|
7
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
8
|
|
|
* later. See the COPYING file. |
|
9
|
|
|
* |
|
10
|
|
|
* @author Maxence Lange <[email protected]> |
|
11
|
|
|
* @copyright 2017 |
|
12
|
|
|
* @license GNU AGPL version 3 or any later version |
|
13
|
|
|
* |
|
14
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
15
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
16
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
17
|
|
|
* License, or (at your option) any later version. |
|
18
|
|
|
* |
|
19
|
|
|
* This program is distributed in the hope that it will be useful, |
|
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22
|
|
|
* GNU Affero General Public License for more details. |
|
23
|
|
|
* |
|
24
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
25
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
namespace OCA\Circles\GlobalScale; |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
use OC\User\NoUserException; |
|
34
|
|
|
use OCA\Circles\Exceptions\CircleDoesNotExistException; |
|
35
|
|
|
use OCA\Circles\Exceptions\CircleTypeNotValidException; |
|
36
|
|
|
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException; |
|
37
|
|
|
use OCA\Circles\Exceptions\EmailAccountInvalidFormatException; |
|
38
|
|
|
use OCA\Circles\Exceptions\GlobalScaleDSyncException; |
|
39
|
|
|
use OCA\Circles\Exceptions\GlobalScaleEventException; |
|
40
|
|
|
use OCA\Circles\Exceptions\MemberAlreadyExistsException; |
|
41
|
|
|
use OCA\Circles\Exceptions\MemberCantJoinCircleException; |
|
42
|
|
|
use OCA\Circles\Exceptions\MemberIsNotModeratorException; |
|
43
|
|
|
use OCA\Circles\Exceptions\MembersLimitException; |
|
44
|
|
|
use OCA\Circles\Model\GlobalScale\GSEvent; |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Class MemberAdd |
|
49
|
|
|
* |
|
50
|
|
|
* @package OCA\Circles\GlobalScale |
|
51
|
|
|
*/ |
|
52
|
|
|
class MemberAdd extends AGlobalScaleEvent { |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param GSEvent $event |
|
57
|
|
|
* @param bool $localCheck |
|
58
|
|
|
* @param bool $mustBeChecked |
|
59
|
|
|
* |
|
60
|
|
|
* @throws CircleDoesNotExistException |
|
61
|
|
|
* @throws ConfigNoCircleAvailableException |
|
62
|
|
|
* @throws EmailAccountInvalidFormatException |
|
63
|
|
|
* @throws GlobalScaleDSyncException |
|
64
|
|
|
* @throws GlobalScaleEventException |
|
65
|
|
|
* @throws MemberAlreadyExistsException |
|
66
|
|
|
* @throws MemberCantJoinCircleException |
|
67
|
|
|
* @throws MembersLimitException |
|
68
|
|
|
* @throws NoUserException |
|
69
|
|
|
* @throws CircleTypeNotValidException |
|
70
|
|
|
* @throws MemberIsNotModeratorException |
|
71
|
|
|
*/ |
|
72
|
|
|
public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void { |
|
73
|
|
|
parent::verify($event, $localCheck, true); |
|
74
|
|
|
|
|
75
|
|
|
$eventMember = $event->getMember(); |
|
76
|
|
|
$this->cleanMember($eventMember); |
|
77
|
|
|
|
|
78
|
|
|
$ident = $eventMember->getUserId(); |
|
79
|
|
|
$this->membersService->verifyIdentBasedOnItsType( |
|
80
|
|
|
$ident, $eventMember->getType(), $eventMember->getInstance() |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
$eventCircle = $event->getCircle(); |
|
84
|
|
|
$eventViewer = $event->getViewer(); |
|
85
|
|
|
$this->cleanMember($eventViewer); |
|
86
|
|
|
|
|
87
|
|
|
$circle = |
|
88
|
|
|
$this->circlesRequest->getCircle( |
|
89
|
|
|
$eventCircle->getUniqueId(), $eventViewer->getUserId(), $eventViewer->getInstance() |
|
90
|
|
|
); |
|
91
|
|
|
$circle->getHigherViewer() |
|
92
|
|
|
->hasToBeModerator(); |
|
93
|
|
|
|
|
94
|
|
|
$member = $this->membersRequest->getFreshNewMember( |
|
95
|
|
|
$circle->getUniqueId(), $ident, $eventMember->getType(), $eventMember->getInstance() |
|
96
|
|
|
); |
|
97
|
|
|
// $this->membersRequest->createMember($member); |
|
98
|
|
|
$member->hasToBeInviteAble(); |
|
99
|
|
|
|
|
100
|
|
|
$this->circlesService->checkThatCircleIsNotFull($circle); |
|
101
|
|
|
|
|
102
|
|
|
$this->membersService->addMemberBasedOnItsType($circle, $member); |
|
103
|
|
|
|
|
104
|
|
|
$event->setMember($member); |
|
105
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param GSEvent $event |
|
111
|
|
|
* |
|
112
|
|
|
* @throws MemberAlreadyExistsException |
|
113
|
|
|
*/ |
|
114
|
|
|
public function manage(GSEvent $event): void { |
|
115
|
|
|
$circle = $event->getCircle(); |
|
116
|
|
|
$member = $event->getMember(); |
|
117
|
|
|
$this->miscService->log('add member; ' . json_encode($member)); |
|
118
|
|
|
if ($member->getJoined() === '') { |
|
119
|
|
|
$this->membersRequest->createMember($member); |
|
120
|
|
|
} else { |
|
121
|
|
|
$this->membersRequest->updateMember($member); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
$this->eventsService->onMemberNew($circle, $member); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
|