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 @@
##############################################################################
"""Access control package"""
__version__='$Revision: 1.171 $'[11:-2]
__version__='$Revision: 1.172 $'[11:-2]
import Globals, socket, SpecialUsers,re
import os
......@@ -85,7 +85,7 @@ class BasicUser(Implicit):
"""Return the list of roles assigned to the user,
including local roles assigned in context of
the passed in object."""
name=self.getUserName()
userid=self.getId()
roles=self.getRoles()
local={}
object=getattr(object, 'aq_inner', object)
......@@ -95,7 +95,7 @@ class BasicUser(Implicit):
if callable(local_roles):
local_roles=local_roles()
dict=local_roles or {}
for r in dict.get(name, []):
for r in dict.get(userid, []):
local[r]=1
inner = getattr(object, 'aq_inner', object)
parent = getattr(inner, 'aq_parent', None)
......@@ -207,14 +207,14 @@ class BasicUser(Implicit):
# this manually rather than call getRolesInContext so that
# we can incur only the overhead required to find a match.
inner_obj = getattr(object, 'aq_inner', object)
user_name = self.getUserName()
userid = self.getId()
while 1:
local_roles = getattr(inner_obj, '__ac_local_roles__', None)
if local_roles:
if callable(local_roles):
local_roles = local_roles()
dict = local_roles or {}
local_roles = dict.get(user_name, [])
local_roles = dict.get(userid, [])
for role in object_roles:
if role in local_roles:
if self._check_context(object):
......
......@@ -13,20 +13,17 @@
"""User folder tests
"""
__rcs_id__='$Id: testUserFolder.py,v 1.5 2002/08/14 21:28:08 mj Exp $'
__version__='$Revision: 1.5 $'[11:-2]
__rcs_id__='$Id: testUserFolder.py,v 1.6 2002/10/16 21:14:41 chrism Exp $'
__version__='$Revision: 1.6 $'[11:-2]
import os, sys, unittest
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.User import BasicUserFolder
from AccessControl.User import BasicUserFolder, UserFolder, User
from ExtensionClass import Base
class SecurityTests (DTMLTests):
class UserFolderTests(unittest.TestCase):
def testMaxListUsers(self):
# create a folder-ish thing which contains a roleManager,
......@@ -67,10 +64,38 @@ class SecurityTests (DTMLTests):
except OverflowError:
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():
suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite( SecurityTests ) )
suite.addTest(unittest.makeSuite(UserFolderTests))
suite.addTest(unittest.makeSuite(UserTests))
return suite
def main():
......
......@@ -13,7 +13,7 @@
"""Property sheets"""
__version__='$Revision: 1.87 $'[11:-2]
__version__='$Revision: 1.88 $'[11:-2]
import time, App.Management, Globals
from webdav.WriteLockInterface import WriteLockInterface
......@@ -558,7 +558,7 @@ class DAVProperties(Virtual, PropertySheet, View):
def dav__lockdiscovery(self):
security = getSecurityManager()
user = security.getUser().getUserName()
user = security.getUser().getId()
vself = self.v_self()
......
......@@ -13,7 +13,7 @@
##############################################################################
"""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
......@@ -149,10 +149,13 @@ class SiteErrorLog (SimpleItem):
request = getattr(self, 'REQUEST', None)
url = None
username = None
userid = None
req_html = None
if request:
url = request.get('URL', '?')
username = getSecurityManager().getUser().getUserName()
usr = getSecurityManager().getUser()
username = usr.getUserName()
userid = usr.getUserId()
try:
req_html = str(request)
except:
......@@ -173,6 +176,7 @@ class SiteErrorLog (SimpleItem):
'tb_text': tb_text,
'tb_html': tb_html,
'username': username,
'userid': userid,
'url': url,
'req_html': req_html,
})
......
......@@ -67,7 +67,7 @@ No exceptions logged.
<table tal:condition="entries">
<tr>
<th align="left">Time</th>
<th align="left">User</th>
<th align="left">Username (User Id)</th>
<th align="left">Exception</th>
</tr>
<tr tal:repeat="entry entries">
......@@ -75,7 +75,9 @@ No exceptions logged.
<span tal:content="python: DateTime(entry['time']).Time()">13:04:41</span>
</td>
<td>
<span tal:content="entry/username">joe</span>
<span tal:content="string: ${entry/username} (${entry/userid})">
joe (joe)
</span>
</td>
<td valign="top">
<a href="showEntry" tal:attributes="href string:showEntry?id=${entry/id}"
......
......@@ -198,7 +198,7 @@ def changeOwner(obj, owner):
if 'Owner' in roles:
obj.manage_delLocalRoles([user])
break
obj.manage_setLocalRoles(owner.getUserName(), ['Owner'])
obj.manage_setLocalRoles(owner.getId(), ['Owner'])
for subobj in obj.objectValues():
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