本文整理汇总了Python中Products.DCWorkflow.Guard.Guard类的典型用法代码示例。如果您正苦于以下问题:Python Guard类的具体用法?Python Guard怎么用?Python Guard使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Guard类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_checkWithKwargs
def test_checkWithKwargs(self):
#
# Checks with kwargs
#
guard = Guard()
# Create compulsory context elements
sm = getSecurityManager()
self.site._setObject('dummy', DummyContent('dummy'))
ob = self.site.dummy
wf_def = self._getDummyWorkflow()
# Initialize the guard with an ok guard
guard_props = {'guard_permissions':'',
'guard_roles':'',
'guard_expr' :'python:1'}
res = guard.changeFromProperties(guard_props)
self.assert_(res)
self.assert_(guard.check(sm, wf_def, ob, arg1=1, arg2=2))
# Initialize the guard with a not ok guard
guard_props = {'guard_permissions':'',
'guard_roles':'',
'guard_expr' :'python:0'}
res = guard.changeFromProperties(guard_props)
self.assert_(res)
self.assert_(not guard.check(sm, wf_def, ob, arg1=1, arg2=2))
示例2: setProperties
def setProperties(self, title, new_state_id,
trigger_type=TRIGGER_USER_ACTION, script_name='',
after_script_name='',
actbox_name='', actbox_url='',
actbox_category='workflow', actbox_icon='',
props=None, REQUEST=None, description=''):
'''
'''
self.title = str(title)
self.description = str(description)
self.new_state_id = str(new_state_id)
self.trigger_type = int(trigger_type)
self.script_name = str(script_name)
self.after_script_name = str(after_script_name)
g = Guard()
if g.changeFromProperties(props or REQUEST):
self.guard = g
else:
self.guard = None
self.actbox_name = str(actbox_name)
self.actbox_url = str(actbox_url)
self.actbox_icon = str(actbox_icon)
self.actbox_category = str(actbox_category)
if REQUEST is not None:
return self.manage_properties(REQUEST, 'Properties changed.')
示例3: test_checkGuardExpr
def test_checkGuardExpr(self):
#
# Basic checks.
#
guard = Guard()
# Create compulsory context elements
sm = getSecurityManager()
self.site._setObject("dummy", DummyContent("dummy"))
ob = self.site.dummy
wf_def = self._getDummyWorkflow()
# Initialize the guard with an ok guard
guard_props = {"guard_permissions": "", "guard_roles": "", "guard_expr": "python:1"}
res = guard.changeFromProperties(guard_props)
self.assert_(res)
self.assert_(guard.check(sm, wf_def, ob))
# Initialize the guard with a not ok guard
guard_props = {"guard_permissions": "", "guard_roles": "", "guard_expr": "python:0"}
res = guard.changeFromProperties(guard_props)
self.assert_(res)
self.assert_(not guard.check(sm, wf_def, ob))
示例4: test_checkGuardExpr
def test_checkGuardExpr(self):
#
# Basic checks.
#
guard = Guard()
# Create compulsory context elements
sm = getSecurityManager()
ob = DummyContent('dummy')
wf_def = self._getDummyWorkflow()
# Initialize the guard with an ok guard
guard_props = {'guard_permissions':'',
'guard_roles':'',
'guard_expr' :'python:1'}
res = guard.changeFromProperties(guard_props)
self.assert_(res)
self.assert_(guard.check(sm, wf_def, ob))
# Initialize the guard with a not ok guard
guard_props = {'guard_permissions':'',
'guard_roles':'',
'guard_expr' :'python:0'}
res = guard.changeFromProperties(guard_props)
self.assert_(res)
self.assert_(not guard.check(sm, wf_def, ob))
示例5: setProperties
def setProperties(
self,
description,
default_value="",
default_expr="",
for_catalog=0,
for_status=0,
update_always=0,
props=None,
REQUEST=None,
):
"""
"""
self.description = str(description)
self.default_value = str(default_value)
if default_expr:
self.default_expr = Expression(default_expr)
else:
self.default_expr = None
g = Guard()
if g.changeFromProperties(props or REQUEST):
self.info_guard = g
else:
self.info_guard = None
self.for_catalog = bool(for_catalog)
self.for_status = bool(for_status)
self.update_always = bool(update_always)
if REQUEST is not None:
return self.manage_properties(REQUEST, "Properties changed.")
示例6: setProperties
def setProperties(self, title,
portal_type_filter=None,
portal_type_group_filter=None,
trigger_type=TRIGGER_WORKFLOW_METHOD,
once_per_transaction=False,
temporary_document_disallowed=False,
script_name=(),
after_script_name=(),
before_commit_script_name=(),
activate_script_name=(),
actbox_name='', actbox_url='',
actbox_category='workflow',
method_id=(),
props=None, REQUEST=None, description=''):
"""
Update transition properties
XXX - then make sure that method_id is WorkflowMethod for portal_type_filter
XXX - this will likely require dynamic
"""
if type(method_id) is type(''):
self.method_id = method_id.split()
else:
self.method_id = method_id
if portal_type_filter is not None and 'None' in portal_type_filter:
portal_type_filter = None
if portal_type_group_filter is not None and 'None' in portal_type_group_filter:
portal_type_group_filter = None
if 'None' in after_script_name:
after_script_name = ()
if 'None' in activate_script_name:
activate_script_name = ()
if 'None' in script_name:
script_name = ()
if 'None' in before_commit_script_name:
before_commit_script_name = ()
self.portal_type_filter = portal_type_filter
self.portal_type_group_filter = portal_type_group_filter
self.title = str(title)
self.description = str(description)
self.trigger_type = int(trigger_type)
self.once_per_transaction = bool(once_per_transaction)
self.temporary_document_disallowed = bool(temporary_document_disallowed)
self.script_name = script_name
self.after_script_name = after_script_name
self.before_commit_script_name = before_commit_script_name
self.activate_script_name = activate_script_name
g = Guard()
if g.changeFromProperties(props or REQUEST):
self.guard = g
else:
self.guard = None
self.actbox_name = str(actbox_name)
self.actbox_url = str(actbox_url)
self.actbox_category = str(actbox_category)
# reset cached methods
self.getPortalObject().portal_types.resetDynamicDocuments()
if REQUEST is not None:
return self.manage_properties(REQUEST, 'Properties changed.')
示例7: manage_setGuard
def manage_setGuard(self, props=None, REQUEST=None):
'''
'''
g = Guard()
if g.changeFromProperties(props or REQUEST):
self.guard = g
else:
self.guard = None
if REQUEST is not None:
return self.manage_guardForm(REQUEST, 'Properties changed.')
示例8: _initDCWorkflowCreationGuard
def _initDCWorkflowCreationGuard(workflow, guard):
"""Initialize Instance creation conditions guard
"""
if guard is None:
workflow.creation_guard = None
else:
props = {'guard_roles': ';'.join(guard['roles']),
'guard_permissions': ';'.join(guard['permissions']),
'guard_groups': ';'.join(guard['groups']),
'guard_expr': guard['expression']}
g = Guard()
g.changeFromProperties(props)
workflow.creation_guard = g
示例9: setProperties
def setProperties(self, title, manager_bypass=0, props=None,
REQUEST=None, description=''):
"""Sets basic properties.
"""
self.title = str(title)
self.description = str(description)
self.manager_bypass = manager_bypass and 1 or 0
g = Guard()
if g.changeFromProperties(props or REQUEST):
self.creation_guard = g
else:
self.creation_guard = None
if REQUEST is not None:
return self.manage_properties(
REQUEST, manage_tabs_message='Properties changed.')
示例10: clone_transition
def clone_transition(transition, clone):
transition.description = clone.description
transition.new_state_id = clone.new_state_id
transition.trigger_type = clone.trigger_type
if clone.guard:
guard = Guard()
guard.permissions = clone.guard.permissions[:]
guard.roles = clone.guard.roles[:]
guard.groups = clone.guard.groups[:]
transition.guard = guard
transition.actbox_name = transition.title
transition.actbox_url = clone.actbox_url.replace(clone.id, transition.id)
transition.actbox_category = clone.actbox_category
transition.var_exprs = clone.var_exprs
transition.script_name = clone.script_name
transition.after_script_name = clone.after_script_name
示例11: manage_setGuard
def manage_setGuard(self, props=None, REQUEST=None):
'''
'''
g = Guard()
if g.changeFromProperties(props or REQUEST):
guard = self.guard
if guard is None:
self.guard = g
else:
guard._p_activate()
if guard.__dict__ != g.__dict__:
guard.__dict__.clear()
guard.__dict__.update(g.__dict__)
guard._p_changed = 1
else:
try:
del self.guard
except AttributeError:
pass
if REQUEST is not None:
return self.manage_guardForm(REQUEST, 'Properties changed.')
示例12: setProperties
def setProperties(self, description,
actbox_name='', actbox_url='', actbox_category='global',
actbox_icon='', props=None, REQUEST=None):
'''
'''
if props is None:
props = REQUEST
self.description = str(description)
for key in self.getAvailableCatalogVars():
# Populate var_matches.
fieldname = 'var_match_%s' % key
v = props.get(fieldname, '')
if v:
if not self.var_matches:
self.var_matches = PersistentMapping()
if tales_re.match(v).group(1):
# Found a TALES prefix
self.var_matches[key] = Expression(v)
else:
# Falling back to formatted string
v = [ var.strip() for var in v.split(';') ]
self.var_matches[key] = tuple(v)
else:
if self.var_matches and self.var_matches.has_key(key):
del self.var_matches[key]
self.actbox_name = str(actbox_name)
self.actbox_url = str(actbox_url)
self.actbox_category = str(actbox_category)
self.actbox_icon = str(actbox_icon)
g = Guard()
if g.changeFromProperties(props or REQUEST):
self.guard = g
else:
self.guard = None
if REQUEST is not None:
return self.manage_properties(REQUEST, 'Properties changed.')
示例13: test_BaseGuardAPI
def test_BaseGuardAPI(self):
#
# Test guard basic API
#
guard = Guard()
self.assertNotEqual(guard, None)
# Test default values
self.assertEqual(guard.getPermissionsText(), '')
self.assertEqual(guard.getRolesText(), '')
self.assertEqual(guard.getExprText(), '')
# Initialize the guard with empty values
# not initialization
guard_props = {'guard_permissions':'',
'guard_roles':'',
'guard_expr' :''}
res = guard.changeFromProperties(guard_props)
self.assert_(res==0)
# Test default values
self.assertEqual(guard.getPermissionsText(), '')
self.assertEqual(guard.getRolesText(), '')
self.assertEqual(guard.getExprText(), '')
# Change guard
guard_props = {'guard_roles':'Manager',
'guard_permissions':'',
'guard_expr' :''}
res = guard.changeFromProperties(guard_props)
self.assert_(res==1)
self.assertEqual(guard.getRolesText(), 'Manager')
self.assertEqual(guard.getPermissionsText(), '')
self.assertEqual(guard.getExprText(), '')
# Change guard
guard_props = {'guard_roles':'Manager;',
'guard_permissions':'',
'guard_expr' :''}
res = guard.changeFromProperties(guard_props)
self.assert_(res==1)
# With one space after the ';'
self.assertEqual(guard.getRolesText(), 'Manager; ')
self.assertEqual(guard.getPermissionsText(), '')
self.assertEqual(guard.getExprText(), '')
# Change guard
guard_props = {'guard_roles':'Manager;Member',
'guard_permissions':'',
'guard_expr' :''}
res = guard.changeFromProperties(guard_props)
self.assert_(res==1)
# With one space after the ';'
self.assertEqual(guard.getRolesText(), 'Manager; Member')
self.assertEqual(guard.getPermissionsText(), '')
self.assertEqual(guard.getExprText(), '')
# Change guard
guard_props = {'guard_roles':'Manager;Member',
'guard_permissions':'',
'guard_expr' :''}
res = guard.changeFromProperties(guard_props)
self.assert_(res==1)
# With one space after the ';'
self.assertEqual(guard.getRolesText(), 'Manager; Member')
self.assertEqual(guard.getPermissionsText(), '')
self.assertEqual(guard.getExprText(), '')
# Change guard
guard_props = {'guard_roles':'Manager',
'guard_permissions':'',
'guard_expr' :''}
res = guard.changeFromProperties(guard_props)
self.assert_(res==1)
self.assertEqual(guard.getRolesText(), 'Manager')
self.assertEqual(guard.getPermissionsText(), '')
self.assertEqual(guard.getExprText(), '')
# Change guard
guard_props = {'guard_roles':'Manager',
'guard_permissions':'ManagePortal;',
'guard_expr' :''}
res = guard.changeFromProperties(guard_props)
self.assert_(res==1)
self.assertEqual(guard.getRolesText(), 'Manager')
self.assertEqual(guard.getPermissionsText(), 'ManagePortal; ')
self.assertEqual(guard.getExprText(), '')
# Change guard
guard_props = {'guard_roles':'Manager',
'guard_permissions':'ManagePortal',
'guard_expr' :''}
res = guard.changeFromProperties(guard_props)
self.assert_(res==1)
self.assertEqual(guard.getRolesText(), 'Manager')
self.assertEqual(guard.getPermissionsText(), 'ManagePortal')
self.assertEqual(guard.getExprText(), '')
#.........这里部分代码省略.........
示例14: test_BaseGuardAPI
def test_BaseGuardAPI(self):
#
# Test guard basic API
#
guard = Guard()
self.assertNotEqual(guard, None)
# Test default values
self.assertEqual(guard.getPermissionsText(), "")
self.assertEqual(guard.getRolesText(), "")
self.assertEqual(guard.getExprText(), "")
# Initialize the guard with empty values
# not initialization
guard_props = {"guard_permissions": "", "guard_roles": "", "guard_expr": ""}
res = guard.changeFromProperties(guard_props)
self.assert_(res == 0)
# Test default values
self.assertEqual(guard.getPermissionsText(), "")
self.assertEqual(guard.getRolesText(), "")
self.assertEqual(guard.getExprText(), "")
# Change guard
guard_props = {"guard_roles": "Manager", "guard_permissions": "", "guard_expr": ""}
res = guard.changeFromProperties(guard_props)
self.assert_(res == 1)
self.assertEqual(guard.getRolesText(), "Manager")
self.assertEqual(guard.getPermissionsText(), "")
self.assertEqual(guard.getExprText(), "")
# Change guard
guard_props = {"guard_roles": "Manager;", "guard_permissions": "", "guard_expr": ""}
res = guard.changeFromProperties(guard_props)
self.assert_(res == 1)
# With one space after the ';'
self.assertEqual(guard.getRolesText(), "Manager; ")
self.assertEqual(guard.getPermissionsText(), "")
self.assertEqual(guard.getExprText(), "")
# Change guard
guard_props = {"guard_roles": "Manager;Member", "guard_permissions": "", "guard_expr": ""}
res = guard.changeFromProperties(guard_props)
self.assert_(res == 1)
# With one space after the ';'
self.assertEqual(guard.getRolesText(), "Manager; Member")
self.assertEqual(guard.getPermissionsText(), "")
self.assertEqual(guard.getExprText(), "")
# Change guard
guard_props = {"guard_roles": "Manager;Member", "guard_permissions": "", "guard_expr": ""}
res = guard.changeFromProperties(guard_props)
self.assert_(res == 1)
# With one space after the ';'
self.assertEqual(guard.getRolesText(), "Manager; Member")
self.assertEqual(guard.getPermissionsText(), "")
self.assertEqual(guard.getExprText(), "")
# Change guard
guard_props = {"guard_roles": "Manager", "guard_permissions": "", "guard_expr": ""}
res = guard.changeFromProperties(guard_props)
self.assert_(res == 1)
self.assertEqual(guard.getRolesText(), "Manager")
self.assertEqual(guard.getPermissionsText(), "")
self.assertEqual(guard.getExprText(), "")
# Change guard
guard_props = {"guard_roles": "Manager", "guard_permissions": "ManagePortal;", "guard_expr": ""}
res = guard.changeFromProperties(guard_props)
self.assert_(res == 1)
self.assertEqual(guard.getRolesText(), "Manager")
self.assertEqual(guard.getPermissionsText(), "ManagePortal; ")
self.assertEqual(guard.getExprText(), "")
# Change guard
guard_props = {"guard_roles": "Manager", "guard_permissions": "ManagePortal", "guard_expr": ""}
res = guard.changeFromProperties(guard_props)
self.assert_(res == 1)
self.assertEqual(guard.getRolesText(), "Manager")
self.assertEqual(guard.getPermissionsText(), "ManagePortal")
self.assertEqual(guard.getExprText(), "")
# Change guard
guard_props = {"guard_roles": "Manager", "guard_permissions": "ManagePortal", "guard_expr": "python:1"}
res = guard.changeFromProperties(guard_props)
self.assert_(res == 1)
self.assertEqual(guard.getRolesText(), "Manager")
self.assertEqual(guard.getPermissionsText(), "ManagePortal")
self.assertEqual(guard.getExprText(), "python:1")
# Change guard
guard_props = {"guard_roles": "Manager", "guard_permissions": "ManagePortal", "guard_expr": "string:"}
res = guard.changeFromProperties(guard_props)
self.assert_(res == 1)
self.assertEqual(guard.getRolesText(), "Manager")
self.assertEqual(guard.getPermissionsText(), "ManagePortal")
self.assertEqual(guard.getExprText(), "string:")
#.........这里部分代码省略.........