Permalink
Browse files

Removing the cake (bug 747570)

  • Loading branch information...
1 parent 7ace119 commit f9f3abce90a2b89f91d547cc05fc8c312212d22b @robhudson robhudson committed Feb 3, 2013
@@ -16,15 +16,6 @@
}
},
{
- "pk": 2,
- "model": "cake.session",
- "fields": {
- "session_id": "1234",
- "expires": 1426308304,
- "data": "User|a:1:{s:2:\"id\";s:1:\"1\";}"
- }
- },
- {
"pk": 2,
"model": "users.userprofile",
"fields": {
@@ -40,15 +31,6 @@
}
},
{
- "pk": 3,
- "model": "cake.session",
- "fields": {
- "session_id": "4567",
- "expires": 1426308304,
- "data": "User|a:1:{s:2:\"id\";s:1:\"2\";}"
- }
- },
- {
"pk": 1,
"model": "access.group",
"fields": {
View
@@ -1,13 +1,12 @@
from django.http import HttpRequest
import mock
-from nose.tools import assert_false, eq_
+from nose.tools import assert_false
import amo
from amo.tests import TestCase
from amo.urlresolvers import reverse
from addons.models import Addon, AddonUser
-from cake.models import Session
from users.models import UserProfile
from .acl import (action_allowed, check_addon_ownership, check_ownership,
@@ -75,21 +74,6 @@ def test_admin_login_anon(self):
r = self.client.get(url)
self.assertRedirects(r, '%s?to=%s' % (reverse('users.login'), url))
- def test_admin_login_adminuser(self):
- # No form should be present for an admin
- c = self.client
- session = Session.objects.get(pk='1234')
- c.login(session=session)
- response = c.get('/en-US/admin/models/')
- assert response.context['user'].is_authenticated()
- self.assertNotContains(response, 'login-form')
-
- def test_admin_login(self):
- # Non admin user should get a 403.
- session = Session.objects.get(pk='4567')
- self.client.login(session=session)
- eq_(self.client.get('/en-US/admin/models/').status_code, 403)
-
class TestHasPerm(TestCase):
fixtures = ['base/apps', 'base/users', 'base/addon_3615']
@@ -8,10 +8,9 @@
import amo
from amo.helpers import loc
-from amo.urlresolvers import reverse
+from amo.urlresolvers import remora_url, reverse
from amo.utils import memoize
from access import acl
-from cake.urlresolvers import remora_url
from zadmin.models import get_config
View
@@ -1,5 +1,4 @@
import itertools
-import calendar
from datetime import datetime, timedelta
from subprocess import Popen, PIPE
@@ -13,9 +12,8 @@
import amo
from amo.utils import chunked
from bandwagon.models import Collection
-from cake.models import Session
from constants.base import VALID_STATUSES
-from devhub.models import ActivityLog, LegacyAddonLog
+from devhub.models import ActivityLog
from lib.es.utils import raise_if_reindex_in_progress
from sharing import SERVICES_LIST, LOCAL_SERVICES_LIST
from stats.models import AddonShareCount, Contribution
@@ -30,7 +28,6 @@ def gc(test_result=True):
"""Site-wide garbage collections."""
days_ago = lambda days: datetime.today() - timedelta(days=days)
- one_hour_ago = datetime.today() - timedelta(hours=1)
log.debug('Collecting data to delete')
@@ -69,11 +66,6 @@ def gc(test_result=True):
AddonShareCount.objects.exclude(service__in=set(service_names)).delete()
- log.debug('Cleaning up cake sessions.')
- # cake.Session uses Unix Timestamps
- two_days_ago = calendar.timegm(days_ago(2).utctimetuple())
- Session.objects.filter(expires__lt=two_days_ago).delete()
-
log.debug('Cleaning up test results extraction cache.')
# lol at check for '/'
if settings.NETAPP_STORAGE and settings.NETAPP_STORAGE != '/':
@@ -1,14 +1,5 @@
[
{
- "pk": 2,
- "model": "cake.session",
- "fields": {
- "session_id": "17f051c99f083244bf653d5798111216",
- "expires": 1,
- "data": "User|a:1:{s:2:\"id\";s:1:\"1\";}"
- }
- },
- {
"pk": 2567,
"model": "stats.addonsharecount",
"fields": {
View
@@ -535,3 +535,19 @@ def loc(s):
@register.function
def site_event_type(type):
return amo.SITE_EVENT_CHOICES[type]
+
+
+@register.function
+@jinja2.contextfunction
+def remora_url(context, url, lang=None, app=None, prefix=''):
+ """Wrapper for urlresolvers.remora_url"""
+ if lang is None:
+ _lang = context['LANG']
+ if _lang:
+ lang = translation.to_locale(_lang).replace('_', '-')
+ if app is None:
+ try:
+ app = context['APP'].short
+ except (AttributeError, KeyError):
+ pass
+ return urlresolvers.remora_url(url=url, lang=lang, app=app, prefix=prefix)
@@ -3,7 +3,6 @@
import amo.tests
from amo.cron import gc
from bandwagon.models import Collection
-from cake.models import Session
from devhub.models import ActivityLog
from stats.models import AddonShareCount, Contribution
@@ -14,13 +13,11 @@ class GarbageTest(amo.tests.TestCase):
def test_garbage_collection(self):
"This fixture is expired data that should just get cleaned up."
eq_(Collection.objects.all().count(), 1)
- eq_(Session.objects.all().count(), 1)
eq_(ActivityLog.objects.all().count(), 1)
eq_(AddonShareCount.objects.all().count(), 1)
eq_(Contribution.objects.all().count(), 1)
gc(test_result=False)
eq_(Collection.objects.all().count(), 0)
- eq_(Session.objects.all().count(), 0)
eq_(ActivityLog.objects.all().count(), 0)
eq_(AddonShareCount.objects.all().count(), 0)
eq_(Contribution.objects.all().count(), 0)
@@ -227,3 +227,21 @@ def lang_from_accept_header(header):
return langs[lookup]
return settings.LANGUAGE_CODE
+
+
+def remora_url(url, lang=None, app=None, prefix=''):
+ """
+ Builds a remora-style URL, independent from Zamboni's prefixer logic.
+ If app and/or lang are None, the current Zamboni values will be used.
+ To omit them from the URL, set them to ''.
+ """
+ prefixer = get_url_prefix()
+ if lang is None:
+ lang = getattr(prefixer, 'locale', settings.LANGUAGE_CODE)
+ if app is None:
+ app = getattr(prefixer, 'app', settings.DEFAULT_APP)
+
+ url_parts = [p for p in (prefix.strip('/'), lang, app, url.lstrip('/'))
+ if p]
+
+ return url_fix('/' + '/'.join(url_parts))
@@ -4,11 +4,10 @@
from jingo import register, env
from tower import ugettext as _
+from addons.helpers import new_context
from amo.helpers import login_link
+from amo.urlresolvers import remora_url, reverse
from amo.utils import chunked
-from addons.helpers import new_context
-from cake.urlresolvers import remora_url
-from amo.urlresolvers import reverse
@register.inclusion_tag('bandwagon/collection_listing_items.html')
@@ -10,7 +10,6 @@
from bandwagon.helpers import (user_collection_list, barometer,
collection_favorite)
from bandwagon.models import Collection
-from cake.urlresolvers import remora_url
from users.models import UserProfile
No changes.
View
@@ -1,79 +0,0 @@
-from time import time
-
-from django.contrib.auth.models import User
-from django.db import IntegrityError
-from django.utils.encoding import smart_str
-
-import commonware.log
-import phpserialize
-
-from users.models import UserProfile
-
-log = commonware.log.getLogger('z.cake')
-
-
-class SessionBackend:
- supports_anonymous_user = False
- supports_inactive_user = False
- supports_object_permissions = False
-
- def authenticate(self, session):
- """
- Given a CakeSession object we'll authenticate it to an actual user.
- """
-
- if (time() > session.expires or
- not session.data.startswith('User|')):
- session.delete()
- return None
-
- try:
- serialized_data = smart_str(session.data[5:])
- php_user = phpserialize.loads(serialized_data)
- except ValueError, e:
- # Bug 553397
- log.warning("Found corrupt session (%s): %s" % (session.pk, e))
- session.delete()
- return None
-
- user_id = int(php_user.get('id'))
-
- try:
- profile = UserProfile.objects.get(pk=user_id)
- except UserProfile.DoesNotExist:
- session.delete()
- return None
-
- def retrieve_from_master(pk):
- return UserProfile.objects.using('default').no_cache().get(pk=pk)
-
- # User will hit this if they are new to zamboni.
- try:
- if profile.user is None:
- # This will catch replication lags in case we created a user.
- profile = retrieve_from_master(user_id)
- if profile.user is None:
- profile.create_django_user()
- except User.DoesNotExist:
- log.warning('Bad user_id {0} on UserProfile {1}.'.format(
- profile.id, profile.user_id))
- # Chances are we are suffering from replication lag, but
- # let's play it safe and just not authenticate.
- return None
- except IntegrityError, e:
- # Typically a duplicate key.
- log.warning('DB Error for UserProfile {0}: {1}'.format(user_id, e))
- return None
-
- except Exception, e:
- log.error('Unknown exception for UserProfile {0}: {1}'.format(
- user_id, e))
- return None
-
- return profile.user
-
- def get_user(self, user_id):
- try:
- return User.objects.get(pk=user_id)
- except User.DoesNotExist:
- return None
@@ -1,55 +0,0 @@
-[
- {
- "pk": 1,
- "model": "users.userprofile",
- "fields": {
- "username": "fligtard",
- "display_name": "Scott \u0627\u0644\u062a\u0637\u0628",
- "emailhidden": 1,
- "display_collections": 1,
- "display_collections_fav": 1,
- "notifycompat": 1,
- "email": "sunshine@sparkles.com",
- "notifyevents": 1,
- "created": "2009-06-01 18:55:23",
- "modified": "2009-06-01 17:55:23"
- }
- },
- {
- "pk": 2,
- "model": "cake.session",
- "fields": {
- "session_id": "17f051c99f083244bf653d5798111216",
- "expires": 1426308304,
- "data": "User|a:1:{s:2:\"id\";s:1:\"1\";}"
- }
- },
- {
- "pk": 3,
- "model": "cake.session",
- "fields": {
- "session_id": "27f051c99f083244bf653d5798111216",
- "expires": 1,
- "data": "User|a:1:{s:2:\"id\";s:1:\"1\";}"
- }
- },
- {
- "pk": 4,
- "model": "cake.session",
- "fields": {
- "session_id": "37f051c99f083244bf653d5798111216",
- "expires": 1426308304,
- "data": "User|a:1:{s:2:\"id\";s:1:\"9\";}"
- }
- },
- {
- "pk": 5,
- "model": "cake.session",
- "fields": {
- "session_id": "47f051c99f083244bf653d5798111216",
- "expires": 1426308304,
- "data": "User|a:2:{s:2:\"id\";s:1:\"1\";s:1:\"a\";s:2:\"ä\";}"
- }
- }
-
-]
Oops, something went wrong.

0 comments on commit f9f3abc

Please sign in to comment.