Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
15 / 15 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
CancelEventRegistrationHandler | |
100.00% |
15 / 15 |
|
100.00% |
5 / 5 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
validate | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
run | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
3 | |||
getParamSettings | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getBodyParamSettings | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare( strict_types=1 ); |
4 | |
5 | namespace MediaWiki\Extension\CampaignEvents\Rest; |
6 | |
7 | use MediaWiki\Extension\CampaignEvents\Event\Store\IEventLookup; |
8 | use MediaWiki\Extension\CampaignEvents\MWEntity\MWAuthorityProxy; |
9 | use MediaWiki\Extension\CampaignEvents\Participants\UnregisterParticipantCommand; |
10 | use MediaWiki\Permissions\PermissionStatus; |
11 | use MediaWiki\Rest\Response; |
12 | use MediaWiki\Rest\SimpleHandler; |
13 | use MediaWiki\Rest\TokenAwareHandlerTrait; |
14 | use MediaWiki\Rest\Validator\Validator; |
15 | |
16 | class CancelEventRegistrationHandler extends SimpleHandler { |
17 | use EventIDParamTrait; |
18 | use TokenAwareHandlerTrait; |
19 | use FailStatusUtilTrait; |
20 | |
21 | private IEventLookup $eventLookup; |
22 | private UnregisterParticipantCommand $unregisterParticipantCommand; |
23 | |
24 | /** |
25 | * @param IEventLookup $eventLookup |
26 | * @param UnregisterParticipantCommand $unregisterParticipantCommand |
27 | */ |
28 | public function __construct( |
29 | IEventLookup $eventLookup, |
30 | UnregisterParticipantCommand $unregisterParticipantCommand |
31 | ) { |
32 | $this->eventLookup = $eventLookup; |
33 | $this->unregisterParticipantCommand = $unregisterParticipantCommand; |
34 | } |
35 | |
36 | /** |
37 | * @inheritDoc |
38 | */ |
39 | public function validate( Validator $restValidator ): void { |
40 | parent::validate( $restValidator ); |
41 | $this->validateToken(); |
42 | } |
43 | |
44 | /** |
45 | * @param int $eventID |
46 | * @return Response |
47 | */ |
48 | protected function run( int $eventID ): Response { |
49 | $eventRegistration = $this->getRegistrationOrThrow( $this->eventLookup, $eventID ); |
50 | $performer = new MWAuthorityProxy( $this->getAuthority() ); |
51 | $status = $this->unregisterParticipantCommand->unregisterIfAllowed( $eventRegistration, $performer ); |
52 | if ( !$status->isGood() ) { |
53 | $httptStatus = $status instanceof PermissionStatus ? 403 : 400; |
54 | $this->exitWithStatus( $status, $httptStatus ); |
55 | } |
56 | return $this->getResponseFactory()->createJson( [ |
57 | 'modified' => $status->getValue() |
58 | ] ); |
59 | } |
60 | |
61 | /** |
62 | * @inheritDoc |
63 | */ |
64 | public function getParamSettings(): array { |
65 | return $this->getIDParamSetting(); |
66 | } |
67 | |
68 | /** |
69 | * @inheritDoc |
70 | */ |
71 | public function getBodyParamSettings(): array { |
72 | return $this->getTokenParamDefinition(); |
73 | } |
74 | } |