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 @@
- {% 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 @@
{{ member.email }} {{ member.email }}
@@ -15,11 +16,14 @@
{% for questionnaire in questionnaires %}
{% trans %}questionnaire.label{% endtrans %}
+ {% trans from 'academy' %}academyCourses{% endtrans %}
{% trans from 'general' %}createdAt{% endtrans %}
{% trans from 'general' %}action.word{% endtrans %}
{% 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 @@
{{ 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 %}
{% trans %}openInvitations{% endtrans %}
-
- {% for member in team.members |filter(member => member.registerId) %}
-
+ {% set openInvitations = team.members|filter(member => member.registerId) %}
+ {% if openInvitations|length %}
+ {% trans %}openInvitations{% endtrans %}
+
+ {% for member in openInvitations %}
+
+ {% 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 %}