← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~jugmac00/launchpad:populate-signedcodeofconduct.affirmed into launchpad:master

 

jugmac00 has proposed merging ~jugmac00/launchpad:populate-signedcodeofconduct.affirmed into launchpad:master.

Commit message:
Populate SignedCodeOfConduct.affirmed

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jugmac00/launchpad/+git/launchpad/+merge/410227
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~jugmac00/launchpad:populate-signedcodeofconduct.affirmed into launchpad:master.
diff --git a/lib/lp/scripts/garbo.py b/lib/lp/scripts/garbo.py
index e2471dc..ce28426 100644
--- a/lib/lp/scripts/garbo.py
+++ b/lib/lp/scripts/garbo.py
@@ -75,6 +75,7 @@ from lp.code.model.revision import (
     )
 from lp.oci.model.ocirecipebuild import OCIFile
 from lp.registry.interfaces.person import IPersonSet
+from lp.registry.model.codeofconduct import SignedCodeOfConduct
 from lp.registry.model.person import Person
 from lp.registry.model.product import Product
 from lp.registry.model.sourcepackagename import SourcePackageName
@@ -1764,6 +1765,29 @@ class PopulateSnapBuildStoreRevision(TunableLoop):
         transaction.commit()
 
 
+class PopulateSignedCodeOfConductAffirmed(TunableLoop):
+    """Populates SignedCodeOfConduct.affirmed if not set"""
+
+    maximum_chunk_size = 5000
+
+    def __init__(self, log, abort_time=None):
+        super().__init__(log, abort_time)
+        self.store = IMasterStore(SignedCodeOfConduct)
+
+    def findSignedCodeOfConducts(self):
+        return self.store.find(
+            SignedCodeOfConduct,
+            SignedCodeOfConduct.affirmed == None
+        )
+
+    def isDone(self):
+        return self.findSignedCodeOfConducts().is_empty()
+
+    def __call__(self, chunk_size):
+        self.findSignedCodeOfConducts()[:chunk_size].set(affirmed=False)
+        transaction.commit()
+
+
 class BaseDatabaseGarbageCollector(LaunchpadCronScript):
     """Abstract base class to run a collection of TunableLoops."""
     script_name = None  # Script name for locking and database user. Override.
@@ -2024,6 +2048,7 @@ class HourlyDatabaseGarbageCollector(BaseDatabaseGarbageCollector):
         GitRepositoryPruner,
         RevisionCachePruner,
         UnusedSessionPruner,
+        PopulateSignedCodeOfConductAffirmed,
         ]
     experimental_tunable_loops = []
 
diff --git a/lib/lp/scripts/tests/test_garbo.py b/lib/lp/scripts/tests/test_garbo.py
index bb2bfb2..220d439 100644
--- a/lib/lp/scripts/tests/test_garbo.py
+++ b/lib/lp/scripts/tests/test_garbo.py
@@ -84,6 +84,7 @@ from lp.registry.enums import (
 from lp.registry.interfaces.accesspolicy import IAccessPolicySource
 from lp.registry.interfaces.person import IPersonSet
 from lp.registry.interfaces.teammembership import TeamMembershipStatus
+from lp.registry.model.codeofconduct import SignedCodeOfConduct
 from lp.registry.model.commercialsubscription import CommercialSubscription
 from lp.registry.model.teammembership import TeamMembership
 from lp.scripts.garbo import (
@@ -96,6 +97,7 @@ from lp.scripts.garbo import (
     load_garbo_job_state,
     LoginTokenPruner,
     OpenIDConsumerAssociationPruner,
+    PopulateSignedCodeOfConductAffirmed,
     PopulateSnapBuildStoreRevision,
     ProductVCSPopulator,
     save_garbo_job_state,
@@ -2045,6 +2047,21 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory):
         switch_dbuser('testadmin')
         self.assertEqual(build1._store_upload_revision, 1)
 
+    def test_PopulateSignedCodeOfConductAffirmed(self):
+        switch_dbuser('testadmin')
+        populator = PopulateSignedCodeOfConductAffirmed(log=None)
+        for _ in range(5):
+            person = self.factory.makePerson()
+            SignedCodeOfConduct(owner=person).affirmed = None
+
+        result_set = populator.findSignedCodeOfConducts()
+        self.assertGreater(result_set.count(), 0)
+
+        self.runHourly()
+
+        result_set = populator.findSignedCodeOfConducts()
+        self.assertTrue(result_set.is_empty())
+
 
 class TestGarboTasks(TestCaseWithFactory):
     layer = LaunchpadZopelessLayer

Follow ups