Skip to content

Commit

Permalink
chore: isort + black
Browse files Browse the repository at this point in the history
  • Loading branch information
gforcada committed Feb 8, 2023
1 parent 9c01c2f commit f6bb099
Show file tree
Hide file tree
Showing 12 changed files with 406 additions and 417 deletions.
2 changes: 1 addition & 1 deletion borg/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
__import__("pkg_resources").declare_namespace(__name__)
2 changes: 1 addition & 1 deletion borg/localrole/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ def initialize(context):
workspace.manage_addWorkspaceLocalRoleManagerForm,
workspace.manage_addWorkspaceLocalRoleManager,
),
visibility=None
visibility=None,
)
4 changes: 2 additions & 2 deletions borg/localrole/bbb/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# BBB: These interfaces will be removed in a later version of borg.locarole.
# You should use the interfaces in borg.localrole.interfaces instead!


class IWorkspace(Interface):
"""A workspace in which custom local roles are needed
Expand All @@ -13,8 +14,7 @@ class IWorkspace(Interface):
"""

def getLocalRolesForPrincipal(principal):
"""Return a sequence of all local roles for a principal.
"""
"""Return a sequence of all local roles for a principal."""

def getLocalRoles():
"""Return a dictonary mapping principals to their roles within
Expand Down
2 changes: 1 addition & 1 deletion borg/localrole/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Configuration constants

LOCALROLE_PLUGIN_NAME = 'borg_localroles'
LOCALROLE_PLUGIN_NAME = "borg_localroles"
2 changes: 1 addition & 1 deletion borg/localrole/default_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self, context):

@property
def _rolemap(self):
rolemap = getattr(self.context, '__ac_local_roles__', {})
rolemap = getattr(self.context, "__ac_local_roles__", {})
# None is the default value from AccessControl.Role.RoleMananger
if rolemap is None:
return {}
Expand Down
2 changes: 1 addition & 1 deletion borg/localrole/factory_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __init__(self, obj):
self.folder = obj

def getRoles(self, principal_id):
uf = aq_inner(getToolByName(self.folder, 'acl_users'))
uf = aq_inner(getToolByName(self.folder, "acl_users"))
user = aq_inner(uf.getUserById(principal_id, default=None))
# use the folder we are creating in as role generating context
source = aq_parent(aq_parent(self.folder))
Expand Down
13 changes: 6 additions & 7 deletions borg/localrole/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@


deprecated(
'Please use borg.localrole.interfaces.ILocalRoleProvider instead',
IWorkspace='borg.localrole.bbb.interfaces:IWorkspace'
"Please use borg.localrole.interfaces.ILocalRoleProvider instead",
IWorkspace="borg.localrole.bbb.interfaces:IWorkspace",
)

deprecated(
'Please use borg.localrole.interfaces.ILocalRoleProvider instead',
IGroupAwareWorkspace='borg.localrole.bbb.interfaces:IGroupAwareWorkspace'
"Please use borg.localrole.interfaces.ILocalRoleProvider instead",
IGroupAwareWorkspace="borg.localrole.bbb.interfaces:IGroupAwareWorkspace",
)


class ILocalRoleProvider(Interface):
"""An interface which allows querying the local roles on an object"""

def getRoles(principal_id):
"""Returns an iterable of roles granted to the specified user object
"""
"""Returns an iterable of roles granted to the specified user object"""

def getAllRoles():
"""Returns an iterable consisting of tuples of the form:
(principal_id, sequence_of_roles)
(principal_id, sequence_of_roles)
"""


Expand Down
2 changes: 1 addition & 1 deletion borg/localrole/setuphandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def importVarious(context):

if context.readDataFile('borg.localrole_various.txt') is None:
if context.readDataFile("borg.localrole_various.txt") is None:
return

portal = context.getSite()
Expand Down
25 changes: 11 additions & 14 deletions borg/localrole/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@

@implementer(borg.localrole.interfaces.ILocalRoleProvider)
class SimpleLocalRoleProvider:

def __init__(self, context):
self.context = context

def getRoles(self, user):
"""Grant everyone the 'Foo' role"""
return ('Foo', )
return ("Foo",)

def getAllRoles(self):
"""In the real world we would enumerate all users and
grant the 'Foo' role to each, but we won't"""
yield ('bogus_user', ('Foo', ))
yield ("bogus_user", ("Foo",))


class DummyUser:
Expand All @@ -50,36 +49,34 @@ class Py23DocChecker(doctest.OutputChecker):
def check_output(self, want, got, optionflags):
if six.PY2:
got = re.sub(r"set\(\[(.*?)\]\)", "{\\1}", got)
want = re.sub(
'plone.memoize.volatile.DontCache',
'DontCache', want
)
want = re.sub("plone.memoize.volatile.DontCache", "DontCache", want)
return doctest.OutputChecker.check_output(self, want, got, optionflags)


def test_suite():
suite = [
layered(
doctest.DocFileSuite(
'README.txt',
package='borg.localrole',
optionflags=(doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
"README.txt",
package="borg.localrole",
optionflags=(doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE),
),
layer=PLONE_INTEGRATION_TESTING),
layer=PLONE_INTEGRATION_TESTING,
),
layered(
doctest.DocTestSuite(
borg.localrole.workspace,
optionflags=(doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE),
checker=Py23DocChecker(),
),
layer=zca.UNIT_TESTING
layer=zca.UNIT_TESTING,
),
layered(
doctest.DocTestSuite(
factory_adapter,
optionflags=(doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
optionflags=(doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE),
),
layer=zca.UNIT_TESTING
layer=zca.UNIT_TESTING,
),
doctest.DocTestSuite(default_adapter),
]
Expand Down
17 changes: 8 additions & 9 deletions borg/localrole/utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
from Acquisition import aq_base
from borg.localrole.config import LOCALROLE_PLUGIN_NAME
from borg.localrole.workspace import manage_addWorkspaceLocalRoleManager
from io import StringIO
from Products.CMFCore.utils import getToolByName
from Products.PlonePAS.plugins.local_role import LocalRolesManager
from Products.PlonePAS.setuphandlers import activatePluginInterfaces
from io import StringIO


def setup_localrole_plugin(portal):
"""Install and prioritize the local-role PAS plug-in
"""
"""Install and prioritize the local-role PAS plug-in"""
out = StringIO()

uf = getToolByName(portal, 'acl_users')
uf = getToolByName(portal, "acl_users")

existing = uf.objectIds()

Expand All @@ -28,13 +27,13 @@ def setup_localrole_plugin(portal):
def replace_local_role_manager(portal):
"""Installs the borg local role manager in place of the standard one from
PlonePAS"""
uf = getToolByName(portal, 'acl_users', None)
uf = getToolByName(portal, "acl_users", None)
# Make sure we have a PAS user folder
if uf is not None and hasattr(aq_base(uf), 'plugins'):
if uf is not None and hasattr(aq_base(uf), "plugins"):
# Remove the original plugin if it's there
if 'local_roles' in uf.objectIds():
orig_lr = getattr(uf, 'local_roles')
if "local_roles" in uf.objectIds():
orig_lr = getattr(uf, "local_roles")
if isinstance(orig_lr, LocalRolesManager):
uf.plugins.removePluginById('local_roles')
uf.plugins.removePluginById("local_roles")
# Install the borg.localrole plugin if it's not already there
setup_localrole_plugin(portal)
Loading

0 comments on commit f6bb099

Please sign in to comment.