Skip to content

Commit

Permalink
Merge pull request #146 from VSVverkeerskunde/feature/VSVGVQ-183
Browse files Browse the repository at this point in the history
VSVGVQ-183 Final report is controlled by env variable.
  • Loading branch information
Luc Wollants committed Oct 16, 2018
2 parents 8817e10 + 77cf7a2 commit 419315b
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ REDIS_PORT=6379

### Open (1) or block (0) the quiz for anonymous users ###
QUIZ_ALLOW_ANONYMOUS=0

### Open (1) or block (0) the final report for contact users ###
REPORT_ALLOW_CONTACT=0
2 changes: 2 additions & 0 deletions config/packages/twig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ twig:
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
form_themes: ['bootstrap_4_layout.html.twig']
globals:
report_allow_contact: '%env(REPORT_ALLOW_CONTACT)%'
4 changes: 4 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ parameters:
team_file : '%kernel.project_dir%/config/teams.yaml'
env(REDIS_HOST): 'redis'
env(REDIS_PORT): 6379
env(QUIZ_ALLOW_ANONYMOUS): 0
quiz_allow_anonymous: '%env(QUIZ_ALLOW_ANONYMOUS)%'
env(REPORT_ALLOW_CONTACT): 0
report_allow_contact: '%env(REPORT_ALLOW_CONTACT)%'

services:
# default configuration for services in *this* file
Expand Down Expand Up @@ -487,6 +490,7 @@ services:
VSV\GVQ_API\Report\Controllers\ReportViewController:
arguments:
$reportService: '@report_service'
$allowContact: '%report_allow_contact%'
tags: ['controller.service_arguments']

VSV\GVQ_API\Document\Controllers\DocumentViewController:
Expand Down
91 changes: 59 additions & 32 deletions src/Report/Controllers/ReportViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,78 @@ class ReportViewController extends AbstractController
*/
private $reportService;

/**
* @var bool
*/
private $allowContact;

/**
* @param ReportService $reportService
* @param bool $allowContact
*/
public function __construct(ReportService $reportService)
{
public function __construct(
ReportService $reportService,
bool $allowContact
) {
$this->reportService = $reportService;
$this->allowContact = $allowContact;
}

/**
* @return Response
*/
public function report(): Response
{
$correctNlQuestions = $this->reportService->getCorrectQuestions(
new Language(Language::NL)
)->toArray();
$inCorrectNlQuestions = $this->reportService->getInCorrectQuestions(
new Language(Language::NL)
)->toArray();
if ($this->canViewReport()) {
$correctNlQuestions = $this->reportService->getCorrectQuestions(
new Language(Language::NL)
)->toArray();
$inCorrectNlQuestions = $this->reportService->getInCorrectQuestions(
new Language(Language::NL)
)->toArray();

$correctFrQuestions = $this->reportService->getCorrectQuestions(
new Language(Language::FR)
)->toArray();
$inCorrectFrQuestions = $this->reportService->getInCorrectQuestions(
new Language(Language::FR)
)->toArray();
$correctFrQuestions = $this->reportService->getCorrectQuestions(
new Language(Language::FR)
)->toArray();
$inCorrectFrQuestions = $this->reportService->getInCorrectQuestions(
new Language(Language::FR)
)->toArray();

$categoriesPercentagesNl = $this->reportService->getCategoriesPercentages(
new Language(Language::NL)
);
$categoriesPercentagesFr = $this->reportService->getCategoriesPercentages(
new Language(Language::FR)
);
$categoriesPercentagesNl = $this->reportService->getCategoriesPercentages(
new Language(Language::NL)
);
$categoriesPercentagesFr = $this->reportService->getCategoriesPercentages(
new Language(Language::FR)
);

return $this->render(
'report/report.html.twig',
[
'correctNlQuestions' => $correctNlQuestions,
'inCorrectNlQuestions' => $inCorrectNlQuestions,
'correctFrQuestions' => $correctFrQuestions,
'inCorrectFrQuestions' => $inCorrectFrQuestions,
'categoriesPercentagesNl' => $categoriesPercentagesNl,
'categoriesPercentagesFr' => $categoriesPercentagesFr,
'uploadPath' => getenv('UPLOAD_PATH'),
]
);
return $this->render(
'report/report.html.twig',
[
'correctNlQuestions' => $correctNlQuestions,
'inCorrectNlQuestions' => $inCorrectNlQuestions,
'correctFrQuestions' => $correctFrQuestions,
'inCorrectFrQuestions' => $inCorrectFrQuestions,
'categoriesPercentagesNl' => $categoriesPercentagesNl,
'categoriesPercentagesFr' => $categoriesPercentagesFr,
'uploadPath' => getenv('UPLOAD_PATH'),
]
);
} else {
return $this->redirectToRoute('dashboard');
}
}

/**
* @return bool
*/
private function canViewReport(): bool
{
if ($this->get('security.authorization_checker')->isGranted('ROLE_CONTACT')) {
return $this->allowContact;
} else {
// Security on the route is still in place.
// So this point is admin or vsv role.
return true;
}
}
}
7 changes: 7 additions & 0 deletions templates/includes/contact_nav.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@
href="{{ path('documents') }}">{% trans %}Documents{% endtrans %}
</a>
</li>
{% if report_allow_contact %}
<li class="nav-item {% if 'report' in app.request.get('_route') %}active{% endif %}">
<a class="nav-link {% if 'report' in app.request.get('_route') %}active{% endif %}"
href="{{ path('report') }}">{% trans %}Report{% endtrans %}
</a>
</li>
{% endif %}
</ul>

0 comments on commit 419315b

Please sign in to comment.