Commit 9985bb44 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_accounting: Use script to fetch organisation as SHADOW User

   Organisation is usually linked as Source Section or Destination
   Section.

   The user don't have access to the Organisations so use Shadow User
   (via script) to get the required information for the printout.
parent 5f8786f3
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
assert context.getPortalType() == 'Sale Invoice Transaction'
# The source_section is usually not accessible from the user,
# So to not leak information, we rely on Shadow User to retrive
# the information rather them flex security.
def wrapShadowFunction(invoice, base_category):
document_list = invoice.getValueList(base_category)
if not document_list:
return {'title': ''}
document = document_list[0]
printout_dict = {
'title': document.getTitle(),
'default_address': document.getDefaultAddressText(),
'default_region': document.getDefaultRegionTitle()
}
if document.getPortalType() == 'Organisation':
printout_dict.update({
"registration_code": document.getCorporateRegistrationCode(),
"vat_code": document.getVatCode(),
'corportate_name': document.getCorporateName()
})
return printout_dict
if person is not None:
return person.Person_restrictMethodAsShadowUser(
shadow_document=person,
callable_object=wrapShadowFunction,
argument_list=[context, base_category])
return wrapShadowFunction(context, base_category)
<?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, REQUEST=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SaleInvoiceTransaction_getBaseCategoryDictForPrintout</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -126,6 +126,7 @@ table.resource td { font-size: 90% }
/* aside h1 { border: none; border-width: 0 0 1px; margin: 0 0 1em; }*/
aside h1 { text-align: left; padding-bottom: 10px;}
aside {margin-top: 20px;}
aside p.note { font-size: 75%; padding-top: 10px; padding-bottom: 10px }
/* bottom */
......
......@@ -154,6 +154,7 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template):
'slapos_accounting/PaymentTransaction_acceptDepositPayment',
'slapos_accounting/PaymentTransaction_getExternalPaymentId',
'slapos_accounting/PaymentTransaction_postOrderBuild',
'slapos_accounting/SaleInvoiceTransaction_getBaseCategoryDictForPrintout',
'slapos_accounting/SaleInvoiceTransaction_init',
'slapos_accounting/SaleInvoiceTransaction_isTotalPriceEqualAccounting',
'slapos_accounting/SaleInvoiceTransaction_isTotalPriceMatchingSalePackingList',
......
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