From 4449daa3e38e26ebd0e922cdbef659482df4836b Mon Sep 17 00:00:00 2001 From: Rayvented Date: Thu, 8 Feb 2024 10:07:21 +0100 Subject: [PATCH 1/7] Disable form elements when form is disabled --- assets/controllers/appUi_controller.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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() { From f5e5bb0b73c592c44f2b98ec1994f29bd3c4766c Mon Sep 17 00:00:00 2001 From: Rayvented Date: Thu, 8 Feb 2024 11:00:25 +0100 Subject: [PATCH 2/7] Fix blank in templates/assign/__assign.html.twig --- templates/assign/__assign.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 }} From ff1cd1954902ca51aa08c3d5560c0cdaaa389c5a Mon Sep 17 00:00:00 2001 From: Rayvented Date: Thu, 8 Feb 2024 13:36:29 +0100 Subject: [PATCH 3/7] Fix deleting Questionnaire --- src/Controller/QuestionnaireController.php | 4 ++++ src/Entity/Questionnaire.php | 5 +++++ templates/questionnaire/questionnaire/list.html.twig | 6 +++++- 3 files changed, 14 insertions(+), 1 deletion(-) 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/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/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 %} From 1933bc6e05f3a9273d97935757a4071a9ac4c19a Mon Sep 17 00:00:00 2001 From: Rayvented Date: Thu, 8 Feb 2024 14:00:32 +0100 Subject: [PATCH 4/7] Fix empty array error in akademie/index.html.twig --- templates/akademie/index.html.twig | 80 ++++++++++++++++-------------- 1 file changed, 43 insertions(+), 37 deletions(-) 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 %} From ee8708541c82020bacf89bb59aa2dc09a1855efe Mon Sep 17 00:00:00 2001 From: Rayvented Date: Fri, 9 Feb 2024 12:47:05 +0100 Subject: [PATCH 5/7] Fix title in team admin page --- templates/team/index.html.twig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 %} From 68e24bfeff4ecb0ec07ed66272315611f8b20e08 Mon Sep 17 00:00:00 2001 From: Rayvented Date: Fri, 9 Feb 2024 12:50:31 +0100 Subject: [PATCH 6/7] Fix removing team member --- src/Controller/TeamMemberController.php | 2 +- src/Entity/Team.php | 12 ++++++++++++ src/Entity/User.php | 11 +++++++++++ templates/team/member.html.twig | 2 +- 4 files changed, 25 insertions(+), 2 deletions(-) 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/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/team/member.html.twig b/templates/team/member.html.twig index db5fad71..30e1f3d1 100644 --- a/templates/team/member.html.twig +++ b/templates/team/member.html.twig @@ -91,7 +91,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 %} From 8a38b5825cdf72bdb73a9fd4edc701dabae23429 Mon Sep 17 00:00:00 2001 From: Rayvented Date: Fri, 9 Feb 2024 13:47:21 +0100 Subject: [PATCH 7/7] Fix removing team member (open invitations) --- templates/team/member.html.twig | 53 ++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/templates/team/member.html.twig b/templates/team/member.html.twig index 30e1f3d1..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 %}