Commit 81b04b70 authored by Rafael Monnerat's avatar Rafael Monnerat

*: Use ERP5User to check for user types

  Rather them hardcode portal type, use property sheet to identify
  if the document is an user.

  This is way simpler to manage via Business Template

  Introduce new method on Base class to return the property sheet ids,
  so we don't have to put the getattr-way everywhere.
parent 036f0c50
Pipeline #38171 failed with stage
in 0 seconds
......@@ -9,18 +9,9 @@ for user_value in user_value_list:
portal_type_dict[user_value.getPortalType()].add(user_value)
user_value_set = set()
portal = context.getPortalObject()
portal_types = portal.portal_types
for portal_type, document_value_set in six.iteritems(portal_type_dict):
for document_value_set in six.itervalues(portal_type_dict):
# Ignore non-user documents
if 'ERP5User' in getattr(
getattr(
portal_types,
portal_type,
None,
),
'getTypePropertySheetList',
lambda: (),
)():
if 'ERP5User' in document_value_set.getPropertySheetIdSet():
user_value_set.update(document_value_set)
if user_value_set:
for oauth2_session_value in portal.portal_catalog(
......
......@@ -175,7 +175,7 @@ def asSecurityGroupIdSet(category_dict, key_sort=sorted):
except KeyError:
continue
for category_value, is_child_category in category_list:
if category_value.getPortalType() == 'Person':
if 'ERP5User' in category_value.getPropertySheetIdSet():
user_name = category_value.Person_getUserId()
if user_name is not None:
user_list.append(user_name)
......
......@@ -41,7 +41,7 @@ getUserId</string> </value>
</item>
<item>
<key> <string>expression</string> </key>
<value> <string>python: \'ERP5User\' in getattr(getattr(context.getPortalObject().portal_types, context.getPortalType(), None), \'getTypePropertySheetList\', lambda: ())()</string> </value>
<value> <string>python: \'ERP5User\' in context.getPropertySheetIdSet()</string> </value>
</item>
<item>
<key> <string>expression_cache_key</string> </key>
......
......@@ -914,6 +914,13 @@ class Base(
# A method which does nothing (and can be used to build WorkflowMethods which trigger worklow transitions)
pass
def getPropertySheetIdSet(self):
portal_type_value = getattr(
self._getTypesTool(), self.getPortalType(), None)
if portal_type_value is not None:
return set(portal_type_value.getTypePropertySheetList())
return set()
# Generic accessor
def _getDefaultAcquiredProperty(self, key, default_value, null_value,
acquisition_object_id=None, base_category=None, portal_type=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