Commit 10275ad1 authored by Jim Fulton's avatar Jim Fulton

Added default implementation for new interfaces for getting user IDs

and asking for a user from a user database given an ID.  The default
implementations, in BasicUser and BasicUserFolder assume that user
names are used as IDs.

Refactored the user classes so that super and nobody aren't persistent
and don't have IDs. There is now a SimpleUser that is the same as
User, sans persistence.  There is a SpecialUser that subclasses
SimpleUser.  The special user nobody is a SpecialUser. The class Super
not subclasses SpecialUser.
parent de2e2b78
......@@ -84,7 +84,7 @@
##############################################################################
"""Access control package"""
__version__='$Revision: 1.101 $'[11:-2]
__version__='$Revision: 1.102 $'[11:-2]
import Globals, App.Undo, socket, regex
from Globals import HTMLFile, MessageDialog, Persistent, PersistentMapping
......@@ -102,7 +102,7 @@ from AuthEncoding import pw_validate
ListType=type([])
NotImplemented='NotImplemented'
_marker=[]
class BasicUser(Implicit):
"""Base class for all User objects"""
......@@ -118,6 +118,14 @@ class BasicUser(Implicit):
"""Return the username of a user"""
raise NotImplemented
def getId(self):
"""Get the ID of the user. The ID can be used, at least from
Python, to get the user from the user's
UserDatabase"""
return self.getUserName()
def _getPassword(self):
"""Return the password of the user."""
raise NotImplemented
......@@ -250,10 +258,10 @@ class BasicUser(Implicit):
__repr__=__str__
class SimpleUser(BasicUser):
"""A very simple user implementation
class User(BasicUser, Persistent):
"""Standard User object"""
that doesn't make a database commitment"""
def __init__(self,name,password,roles,domains):
self.name =name
......@@ -277,8 +285,14 @@ class User(BasicUser, Persistent):
"""Return the list of domain restrictions for a user"""
return self.domains
class SpecialUser(SimpleUser):
"""Class for special users, like super and nobody"""
def getId(self): pass
class User(SimpleUser, Persistent):
"""Standard User object"""
class Super(User):
class Super(SpecialUser):
"""Super user
"""
def allowed(self,parent,roles=None):
......@@ -309,7 +323,7 @@ except:
raise 'InstallError', 'Invalid format for access file - see INSTALL.txt'
nobody=User('Anonymous User','',('Anonymous',), [])
nobody=SpecialUser('Anonymous User','',('Anonymous',), [])
class BasicUserFolder(Implicit, Persistent, Navigation, Tabs, RoleManager,
......@@ -356,6 +370,14 @@ class BasicUserFolder(Implicit, Persistent, Navigation, Tabs, RoleManager,
"""Return the named user object or None"""
raise NotImplemented
def getUserById(self, id, default=_marker):
"""Return the user corresponding to the given id.
"""
try: return self.getUser(id)
except:
if default is _marker: raise
return default
def _doAddUser(self, name, password, roles, domains):
"""Create a new user"""
raise NotImplemented
......
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