diff --git a/assets/controllers/appUi_controller.js b/assets/controllers/appUi_controller.js index 750c1a23..9d8d6c1d 100644 --- a/assets/controllers/appUi_controller.js +++ b/assets/controllers/appUi_controller.js @@ -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() { diff --git a/src/Controller/QuestionnaireController.php b/src/Controller/QuestionnaireController.php index 8d0e5776..4c0be0f2 100644 --- a/src/Controller/QuestionnaireController.php +++ b/src/Controller/QuestionnaireController.php @@ -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); } diff --git a/src/Controller/TeamMemberController.php b/src/Controller/TeamMemberController.php index eb1a570e..a62afe3f 100644 --- a/src/Controller/TeamMemberController.php +++ b/src/Controller/TeamMemberController.php @@ -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); } diff --git a/src/Entity/Questionnaire.php b/src/Entity/Questionnaire.php index 1c916cee..0f21a65d 100644 --- a/src/Entity/Questionnaire.php +++ b/src/Entity/Questionnaire.php @@ -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; diff --git a/src/Entity/Team.php b/src/Entity/Team.php index 27c15816..3b3eedab 100644 --- a/src/Entity/Team.php +++ b/src/Entity/Team.php @@ -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 { diff --git a/src/Entity/User.php b/src/Entity/User.php index 58ab86a0..0b08004c 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -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()); diff --git a/templates/akademie/index.html.twig b/templates/akademie/index.html.twig index fde6abbc..8560c761 100644 --- a/templates/akademie/index.html.twig +++ b/templates/akademie/index.html.twig @@ -33,47 +33,53 @@ {{ b.zugewiesen|date('d.m.Y') }} {{ b.start|date('d.m.Y') }} - - {% if b.participations[0].state == 'finished' %} - {% trans from 'general' %}finished{% endtrans %} - {% else %} - {{ b.participations[0].state|trans }} - {% endif %} - - - {% if b.participations[0].state == 'finished' and b.participations[0].passed %} - - - - - {% endif %} - - - {% if b.participations[0].state == 'finished' %} - {% if b.participations[0].passed %} - - {{ 'result.success.button_cert'|trans }} - + {% if b.participations|length %} + + {% if b.participations[0].state == 'finished' %} + {% trans from 'general' %}finished{% endtrans %} {% else %} - - {% trans from 'questionnaire' %}retry{% endtrans %} - + {{ b.participations[0].state|trans }} + {% endif %} + + + {% if b.participations[0].state == 'finished' and b.participations[0].passed %} + + + + + {% endif %} + + + {% if b.participations[0].state == 'finished' %} + {% if b.participations[0].passed %} + + {{ 'result.success.button_cert'|trans }} + + {% else %} + + {% trans from 'questionnaire' %}retry{% endtrans %} + + {% endif %} {% endif %} - {% endif %} - {% if b.participations[0].state == 'ongoing' %} - - {% trans from 'general' %}continue{% endtrans %} - - {% else %} - {% if b.zugewiesen < today and b.user.akademieUser in b.kurs.team and b.participations[0].state == 'assigned' %} - - {% trans from 'general' %}start{% endtrans %} - + {% if b.participations[0].state == 'ongoing' %} + + {% trans from 'general' %}continue{% endtrans %} + + {% else %} + {% if b.zugewiesen < today and b.user.akademieUser in b.kurs.team and b.participations[0].state == 'assigned' %} + + {% trans from 'general' %}start{% endtrans %} + + {% endif %} {% endif %} - {% endif %} - + + {% else %} + - + - + - + {% endif %} {% endfor %} diff --git a/templates/assign/__assign.html.twig b/templates/assign/__assign.html.twig index 938ed7ec..067d8922 100644 --- a/templates/assign/__assign.html.twig +++ b/templates/assign/__assign.html.twig @@ -27,7 +27,7 @@ {% else %}

- {% trans from 'general' %}assignedTo{% endtrans %}: + {% trans from 'general' %}assignedTo{% endtrans %}: {{ data.assignedUser.email }} {{ 'removeAssign'|trans }} diff --git a/templates/questionnaire/questionnaire/list.html.twig b/templates/questionnaire/questionnaire/list.html.twig index 5a484bc3..d7dd065c 100644 --- a/templates/questionnaire/questionnaire/list.html.twig +++ b/templates/questionnaire/questionnaire/list.html.twig @@ -7,6 +7,7 @@ {% trans %}questionnaire.label{% endtrans %} + {% trans from 'academy' %}academyCourses{% endtrans %} {% trans from 'general' %}createdAt{% endtrans %} {% trans from 'general' %}action.word{% endtrans %} @@ -15,11 +16,14 @@ {% for questionnaire in questionnaires %} {{ questionnaire.label }} + {{ questionnaire.academyLessons|length }} {{ questionnaire.createdAt | date('Y-m-d H:i:s') }} {% trans from 'general' %}show{% endtrans %} {% trans from 'general' %}edit{% endtrans %} - {% trans from 'general' %}remove{% endtrans %} + {% if questionnaire.isDeletable %} + {% trans from 'general' %}remove{% endtrans %} + {% endif %} {% endfor %} diff --git a/templates/team/index.html.twig b/templates/team/index.html.twig index 4d8fd89f..1e7e1b88 100644 --- a/templates/team/index.html.twig +++ b/templates/team/index.html.twig @@ -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 %} diff --git a/templates/team/member.html.twig b/templates/team/member.html.twig index db5fad71..38f4ecec 100644 --- a/templates/team/member.html.twig +++ b/templates/team/member.html.twig @@ -22,30 +22,35 @@

{# Hide this section if keycloak groups are used to avoid confusing users #} {% if not useKeycloakGroups %} -

{% trans %}openInvitations{% endtrans %}

- + {% set openInvitations = team.members|filter(member => member.registerId) %} + {% if openInvitations|length %} +

{% trans %}openInvitations{% endtrans %}

+ + {% endif %} {% endif %}

{% trans from 'base' %}users{% endtrans %}

@@ -91,7 +96,7 @@ {% endif %} {# Hide this button if keycloak groups are used #} - {% if not useKeycloakGroups %} + {% if not useKeycloakGroups and team.isMemberRemovable(member, app.user) %} {% trans from 'general' %}remove{% endtrans %}