Skip to content

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
KaydenLiss committed Aug 29, 2023
1 parent 61cf80c commit 6b5a0ac
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 58 deletions.
18 changes: 9 additions & 9 deletions src/Controller/AssignController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function assignAudit(

$success = $assignService->assignAudit($request, $audit);
if (!$success) {
$this->addFlash('danger', 'assignError');
$this->addFlash('danger', 'error.assign');
}
return $this->redirect($request->headers->get('referer'));
}
Expand All @@ -61,7 +61,7 @@ public function assignDataTransfer(

$success = $assignService->assignDatenweitergabe($request, $daten);
if (!$success) {
$this->addFlash('danger', 'assignError');
$this->addFlash('danger', 'error.assign');
}
return $this->redirect($request->headers->get('referer'));
}
Expand All @@ -80,7 +80,7 @@ public function assignDsfa(
if ($securityService->teamDataCheck($impactAssessment->getVvt(), $team)) {
$success = $assignService->assignDsfa($request, $impactAssessment);
if (!$success) {
$this->addFlash('danger', 'assignError');
$this->addFlash('danger', 'error.assign');
}
return $this->redirect($request->headers->get('referer'));
}
Expand All @@ -104,7 +104,7 @@ public function assignForm(

$success = $assignService->assignForm($request, $form);
if (!$success) {
$this->addFlash('danger', 'assignError');
$this->addFlash('danger', 'error.assign');
}
return $this->redirect($request->headers->get('referer'));
}
Expand All @@ -126,7 +126,7 @@ public function assignPolicy(

$success = $assignService->assignPolicy($request, $policy);
if (!$success) {
$this->addFlash('danger', 'assignError');
$this->addFlash('danger', 'error.assign');
}
return $this->redirect($request->headers->get('referer'));
}
Expand All @@ -148,7 +148,7 @@ public function assignSoftware(

$success = $assignService->assignSoftware($request, $software);
if (!$success) {
$this->addFlash('danger', 'assignError');
$this->addFlash('danger', 'error.assign');
}
return $this->redirect($request->headers->get('referer'));
}
Expand All @@ -170,7 +170,7 @@ public function assignTask(

$success = $assignService->assignTask($request, $task);
if (!$success) {
$this->addFlash('danger', 'assignError');
$this->addFlash('danger', 'error.assign');
}
return $this->redirect($request->headers->get('referer'));
}
Expand All @@ -192,7 +192,7 @@ public function assignVorfall(

$success = $assignService->assignVorfall($request, $vorfall);
if (!$success) {
$this->addFlash('danger', 'assignError');
$this->addFlash('danger', 'error.assign');
}
return $this->redirect($request->headers->get('referer'));
}
Expand All @@ -214,7 +214,7 @@ public function assignVvt(

$success = $assignService->assignVvt($request, $vvt);
if (!$success) {
$this->addFlash('danger', 'assignError');
$this->addFlash('danger', 'error.assign');
}
return $this->redirect($request->headers->get('referer'));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/DatenweitergabeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,12 @@ public function indexDataTransfer(
private function checkAccess(SecurityService $securityService, ?Datenweitergabe $transfer, Team $team): bool
{
if (!$transfer) {
$this->addFlash('danger', 'elementDoesNotExistError');
$this->addFlash('danger', 'error.elementDoesNotExist');
return false;
}

if (!$securityService->checkTeamAccessToTransfer($transfer, $team)) {
$this->addFlash('danger', 'accessDeniedError');
$this->addFlash('danger', 'error.accessDenied');
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/KontaktController.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function editKontakt(
$team = $currentTeamService->getCurrentTeam($this->getUser());
$contact = $contactRepository->find($request->get('id'));
if (!$securityService->checkTeamAccessToContact($contact, $team)) {
$this->addFlash('danger', 'accessDeniedError');
$this->addFlash('danger', 'error.accessDenied');
return $this->redirectToRoute('kontakt');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/PoliciesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function editPolicy(
$policy = $policiesRepository->find($request->get('id'));

if (!$securityService->checkTeamAccessToPolicy($policy, $team)) {
$this->addFlash('danger', 'accessDeniedError');
$this->addFlash('danger', 'error.accessDenied');
return $this->redirectToRoute('policies');
}
$newPolicy = $policiesService->clonePolicy($policy, $this->getUser());
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/SoftwareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,12 @@ public function index(
private function checkAccess(SecurityService $securityService, ?Software $software, Team $team): bool
{
if (!$software) {
$this->addFlash('danger', 'elementDoesNotExistError');
$this->addFlash('danger', 'error.elementDoesNotExist');
return false;
}

if (!$securityService->checkTeamAccessToSoftware($software, $team)) {
$this->addFlash('danger', 'accessDeniedError');
$this->addFlash('danger', 'error.accessDenied');
return false;
}

Expand Down
44 changes: 30 additions & 14 deletions src/Controller/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
use App\Repository\TaskRepository;
use App\Service\AssignService;
use App\Service\CurrentTeamService;
use App\Service\NotificationService;
use App\Service\SecurityService;
use App\Service\TaskService;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;

class TaskController extends AbstractController
{
Expand Down Expand Up @@ -119,12 +122,14 @@ public function done(

#[Route(path: '/task/edit', name: 'task_edit')]
public function editTask(
ValidatorInterface $validator,
Request $request,
SecurityService $securityService,
AssignService $assignService,
CurrentTeamService $currentTeamService,
TaskRepository $taskRepository,
ValidatorInterface $validator,
Request $request,
SecurityService $securityService,
AssignService $assignService,
CurrentTeamService $currentTeamService,
TaskRepository $taskRepository,
NotificationService $notificationService,
Environment $twig,
): Response
{
$team = $currentTeamService->getCurrentTeam($this->getUser());
Expand All @@ -139,21 +144,32 @@ public function editTask(
$assign = $assignService->createForm($task, $team);
$errors = array();
if ($form->isSubmitted() && $form->isValid() && $task->getActiv() === 1) {

$userChanged = $task->getAssignedUser() && !$task->getAssignedUser()->getTasks()->contains($task);
$task = $form->getData();
$task->setUpdatedBy($this->getUser());
$errors = $validator->validate($task);
if (count($errors) == 0) {
if ($userChanged) {
$content = $twig->render(
'email/assignementTask.html.twig',
[
'assign' => $task->getTitle(),
'data' => $task,
'team' => $task->getTeam(),
],
);
try {
$notificationService->sendNotificationAssign($content, $task->getAssignedUser());
} catch (Exception $exception) {
$this->addFlash('danger', 'error.mailSend');
}
}
$this->em->persist($task);
$this->em->flush();

return $this->redirectToRoute(
'task_edit',
[
'id' => $task->getId(),
'snack' => $this->translator->trans(id: 'save.successful', domain: 'general'),
],
);
$this->addFlash('success', 'save.successful');

return $this->redirectToRoute('task_edit', ['id' => $task->getId()]);
}
}
return $this->render('task/edit.html.twig', [
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/TomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function editTom(
$tom = $tomRepository->find($request->get('tom'));

if ($securityService->checkTeamAccessToTom($tom, $team) === false) {
$this->addFlash('danger', 'accessDeniedError');
$this->addFlash('danger', 'error.accessDenied');
return $this->redirectToRoute('tom');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/VvtController.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public function editVvt(
$vvt = $vvtRepository->find($request->get('id'));

if ($securityService->checkTeamAccessToProcess($vvt, $team) === false) {
$this->addFlash('danger', 'accessDeniedError');
$this->addFlash('danger', 'error.accessDenied');
return $this->redirectToRoute('vvt');
}
$newVvt = $VVTService->cloneVvt($vvt, $this->getUser());
Expand Down
1 change: 0 additions & 1 deletion src/Service/AssignService.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ public function assignDsfa($request, VVTDsfa $dsfa): bool
$this->notificationService->sendNotificationAssign($content, $user);
}
$this->em->persist($dsfa);
$this->em->persist($dsfa);
$this->em->flush();
return true;
} catch (Exception $exception) {
Expand Down
2 changes: 1 addition & 1 deletion templates/base/__flashMessage.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% trans_default_domain domain|default('base') %}
{% trans_default_domain domain|default('general') %}
{% if app.request.hasPreviousSession %}
{% for type, messages in app.session.flashbag.all() %}
{% for message in messages %}
Expand Down
5 changes: 4 additions & 1 deletion templates/forms/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
<h2 class="h2-responsive">{{ title }}</h2>
{{ include('base/__approvedBy.html.twig', {'data':daten}) }}
</div>
<div class="col-md-4 text-right">
<div class="col-md-4 text-md-right">
{{ include('assign/__assign.html.twig',{'data':daten,'path':'assign_form'}) }}
</div>
<div class="col-12">
{% include 'base/__flashMessage.html.twig' with {app:app} %}
</div>
</div>

<div class="card card-body">
Expand Down
23 changes: 13 additions & 10 deletions templates/software/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,29 @@
<h2 class="h2-responsive">{{ software.name }}: {{ title }}</h2>
{{ include('base/__approvedBy.html.twig', {'data':software}) }}
</div>
<div class="col-md-4 text-right">
<div class="col-md-4 text-md-right">
{% if isEditable %}
{{ include('assign/__assign.html.twig',{'data':software,'path':'assign_software'}) }}
{% endif %}
</div>
<div class="col-12">
{% include 'base/__flashMessage.html.twig' with {app:app} %}
</div>
</div>

<div class="accordion" id="accordionExample">
<div class="accordion" id="softwareAccordion">
<div class="card z-depth-0 bordered">
<div class="card-header" id="headingOne">
<div class="card-header p-0" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link collapsed" type="button" data-toggle="collapse"
<button class="btn btn-link btn-block text-left collapsed" type="button" data-toggle="collapse"
data-target="#collapseOne"
aria-expanded="false" aria-controls="collapseOne">
<h4 class="h4-responsive">{% trans %}software.baseData{% endtrans %}</h4>
<span class="h4-responsive">{% trans %}software.baseData{% endtrans %}</span>
</button>
</h5>
</div>
<div id="collapseOne" class="collapse{% if not isEditable %} show{% endif %}" aria-labelledby="headingOne"
data-parent="#accordionExample">
data-parent="#softwareAccordion">
<div class="card-body {% if not activ or software.approved %}disabled{% endif %}">
{{ include('software/__form.html.twig') }}
<p>{% trans from 'general' %}createdBy{% endtrans %}: {{ software.user.email }}</p>
Expand All @@ -50,15 +53,15 @@
</div>
{% if isEditable %}
<div class="card z-depth-0 bordered">
<div class="card-header" id="headingTwo">
<div class="card-header p-0" id="headingTwo">
<h5 class="mb-0">
<button class="btn btn-link " type="button" data-toggle="collapse"
<button class="btn btn-link btn-block text-left" type="button" data-toggle="collapse"
data-target="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">
<h4 class="h4-responsive">{% trans %}config.attached{% endtrans %}</h4>
<span class="h4-responsive">{% trans %}config.attached{% endtrans %}</span>
</button>
</h5>
</div>
<div id="collapseTwo" class="collapse show" aria-labelledby="headingTwo" data-parent="#accordionExample">
<div id="collapseTwo" class="collapse show" aria-labelledby="headingTwo" data-parent="#softwareAccordion">
<div class="card-body {% if not activ or software.approved %}disabled{% endif %}">
{{ include('software/__config.html.twig') }}
</div>
Expand Down
5 changes: 4 additions & 1 deletion templates/task/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
<div class="col-md-8">
<h2 class="h2-responsive">{% if edit %}{{ title }}{% else %}{{ task.title }}{% endif %}</h2>
</div>
<div class="col-md-4 text-right">
<div class="col-md-4 text-md-right">
{{ include('assign/__assign.html.twig',{'data':task,'path':'assign_task'}) }}
</div>
<div class="col-12">
{% include 'base/__flashMessage.html.twig' with {app:app} %}
</div>
</div>
<div class="card card-body">
{% if edit %}
Expand Down
9 changes: 1 addition & 8 deletions templates/vorfall/__form.html.twig
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
{% trans_default_domain 'vorfall' %}
<div class="row">
<div class="col-md-3">
<p>{% trans %}incident.assign{% endtrans %}</p>
</div>
<div class="col-md-9">
{% if assignForm is defined %}{{ include('assign/__assign.html.twig',{'data':vorfall,'path':'assign_vorfall'}) }}{% endif %}
</div>
</div>

{{ form_start(form) }}
<div class="{% if not activ or vorfall.approved %}disabled{% endif %}">
<div class="row mt-4">
Expand Down
14 changes: 12 additions & 2 deletions templates/vorfall/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@

{% block body %}

<h2 class="h2-responsive">{{ title }} ({% trans from 'general' %}number{% endtrans %}: {{ vorfall.id }})</h2>
{{ include('base/__approvedBy.html.twig', {'data':vorfall}) }}
<div class="row">
<div class="col-md-8">
<h2 class="h2-responsive">{{ title }} ({% trans from 'general' %}number{% endtrans %}: {{ vorfall.id }})</h2>
{{ include('base/__approvedBy.html.twig', {'data':vorfall}) }}
</div>
<div class="col-md-4 text-md-right">
{% if assignForm is defined %}{{ include('assign/__assign.html.twig',{'data':vorfall,'path':'assign_vorfall'}) }}{% endif %}
</div>
<div class="col-12">
{% include 'base/__flashMessage.html.twig' with {app:app} %}
</div>
</div>

<div class="card card-body">
{{ include('vorfall/__form.html.twig') }}
Expand Down
3 changes: 0 additions & 3 deletions translations/base/base.de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,3 @@ manageOdc: ODC Einstellungen
manageTeams: Teams verwalten
teamAdminArea: Team Adminbereich
superAdminArea: ODC Adminbereich
assignError: Die Zuweisung ist fehlgeschlagen. Wenden Sie sich an Ihren Admin wenn das Problem bestehen bleibt.
accessDeniedError: Sie haben versucht, auf ein Element zuzugreifen, das für Ihr Team nicht freigegeben ist.
elementDoesNotExistError: Sie haben versucht, auf ein Element zuzugreifen, das nicht existiert.
4 changes: 4 additions & 0 deletions translations/general/general.de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ error:
userNotInTeamAccessDenied: Benutzer*in nicht in Team und nicht berechtigt
userNotAuthorizedToManageTeam: Benutzer*in ist nicht berechtigt, Teams zu verwalten
signature: Die Signatur ist ungültig. Bitte kontaktieren Sie die Personen, die Ihnen die Datei überlassen hat.
assign: Die Zuweisung ist fehlgeschlagen. Wenden Sie sich an Ihren Admin wenn das Problem bestehen bleibt.
accessDenied: Sie haben versucht, auf ein Element zuzugreifen, das für Ihr Team nicht freigegeben ist.
elementDoesNotExist: Sie haben versucht, auf ein Element zuzugreifen, das nicht existiert.
mailSend: Die E-Mail konnte nicht verschickt werden. Wenden Sie sich an Ihren Admin wenn das Problem bestehen bleibt.
file: '
Die Datei ist fehlerhaft und kann nicht eingelesen werden.
Es können jedoch bereits Daten in Ihren Datenstamm eingetragen worden sein.
Expand Down

0 comments on commit 6b5a0ac

Please sign in to comment.