← Back to team overview

launchpad-reviewers team mailing list archive

Re: [Merge] lp:~sinzui/launchpad/licenses-modified into lp:launchpad

 

Launchpad is struggling to show the diff, yet loggerhead can show it :(.

Attached is the diff of this branch against devel.

-- 
Curtis Hovey
http://launchpad.net/~sinzui

https://code.launchpad.net/~sinzui/launchpad/licenses-modified/+merge/107229
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~sinzui/launchpad/licenses-modified into lp:launchpad.
=== modified file 'lib/lp/registry/configure.zcml'
--- lib/lp/registry/configure.zcml	2012-04-12 04:39:58 +0000
+++ lib/lp/registry/configure.zcml	2012-05-23 20:51:01 +0000
@@ -1070,7 +1070,7 @@
             interface="lp.registry.interfaces.milestonetag.IProjectGroupMilestoneTag"/>
     </class>
     <subscriber
-        for="lp.registry.interfaces.product.IProduct zope.lifecycleevent.interfaces.IObjectModifiedEvent"
+        for="lp.registry.interfaces.product.IProduct lp.registry.interfaces.product.ILicensesModifiedEvent"
         handler="lp.registry.subscribers.product_licenses_modified"/>
     <class
         class="lp.registry.model.mailinglist.MailingList">

=== modified file 'lib/lp/registry/interfaces/product.py'
--- lib/lp/registry/interfaces/product.py	2012-03-06 20:43:07 +0000
+++ lib/lp/registry/interfaces/product.py	2012-05-24 16:05:36 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 # pylint: disable-msg=E0211,E0213
@@ -8,6 +8,7 @@
 __metaclass__ = type
 
 __all__ = [
+    'ILicensesModifiedEvent',
     'InvalidProductName',
     'IProduct',
     'IProductModerateRestricted',
@@ -341,6 +342,18 @@
     OTHER_OPEN_SOURCE = DBItem(1010, "Other/Open Source")
 
 
+class ILicensesModifiedEvent(Interface):
+    """A Product's licenses were changed."""
+
+    def __init__(self, product, user=None):
+        """Create an an event about a license change to a product.
+
+        :param product: The product that was modified.
+        :param user: The user who modified the object. The user comes from
+            the current interaction if the user is not provided.
+        """
+
+
 class IProductDriverRestricted(Interface):
     """`IProduct` properties which require launchpad.Driver permission."""
 

=== modified file 'lib/lp/registry/model/product.py'
--- lib/lp/registry/model/product.py	2012-04-11 08:49:12 +0000
+++ lib/lp/registry/model/product.py	2012-05-23 22:02:31 +0000
@@ -6,6 +6,7 @@
 
 __metaclass__ = type
 __all__ = [
+    'LicensesModifiedEvent',
     'Product',
     'ProductSet',
     'ProductWithLicenses',
@@ -127,6 +128,7 @@
     )
 from lp.registry.interfaces.pillar import IPillarNameSet
 from lp.registry.interfaces.product import (
+    ILicensesModifiedEvent,
     IProduct,
     IProductSet,
     License,
@@ -188,6 +190,15 @@
 from lp.translations.model.translationpolicy import TranslationPolicyMixin
 
 
+class LicensesModifiedEvent(ObjectModifiedEvent):
+    """See `ILicensesModifiedEvent`."""
+    implements(ILicensesModifiedEvent)
+
+    def __init__(self, product, user=None):
+        super(LicensesModifiedEvent, self).__init__(
+            product, product, [], user)
+
+
 def get_license_status(license_approved, project_reviewed, licenses):
     """Decide the license status for an `IProduct`.
 
@@ -788,8 +799,7 @@
                 registrant=lp_janitor, purchaser=lp_janitor,
                 sales_system_id=sales_system_id, whiteboard=whiteboard)
             get_property_cache(self).commercial_subscription = subscription
-        # Do not use a snapshot because the past is unintersting.
-        notify(ObjectModifiedEvent(self, self, edited_fields=['licenses']))
+        notify(LicensesModifiedEvent(self))
 
     licenses = property(_getLicenses, _setLicenses)
 

=== modified file 'lib/lp/registry/subscribers.py'
--- lib/lp/registry/subscribers.py	2012-04-12 04:39:58 +0000
+++ lib/lp/registry/subscribers.py	2012-05-24 16:05:34 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 """Functions and classes that are subscribed to registry events."""
 
@@ -16,7 +16,6 @@
 
 from lp.registry.interfaces.person import (
     IPerson,
-    IPersonViewRestricted,
     )
 from lp.registry.interfaces.product import License
 from lp.services.config import config
@@ -34,11 +33,7 @@
 
 def product_licenses_modified(product, event):
     """Send a notification if licenses changed and a license is special."""
-    if not event.edited_fields:
-        return
-    licenses_changed = 'licenses' in event.edited_fields
-    needs_notification = LicenseNotification.needs_notification(product)
-    if licenses_changed and needs_notification:
+    if LicenseNotification.needs_notification(product):
         user = IPerson(event.user)
         notification = LicenseNotification(product, user)
         notification.send()

=== modified file 'lib/lp/registry/tests/test_subscribers.py'
--- lib/lp/registry/tests/test_subscribers.py	2012-04-12 04:39:58 +0000
+++ lib/lp/registry/tests/test_subscribers.py	2012-05-24 15:30:39 +0000
@@ -7,11 +7,11 @@
 
 from datetime import datetime
 
-from lazr.lifecycle.event import ObjectModifiedEvent
 import pytz
 from zope.security.proxy import removeSecurityProxy
 
 from lp.registry.interfaces.product import License
+from lp.registry.model.product import LicensesModifiedEvent
 from lp.registry.subscribers import (
     LicenseNotification,
     product_licenses_modified,
@@ -26,25 +26,37 @@
 from lp.testing.mail_helpers import pop_notifications
 
 
+class LicensesModifiedEventTestCase(TestCaseWithFactory):
+
+    layer = DatabaseFunctionalLayer
+
+    def test_init(self):
+        product = self.factory.makeProduct()
+        login_person(product.owner)
+        event = LicensesModifiedEvent(product)
+        self.assertEqual(product.owner, event.user.person)
+        self.assertEqual(product, event.object)
+        self.assertEqual(product, event.object_before_modification)
+        self.assertEqual([], event.edited_fields)
+
+    def test_init_with_user(self):
+        product = self.factory.makeProduct()
+        login_person(product.owner)
+        event = LicensesModifiedEvent(product, user=product.owner)
+        self.assertEqual(product.owner, event.user)
+
+
 class ProductLicensesModifiedTestCase(TestCaseWithFactory):
 
     layer = DatabaseFunctionalLayer
 
-    def make_product_event(self, licenses, edited_fields='licenses'):
+    def make_product_event(self, licenses):
         product = self.factory.makeProduct(licenses=licenses)
         pop_notifications()
         login_person(product.owner)
-        event = ObjectModifiedEvent(
-            product, product, edited_fields, user=product.owner)
+        event = LicensesModifiedEvent(product, user=product.owner)
         return product, event
 
-    def test_product_licenses_modified_licenses_not_edited(self):
-        product, event = self.make_product_event(
-            [License.OTHER_PROPRIETARY], edited_fields='_owner')
-        product_licenses_modified(product, event)
-        notifications = pop_notifications()
-        self.assertEqual(0, len(notifications))
-
     def test_product_licenses_modified_licenses_common_license(self):
         product, event = self.make_product_event([License.MIT])
         product_licenses_modified(product, event)


References