Commit 849a2d1e authored by Rafael Monnerat's avatar Rafael Monnerat

erp5_oauth_facebook_login: Use unrestrictedSearchResults to avoid security_uid (Speed up)

When a script with manager proxy role is called from anonymous context, it include a HUGE list of security_uids, use unrestrictedSearchResults skips the unecessary usage of security_uids on catalog.
parent ec360085
......@@ -2,6 +2,7 @@ import facebook
from ZTUtils import make_query
from Products.ERP5Security.ERP5ExternalOauth2ExtractionPlugin import getFacebookUserEntry
from zExceptions import Unauthorized
def _getFacebookClientIdAndSecretKey(portal, reference="default"):
"""Returns facebook client id and secret key.
......@@ -37,5 +38,21 @@ def getAccessTokenFromCode(self, code, redirect_uri):
code=code, redirect_uri=redirect_uri,
app_id=client_id, app_secret=secret_key)
def unrestrictedSearchFacebookConnector(self):
return self.getPortalObject().portal_catalog.unrestrictedSearchResults(
portal_type="Facebook Connector",
reference="default",
validation_state="validated",
limit=2)
def unrestrictedSearchFacebookLogin(self, login, REQUEST=None):
if REQUEST is not None:
raise Unauthorized
return self.getPortalObject().portal_catalog.unrestrictedSearchResults(
portal_type="Facebook Login",
reference=login,
validation_state="validated", limit=1)
def getUserEntry(token):
return getFacebookUserEntry(token)
<?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>unrestrictedSearchFacebookConnector</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>FacebookLoginUtility</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_getFacebookConnector</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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>unrestrictedSearchFacebookLogin</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>FacebookLoginUtility</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_getFacebookLogin</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -3,12 +3,12 @@ from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal_catalog = context.getPortalObject().portal_catalog
login = context.ERP5Site_getFacebookLogin(login)
login = portal_catalog.getResultValue(
portal_type="Facebook Login",
reference=login,
validation_state="validated")
if login is None:
return login
if login is not None:
return login.getParentValue().getRelativeUrl()
if len(login) > 1:
raise ValueError("Duplicated User")
return login[0].getParentValue().getRelativeUrl()
......@@ -115,7 +115,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Faceook Connector</string> </value>
<value> <string>Facebook Connector</string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
......
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