Переглянути джерело

Drop deprecated functionality scheduled for removal in Oscar 2.1

master
Samir Shah 5 роки тому
джерело
коміт
9eae894cf9

+ 2
- 2
docs/source/releases/v2.0.rst Переглянути файл

@@ -345,5 +345,5 @@ Deprecated features
345 345
 - ``catalogue.managers.BrowsableProductManager`` is deprecated.  Use
346 346
   ``Product.objects.browsable()`` instead.
347 347
 
348
-- ``catalogue.Product.browseable`` is deprecated. Use
349
-  ``Product.objects.browseable()`` instead.
348
+- ``catalogue.Product.browsable`` is deprecated. Use
349
+  ``Product.objects.browsable()`` instead.

+ 21
- 0
docs/source/releases/v2.1.rst Переглянути файл

@@ -115,6 +115,27 @@ Bug fixes
115 115
 Removal of deprecated features
116 116
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117 117
 
118
+- Support for verifying order hashes using an insecure MD5 algorithm generated
119
+  by Oscar 1.5 and below has been dropped. The ``OSCAR_DEPRECATED_ORDER_VERIFY_KEY``
120
+  setting is no longer used. Order verification hashes generated by Oscar 1.5
121
+  and lower will no longer validate.
122
+
123
+- ``offer.Range.contains()`` has been removed. Use ``contains_product()`` instead.
124
+
125
+- ``catalogue.managers.ProductManager`` has been removed.  Use
126
+  ``catalogue.managers.ProductQuerySet.as_manager()`` instead.
127
+
128
+- ``catalogue.managers.BrowsableProductManager`` has been removed.  Use
129
+  ``Product.objects.browsable()`` instead.
130
+
131
+- ``catalogue.Product.browsable`` has been removed. Use
132
+  ``Product.objects.browsable()`` instead.
133
+
134
+- Invalid URLs supplied to ``OSCAR_DASHBOARD_NAVIGATION`` are no longer ignored.
135
+  URLs that cannot be resolved will now result in a ``NoReverseMatch`` exception.
136
+  URLs that are not provided by a subclass of ``oscar.core.application.OscarDashboardConfig``
137
+  will result in a ``KeyError``.
138
+
118 139
 Minor changes
119 140
 ~~~~~~~~~~~~~
120 141
 

+ 0
- 4
src/oscar/apps/catalogue/abstract_models.py Переглянути файл

@@ -30,7 +30,6 @@ from oscar.models.fields import AutoSlugField, NullCharField
30 30
 from oscar.models.fields.slugfield import SlugField
31 31
 from oscar.utils.models import get_image_upload_path
32 32
 
33
-BrowsableProductManager = get_class('catalogue.managers', 'BrowsableProductManager')
34 33
 CategoryQuerySet, ProductQuerySet = get_classes(
35 34
     'catalogue.managers', ['CategoryQuerySet', 'ProductQuerySet'])
36 35
 ProductAttributesContainer = get_class(
@@ -425,9 +424,6 @@ class AbstractProduct(models.Model):
425 424
             "or not"))
426 425
 
427 426
     objects = ProductQuerySet.as_manager()
428
-    # browsable property is deprecated and will be removed in Oscar 2.1
429
-    # Use Product.objects.browsable() instead.
430
-    browsable = BrowsableProductManager()
431 427
 
432 428
     class Meta:
433 429
         abstract = True

+ 0
- 31
src/oscar/apps/catalogue/managers.py Переглянути файл

@@ -5,7 +5,6 @@ from django.db.models import Exists, OuterRef
5 5
 from django.db.models.constants import LOOKUP_SEP
6 6
 from treebeard.mp_tree import MP_NodeQuerySet
7 7
 
8
-from oscar.core.decorators import deprecated
9 8
 from oscar.core.loading import get_model
10 9
 
11 10
 
@@ -117,36 +116,6 @@ class ProductQuerySet(models.query.QuerySet):
117 116
         return self.filter(parent=None)
