← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~laney/launchpad/add-sponsor-field-to-spph into lp:launchpad

 

Iain Lane has proposed merging lp:~laney/launchpad/add-sponsor-field-to-spph into lp:launchpad with lp:~laney/launchpad/spph-sponsor as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #912247 in Launchpad itself: "Sync sponsor not exposed via API"
  https://bugs.launchpad.net/launchpad/+bug/912247

For more details, see:
https://code.launchpad.net/~laney/launchpad/add-sponsor-field-to-spph/+merge/87930

If copyPackage is sponsored, save sponsor in SPPH.
-- 
https://code.launchpad.net/~laney/launchpad/add-sponsor-field-to-spph/+merge/87930
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~laney/launchpad/add-sponsor-field-to-spph into lp:launchpad.
=== modified file 'lib/lp/soyuz/interfaces/publishing.py'
--- lib/lp/soyuz/interfaces/publishing.py	2011-12-24 16:54:44 +0000
+++ lib/lp/soyuz/interfaces/publishing.py	2012-01-09 13:01:36 +0000
@@ -495,6 +495,13 @@
             required=False, readonly=True
         ))
 
+    sponsor = exported(
+        Reference(
+            IPerson,
+            title=_('Publication sponsor'),
+            description=_('The IPerson who sponsored the creation of this publication.'),
+            required=False, readonly=True
+        ))
     # Really IBinaryPackagePublishingHistory, see below.
     @operation_returns_collection_of(Interface)
     @export_read_operation()
@@ -1009,6 +1016,7 @@
              should be created for the new source publication.
         :param creator: An optional `IPerson`. If this is None, the
             sourcepackagerelease's creator will be used.
+        :param sponsor: An optional `IPerson` indicating the sponsor of this publication.
 
         datecreated will be UTC_NOW.
         status will be PackagePublishingStatus.PENDING

=== modified file 'lib/lp/soyuz/model/publishing.py'
--- lib/lp/soyuz/model/publishing.py	2011-12-30 06:14:56 +0000
+++ lib/lp/soyuz/model/publishing.py	2012-01-09 13:01:36 +0000
@@ -816,7 +816,7 @@
             archive=current.archive)
 
     def copyTo(self, distroseries, pocket, archive, override=None,
-               create_dsd_job=True, creator=None):
+               create_dsd_job=True, creator=None, sponsor=None):
         """See `ISourcePackagePublishingHistory`."""
         component = self.component
         section = self.section
@@ -834,7 +834,8 @@
             pocket,
             ancestor=self,
             create_dsd_job=create_dsd_job,
-            creator=creator)
+            creator=creator,
+            sponsor=sponsor)
 
     def getStatusSummaryForBuilds(self):
         """See `ISourcePackagePublishingHistory`."""
@@ -1511,7 +1512,7 @@
     def newSourcePublication(self, archive, sourcepackagerelease,
                              distroseries, component, section, pocket,
                              ancestor=None, create_dsd_job=True,
-                             creator=None):
+                             creator=None, sponsor=None):
         """See `IPublishingSet`."""
         # Avoid circular import.
         from lp.registry.model.distributionsourcepackage import (
@@ -1528,7 +1529,8 @@
             status=PackagePublishingStatus.PENDING,
             datecreated=UTC_NOW,
             ancestor=ancestor,
-            creator=creator)
+            creator=creator,
+            sponsor=sponsor)
         DistributionSourcePackage.ensure(pub)
 
         if create_dsd_job:

=== modified file 'lib/lp/soyuz/scripts/packagecopier.py'
--- lib/lp/soyuz/scripts/packagecopier.py	2012-01-06 11:08:30 +0000
+++ lib/lp/soyuz/scripts/packagecopier.py	2012-01-09 13:01:36 +0000
@@ -652,13 +652,16 @@
             if sponsored is not None:
                 announce_from_person = sponsored
                 creator = sponsored
+                sponsor = person
             else:
                 creator = person
