Projet

Général

Profil

0001-update-to-new-tracking-code-mechanism-13875.patch

Frédéric Péters, 11 novembre 2016 15:09

Télécharger (3,44 ko)

Voir les différences:

Subject: [PATCH] update to "new" tracking code mechanism (#13875)

 extra/modules/root.py | 40 +++++++---------------------------------
 1 file changed, 7 insertions(+), 33 deletions(-)
extra/modules/root.py
767 767
            'accessibility', 'contact', 'help',
768 768
            'myspace', 'services', 'agenda', 'categories', 'user',
769 769
            ('tmp-upload', 'tmp_upload'), 'json', '__version__',
770
            'themes', 'pages', 'payment', 'invoices', 'accesscode', 'roles',
770
            'themes', 'pages', 'payment', 'invoices', 'roles',
771 771
            'api', 'code', 'fargo', 'tryauth', 'auth', 'preview',
772 772
            ('reload-top', 'reload_top'), 'static',
773 773
            ('i18n.js', 'i18n_js')]
......
1094 1094
        r = TemplateIO(html=True)
1095 1095
        root_url = get_publisher().get_root_url()
1096 1096

  
1097
        if self.has_anonymous_access_codes():
1098
            r += htmltext('<form id="follow-form" action="%saccesscode">') % root_url
1099
            r += htmltext('<h3>%s</h3>') % _('Tracking')
1100
            r += htmltext('<label>%s</label> ') % _('Code:')
1101
            r += htmltext('<input name="code" size="10"/>')
1097
        if self.has_anonymous_access_codes() and path == ['']:
1098
            r += htmltext('<form id="follow-form" action="%scode/load">') % root_url
1099
            r += htmltext('<h3>%s</h3>') % _('Tracking code')
1100
            r += htmltext('<input size="12" name="code" placeholder="%s"/>') % _('ex: RPQDFVCD')
1101
            r += htmltext('<input type="submit" value="%s"/>') % _('Load')
1102 1102
            r += htmltext('</form>')
1103 1103

  
1104 1104
        r += self.links()
......
1143 1143
        return None
1144 1144

  
1145 1145
    def has_anonymous_access_codes(self):
1146
        for workflow in Workflow.select():
1147
            for wfstatus in workflow.possible_status:
1148
                for wfitem in wfstatus.items:
1149
                    if wfitem.key == 'create-anonymous-access-code':
1150
                        return True
1151
        return False
1152

  
1153
    def accesscode(self):
1154
        code = get_request().form.get('code')
1155
        if not code:
1156
            return redirect(get_publisher().get_root_url())
1157
        try:
1158
            token = Token.get(code)
1159
        except KeyError:
1160
            return redirect(get_publisher().get_root_url())
1161
        if token.type != 'anonymous-access-code':
1162
            return redirect(get_publisher().get_root_url())
1163
        formdef_urlname, formdata_id = token.formdata_reference
1164
        try:
1165
            formdata = FormDef.get_by_urlname(formdef_urlname).data_class().get(formdata_id)
1166
        except KeyError:
1167
            return redirect(get_publisher().get_root_url())
1168
        session = get_session()
1169
        if not hasattr(session, '_wf_anonymous_access_authorized'):
1170
            session._wf_anonymous_access_authorized = []
1171
        session._wf_anonymous_access_authorized.append(formdata.get_url())
1172
        return redirect(formdata.get_url() + 'access/')
1146
        return any((x for x in FormDef.select() if x.enable_tracking_codes))
1173 1147

  
1174 1148
    def links(self):
1175 1149
        links = Link.select()
1176
-