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