+                sponsor = None
             sub_copies = _do_direct_copy(
                 source, archive, destination_series, pocket,
                 include_binaries, override, close_bugs=close_bugs,
                 create_dsd_job=create_dsd_job,
-                close_bugs_since_version=old_version, creator=creator)
+                close_bugs_since_version=old_version, creator=creator,
+                sponsor=sponsor)
             if send_email:
                 notify(
                     person, source.sourcepackagerelease, [], [], archive,
@@ -674,7 +677,8 @@
 
 def _do_direct_copy(source, archive, series, pocket, include_binaries,
                     override=None, close_bugs=True, create_dsd_job=True,
-                    close_bugs_since_version=None, creator=None):
+                    close_bugs_since_version=None, creator=None,
+                    sponsor=None):
     """Copy publishing records to another location.
 
     Copy each item of the given list of `SourcePackagePublishingHistory`
@@ -701,6 +705,7 @@
         then this parameter says which changelog entries to parse looking
         for bugs to close.  See `close_bugs_for_sourcepackagerelease`.
     :param creator: the requester `IPerson`.
+    :param sponsor: the sponsor `IPerson`, if this copy is being sponsored.
 
     :return: a list of `ISourcePackagePublishingHistory` and
         `BinaryPackagePublishingHistory` corresponding to the copied
@@ -731,7 +736,7 @@
             override = overrides[0]
         source_copy = source.copyTo(
             series, pocket, archive, override, create_dsd_job=create_dsd_job,
-            creator=creator)
+            creator=creator, sponsor=sponsor)
         if close_bugs:
             close_bugs_for_sourcepublication(
                 source_copy, close_bugs_since_version)

=== modified file 'lib/lp/soyuz/scripts/tests/test_copypackage.py'
--- lib/lp/soyuz/scripts/tests/test_copypackage.py	2011-12-30 06:14:56 +0000
+++ lib/lp/soyuz/scripts/tests/test_copypackage.py	2012-01-09 13:01:36 +0000
@@ -1526,6 +1526,30 @@
             'Sponsored <sponsored@xxxxxxxxxxx>', announcement['From'])
         self.assertEqual(sponsored_person, copied_source.creator)
 
+    def test_sponsored_copy_sponsor_field(self):
+        # If it's a sponsored copy then the SPPH's sponsored field is set to
+        # the user who sponsored the copy.
+        archive = self.test_publisher.ubuntutest.main_archive
+        source = self.test_publisher.getPubSource(
+            archive=archive, version='1.0-2', architecturehintlist='any')
+        changelog = self.factory.makeChangelog(spn="foo", versions=["1.0-2"])
+        source.sourcepackagerelease.changelog = changelog
+        # Copying to a primary archive reads the changes to close bugs.
+        transaction.commit()
+        nobby = self.createNobby(('i386', 'hppa'))
+        getUtility(ISourcePackageFormatSelectionSet).add(
+            nobby, SourcePackageFormat.FORMAT_1_0)
+        nobby.changeslist = 'nobby-changes@xxxxxxxxxxx'
+        sponsored_person = self.factory.makePerson(
+            displayname="Sponsored", email="sponsored@xxxxxxxxxxx")
+        [copied_source] = do_copy(
+            [source], archive, nobby, source.pocket, False,
+                    person=source.sourcepackagerelease.creator,
+                    check_permissions=False, send_email=True,
+                    sponsored=sponsored_person)
+        self.assertEqual(source.sourcepackagerelease.creator,
+            copied_source.sponsor)
+
     def test_copy_notification_contains_aggregate_change_log(self):
         # When copying a package that generates a notification,
         # the changelog should contain all of the changelog_entry texts for
@@ -1663,6 +1687,25 @@
             target_archive.owner,
             copied_source.creator)
 
+    def test_unsponsored_copy_does_not_set_sponsor(self):
+        # If the copy is not sponsored, SPPH.sponsor is none
+        archive = self.test_publisher.ubuntutest.main_archive
+        source = self.test_publisher.getPubSource(
+            archive=archive, version='1.0-2', architecturehintlist='any')
+        source.sourcepackagerelease.changelog_entry = '* Foo!'
+        nobby = self.createNobby(('i386', 'hppa'))
+        getUtility(ISourcePackageFormatSelectionSet).add(
+            nobby, SourcePackageFormat.FORMAT_1_0)
+        target_archive = self.factory.makeArchive(
+            distribution=self.test_publisher.ubuntutest)
+        [copied_source] = do_copy(
+            [source], target_archive, nobby, source.pocket, False,
+            person=target_archive.owner, check_permissions=False,
+            send_email=False)
+
+        self.assertEqual(
+            copied_source.sponsor,
+            None)
 
 class TestDoDelayedCopy(TestCaseWithFactory, BaseDoCopyTests):
 


Follow ups