c.
"""
- c.user = None
-
if not 'user_id' in session:
+ c.user = users_model.AnonymousUser()
return
user = meta.Session.query(users_model.User).get(session['user_id'])
# Bogus id in the session somehow. Clear it
del session['user_id']
session.save()
+
+ c.user = users_model.AnonymousUser()
return
c.user = user
from spline.model.meta import TableBase
+class AnonymousUser(object):
+ """Fake user object, for when the user isn't actually logged in.
+
+ Tests as false and tries to respond to method calls the expected way.
+ """
+
+ def __nonzero__(self):
+ return False
+ def __bool__(self):
+ return False
+
+ def can(self, action):
+ # XXX if viewing is ever a permission, this should probably change.
+ return False
+
+
class User(TableBase):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
super(User, self).__init__(*args, **kwargs)
+ def can(self, action):
+ # XXX this is probably not desired.
+ return True
+
@property
def unique_colors(self):
"""Returns a list of (width, '#rrggbb') tuples that semi-uniquely