Commit 91f27016 authored by Hanno Schlichting's avatar Hanno Schlichting

Removed the deprecated ``hasRole`` method from user objects - 9 years should be enough ;)

parent 047f2030
......@@ -11,6 +11,8 @@ Trunk (unreleased)
Restructuring
+++++++++++++
- Removed the deprecated ``hasRole`` method from user objects.
- Removed deprecated support for specifying ``__ac_permissions__``,
``meta_types`` and ``methods`` in a product's ``__init__``.
......
......@@ -244,19 +244,6 @@ class BasicUser(Implicit):
break
return None
def hasRole(self, *args, **kw):
"""hasRole is an alias for 'allowed' and has been deprecated.
Code still using this method should convert to either 'has_role' or
'allowed', depending on the intended behaviour.
"""
import warnings
warnings.warn('BasicUser.hasRole is deprecated, please use '
'BasicUser.allowed instead; hasRole was an alias for allowed, but '
'you may have ment to use has_role.', DeprecationWarning)
return self.allowed(*args, **kw)
domains=[]
def has_role(self, roles, object=None):
......@@ -325,26 +312,15 @@ class UnrestrictedUser(SpecialUser):
"""User that passes all security checks. Note, however, that modules
like Owner.py can still impose restrictions.
"""
def allowed(self,parent,roles=None):
return roles is not _what_not_even_god_should_do
def hasRole(self, *args, **kw):
"""hasRole is an alias for 'allowed' and has been deprecated.
Code still using this method should convert to either 'has_role' or
'allowed', depending on the intended behaviour.
"""
import warnings
warnings.warn('UnrestrictedUser.hasRole is deprecated, please use '
'UnrestrictedUser.allowed instead; hasRole was an alias for '
'allowed, but you may have ment to use has_role.',
DeprecationWarning)
self.allowed(*args, **kw)
def has_role(self, roles, object=None): return 1
def has_role(self, roles, object=None):
return 1
def has_permission(self, permission, object): return 1
def has_permission(self, permission, object):
return 1
class NullUnrestrictedUser(SpecialUser):
......@@ -380,20 +356,6 @@ class NullUnrestrictedUser(SpecialUser):
def allowed(self, parent, roles=None):
return 0
def hasRole(self, *args, **kw):
"""hasRole is an alias for 'allowed' and has been deprecated.
Code still using this method should convert to either 'has_role' or
'allowed', depending on the intended behaviour.
"""
import warnings
warnings.warn('NullUnrestrictedUser.hasRole is deprecated, please use '
'NullUnrestrictedUser.allowed instead; hasRole was an alias for '
'allowed, but you may have ment to use has_role.',
DeprecationWarning)
self.allowed(*args, **kw)
def has_role(self, roles, object=None):
return 0
......
##############################################################################
#
# Copyright (c) 2002 Zope Foundation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Tests for the DeprecationWarning thrown by accessing hasRole
To be removed together with the API in due time.
"""
__rcs_id__='$Id$'
__version__='$Revision: 1.6 $'[11:-2]
import ZODB # Sigh. Persistent needs to be set, so we import ZODB.
from AccessControl import User
import unittest, warnings
class DeprecatedAPI(unittest.TestCase):
def setUp(self):
# There is no official API to restore warning filters to a previous
# state. Here we cheat.
self.original_warning_filters = warnings.filters[:]
# We test for warnings by turning them into exceptions
warnings.filterwarnings('error', category=DeprecationWarning,
module='AccessControl')
def tearDown(self):
warnings.filters[:] = self.original_warning_filters
def testDeprecatedHasRole(self):
# hasRole has been deprecated, we expect a warning.
try:
self.userObject.hasRole(None)
except DeprecationWarning:
pass
else:
self.fail('Expected DeprecationWarning, none given')
def testAllowed(self):
# hasRole is an alias for allowed, which should be unaffected.
try:
self.userObject.allowed(None)
except DeprecationWarning:
self.fail('Unexpected DeprecationWarning, '
'no warnings expected here')
else:
pass
class BasicUser(DeprecatedAPI):
userObject = User.SimpleUser('JoeBloke', '123', [], [])
class UnrestrictedUser(DeprecatedAPI):
userObject = User.UnrestrictedUser('Special', '123', [], [])
class NullUnrestrictedUser(DeprecatedAPI):
userObject = User.NullUnrestrictedUser()
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(BasicUser))
suite.addTest(unittest.makeSuite(UnrestrictedUser))
suite.addTest(unittest.makeSuite(NullUnrestrictedUser))
return suite
......@@ -19,7 +19,7 @@ static char cDocumentTemplate_module_documentation[] =
static PyObject *py_isDocTemp=0, *py_blocks=0, *py_=0, *join=0, *py_acquire;
static PyObject *py___call__, *py___roles__, *py_AUTHENTICATED_USER;
static PyObject *py_hasRole, *py__proxy_roles, *py_Unauthorized;
static PyObject *py__proxy_roles, *py_Unauthorized;
static PyObject *py_Unauthorized_fmt, *py_guarded_getattr;
static PyObject *py__push, *py__pop, *py_aq_base, *py_renderNS;
static PyObject *py___class__, *html_quote, *ustr, *untaint_name;
......@@ -986,7 +986,6 @@ initcDocumentTemplate(void)
UNLESS(py___call__=PyString_FromString("__call__")) return;
UNLESS(py___roles__=PyString_FromString("__roles__")) return;
UNLESS(py__proxy_roles=PyString_FromString("_proxy_roles")) return;
UNLESS(py_hasRole=PyString_FromString("hasRole")) return;
UNLESS(py_guarded_getattr=PyString_FromString("guarded_getattr")) return;
UNLESS(py__push=PyString_FromString("_push")) return;
UNLESS(py__pop=PyString_FromString("_pop")) return;
......
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