Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
BasicRequestAuthorizer | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
authorize | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
5 | |||
isReadAllowed | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
isWriteAllowed | n/a |
0 / 0 |
n/a |
0 / 0 |
0 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Rest\BasicAccess; |
4 | |
5 | use MediaWiki\Rest\Handler; |
6 | use MediaWiki\Rest\RequestInterface; |
7 | |
8 | /** |
9 | * A request authorizer which checks needsReadAccess() and needsWriteAccess() in the |
10 | * handler and calls isReadAllowed() and/or isWriteAllowed() in the subclass |
11 | * accordingly. |
12 | * |
13 | * @internal |
14 | */ |
15 | abstract class BasicRequestAuthorizer { |
16 | protected $request; |
17 | protected $handler; |
18 | |
19 | /** |
20 | * @param RequestInterface $request |
21 | * @param Handler $handler |
22 | */ |
23 | public function __construct( RequestInterface $request, Handler $handler ) { |
24 | $this->request = $request; |
25 | $this->handler = $handler; |
26 | } |
27 | |
28 | /** |
29 | * @see BasicAuthorizerInterface::authorize() |
30 | * @return string|null If the request is denied, the string error code. If |
31 | * the request is allowed, null. |
32 | */ |
33 | public function authorize() { |
34 | if ( $this->handler->needsReadAccess() && !$this->isReadAllowed() ) { |
35 | return 'rest-read-denied'; |
36 | } |
37 | if ( $this->handler->needsWriteAccess() && !$this->isWriteAllowed() ) { |
38 | return 'rest-write-denied'; |
39 | } |
40 | return null; |
41 | } |
42 | |
43 | /** |
44 | * Check if the current user is allowed to read from the wiki |
45 | * |
46 | * @return bool |
47 | */ |
48 | abstract protected function isReadAllowed(); |
49 | |
50 | /** |
51 | * Check if the current user is allowed to write to the wiki |
52 | * |
53 | * @return bool |
54 | */ |
55 | abstract protected function isWriteAllowed(); |
56 | } |