Repository: ephios-dev/ephios

Issue:
Allow users with management permissions to make events visible for all groups
Allow users with management permissions to make events visible for all groups by attributing the global permission instead of an object-level permission. Make sure that all views respect the global permission.
Also reword the label of the management checkbox on the GroupForm, as we are now using "ephios instance" as a label for the settings that require the is_staff flag


Discussion:

Resolving patch:
diff --git a/ephios/core/forms/users.py b/ephios/core/forms/users.py
--- a/ephios/core/forms/users.py
+++ b/ephios/core/forms/users.py
@@ -31,7 +31,7 @@
 from ephios.modellogging.log import add_log_recorder
 from ephios.modellogging.recorders import DerivedFieldsLogRecorder
 
-MANAGEMENT_PERMISSIONS = [
+CORE_MANAGEMENT_PERMISSIONS = [
     "auth.add_group",
     "auth.change_group",
     "auth.delete_group",
@@ -52,6 +52,7 @@
     "core.add_qualification",
     "core.change_qualification",
     "core.delete_qualification",
+    "auth.publish_event_for_group",
     "modellogging.view_logentry",
 ]
 
@@ -118,11 +119,11 @@ class GroupForm(PermissionFormMixin, ModelForm):
         required=False,
     )
     is_management_group = PermissionField(
-        label=_("Can manage ephios"),
+        label=_("Can manage permissions and qualifications"),
         help_text=_(
             "If checked, users in this group can manage users, groups, all group memberships, eventtypes and qualifications"
         ),
-        permissions=MANAGEMENT_PERMISSIONS,
+        permissions=CORE_MANAGEMENT_PERMISSIONS,
         required=False,
     )
 


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -10,7 +10,7 @@
 from guardian.shortcuts import assign_perm
 
 from ephios.core.consequences import QualificationConsequenceHandler, WorkingHoursConsequenceHandler
-from ephios.core.forms.users import MANAGEMENT_PERMISSIONS
+from ephios.core.forms.users import CORE_MANAGEMENT_PERMISSIONS
 from ephios.core.models import (
     AbstractParticipation,
     Event,
@@ -153,7 +153,7 @@ def groups(superuser, manager, planner, volunteer, qualified_volunteer):
     assign_perm("core.add_event", planners)
     assign_perm("core.delete_event", planners)
     assign_perm("core.view_past_event", planners)
-    for perm in MANAGEMENT_PERMISSIONS:
+    for perm in CORE_MANAGEMENT_PERMISSIONS:
         assign_perm(perm, managers)
     assign_perm("decide_workinghours_for_group", managers, volunteers)
     return managers, planners, volunteers
diff --git a/tests/core/test_event_form.py b/tests/core/test_event_form.py
--- a/tests/core/test_event_form.py
+++ b/tests/core/test_event_form.py
@@ -1,7 +1,8 @@
 from datetime import date, time
 
+from django.contrib.auth.models import Group
 from django.urls import reverse
-from guardian.shortcuts import get_users_with_perms
+from guardian.shortcuts import get_objects_for_user, get_users_with_perms
 
 from ephios.core.models import AbstractParticipation, LocalParticipation
 from ephios.extra.permissions import get_groups_with_perms
@@ -83,3 +84,20 @@ def test_participating_users_can_see_otherwise_invisible_event(
 
     # check that we can get (200 OK) the event details as a participant
     assert django_app.get(event.get_absolute_url(), user=volunteer)
+
+
+def test_management_group_can_make_event_visible_for_all_groups(
+    django_app, service_event_type, manager, groups
+):
+    event_form = django_app.get(
+        reverse("core:event_create", kwargs=dict(type=service_event_type.pk)),
+        user=manager,
+    ).form
+    num_groups = Group.objects.count()
+    assert (
+        get_objects_for_user(
+            manager, "publish_event_for_group", klass=Group, accept_global_perms=False
+        ).count()
+        < num_groups
+    )
+    assert num_groups == len(event_form["visible_for"].options)
diff --git a/tests/core/test_views_group.py b/tests/core/test_views_group.py
--- a/tests/core/test_views_group.py
+++ b/tests/core/test_views_group.py
@@ -1,7 +1,7 @@
 import pytest
 from django.contrib.auth.models import Group
 from django.urls import reverse
-from guardian.shortcuts import get_group_perms, get_objects_for_group
+from guardian.shortcuts import get_group_perms
 
 
 class TestGroupView:
@@ -104,24 +104,6 @@ def test_group_edit(self, django_app, groups, manager):
             group, Group.objects.get(name="Volunteers")
         )
 
-    def test_publish_for_groups_gets_saved_for_non_planner_groups(
-        self, django_app, groups, manager
-    ):
-        managers, planners, volunteers = groups
-        form = django_app.get(
-            reverse("core:group_edit", kwargs={"pk": managers.id}), user=manager
-        ).form
-        form["users"].force_value([manager.id])
-        form["is_planning_group"] = False
-        form["is_management_group"] = True
-        form["is_hr_group"] = False
-        form["publish_event_for_group"].select_multiple(texts=["Volunteers"])
-        form.submit().follow()
-        managers.refresh_from_db()
-        assert set(get_objects_for_group(managers, ["publish_event_for_group"], klass=Group)) == {
-            volunteers
-        }
-
     def test_group_delete(self, django_app, groups, manager):
         group = Group(name="Testgroup")
         group.save()