Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
WelcomeSurveySkipHandler | |
0.00% |
0 / 14 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
getParamSettings | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\Rest\Handler; |
4 | |
5 | use GrowthExperiments\WelcomeSurveyFactory; |
6 | use MediaWiki\Rest\Handler; |
7 | use MediaWiki\Rest\HttpException; |
8 | use MediaWiki\Rest\Response; |
9 | use RequestContext; |
10 | use Wikimedia\ParamValidator\ParamValidator; |
11 | |
12 | /** |
13 | * Handle POST requests to /growthexperiments/v0/welcomesurvey/skip |
14 | * |
15 | * Dismisses the welcome survey (in practice, used to dismiss reminder notices about the survey). |
16 | * |
17 | * As a no-JS fallback Special:WelcomeSurvey/skip is used. |
18 | */ |
19 | class WelcomeSurveySkipHandler extends Handler { |
20 | |
21 | /** @var WelcomeSurveyFactory */ |
22 | private $welcomeSurveyFactory; |
23 | |
24 | /** |
25 | * @param WelcomeSurveyFactory $welcomeSurveyFactory |
26 | */ |
27 | public function __construct( |
28 | WelcomeSurveyFactory $welcomeSurveyFactory |
29 | ) { |
30 | $this->welcomeSurveyFactory = $welcomeSurveyFactory; |
31 | } |
32 | |
33 | /** |
34 | * @return array|Response |
35 | * @throws HttpException |
36 | */ |
37 | public function execute() { |
38 | $params = $this->getValidatedParams(); |
39 | if ( !$this->getSession()->getToken( 'welcomesurvey' )->match( $params['token'] ) ) { |
40 | throw new HttpException( 'Invalid token', 400 ); |
41 | } |
42 | |
43 | $welcomeSurvey = $this->welcomeSurveyFactory->newWelcomeSurvey( RequestContext::getMain() ); |
44 | $welcomeSurvey->dismiss(); |
45 | |
46 | return [ 'success' => true ]; |
47 | } |
48 | |
49 | /** @inheritDoc */ |
50 | public function getParamSettings() { |
51 | return [ |
52 | 'token' => [ |
53 | self::PARAM_SOURCE => 'post', |
54 | ParamValidator::PARAM_TYPE => 'string', |
55 | ParamValidator::PARAM_REQUIRED => true, |
56 | ], |
57 | ]; |
58 | } |
59 | |
60 | } |