Commit 1aaab8ec authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_subscription_request: Speed up existing user search

As the query is done by annonymous with proxy role, so it is faster to just skip the usage of security_uids
parent b4eac683
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from lxml import etree
from zExceptions import Unauthorized
from zLOG import LOG, INFO
def SubscriptionRequest_saveTransactionalUser(self, person=None):
......@@ -32,3 +34,25 @@ def SubscriptionCondition_renderParameter(self, amount=0, **kw):
return self.getTextContent()
def SubscriptionRequest_searchExistingUserByEmail(self, email, REQUEST=None):
if REQUEST is not None:
raise Unauthorized
portal = self.getPortalObject()
erp5_login_list = portal.portal_catalog.unrestrictedSearchResults(
portal_type="ERP5 Login",
reference=email,
validation_state="validated")
if len(erp5_login_list):
return erp5_login_list[0].getParentValue()
# Already has login with this.
person_list = portal.portal_catalog.unrestrictedSearchResults(
portal_type="Person",
default_email_text=email,
validation_state="validated")
if len(person_list):
return person_list[0]
......@@ -13,16 +13,7 @@ if person is not None:
return person, False
# Already has login with this.
erp5_login = portal.portal_catalog.getResultValue(portal_type="ERP5 Login",
reference=email, validation_state="validated")
if erp5_login is not None:
return erp5_login.getParentValue(), False
# Already has login with this.
person = portal.portal_catalog.getResultValue(
portal_type="Person",
default_email_text=email,
validation_state="validated")
person = context.SubscriptionRequest_searchExistingUserByEmail(email)
if person is not None:
return person, False
......@@ -42,6 +33,7 @@ login = person.newContent(
login.validate()
# The rest of the information will be used later.
person.SubscriptionRequest_saveTransactionalUser(person)
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>SubscriptionRequest_searchExistingUserByEmail</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>SlapOSSubscriptionRequest</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SubscriptionRequest_searchExistingUserByEmail</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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