Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VSVGVQ-183 Final report is controlled by env variable. #146

Merged
merged 2 commits into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -484,6 +487,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>