118 117
 
119 118
 
120
-@deprecated
121
-class ProductManager(models.Manager):
122
-    """
123
-    Deprecated. Use ProductQuerySet.as_manager() instead.
124
-    """
125
-
126
-    def get_queryset(self):
127
-        return ProductQuerySet(self.model, using=self._db)
128
-
129
-    def browsable(self):
130
-        return self.get_queryset().browsable()
131
-
132
-    def base_queryset(self):
133
-        return self.get_queryset().base_queryset()
134
-
135
-
136
-class BrowsableProductManager(ProductManager):
137
-    """
138
-    Deprecated. Use Product.objects.browsable() instead.
139
-
140
-    The @deprecated decorator isn't applied to the class, because doing
141
-    so would log warnings, and we still initialise this class
142
-    in the Product.browsable for backward compatibility.
143
-    """
144
-
145
-    @deprecated
146
-    def get_queryset(self):
147
-        return super().get_queryset().browsable()
148
-
149
-
150 119
 class CategoryQuerySet(MP_NodeQuerySet):
151 120
 
152 121
     def browsable(self):

+ 1
- 1
src/oscar/apps/customer/alerts/utils.py Переглянути файл

@@ -37,7 +37,7 @@ class AlertsDispatcher:
37 37
         availability and send out email alerts when a product is
38 38
         available to buy.
