1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2014 SURFnet bv |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Surfnet\StepupMiddleware\ApiBundle\Controller; |
20
|
|
|
|
21
|
|
|
use Surfnet\Stepup\Identity\Value\Institution; |
22
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Query\RaSecondFactorQuery; |
23
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Service\RaSecondFactorService; |
24
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Response\JsonCollectionResponse; |
25
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
26
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
27
|
|
|
use Symfony\Component\HttpFoundation\Request; |
28
|
|
|
|
29
|
|
|
final class RaSecondFactorController extends Controller |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var RaSecondFactorService |
33
|
|
|
*/ |
34
|
|
|
private $raSecondFactorService; |
35
|
|
|
|
36
|
|
|
public function __construct(RaSecondFactorService $raSecondFactorService) |
37
|
|
|
{ |
38
|
|
|
$this->raSecondFactorService = $raSecondFactorService; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function collectionAction(Request $request, Institution $institution) |
42
|
|
|
{ |
43
|
|
|
$this->denyAccessUnlessGranted(['ROLE_RA']); |
44
|
|
|
|
45
|
|
|
$query = $this->buildRaSecondFactorQuery($request, $institution); |
46
|
|
|
|
47
|
|
|
$paginator = $this->raSecondFactorService->search($query); |
48
|
|
|
|
49
|
|
|
return JsonCollectionResponse::fromPaginator($paginator); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function exportAction(Request $request, Institution $institution) |
53
|
|
|
{ |
54
|
|
|
$this->denyAccessUnlessGranted(['ROLE_RA']); |
55
|
|
|
|
56
|
|
|
$query = $this->buildRaSecondFactorQuery($request, $institution); |
57
|
|
|
|
58
|
|
|
$results = $this->raSecondFactorService->searchUnpaginated($query); |
59
|
|
|
|
60
|
|
|
return new JsonResponse($results); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param Request $request |
65
|
|
|
* @param Institution $institution |
66
|
|
|
* @return RaSecondFactorQuery |
67
|
|
|
*/ |
68
|
|
|
private function buildRaSecondFactorQuery(Request $request, Institution $institution) |
69
|
|
|
{ |
70
|
|
|
$query = new RaSecondFactorQuery(); |
71
|
|
|
$query->institution = $institution; |
72
|
|
|
$query->pageNumber = (int)$request->get('p', 1); |
73
|
|
|
$query->name = $request->get('name'); |
74
|
|
|
$query->type = $request->get('type'); |
75
|
|
|
$query->secondFactorId = $request->get('secondFactorId'); |
76
|
|
|
$query->email = $request->get('email'); |
77
|
|
|
$query->status = $request->get('status'); |
78
|
|
|
$query->orderBy = $request->get('orderBy'); |
79
|
|
|
$query->orderDirection = $request->get('orderDirection'); |
80
|
|
|
|
81
|
|
|
return $query; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|