Commit 364ebb48 authored by Mame Coumba Sall's avatar Mame Coumba Sall Committed by Vincent Pelletier

Simplify fetching user assignment and its root site.

Those are single-valued, so just check consistency internally and return
a single value.
Changelog and some cleanups by Vincent Pelletier <vincent@nexedi.com>.
parent fbc8dc30
...@@ -50,13 +50,12 @@ ...@@ -50,13 +50,12 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>site_list = context.Baobab_getUserAssignedRootSiteList()\n <value> <string>site = context.Baobab_getUserAssignedRootSite()\n
if len(site_list) == 0:\n if site in (\'\', None):\n
from Products.ERP5Type.Message import Message\n from Products.ERP5Type.Message import Message\n
message = Message(domain="ui", message="The owner is not assigned to the right vault.")\n message = Message(domain="ui", message="The owner is not assigned to the right vault.")\n
raise ValueError,message\n raise ValueError,message\n
\n \n
site = site_list[0]\n
\n \n
context.setSource("%s/caveau/auxiliaire/encaisse_des_billets_a_ventiler_et_a_detruire" %(site,))\n context.setSource("%s/caveau/auxiliaire/encaisse_des_billets_a_ventiler_et_a_detruire" %(site,))\n
context.setDestination("%s/caveau/auxiliaire/encaisse_des_billets_ventiles_et_detruits" %(site,))\n context.setDestination("%s/caveau/auxiliaire/encaisse_des_billets_ventiles_et_detruits" %(site,))\n
......
...@@ -236,11 +236,11 @@ def split_head(CD_file_line_list):\n ...@@ -236,11 +236,11 @@ def split_head(CD_file_line_list):\n
return {\'error\':True, \'message\':message_dict[\'12\'], \'head_dict\':{}}\n return {\'error\':True, \'message\':message_dict[\'12\'], \'head_dict\':{}}\n
\n \n
# Define destination\n # Define destination\n
user_site_list = context.Baobab_getUserAssignedRootSiteList()\n user_site = context.Baobab_getUserAssignedRootSite()\n
if user_site_list is None:\n if user_site is None:\n
return {\'error\':True, \'message\':message_dict[\'13\'], \'head_dict\':{}}\n return {\'error\':True, \'message\':message_dict[\'13\'], \'head_dict\':{}}\n
\n \n
head_destination = \'%s/%s\' % (user_site_list[0],\'caveau/serre\')\n head_destination = \'%s/%s\' % (user_site,\'caveau/serre\')\n
if head_emission_letter in context.Baobab_getUserEmissionLetterList():\n if head_emission_letter in context.Baobab_getUserEmissionLetterList():\n
head_destination = \'%s/%s\' % (head_destination,\'encaisse_des_billets_neufs_non_emis\')\n head_destination = \'%s/%s\' % (head_destination,\'encaisse_des_billets_neufs_non_emis\')\n
else:\n else:\n
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>user_site = context.Baobab_getUserAssignedRootSiteList()[0]\n <value> <string>user_site = context.Baobab_getUserAssignedRootSite()\n
user_counter = context.Baobab_getUserAssignedSiteList()[0]\n user_counter = context.Baobab_getUserAssignedSiteList()[0]\n
if user_site in (\'\', None) or user_counter in (\'\', None):\n if user_site in (\'\', None) or user_counter in (\'\', None):\n
raise ValueError, "Unable to determine site"\n raise ValueError, "Unable to determine site"\n
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>transaction = context\n <value> <string>transaction = context\n
\n \n
user_site = context.Baobab_getUserAssignedRootSiteList()[0]\n user_site = context.Baobab_getUserAssignedRootSite()\n
context.setSite(user_site)\n context.setSite(user_site)\n
\n \n
# XXX it might be better to set resource according to source_payment.\n # XXX it might be better to set resource according to source_payment.\n
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
<value> <string>reference_currency = context.Baobab_getPortalReferenceCurrencyID()\n <value> <string>reference_currency = context.Baobab_getPortalReferenceCurrencyID()\n
context.setPriceCurrency(\'currency_module/%s\' %(reference_currency,))\n context.setPriceCurrency(\'currency_module/%s\' %(reference_currency,))\n
context.setCurrencyExchangeType(\'transfer\')\n context.setCurrencyExchangeType(\'transfer\')\n
site = context.Baobab_getUserAssignedRootSiteList()[0]\n site = context.Baobab_getUserAssignedRootSite()\n
context.setSource(site)\n context.setSource(site)\n
</string> </value> </string> </value>
</item> </item>
......
...@@ -60,7 +60,7 @@ from Products.ERP5Type.Message import Message\n ...@@ -60,7 +60,7 @@ from Products.ERP5Type.Message import Message\n
from Products.DCWorkflow.DCWorkflow import ValidationFailed\n from Products.DCWorkflow.DCWorkflow import ValidationFailed\n
\n \n
if site is None:\n if site is None:\n
root_site_url = context.Baobab_getUserAssignedRootSiteList()[0]\n root_site_url = context.Baobab_getUserAssignedRootSite()\n
site = context.portal_categories.restrictedTraverse(root_site_url)\n site = context.portal_categories.restrictedTraverse(root_site_url)\n
\n \n
resource_uid_list = [x.uid for x in context.currency_cash_module.searchFolder()]\n resource_uid_list = [x.uid for x in context.currency_cash_module.searchFolder()]\n
......
...@@ -57,7 +57,7 @@ if site is None:\n ...@@ -57,7 +57,7 @@ if site is None:\n
if getattr(context,\'getSiteValue\',None) is not None:\n if getattr(context,\'getSiteValue\',None) is not None:\n
site = context.getSiteValue()\n site = context.getSiteValue()\n
if site is None:\n if site is None:\n
root_site_url = context.Baobab_getUserAssignedRootSiteList()[0]\n root_site_url = context.Baobab_getUserAssignedRootSite()\n
site = context.portal_categories.restrictedTraverse(root_site_url)\n site = context.portal_categories.restrictedTraverse(root_site_url)\n
\n \n
resource_uid_list = [x.uid for x in context.currency_cash_module.searchFolder()]\n resource_uid_list = [x.uid for x in context.currency_cash_module.searchFolder()]\n
......
...@@ -61,11 +61,11 @@ if user_id is None:\n ...@@ -61,11 +61,11 @@ if user_id is None:\n
\n \n
def getFunctionList(user_id=user_id):\n def getFunctionList(user_id=user_id):\n
\n \n
valid_assignment_list = context.Baobab_getUserAssignmentList(user_id=user_id)\n valid_assignment = context.Baobab_getUserAssignment(user_id=user_id)\n
\n \n
function_list = []\n function_list = []\n
for a in valid_assignment_list:\n if valid_assignment != None:\n
new_function_list = a.getFunctionList()\n new_function_list = valid_assignment.getFunctionList()\n
if len(new_function_list)>0:\n if len(new_function_list)>0:\n
function_list.extend(new_function_list)\n function_list.extend(new_function_list)\n
return function_list\n return function_list\n
......
...@@ -59,11 +59,11 @@ if user_id is None:\n ...@@ -59,11 +59,11 @@ if user_id is None:\n
\n \n
def getGroupList(user_id=user_id):\n def getGroupList(user_id=user_id):\n
\n \n
valid_assignment_list = context.Baobab_getUserAssignmentList(user_id=user_id)\n valid_assignment = context.Baobab_getUserAssignment(user_id=user_id)\n
\n \n
group_list = []\n group_list = []\n
for a in valid_assignment_list:\n if valid_assignment != None:\n
new_group = a.getGroup()\n new_group = valid_assignment.getGroup()\n
if not new_group.startswith(\'group\'):\n if not new_group.startswith(\'group\'):\n
new_group=\'group/%s\' % new_group\n new_group=\'group/%s\' % new_group\n
if new_group not in (\'\', None):\n if new_group not in (\'\', None):\n
......
...@@ -50,28 +50,17 @@ ...@@ -50,28 +50,17 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string># get the current logged user root site (agency)\n <value> <string>new_site = context.Baobab_getUserAssignment(user_id=user_id).getSiteValue()\n
\n while new_site.getVaultType() != \'site\':\n
valid_assignment_list = context.Baobab_getUserAssignmentList(user_id=user_id)\n new_site = new_site.getParentValue()\n
\n if not object:\n
site_list = []\n new_site = new_site.getRelativeUrl()\n
for a in valid_assignment_list:\n return new_site\n
new_site = a.getSiteValue()\n
while new_site.getVaultType()!=\'site\':\n
new_site = new_site.getParentValue()\n
if object:\n
if new_site not in site_list:\n
site_list.append(new_site)\n
else:\n
site_url = new_site.getRelativeUrl()\n
if site_url not in site_list:\n
site_list.append(site_url)\n
return site_list\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>user_id=None, object=0, **kw</string> </value> <value> <string>user_id=None, object=False</string> </value>
</item> </item>
<item> <item>
<key> <string>_proxy_roles</string> </key> <key> <string>_proxy_roles</string> </key>
...@@ -83,7 +72,7 @@ return site_list\n ...@@ -83,7 +72,7 @@ return site_list\n
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>Baobab_getUserAssignedRootSiteList</string> </value> <value> <string>Baobab_getUserAssignedRootSite</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -59,11 +59,11 @@ if user_id is None:\n ...@@ -59,11 +59,11 @@ if user_id is None:\n
\n \n
def getSiteList(user_id=user_id):\n def getSiteList(user_id=user_id):\n
\n \n
valid_assignment_list = context.Baobab_getUserAssignmentList(user_id=user_id)\n valid_assignment = context.Baobab_getUserAssignment(user_id=user_id)\n
\n \n
site_list = []\n site_list = []\n
for a in valid_assignment_list:\n if valid_assignment != None:\n
new_site = a.getSite()\n new_site = valid_assignment.getSite()\n
if not new_site.startswith(\'site\'):\n if not new_site.startswith(\'site\'):\n
new_site=\'site/%s\' % new_site\n new_site=\'site/%s\' % new_site\n
if new_site not in (\'\', None):\n if new_site not in (\'\', None):\n
......
...@@ -52,35 +52,25 @@ ...@@ -52,35 +52,25 @@
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string encoding="cdata"><![CDATA[
# get the current logged user site\n
if user_id is None:\n if user_id is None:\n
login = context.portal_membership.getAuthenticatedMember().getUserName()\n user_id = context.portal_membership.getAuthenticatedMember().getUserName()\n
else:\n person_list = context.acl_users.erp5_users.getUserByLogin(user_id)\n
login = user_id\n if not person_list:\n
persons = context.acl_users.erp5_users.getUserByLogin(login)\n return None\n
\n assignment_list = person_list[0].contentValues(filter={\'portal_type\': \'Assignment\'})\n
if len(persons) == 0:\n if not assignment_list:\n
#context.log(\'Baobab_getUserAssignementList\', \'Person %s not found\' %(login))\n return None\n
return []\n valid_assignment = None\n
else:\n now = DateTime()\n
#person = persons[0].getObject()\n for assignment in assignment_list:\n
person = persons[0]\n if assignment.getValidationState() == \'open\':\n
\n stop = assignment.getStopDate()\n
assignment_list = person.contentValues(filter={\'portal_type\': \'Assignment\'})\n start = assignment.getStartDate()\n
\n if (stop is None or stop > now) and (start is None or start < now):\n
if len(assignment_list) == 0:\n if valid_assignment is not None:\n
return []\n raise ValueError(\'There are too many valid assignments for user %r\' % (user_id, ))\n
\n valid_assignment = assignment\n
valid_assignment_list = []\n return valid_assignment\n
#context.log("Baobab_getUserAssignmentList", "assignment_list = %s" %(assignment_list,))\n
for a in assignment_list:\n
if a.getValidationState() == \'open\':\n
stop = a.getStopDate()\n
start = a.getStartDate()\n
if (stop > DateTime() or stop == None) and (start < DateTime() or start == None): \n
valid_assignment_list.append(a)\n
\n
return valid_assignment_list\n
]]></string> </value> ]]></string> </value>
...@@ -99,7 +89,7 @@ return valid_assignment_list\n ...@@ -99,7 +89,7 @@ return valid_assignment_list\n
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>Baobab_getUserAssignmentList</string> </value> <value> <string>Baobab_getUserAssignment</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
user_id = context.portal_membership.getAuthenticatedMember().getUserName()\n user_id = context.portal_membership.getAuthenticatedMember().getUserName()\n
\n \n
def getUserSiteUid(user_id):\n def getUserSiteUid(user_id):\n
return context.Baobab_getUserAssignedRootSiteList(user_id=user_id, object=1)[0].getSiteUid()\n return context.Baobab_getUserAssignedRootSite(user_id=user_id, object=1).getSiteUid()\n
\n \n
\n \n
getUserSiteUid = CachingMethod(getUserSiteUid, id=\'Baobab_getUserUserSiteUid\', cache_factory=\'erp5_ui_medium\')\n getUserSiteUid = CachingMethod(getUserSiteUid, id=\'Baobab_getUserUserSiteUid\', cache_factory=\'erp5_ui_medium\')\n
......
...@@ -81,18 +81,17 @@ ...@@ -81,18 +81,17 @@
from Products.ERP5Type.Cache import CachingMethod\n from Products.ERP5Type.Cache import CachingMethod\n
\n \n
def getVaultItemList(vault_type=None, exclude_vault_type=None,\n def getVaultItemList(vault_type=None, exclude_vault_type=None,\n
user_site=1, leaf_node=1, strict_membership=0, assignment_list=None,\n user_site=1, leaf_node=1, strict_membership=0, assignment=None,\n
site_list=None, with_base=1, all=0, first_level=0,main_agency=0,\n site_list=None, with_base=1, all=0, first_level=0,main_agency=0,\n
exclude_site_list=None,mode_test=0):\n exclude_site_list=None,mode_test=0):\n
\n \n
if vault_type is None:\n if vault_type is None:\n
organisation_list = []\n organisation_list = []\n
for assignment in assignment_list :\n
# XXX FOR NOW, LET\'S USE SITE UNTIL THE LINK BETWEEN ORGANISATIONS AND SITE HAS BEEN SORTED OUT XXX\n # XXX FOR NOW, LET\'S USE SITE UNTIL THE LINK BETWEEN ORGANISATIONS AND SITE HAS BEEN SORTED OUT XXX\n
# organisation = assignment.getDestinationValue().getMapping()\n # organisation = assignment.getDestinationValue().getMapping()\n
organisation = assignment.getSiteValue()\n organisation = assignment.getSiteValue()\n
if organisation is not None:\n if organisation is not None:\n
organisation_list.append(organisation)\n organisation_list.append(organisation)\n
\n \n
vault_type_dict = {}\n vault_type_dict = {}\n
for organisation in organisation_list:\n for organisation in organisation_list:\n
...@@ -205,9 +204,9 @@ getVaultItemList = CachingMethod(getVaultItemList, id=(\'Delivery_getVaultItemLi ...@@ -205,9 +204,9 @@ getVaultItemList = CachingMethod(getVaultItemList, id=(\'Delivery_getVaultItemLi
\n \n
\n \n
if vault_type is None:\n if vault_type is None:\n
assignment_list = context.Baobab_getUserAssignmentList()\n assignment = context.Baobab_getUserAssignment()\n
else:\n else:\n
assignment_list = None\n assignment = None\n
\n \n
erp5_site = context.getPortalObject()\n erp5_site = context.getPortalObject()\n
mode_test = 0\n mode_test = 0\n
...@@ -255,7 +254,7 @@ if exclude_user_site:\n ...@@ -255,7 +254,7 @@ if exclude_user_site:\n
\n \n
vault_list = getVaultItemList(vault_type=vault_type, exclude_vault_type=exclude_vault_type,\n vault_list = getVaultItemList(vault_type=vault_type, exclude_vault_type=exclude_vault_type,\n
user_site=user_site, leaf_node=leaf_node, strict_membership=strict_membership,\n user_site=user_site, leaf_node=leaf_node, strict_membership=strict_membership,\n
assignment_list=assignment_list, site_list=site_list, with_base=with_base, all=all,\n assignment=assignment, site_list=site_list, with_base=with_base, all=all,\n
first_level=first_level,main_agency=main_agency,exclude_site_list=exclude_site_list,\n first_level=first_level,main_agency=main_agency,exclude_site_list=exclude_site_list,\n
mode_test=mode_test)\n mode_test=mode_test)\n
\n \n
......
...@@ -269,7 +269,7 @@ ...@@ -269,7 +269,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>_text</string> </key> <key> <string>_text</string> </key>
<value> <string>python: here.Delivery_getVaultItemList(all=1,user_site=0,base_site=here.Baobab_getUserAssignedRootSiteList()[0],vault_type=\'site\',leaf_node=0, current_url=here.getDestination())</string> </value> <value> <string>python: here.Delivery_getVaultItemList(all=1,user_site=0,base_site=here.Baobab_getUserAssignedRootSite(),vault_type=\'site\',leaf_node=0, current_url=here.getDestination())</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
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