39 39
         """
40
-        products = Product.browsable.filter(productalert__status=ProductAlert.ACTIVE).distinct()
40
+        products = Product.objects.browsable().filter(productalert__status=ProductAlert.ACTIVE).distinct()
41 41
         self.dispatcher.logger.info("Found %d products with active alerts", products.count())
42 42
         for product in products:
43 43
             self.send_product_alert_email_for_user(product)

+ 3
- 28
src/oscar/apps/dashboard/nav.py Переглянути файл

@@ -1,13 +1,11 @@
1 1
 import logging
2
-import warnings
3 2
 from functools import lru_cache
4 3
 
5 4
 from django.apps import apps
6 5
 from django.core.exceptions import ImproperlyConfigured
7
-from django.urls import NoReverseMatch, resolve, reverse
6
+from django.urls import resolve, reverse
8 7
 
9 8
 from oscar.core.application import OscarDashboardConfig
10
-from oscar.utils.deprecation import RemovedInOscar21Warning
11 9
 from oscar.views.decorators import check_permissions
12 10
 
13 11
 logger = logging.getLogger('oscar.dashboard')
@@ -99,33 +97,10 @@ def default_access_fn(user, url_name, url_args=None, url_kwargs=None):
99 97
     if url_name is None:  # it's a heading
100 98
         return True
101 99
 
102
-    try:
103
-        url = reverse(url_name, args=url_args, kwargs=url_kwargs)
104
-    except NoReverseMatch:
105
-        logger.exception('Invalid URL name {}'.format(url_name))
106
-        warnings.warn(
107
-            'Invalid URL names supplied to oscar.dashboard.nav.default_access_fn'
108
-            'will throw an exception in Oscar 2.1',
109
-            RemovedInOscar21Warning,
110
-            stacklevel=2
111
-        )
112
-        return False
113
-
100
+    url = reverse(url_name, args=url_args, kwargs=url_kwargs)
114 101
     url_match = resolve(url)
115 102
     url_name = url_match.url_name
116
-    try:
117
-        app_config_instance = _dashboard_url_names_to_config()[url_name]
118
-    except KeyError:
119
-        logger.error(
120
-            "{} is not a valid dashboard URL".format(url_match.view_name)
121
-        )
122
-        warnings.warn(
123
-            'Invalid URL names supplied to oscar.dashboard.nav.default_access_fn'
124
-            'will throw an exception in Oscar 2.1',
125
-            RemovedInOscar21Warning,
126
-            stacklevel=2
127
-        )
128
-        return False
103
+    app_config_instance = _dashboard_url_names_to_config()[url_name]
129 104
 
130 105
     permissions = app_config_instance.get_permissions(url_name)
131 106
 

+ 0
- 6
src/oscar/apps/offer/abstract_models.py Переглянути файл

@@ -15,7 +15,6 @@ from django.utils.timezone import get_current_timezone, now
15 15
 from django.utils.translation import gettext_lazy as _
16 16
 
17 17
 from oscar.core.compat import AUTH_USER_MODEL
18
-from oscar.core.decorators import deprecated
19 18
 from oscar.core.loading import (
20 19
     cached_import_string, get_class, get_classes, get_model)
21 20
 from oscar.models import fields
@@ -874,11 +873,6 @@ class AbstractRange(models.Model):
874 873
             return self.proxy.contains_product(product)
875 874
         return self.product_queryset.filter(id=product.id).exists()
876 875
 
877
-    # Deprecated alias
878
-    @deprecated
879
-    def contains(self, product):
880
-        return self.contains_product(product)
881
-
882 876
     def invalidate_cached_queryset(self):
883 877
         try:
884 878
             del self.product_queryset

+ 0
- 31
src/oscar/apps/order/abstract_models.py Переглянути файл

@@ -1,11 +1,8 @@
1
-import hashlib
2 1
 import logging
3
-import warnings
4 2
 from collections import OrderedDict
5 3
 from decimal import Decimal as D
6 4
 
7 5
 from django.conf import settings
8
-from django.core.exceptions import ImproperlyConfigured
9 6
 from django.core.signing import BadSignature, Signer
10 7
 from django.db import models
11 8
 from django.db.models import Sum
@@ -21,7 +18,6 @@ from oscar.core.compat import AUTH_USER_MODEL
21 18
 from oscar.core.loading import get_model
22 19
 from oscar.core.utils import get_default_currency
23 20
 from oscar.models.fields import AutoSlugField
24
-from oscar.utils.deprecation import RemovedInOscar21Warning
25 21
 
26 22
 from . import exceptions
27 23
 
@@ -314,38 +310,11 @@ class AbstractOrder(models.Model):
314 310
         signer = Signer(salt='oscar.apps.order.Order')
315 311
         return signer.sign(self.number)
316 312
 
317
-    def check_deprecated_verification_hash(self, hash_to_check):
318
-        """
319
-        Backward compatible check for MD5 hashes that were generated in
320
-        Oscar 1.5 and lower.
321
-
322
-        This must explicitly be enabled by setting OSCAR_DEPRECATED_ORDER_VERIFY_KEY,
323
-        which must not be equal to SECRET_KEY - i.e., the project must
324
-        have changed its SECRET_KEY since this change was applied.
325
-        """
326
-        old_verification_key = getattr(settings, 'OSCAR_DEPRECATED_ORDER_VERIFY_KEY', None)
327
-        if old_verification_key is None:
328
-            return False
329
-
330
-        warnings.warn('Use of OSCAR_DEPRECATED_ORDER_VERIFY_KEY is deprecated', RemovedInOscar21Warning, stacklevel=2)
331
-
332
-        if old_verification_key == settings.SECRET_KEY:
333
-            raise ImproperlyConfigured(
334
-                'OSCAR_DEPRECATED_ORDER_VERIFY_KEY cannot be equal to SECRET_KEY')
335
-
336
-        logger.warning('Using insecure md5 hashing for order URL hash verification.')
337
-        string_to_hash = '%s%s' % (self.number, old_verification_key)
338
-        order_hash = hashlib.md5(string_to_hash.encode('utf8')).hexdigest()
339
-        return constant_time_compare(order_hash, hash_to_check)
340
-
341 313
     def check_verification_hash(self, hash_to_check):
342 314
         """
343 315
         Checks the received verification hash against this order number.
344 316
         Returns False if the verification failed, True otherwise.
