Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 41 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
ApiStarMentee | |
0.00% |
0 / 41 |
|
0.00% |
0 / 6 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
20 | |||
needsToken | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isWriteMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
mustBePosted | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAllowedParams | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\Api; |
4 | |
5 | use GrowthExperiments\MentorDashboard\MenteeOverview\StarredMenteesStore; |
6 | use MediaWiki\Api\ApiBase; |
7 | use MediaWiki\Api\ApiMain; |
8 | use MediaWiki\ParamValidator\TypeDef\UserDef; |
9 | use MediaWiki\User\UserIdentity; |
10 | use Wikimedia\ParamValidator\ParamValidator; |
11 | |
12 | class ApiStarMentee extends ApiBase { |
13 | private StarredMenteesStore $starredMenteesStore; |
14 | |
15 | public function __construct( |
16 | ApiMain $mainModule, |
17 | string $moduleName, |
18 | StarredMenteesStore $starredMenteesStore |
19 | ) { |
20 | parent::__construct( $mainModule, $moduleName ); |
21 | |
22 | $this->starredMenteesStore = $starredMenteesStore; |
23 | } |
24 | |
25 | /** |
26 | * @inheritDoc |
27 | */ |
28 | public function execute() { |
29 | if ( !$this->getUser()->isNamed() ) { |
30 | $this->dieWithError( [ 'apierror-permissiondenied-generic' ] ); |
31 | } |
32 | |
33 | $params = $this->extractRequestParams(); |
34 | $mentor = $this->getUser(); |
35 | $action = $params['gesaction']; |
36 | /** @var UserIdentity */ |
37 | $mentee = $params['gesmentee']; |
38 | |
39 | if ( $action === 'star' ) { |
40 | $this->starredMenteesStore->starMentee( |
41 | $mentor, |
42 | $mentee |
43 | ); |
44 | } elseif ( $action === 'unstar' ) { |
45 | $this->starredMenteesStore->unstarMentee( |
46 | $mentor, |
47 | $mentee |
48 | ); |
49 | } |
50 | |
51 | $this->getResult()->addValue( null, $this->getModuleName(), [ |
52 | 'status' => 'ok', |
53 | 'action' => $action, |
54 | 'mentee' => $mentee->getName(), |
55 | ] ); |
56 | } |
57 | |
58 | /** |
59 | * @inheritDoc |
60 | */ |
61 | public function needsToken() { |
62 | return 'csrf'; |
63 | } |
64 | |
65 | /** |
66 | * @inheritDoc |
67 | */ |
68 | public function isWriteMode() { |
69 | return true; |
70 | } |
71 | |
72 | /** |
73 | * @inheritDoc |
74 | */ |
75 | public function mustBePosted() { |
76 | return true; |
77 | } |
78 | |
79 | /** |
80 | * @inheritDoc |
81 | */ |
82 | public function getAllowedParams() { |
83 | return [ |
84 | 'gesaction' => [ |
85 | ParamValidator::PARAM_REQUIRED => true, |
86 | ParamValidator::PARAM_TYPE => [ |
87 | 'star', |
88 | 'unstar' |
89 | ], |
90 | ], |
91 | 'gesmentee' => [ |
92 | ParamValidator::PARAM_REQUIRED => true, |
93 | ParamValidator::PARAM_TYPE => 'user', |
94 | UserDef::PARAM_ALLOWED_USER_TYPES => [ 'name', 'id' ], |
95 | UserDef::PARAM_RETURN_OBJECT => true, |
96 | ], |
97 | ]; |
98 | } |
99 | } |