changeset 2161:8a90ebee0e42

fix usages of subscribe(), unsubscribe() and is_subscribed_to() methods in views and templates
author Ana Balica <ana.balica@gmail.com>
date Sat, 20 Jul 2013 21:49:05 +0300
parents 8ce664067edb
children a704bbeb189c
files MoinMoin/apps/frontend/_tests/test_frontend.py MoinMoin/apps/frontend/views.py MoinMoin/templates/itemviews.html
diffstat 3 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/_tests/test_frontend.py	Sat Jul 20 21:30:32 2013 +0300
+++ b/MoinMoin/apps/frontend/_tests/test_frontend.py	Sat Jul 20 21:49:05 2013 +0300
@@ -166,7 +166,7 @@
         self._test_view('frontend.quicklink_item', status='302 FOUND', viewopts=dict(item_name='DoesntExist'), data=['<!DOCTYPE HTML'])
 
     def test_subscribe_item(self):
-        self._test_view('frontend.subscribe_item', status='302 FOUND', viewopts=dict(item_name='DoesntExist'), data=['<!DOCTYPE HTML'])
+        self._test_view('frontend.subscribe_item', status='404 NOT FOUND', viewopts=dict(item_name='DoesntExist'))
 
     def test_register(self):
         self._test_view('frontend.register')
--- a/MoinMoin/apps/frontend/views.py	Sat Jul 20 21:30:32 2013 +0300
+++ b/MoinMoin/apps/frontend/views.py	Sat Jul 20 21:49:05 2013 +0300
@@ -990,18 +990,25 @@
     u = flaskg.user
     cfg = app.cfg
     msg = None
+    try:
+        item = Item.create(item_name)
+    except AccessDenied:
+        abort(403)
+    if isinstance(item, NonExistent):
+        abort(404)
     if not u.valid:
         msg = _("You must login to use this action: %(action)s.", action="subscribe/unsubscribe"), "error"
     elif not u.may.read(item_name):
         msg = _("You are not allowed to subscribe to an item you may not read."), "error"
-    elif u.is_subscribed_to([item_name]):
+    elif u.is_subscribed_to(item):
         # Try to unsubscribe
-        if not u.unsubscribe(item_name):
-            msg = _("Can't remove regular expression subscription!") + u' ' + \
-                _("Edit the subscription regular expressions in your settings."), "error"
+        if not u.unsubscribe(ITEMID, item.meta[ITEMID]):
+            msg = _(
+                "Can't remove the subscription! You are subscribed to this page in some other way.") + u' ' + _(
+                "Please edit the subscription in your settings."), "error"
     else:
         # Try to subscribe
-        if not u.subscribe(item_name):
+        if not u.subscribe(ITEMID, item.meta[ITEMID]):
             msg = _('You could not get subscribed to this item.'), "error"
     if msg:
         flash(*msg)
--- a/MoinMoin/templates/itemviews.html	Sat Jul 20 21:30:32 2013 +0300
+++ b/MoinMoin/templates/itemviews.html	Sat Jul 20 21:49:05 2013 +0300
@@ -57,7 +57,7 @@
             {%- if endpoint == 'frontend.subscribe_item' and user.valid %}
                 <li>
                     <a href="{{ url_for(endpoint, item_name=item_name) }}" title="{{ title }}" rel="nofollow">
-                        {%- if user.is_subscribed_to([item_name]) %}
+                        {%- if user.is_subscribed_to(item) %}
                             {{ _('Unsubscribe') }}
                         {%- else %}
                             {{ _('Subscribe') }}