345 317
         """
346
-        if self.check_deprecated_verification_hash(hash_to_check):
347
-            return True
348
-
349 318
         signer = Signer(salt='oscar.apps.order.Order')
350 319
         try:
351 320
             signed_number = signer.unsign(hash_to_check)

+ 2
- 2
src/oscar/apps/search/search_indexes.py Переглянути файл

@@ -37,10 +37,10 @@ class ProductIndex(indexes.SearchIndex, indexes.Indexable):
37 37
 
38 38
     def index_queryset(self, using=None):
39 39
         # Only index browsable products (not each individual child product)
40
-        return self.get_model().browsable.order_by('-date_updated')
40
+        return self.get_model().objects.browsable().order_by('-date_updated')
41 41
 
42 42
     def read_queryset(self, using=None):
43
-        return self.get_model().browsable.base_queryset()
43
+        return self.get_model().objects.browsable().base_queryset()
44 44
 
45 45
     def prepare_product_class(self, obj):
46 46
         return obj.get_product_class().name

+ 3
- 3
src/oscar/core/decorators.py Переглянути файл

@@ -1,6 +1,6 @@
1 1
 import warnings
2 2
 
3
-from oscar.utils.deprecation import RemovedInOscar21Warning
3
+from oscar.utils.deprecation import RemovedInOscar22Warning
4 4
 
5 5
 
6 6
 def deprecated(obj):
@@ -10,7 +10,7 @@ def deprecated(obj):
10 10
         return _deprecated_func(f=obj)
11 11
 
12 12
 
13
-def _deprecated_func(f, warn_cls=RemovedInOscar21Warning):
13
+def _deprecated_func(f, warn_cls=RemovedInOscar22Warning):
14 14
     def _deprecated(*args, **kwargs):
15 15
         message = "Method '%s' is deprecated and will be " \
16 16
             "removed in the next version of django-oscar" \
@@ -20,7 +20,7 @@ def _deprecated_func(f, warn_cls=RemovedInOscar21Warning):
20 20
     return _deprecated
21 21
 
22 22
 
23
-def _deprecated_cls(cls, warn_cls=RemovedInOscar21Warning):
23
+def _deprecated_cls(cls, warn_cls=RemovedInOscar22Warning):
24 24
     class Deprecated(cls):
25 25
         def __init__(self, *args, **kwargs):
26 26
             message = "Class '%s' is deprecated and will be " \

+ 0
- 4
src/oscar/utils/deprecation.py Переглянути файл

@@ -1,6 +1,2 @@
1
-class RemovedInOscar21Warning(DeprecationWarning):
2
-    pass
3
-
4
-
5 1
 class RemovedInOscar22Warning(DeprecationWarning):
6 2
     pass

+ 0
- 13
tests/integration/catalogue/test_product.py Переглянути файл

@@ -71,12 +71,6 @@ class TopLevelProductTests(ProductTests):
71 71
             product_class=self.product_class, title="Kopfhörer")
72 72
         self.assertEqual(set([product]), set(Product.objects.browsable()))
73 73
 
74
-    def test_top_level_products_are_part_of_browsable_deprecated(self):
75
-        # Test for deprecated Product.browsable.
76
-        product = Product.objects.create(
77
-            product_class=self.product_class, title="Kopfhörer")
78
-        self.assertEqual(set([product]), set(Product.browsable.all()))
79
-
80 74
 
81 75
 class ChildProductTests(ProductTests):
82 76
 
@@ -110,13 +104,6 @@ class ChildProductTests(ProductTests):
110 104
             structure=Product.CHILD)
111 105
         self.assertEqual(set([self.parent]), set(Product.objects.browsable()))
112 106
 
113
-    def test_child_products_are_not_part_of_browsable_deprecated(self):
114
-        # Test for deprecated Product.browsable
115
-        Product.objects.create(
116
-            product_class=self.product_class, parent=self.parent,
117
-            structure=Product.CHILD)
118
-        self.assertEqual(set([self.parent]), set(Product.browsable.all()))
119
-
120 107
 
121 108
 class TestAChildProduct(TestCase):
122 109
 

+ 5
- 2
tests/integration/dashboard/test_nav.py Переглянути файл

@@ -1,5 +1,6 @@
1 1
 from django.test import TestCase
2 2
 from django.urls import reverse
3
+from django.urls.exceptions import NoReverseMatch
3 4
 
4 5
 from oscar.apps.dashboard.menu import get_nodes
5 6
 from oscar.apps.dashboard.nav import default_access_fn
@@ -22,11 +23,13 @@ class DashboardAccessFunctionTestCase(TestCase):
22 23
         self.assertFalse(default_access_fn(self.non_staff_user, 'dashboard:index'))
23 24
 
24 25
     def test_default_access_fn_invalid_url_name(self):
25
-        self.assertFalse(default_access_fn(self.staff_user, 'invalid_module:index'))
26
+        with self.assertRaises(NoReverseMatch):
27
+            default_access_fn(self.staff_user, 'invalid_module:index')
26 28
 
27 29
     def test_default_access_non_dashboard_url_name(self):
28 30
         assert reverse('search:search')
29
-        self.assertFalse(default_access_fn(self.staff_user, 'search:search'))
31
+        with self.assertRaises(KeyError):
32
+            default_access_fn(self.staff_user, 'search:search')
30 33
 
31 34
 
32 35
 class DashboardNavTestCase(TestCase):

+ 0
- 27
tests/integration/order/test_models.py Переглянути файл

@@ -2,7 +2,6 @@ from datetime import datetime, timedelta
2 2
 from decimal import Decimal as D
3 3
 from unittest import mock
4 4
 
5
-from django.core.exceptions import ImproperlyConfigured
6 5
 from django.test import TestCase, override_settings
7 6
 from django.utils import timezone
8 7
 from django.utils.translation import gettext_lazy as _
@@ -431,29 +430,3 @@ class OrderTests(TestCase):
431 430
         order = OrderFactory(number='111000')
432 431
         # Hash is valid, but it is for a different order number
433 432
         self.assertFalse(order.check_verification_hash('222000:knvoMB1KAiJu8meWtGce00Y88j4'))
434
-
435
-    @override_settings(OSCAR_DEPRECATED_ORDER_VERIFY_KEY='deprecated_order_hash_secret')
436
-    def test_check_deprecated_hash_verification(self):
437
-        order = OrderFactory(number='100001')
438
-        # Check that check_deprecated_verification_hash validates the hash
439
-        self.assertTrue(
440
-            order.check_deprecated_verification_hash('3efd0339e8c789447469f37851cbaaaf')
441
-        )
442
-        # Check that check_verification_hash calls it correctly
443
-        self.assertTrue(order.check_verification_hash('3efd0339e8c789447469f37851cbaaaf'))
444
-
445
-    def test_check_deprecated_hash_verification_without_old_key(self):
446
-        order = OrderFactory(number='100001')
447
-        # Check that check_deprecated_verification_hash validates the hash
448
-        self.assertFalse(
449
-            order.check_deprecated_verification_hash('3efd0339e8c789447469f37851cbaaaf')
450
-        )
451
-
452
-    @override_settings(
453
-        OSCAR_DEPRECATED_ORDER_VERIFY_KEY='deprecated_order_hash_secret',
454
-        SECRET_KEY='deprecated_order_hash_secret')
455
-    def test_check_deprecated_hash_verification_old_key_matches_new(self):
456
-        order = OrderFactory(number='100001')
457
-        # OSCAR_DEPRECATED_ORDER_VERIFY_KEY must not be equal to SECRET_KEY.
458
-        with self.assertRaises(ImproperlyConfigured):
459
-            order.check_deprecated_verification_hash('3efd0339e8c789447469f37851cbaaaf')

Завантаження…
Відмінити
Зберегти