Repository: carpentries/amy

Issue:
Add CLDT organisation to workshop Administrator options
CLDT = Collaborative Lesson Development Training.

This can be done through the OrganizationManager class.


Discussion:
Marked as high priority as this is required by the end of September

Resolving patch:
diff --git a/amy/autoemails/actions.py b/amy/autoemails/actions.py
--- a/amy/autoemails/actions.py
+++ b/amy/autoemails/actions.py
@@ -277,6 +277,8 @@ def check(task: Task):  # type: ignore
             and task.event.administrator
             and task.event.administrator.domain != "self-organized"
             and task.event.administrator.domain != "carpentries.org"
+            # 2023-09-20: also exclude CLDT
+            and task.event.administrator.domain != "carpentries.org/community-lessons/"
         )
 
     def get_additional_context(self, objects, *args, **kwargs):
@@ -357,6 +359,7 @@ def check(task: Task):  # type: ignore
             and task.event.administrator
             and task.event.administrator.domain != "self-organized"
             and task.event.administrator.domain != "carpentries.org"
+            and task.event.administrator.domain != "carpentries.org/community-lessons/"
         )
 
     def get_additional_context(self, objects, *args, **kwargs):
@@ -488,6 +491,8 @@ def check(event: Event):  # type: ignore
             #             Instructor Training
             and event.administrator
             and event.administrator.domain != "carpentries.org"
+            # 2023-09-20: also exclude CLDT
+            and event.administrator.domain != "carpentries.org/community-lessons/"
         )
 
     def get_additional_context(self, objects, *args, **kwargs):
diff --git a/amy/workshops/models.py b/amy/workshops/models.py
--- a/amy/workshops/models.py
+++ b/amy/workshops/models.py
@@ -75,7 +75,10 @@ class OrganizationManager(models.Manager):
         "software-carpentry.org",
         "datacarpentry.org",
         "librarycarpentry.org",
-        "carpentries.org",  # Instructor Training organisation
+        # Instructor Training organisation
+        "carpentries.org",
+        # Collaborative Lesson Development Training organisation
+        "carpentries.org/community-lessons/",
     ]
 
     def administrators(self):


Test patch:
diff --git a/amy/fiscal/tests/test_organization.py b/amy/fiscal/tests/test_organization.py
--- a/amy/fiscal/tests/test_organization.py
+++ b/amy/fiscal/tests/test_organization.py
@@ -117,3 +117,33 @@ def test_symmetrical_affiliations(self):
         # Assert
         self.assertIn(self.org_beta, self.org_alpha.affiliated_organizations.all())
         self.assertIn(self.org_alpha, self.org_beta.affiliated_organizations.all())
+
+    def test_manager_administrators(self):
+        """Ensure the correct organizations are returned as possible administrators."""
+        # Arrange - `setUp()` also creates 2 organisations these filters should ignore
+        self._setUpAdministrators()
+        expected_domains = [
+            "self-organized",
+            "software-carpentry.org",
+            "datacarpentry.org",
+            "librarycarpentry.org",
+            # Instructor Training organisation
+            "carpentries.org",
+            # Collaborative Lesson Development Training organisation
+            "carpentries.org/community-lessons/",
+        ]
+
+        # Act
+        organizations_with_admin_domain = Organization.objects.filter(
+            domain__in=expected_domains
+        )
+        administrators = Organization.objects.administrators()
+
+        # Assert
+        # check that all ADMIN_DOMAINS are represented
+        self.assertSetEqual(
+            set(expected_domains), set(Organization.objects.ADMIN_DOMAINS)
+        )
+        self.assertEqual(organizations_with_admin_domain.count(), len(expected_domains))
+        # check that administrators() returns what we expect
+        self.assertQuerysetEqual(organizations_with_admin_domain, administrators)
diff --git a/amy/workshops/tests/base.py b/amy/workshops/tests/base.py
--- a/amy/workshops/tests/base.py
+++ b/amy/workshops/tests/base.py
@@ -529,6 +529,29 @@ def _setUpCommunityRoles(self) -> None:
             award=Award.objects.get(person=self.ron, badge=self.instructor_badge),
         )
 
+    def _setUpAdministrators(self) -> None:
+        """Adds administrator organizations to the database."""
+        Organization.objects.bulk_create(
+            [
+                Organization(domain="self-organized", fullname="Self-Organized"),
+                Organization(
+                    domain="software-carpentry.org",
+                    fullname="Software Carpentry",
+                ),
+                Organization(domain="datacarpentry.org", fullname="Data Carpentry"),
+                Organization(
+                    domain="librarycarpentry.org",
+                    fullname="Library Carpentry",
+                ),
+                Organization(domain="carpentries.org", fullname="Instructor Training"),
+                Organization(
+                    domain="carpentries.org/community-lessons/",
+                    fullname="Collaborative Lesson Development Training",
+                ),
+            ],
+            ignore_conflicts=True,
+        )
+
     @staticmethod
     def reconsent(person: Person, term: Term, term_option: TermOption) -> Consent:
         consent = Consent.objects.get(