update to "new" tracking code mechanism (#13875)
This now requires the theme to declare the "include-tracking-code-form" keyword.
This commit is contained in:
parent
6f4cabac00
commit
dd9903d631
|
@ -767,7 +767,7 @@ class AlternateRootDirectory(OldRootDirectory):
|
|||
'accessibility', 'contact', 'help',
|
||||
'myspace', 'services', 'agenda', 'categories', 'user',
|
||||
('tmp-upload', 'tmp_upload'), 'json', '__version__',
|
||||
'themes', 'pages', 'payment', 'invoices', 'accesscode', 'roles',
|
||||
'themes', 'pages', 'payment', 'invoices', 'roles',
|
||||
'api', 'code', 'fargo', 'tryauth', 'auth', 'preview',
|
||||
('reload-top', 'reload_top'), 'static',
|
||||
('i18n.js', 'i18n_js')]
|
||||
|
@ -1094,11 +1094,12 @@ class AlternateRootDirectory(OldRootDirectory):
|
|||
r = TemplateIO(html=True)
|
||||
root_url = get_publisher().get_root_url()
|
||||
|
||||
if self.has_anonymous_access_codes():
|
||||
r += htmltext('<form id="follow-form" action="%saccesscode">') % root_url
|
||||
r += htmltext('<h3>%s</h3>') % _('Tracking')
|
||||
r += htmltext('<label>%s</label> ') % _('Code:')
|
||||
r += htmltext('<input name="code" size="10"/>')
|
||||
if self.has_anonymous_access_codes() and path == [''] and (
|
||||
'include-tracking-code-form' in get_response().filter.get('keywords', [])):
|
||||
r += htmltext('<form id="follow-form" action="%scode/load">') % root_url
|
||||
r += htmltext('<h3>%s</h3>') % _('Tracking code')
|
||||
r += htmltext('<input size="12" name="code" placeholder="%s"/>') % _('ex: RPQDFVCD')
|
||||
r += htmltext('<input type="submit" value="%s"/>') % _('Load')
|
||||
r += htmltext('</form>')
|
||||
|
||||
r += self.links()
|
||||
|
@ -1143,33 +1144,7 @@ class AlternateRootDirectory(OldRootDirectory):
|
|||
return None
|
||||
|
||||
def has_anonymous_access_codes(self):
|
||||
for workflow in Workflow.select():
|
||||
for wfstatus in workflow.possible_status:
|
||||
for wfitem in wfstatus.items:
|
||||
if wfitem.key == 'create-anonymous-access-code':
|
||||
return True
|
||||
return False
|
||||
|
||||
def accesscode(self):
|
||||
code = get_request().form.get('code')
|
||||
if not code:
|
||||
return redirect(get_publisher().get_root_url())
|
||||
try:
|
||||
token = Token.get(code)
|
||||
except KeyError:
|
||||
return redirect(get_publisher().get_root_url())
|
||||
if token.type != 'anonymous-access-code':
|
||||
return redirect(get_publisher().get_root_url())
|
||||
formdef_urlname, formdata_id = token.formdata_reference
|
||||
try:
|
||||
formdata = FormDef.get_by_urlname(formdef_urlname).data_class().get(formdata_id)
|
||||
except KeyError:
|
||||
return redirect(get_publisher().get_root_url())
|
||||
session = get_session()
|
||||
if not hasattr(session, '_wf_anonymous_access_authorized'):
|
||||
session._wf_anonymous_access_authorized = []
|
||||
session._wf_anonymous_access_authorized.append(formdata.get_url())
|
||||
return redirect(formdata.get_url() + 'access/')
|
||||
return any((x for x in FormDef.select() if x.enable_tracking_codes))
|
||||
|
||||
def links(self):
|
||||
links = Link.select()
|
||||
|
|
Reference in New Issue