Skip to content

Commit

Permalink
Merge branch 'development' into feature/team-hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
holema authored Feb 27, 2024
2 parents 3ac9056 + 7eb12d9 commit 2db64f4
Show file tree
Hide file tree
Showing 18 changed files with 181 additions and 72 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ OAUTH_KEYCLOAK_REALM=addHere

###> demo ###
demo_installation=prod #demo
APP_DEMO=0
###< demo ###

###> LaF ###
Expand Down
12 changes: 12 additions & 0 deletions assets/controllers/appUi_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ export default class extends Controller {
connect() {
this.initTabs();
this.initClickListeners();
this.initDisabledForms();
}

initDisabledForms() {
Array.prototype.forEach.call(document.querySelectorAll('form[disabled]'), function (form) {
Array.prototype.forEach.call(form.querySelectorAll('input, textarea, select, button'), function (element) {
element.disabled = true;
});
Array.prototype.forEach.call(form.querySelectorAll('button[type=submit]'), function (button) {
button.remove();
});
});
}

initClickListeners() {
Expand Down
3 changes: 2 additions & 1 deletion config/packages/twig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ twig:
dataPrivacy: '%env(dataPrivacy)%'
supportMail: '%env(SUPPORT_MAIL)%'
demo: '%env(demo_installation)%'
laf_version: '%env(laF_version)%'
laf_version: '%env(laF_version)%'
APP_DEMO: '%env(APP_DEMO)%'
22 changes: 22 additions & 0 deletions src/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

namespace App\Controller;

use App\Entity\Team;
use App\Form\Type\TeamType;
use App\Repository\AkademieBuchungenRepository;
use App\Repository\AuditTomRepository;
use App\Repository\DatenweitergabeRepository;
Expand Down Expand Up @@ -150,6 +152,26 @@ public function noTeam(): Response
]);
}

#[Route(path: '/no_team/create', name: 'no_team_create')]
public function noTeamCreate(): Response
{
if (!$_ENV['APP_DEMO']) {
return $this->redirectToRoute('dashboard');
}

$team = (new Team())->setActiv(true);
$form = $this->createForm(TeamType::class, $team, [
'action' => $this->generateUrl('team_create')
])
->remove('video')
->remove('externalLink');

return $this->render('dashboard/noteamCreate.html.twig', [
'user' => $this->getUser(),
'form' => $form->createView(),
]);
}

