Commit ebace0cb authored by Chris McDonough's avatar Chris McDonough

Fix up calls to user objects' getUserName which should really be calls to

getId.  This is a change designed to make it possible to disambiguate user names and user ids in subclasses of user folders, while still doing the "right thing" with respect to local data structures that keep pointers to user ids (eg. local roles, etc.)
parent 5b92aa44
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
############################################################################## ##############################################################################
"""Access control package""" """Access control package"""
__version__='$Revision: 1.171 $'[11:-2] __version__='$Revision: 1.172 $'[11:-2]
import Globals, socket, SpecialUsers,re import Globals, socket, SpecialUsers,re
import os import os
...@@ -85,7 +85,7 @@ class BasicUser(Implicit): ...@@ -85,7 +85,7 @@ class BasicUser(Implicit):
"""Return the list of roles assigned to the user, """Return the list of roles assigned to the user,
including local roles assigned in context of including local roles assigned in context of
the passed in object.""" the passed in object."""
name=self.getUserName() userid=self.getId()
roles=self.getRoles() roles=self.getRoles()
local={} local={}
object=getattr(object, 'aq_inner', object) object=getattr(object, 'aq_inner', object)
...@@ -95,7 +95,7 @@ class BasicUser(Implicit): ...@@ -95,7 +95,7 @@ class BasicUser(Implicit):
if callable(local_roles): if callable(local_roles):
local_roles=local_roles() local_roles=local_roles()
dict=local_roles or {} dict=local_roles or {}
for r in dict.get(name, []): for r in dict.get(userid, []):
local[r]=1 local[r]=1
inner = getattr(object, 'aq_inner', object) inner = getattr(object, 'aq_inner', object)
parent = getattr(inner, 'aq_parent', None) parent = getattr(inner, 'aq_parent', None)
...@@ -207,14 +207,14 @@ class BasicUser(Implicit): ...@@ -207,14 +207,14 @@ class BasicUser(Implicit):
# this manually rather than call getRolesInContext so that # this manually rather than call getRolesInContext so that
# we can incur only the overhead required to find a match. # we can incur only the overhead required to find a match.
inner_obj = getattr(object, 'aq_inner', object) inner_obj = getattr(object, 'aq_inner', object)
user_name = self.getUserName() userid = self.getId()
while 1: while 1:
local_roles = getattr(inner_obj, '__ac_local_roles__', None) local_roles = getattr(inner_obj, '__ac_local_roles__', None)
if local_roles: if local_roles:
if callable(local_roles): if callable(local_roles):
local_roles = local_roles() local_roles = local_roles()
dict = local_roles or {} dict = local_roles or {}
local_roles = dict.get(user_name, []) local_roles = dict.get(userid, [])
for role in object_roles: for role in object_roles:
if role in local_roles: if role in local_roles:
if self._check_context(object): if self._check_context(object):
......
...@@ -13,20 +13,17 @@ ...@@ -13,20 +13,17 @@
"""User folder tests """User folder tests
""" """
__rcs_id__='$Id: testUserFolder.py,v 1.5 2002/08/14 21:28:08 mj Exp $' __rcs_id__='$Id: testUserFolder.py,v 1.6 2002/10/16 21:14:41 chrism Exp $'
__version__='$Revision: 1.5 $'[11:-2] __version__='$Revision: 1.6 $'[11:-2]
import os, sys, unittest import os, sys, unittest
import ZODB import ZODB
from DocumentTemplate import HTML
from DocumentTemplate.tests.testDTML import DTMLTests
from Products.PythonScripts.standard import DTML
from AccessControl import User, Unauthorized from AccessControl import User, Unauthorized
from AccessControl.User import BasicUserFolder from AccessControl.User import BasicUserFolder, UserFolder, User
from ExtensionClass import Base from ExtensionClass import Base
class SecurityTests (DTMLTests): class UserFolderTests(unittest.TestCase):
def testMaxListUsers(self): def testMaxListUsers(self):
# create a folder-ish thing which contains a roleManager, # create a folder-ish thing which contains a roleManager,
...@@ -67,10 +64,38 @@ class SecurityTests (DTMLTests): ...@@ -67,10 +64,38 @@ class SecurityTests (DTMLTests):
except OverflowError: except OverflowError:
assert 0, "Raised overflow error erroneously" assert 0, "Raised overflow error erroneously"
class UserTests(unittest.TestCase):
def testGetUserName(self):
f = User('chris', '123', ['Manager'], [])
self.assertEqual(f.getUserName(), 'chris')
def testGetUserId(self):
f = User('chris', '123', ['Manager'], [])
self.assertEqual(f.getId(), 'chris')
def testBaseUserGetIdEqualGetName(self):
# this is true for the default user type, but will not
# always be true for extended user types going forward (post-2.6)
f = User('chris', '123', ['Manager'], [])
self.assertEqual(f.getId(), f.getUserName())
def testGetPassword(self):
f = User('chris', '123', ['Manager'], [])
self.assertEqual(f._getPassword(), '123')
def testGetRoles(self):
f = User('chris', '123', ['Manager'], [])
self.assertEqual(f.getRoles(), ('Manager', 'Authenticated'))
def testGetDomains(self):
f = User('chris', '123', ['Manager'], [])
self.assertEqual(f.getDomains(), ())
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite( SecurityTests ) ) suite.addTest(unittest.makeSuite(UserFolderTests))
suite.addTest(unittest.makeSuite(UserTests))
return suite return suite
def main(): def main():
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
"""Property sheets""" """Property sheets"""
__version__='$Revision: 1.87 $'[11:-2] __version__='$Revision: 1.88 $'[11:-2]
import time, App.Management, Globals import time, App.Management, Globals
from webdav.WriteLockInterface import WriteLockInterface from webdav.WriteLockInterface import WriteLockInterface
...@@ -558,7 +558,7 @@ class DAVProperties(Virtual, PropertySheet, View): ...@@ -558,7 +558,7 @@ class DAVProperties(Virtual, PropertySheet, View):
def dav__lockdiscovery(self): def dav__lockdiscovery(self):
security = getSecurityManager() security = getSecurityManager()
user = security.getUser().getUserName() user = security.getUser().getId()
vself = self.v_self() vself = self.v_self()
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
############################################################################## ##############################################################################
"""Site error log module. """Site error log module.
$Id: SiteErrorLog.py,v 1.11 2002/08/21 14:23:24 shane Exp $ $Id: SiteErrorLog.py,v 1.12 2002/10/16 21:14:42 chrism Exp $
""" """
import os import os
...@@ -149,10 +149,13 @@ class SiteErrorLog (SimpleItem): ...@@ -149,10 +149,13 @@ class SiteErrorLog (SimpleItem):
request = getattr(self, 'REQUEST', None) request = getattr(self, 'REQUEST', None)
url = None url = None
username = None username = None
userid = None
req_html = None req_html = None
if request: if request:
url = request.get('URL', '?') url = request.get('URL', '?')
username = getSecurityManager().getUser().getUserName() usr = getSecurityManager().getUser()
username = usr.getUserName()
userid = usr.getUserId()
try: try:
req_html = str(request) req_html = str(request)
except: except:
...@@ -173,6 +176,7 @@ class SiteErrorLog (SimpleItem): ...@@ -173,6 +176,7 @@ class SiteErrorLog (SimpleItem):
'tb_text': tb_text, 'tb_text': tb_text,
'tb_html': tb_html, 'tb_html': tb_html,
'username': username, 'username': username,
'userid': userid,
'url': url, 'url': url,
'req_html': req_html, 'req_html': req_html,
}) })
......
...@@ -67,7 +67,7 @@ No exceptions logged. ...@@ -67,7 +67,7 @@ No exceptions logged.
<table tal:condition="entries"> <table tal:condition="entries">
<tr> <tr>
<th align="left">Time</th> <th align="left">Time</th>
<th align="left">User</th> <th align="left">Username (User Id)</th>
<th align="left">Exception</th> <th align="left">Exception</th>
</tr> </tr>
<tr tal:repeat="entry entries"> <tr tal:repeat="entry entries">
...@@ -75,7 +75,9 @@ No exceptions logged. ...@@ -75,7 +75,9 @@ No exceptions logged.
<span tal:content="python: DateTime(entry['time']).Time()">13:04:41</span> <span tal:content="python: DateTime(entry['time']).Time()">13:04:41</span>
</td> </td>
<td> <td>
<span tal:content="entry/username">joe</span> <span tal:content="string: ${entry/username} (${entry/userid})">
joe (joe)
</span>
</td> </td>
<td valign="top"> <td valign="top">
<a href="showEntry" tal:attributes="href string:showEntry?id=${entry/id}" <a href="showEntry" tal:attributes="href string:showEntry?id=${entry/id}"
......
...@@ -198,7 +198,7 @@ def changeOwner(obj, owner): ...@@ -198,7 +198,7 @@ def changeOwner(obj, owner):
if 'Owner' in roles: if 'Owner' in roles:
obj.manage_delLocalRoles([user]) obj.manage_delLocalRoles([user])
break break
obj.manage_setLocalRoles(owner.getUserName(), ['Owner']) obj.manage_setLocalRoles(owner.getId(), ['Owner'])
for subobj in obj.objectValues(): for subobj in obj.objectValues():
changeOwner(subobj, owner) changeOwner(subobj, owner)
......
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