Commit e2797512 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_erp5: Drop unused scripts from old security definitions

parent 3aca11ec
"""
WARNING: this script requires proxy manager
This script tries to acquire category values from other objects
base_category_list - list of category values we need to retrieve
object - object which we want to assign roles to.
"""
user_name = ob.Base_getOwnerId() #pylint: disable=redefined-builtin
# XXX Hardcoded role
return {
'Assignee': [user_name],
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>base_category_list, user_name, ob, portal_type</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Type_acquireSecurityFromOwner</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
"""
This script returns a list of dictionaries which represent
the security groups which a person is member of. It extracts
the categories from the current content. It is useful in the
following cases:
- calculate a security group based on a given
category of all Assifbment subobjects (ex. destination_project). This
is used for example in ERP5 to calculate
security of person objects so that members
of the same project can view each other.
The parameters are
base_category_list -- list of category values we need to retrieve
user_name -- string obtained from getSecurityManager().getUser().getId()
object -- object which we want to assign roles to
portal_type -- portal type of object
NOTE: for now, this script requires proxy manager
"""
category_list = []
if obj is None:
return []
person_object = obj
# We look for every valid assignments of this user
for assignment in person_object.contentValues(filter={'portal_type': 'Assignment'}):
if assignment.getValidationState() == 'open':
category_dict = {}
for base_category in base_category_list:
category_value_list = assignment.getAcquiredValueList(base_category)
if category_value_list:
for category_value in category_value_list:
category_dict.setdefault(base_category, []).append('%s' % category_value.getRelativeUrl())
category_list.append(category_dict)
return category_list
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>base_category_list, user_name, obj, portal_type</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Type_getSecurityCategoryFromChildAssignmentList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -55,12 +55,6 @@ class TestSlapOSCoreMixin(SlapOSTestCaseMixinWithAbort):
reference="TESTTREE-%s" % self.generateNewId(),
destination_section=person.getRelativeUrl())
class TestERP5Type_acquireSecurityFromOwner(TestSlapOSCoreMixin):
def test(self):
doc = self.createPerson()
self.assertEqual({'Assignee': [self.user_id]},
self.portal.ERP5Type_acquireSecurityFromOwner([], None, doc, None))
class TestPerson_getSecurityCategoryFromSelfShadow(TestSlapOSCoreMixin):
def test(self):
doc = self.createPerson()
......@@ -208,30 +202,3 @@ class TestPayzenEvent_getSecurityCategoryFromUserr(TestSlapOSCoreMixin):
self.assertEqual({'Assignee': [shadow_user_id]},
self.portal.PayzenEvent_getSecurityCategoryFromUser(["couscous", "destination_section"], None, event, None))
class TestERP5Type_getSecurityCategoryFromChildAssignmentList(TestSlapOSCoreMixin):
def test(self):
person = self.createPerson()
project = self.portal.project_module.newContent(
portal_type="Project"
)
person.newContent(portal_type='Assignment',
destination_project_value=project).open()
self.assertEqual([],
self.portal.ERP5Type_getSecurityCategoryFromChildAssignmentList([], None, None, None))
self.assertEqual([{}],
self.portal.ERP5Type_getSecurityCategoryFromChildAssignmentList([{}], None, person, None))
self.assertEqual([{}],
self.portal.ERP5Type_getSecurityCategoryFromChildAssignmentList(["destination_section"], None, person, None))
self.assertEqual([{'destination_project': [project.getRelativeUrl()]}],
self.portal.ERP5Type_getSecurityCategoryFromChildAssignmentList(["destination_project"], None, person, None))
self.assertEqual([{'destination_project': [project.getRelativeUrl()]}],
self.portal.ERP5Type_getSecurityCategoryFromChildAssignmentList(
["destination_section", "destination_project"], None, person, None))
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