private function getTabsAssignments(): array
{
return [
Expand Down
4 changes: 4 additions & 0 deletions src/Controller/QuestionnaireController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public function edit(
#[ParamConverter('questionnaire', class: 'App\Entity\Questionnaire', options: ['mapping' => ['id' => 'id']])]
public function delete(Questionnaire $questionnaire): RedirectResponse
{
if (!$questionnaire->isDeletable()) {
throw $this->createNotFoundException();
}

foreach ($questionnaire->getParticipationAnswers() as $participationAnswer) {
$this->em->remove($participationAnswer);
}
Expand Down
7 changes: 7 additions & 0 deletions src/Controller/TeamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ public function create(
$em->persist($nTeam);
$em->persist($user);
$em->flush();
$this->addSuccessMessage($this->translator->trans(id: 'team.created', domain: 'team'));

if ($_ENV['APP_DEMO']) {
$teamService->switchToTeam((string) $nTeam->getId());
return $this->redirectToRoute('dashboard');
}

return $this->redirectToRoute('team_edit', ['id' => $nTeam->getId()]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/TeamMemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public function mitgliederRemove(
$target = $this->generateUrl('akademie_admin') . '#tab-user';
break;
default:
if ($member !== $user && $member->hasTeam($team)) {
if ($team->isMemberRemovable($member, $user)) {
$member->removeTeam($team);
$team->removeAdmin($member);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Entity/Questionnaire.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public function __construct()
$this->academyLessons = new ArrayCollection();
}

public function isDeletable(): bool
{
return $this->getAcademyLessons()->isEmpty();
}

public function getLabel(): ?string
{
return $this->label;
Expand Down
12 changes: 12 additions & 0 deletions src/Entity/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,18 @@ public function __toString(): string
return $this->name;
}

public function isMemberRemovable(User $member, User $userLoggedIn): bool
{
if ($userLoggedIn->hasRole('ROLE_SUPER_ADMIN')) {
return true;
}

if ($member === $userLoggedIn) {
return false;
}

return $member->getTeams()->contains($this);
}

public function getId(): ?int
{
Expand Down
11 changes: 11 additions & 0 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ public function getId(): ?int
return $this->id;
}

public function hasRole(string $role): bool
{
foreach ($this->getRoles() as $_role) {
if ($role === $_role) {
return true;
}
}

return false;
}

public function getTeams(): Collection
{
$allTeams = array_merge($this->teams->toArray(), $this->adminRoles->toArray());
Expand Down
80 changes: 43 additions & 37 deletions templates/akademie/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,47 +33,53 @@
</td>
<td>{{ b.zugewiesen|date('d.m.Y') }}</td>
<td>{{ b.start|date('d.m.Y') }}</td>
<td>
{% if b.participations[0].state == 'finished' %}
{% trans from 'general' %}finished{% endtrans %}
{% else %}
{{ b.participations[0].state|trans }}
{% endif %}
</td>
<td>
{% if b.participations[0].state == 'finished' and b.participations[0].passed %}
<svg viewBox="0 0 24 24" class="text-green-600 w-5 h-5">
<path fill="currentColor"
d="M12,0A12,12,0,1,0,24,12,12.014,12.014,0,0,0,12,0Zm6.927,8.2-6.845,9.289a1.011,1.011,0,0,1-1.43.188L5.764,13.769a1,1,0,1,1,1.25-1.562l4.076,3.261,6.227-8.451A1,1,0,1,1,18.927,8.2Z">
</path>
</svg>
{% endif %}
</td>
<td>
{% if b.participations[0].state == 'finished' %}
{% if b.participations[0].passed %}
<a href="{{ path('akademie_kurs_zertifikat', {'id':b.id}) }}">
{{ 'result.success.button_cert'|trans }}
</a>
{% if b.participations|length %}
<td>
{% if b.participations[0].state == 'finished' %}
{% trans from 'general' %}finished{% endtrans %}
{% else %}
<a href="{{ path('participation_reset', {'id': b.participations[0].id }) }}">
{% trans from 'questionnaire' %}retry{% endtrans %}
</a>
{{ b.participations[0].state|trans }}
{% endif %}
</td>
<td>
{% if b.participations[0].state == 'finished' and b.participations[0].passed %}
<svg viewBox="0 0 24 24" class="text-green-600 w-5 h-5">
<path fill="currentColor"
d="M12,0A12,12,0,1,0,24,12,12.014,12.014,0,0,0,12,0Zm6.927,8.2-6.845,9.289a1.011,1.011,0,0,1-1.43.188L5.764,13.769a1,1,0,1,1,1.25-1.562l4.076,3.261,6.227-8.451A1,1,0,1,1,18.927,8.2Z">
</path>
</svg>
{% endif %}
</td>
<td>
{% if b.participations[0].state == 'finished' %}
{% if b.participations[0].passed %}
<a href="{{ path('akademie_kurs_zertifikat', {'id':b.id}) }}">
{{ 'result.success.button_cert'|trans }}
</a>
{% else %}
<a href="{{ path('participation_reset', {'id': b.participations[0].id }) }}">
{% trans from 'questionnaire' %}retry{% endtrans %}
</a>
{% endif %}
{% endif %}
{% endif %}

{% if b.participations[0].state == 'ongoing' %}
<a href="{{ path('participation_continue', {'id': b.participations[0].id}) }}">
{% trans from 'general' %}continue{% endtrans %}
</a>
{% else %}
{% if b.zugewiesen < today and b.user.akademieUser in b.kurs.team and b.participations[0].state == 'assigned' %}
<a href="{{ path('akademie_kurs',{'kurs':b.id}) }}">
{% trans from 'general' %}start{% endtrans %}
</a>
{% if b.participations[0].state == 'ongoing' %}
<a href="{{ path('participation_continue', {'id': b.participations[0].id}) }}">
{% trans from 'general' %}continue{% endtrans %}
</a>
{% else %}
{% if b.zugewiesen < today and b.user.akademieUser in b.kurs.team and b.participations[0].state == 'assigned' %}
<a href="{{ path('akademie_kurs',{'kurs':b.id}) }}">
{% trans from 'general' %}start{% endtrans %}
</a>
{% endif %}
{% endif %}
{% endif %}
</td>
</td>
{% else %}
<td>-</td>
<td>-</td>
<td>-</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
Expand Down
15 changes: 11 additions & 4 deletions templates/dashboard/noteam.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
<h2>{% trans %}noTeam{% endtrans %}</h2>
</div>
<div>
<p>{% trans %}noTeamHelp{% endtrans %}</p>
<hr class="my-5">
<a href="mailto:{{ supportMail }}" class="btn">{% trans %}supportRequest{% endtrans %}</a>
<a href="{{ path('logout_keycloak') }}" class="btn">{% trans %}logout{% endtrans %}</a>
{% if APP_DEMO %}
<p>{% trans %}createTeamHelp{% endtrans %}</p>
<a href="{{ path('no_team_create') }}" class="btn btn-create mt-5">
{% trans from 'team' %}team.create{% endtrans %}
</a>
{% else %}
<p>{% trans %}noTeamHelp{% endtrans %}</p>
<hr class="my-5">
<a href="mailto:{{ supportMail }}" class="btn">{% trans %}supportRequest{% endtrans %}</a>
<a href="{{ path('logout_keycloak') }}" class="btn">{% trans %}logout{% endtrans %}</a>
{% endif %}
</div>
</div>
{% endblock %}
11 changes: 11 additions & 0 deletions templates/dashboard/noteamCreate.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'client_request/base.html.twig' %}
{% trans_default_domain 'dashboard' %}

{% block content %}
<div class="card-outlined">
<h2>{% trans from 'team' %}team.create{% endtrans %}</h2>
{{ form_start(form) }}
{{ form_row(form) }}
{{ form_end(form) }}
</div>
{% endblock %}
6 changes: 5 additions & 1 deletion templates/questionnaire/questionnaire/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<thead>
<tr>
<th scope="col">{% trans %}questionnaire.label{% endtrans %}</th>
<th scope="col">{% trans from 'academy' %}academyCourses{% endtrans %}</th>
<th scope="col">{% trans from 'general' %}createdAt{% endtrans %}</th>
<th scope="col">{% trans from 'general' %}action.word{% endtrans %}</th>
</tr>
Expand All @@ -15,11 +16,14 @@
{% for questionnaire in questionnaires %}
<tr>
<td>{{ questionnaire.label }}</td>
<td>{{ questionnaire.academyLessons|length }}</td>
<td>{{ questionnaire.createdAt | date('Y-m-d H:i:s') }}</td>
<td>
<a href="{{ path('questionnaire_details', {'id': questionnaire.id}) }}">{% trans from 'general' %}show{% endtrans %}</a>
<a href="{{ path('questionnaire_edit', {'id': questionnaire.id}) }}">{% trans from 'general' %}edit{% endtrans %}</a>
<a href="{{ path('questionnaire_delete', {'id': questionnaire.id}) }}" class="text-danger">{% trans from 'general' %}remove{% endtrans %}</a>
{% if questionnaire.isDeletable %}
<a href="{{ path('questionnaire_delete', {'id': questionnaire.id}) }}" class="text-danger">{% trans from 'general' %}remove{% endtrans %}</a>
{% endif %}
</td>
</tr>
{% endfor %}
Expand Down
3 changes: 1 addition & 2 deletions templates/team/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

{% block title %}
{% trans %}adminArea{% endtrans %}
{{ currentTeam is defined and currentTeam ? currentTeam.name }}
{{ title is defined ? ': ' ~ title }}
{{ currentTeam is defined and currentTeam ? currentTeam.name : team is defined ? team }}{{ title is defined ? ': ' ~ title }}
{% endblock %}

{% block body %}
Expand Down
55 changes: 30 additions & 25 deletions templates/team/member.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,35 @@
<div id="content-team-admin">
{# Hide this section if keycloak groups are used to avoid confusing users #}
{% if not useKeycloakGroups %}
<h3>{% trans %}openInvitations{% endtrans %}</h3>
<ul class="stacked-list !mb-10">
{% for member in team.members |filter(member => member.registerId) %}
<li>
<div>
<p>{{ member.email }}</p>
</div>
<div>
{% if team in member.adminRoles %}
<a href="{{ path('team_mitglieder_admin', {'memberId':member.id}) }}" class="text-danger">
{% trans %}admin.remove{% endtrans %}
</a>
{% else %}
<a href="{{ path('team_mitglieder_admin', {'memberId':member.id}) }}">
{% trans %}admin.create{% endtrans %}
</a>
{% endif %}
<a href="{{ path('team_mitglieder_remove',{'memberId':member.id,'type':'odc'}) }}" class="text-danger">
{% trans from 'general' %}remove{% endtrans %}
</a>
</div>
</li>
{% endfor %}
</ul>
{% set openInvitations = team.members|filter(member => member.registerId) %}
{% if openInvitations|length %}
<h3>{% trans %}openInvitations{% endtrans %}</h3>
<ul class="stacked-list !mb-10">
{% for member in openInvitations %}
<li>
<div>
<p>{{ member.email }}</p>
</div>
<div>
{% if team in member.adminRoles %}
<a href="{{ path('team_mitglieder_admin', {'memberId':member.id, 'teamId':team.id}) }}" class="text-danger">
{% trans %}admin.remove{% endtrans %}
</a>
{% else %}
<a href="{{ path('team_mitglieder_admin', {'memberId':member.id, 'teamId':team.id}) }}">
{% trans %}admin.create{% endtrans %}
</a>
{% endif %}
{% if not useKeycloakGroups and team.isMemberRemovable(member, app.user) %}
<a href="{{ path('team_mitglieder_remove',{'memberId':member.id, 'teamId':team.id, 'type':'odc'}) }}" class="text-danger">
{% trans from 'general' %}remove{% endtrans %}
</a>
{% endif %}
</div>
</li>
{% endfor %}
</ul>
{% endif %}
{% endif %}

<h3>{% trans from 'base' %}users{% endtrans %}</h3>
Expand Down Expand Up @@ -91,7 +96,7 @@
</a>
{% endif %}
{# Hide this button if keycloak groups are used #}
{% if not useKeycloakGroups %}
{% if not useKeycloakGroups and team.isMemberRemovable(member, app.user) %}
<a href="{{ path('team_mitglieder_remove',{'memberId':member.id, 'teamId':team.id, 'type':'odc'}) }}" class="text-danger">
{% trans from 'general' %}remove{% endtrans %}
</a>
Expand Down
3 changes: 2 additions & 1 deletion translations/dashboard/dashboard.de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ guideline: Richtlinie
noTeamHelp: Für Ihren Benutzer ist kein Team vorhanden.<br>Fragen Sie Ihrem Administrator oder beim Support der H2 invent nach.
supportRequest: Support anfragen
logout: Logout
noTeam: Kein Team vorhanden
noTeam: Kein Team vorhanden
createTeamHelp: Erstellen Sie Ihr erstes Team.
Loading

0 comments on commit 2db64f4

Please sign in to comment.