Commit a7a30b82 authored by Laurent Bachelier's avatar Laurent Bachelier

Fix support of anonymous users in Event

parent 91c1578d
......@@ -108,7 +108,7 @@ class Event(object):
fp.write('Attendees:\n')
stats = [0, 0, 0]
for username, state in sorted(self.users.items(), key=lambda (k, v): (v, k)):
realname = self.f.storage.get_user(username).realname
realname = self.get_user(username).realname
checked = self.get_sign(state)
stats[state] += 1
fp.write('[%s] %s (%s)\n' % (checked, binary(username), binary(realname)))
......@@ -167,7 +167,10 @@ class Event(object):
def iter_users(self):
for username in sorted(self.users.keys(), key=unicode.lower):
yield self.f.storage.get_user(username)
yield self.get_user(username)
def get_user(self, username):
return self.f.storage.get_user(username, want_fake=True)
def remove_user(self, username):
self.users.pop(username)
......@@ -284,8 +287,9 @@ class EventAction(ViewAction):
except IOError, e:
error_message = unicode(e)
if self.ctx.user.has_perms(event.f, event.f.PERM_WRITE) and \
self.ctx.user.name in event.users:
if self.ctx.user.exists and \
self.ctx.user.has_perms(event.f, event.f.PERM_WRITE) and \
self.ctx.user.name in event.users:
if state is not None:
event.users[self.ctx.user.name] = state
......
......@@ -108,7 +108,7 @@ class Storage(object):
return storage
def get_user(self, name):
def get_user(self, name, want_fake=True):
"""
Get a particular user by its name.
Returns Anonymous if no user is found.
......@@ -116,6 +116,8 @@ class Storage(object):
user = User(self, name)
user.read()
if not user.exists:
if want_fake:
return Anonymous(name)
return Anonymous()
return user
......
......@@ -146,6 +146,10 @@ class Anonymous(IUser):
key = None
groups = []
def __init__(self, fake_name=None):
if fake_name:
self.name = fake_name
def has_perms(self, f, perm):
f_perms = f.get_all_perms()
if f_perms is not None:
......
......@@ -40,6 +40,7 @@ Somewhere
Attendees:
[ ] penguin (Penguin)
[x] platypus (Platypus)
[ ] doesnotexist (Does Not Exist)
-- 0 confirmed, 0 waiting, 0 declined
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment