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

Fix/development issues #246

Merged
merged 7 commits into from
Feb 9, 2024
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
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
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
2 changes: 1 addition & 1 deletion src/Controller/TeamMemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,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 @@ -214,6 +214,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
2 changes: 1 addition & 1 deletion templates/assign/__assign.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{% else %}
<div class="card card-outlined bg-primary-50 block flex-none">
<p class="text-sm">
<strong>{% trans from 'general' %}assignedTo{% endtrans %}:</strong>
<strong>{% trans from 'general' %}assignedTo{% endtrans %}: </strong>
<span>{{ data.assignedUser.email }}</span>
<a href="{{ path(path,{'id':data.id}) }}" title="{{ 'removeAssign'|trans }}" class="float-right underline">
{{ 'removeAssign'|trans }}
Expand Down
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
Loading