misc: add {% temporary_access_button %} tag (#78135) #921
|
@ -4316,6 +4316,51 @@ def test_card_email_actions(pub, emails):
|
|||
assert carddata.status == 'wf-accepted'
|
||||
|
||||
|
||||
def test_email_temporary_form_button(pub, emails):
|
||||
pub.role_class.wipe()
|
||||
role = pub.role_class(name='xxx')
|
||||
role.emails_to_members = True
|
||||
role.store()
|
||||
user = create_user(pub)
|
||||
user.roles = [role.id]
|
||||
user.store()
|
||||
|
||||
workflow = Workflow.get_default_workflow()
|
||||
workflow.id = '2'
|
||||
|
||||
workflow.possible_status[0].items[0].subject = None # disable first mail
|
||||
workflow.possible_status[0].items[1].subject = 'New form'
|
||||
workflow.possible_status[0].items[1].body = 'Hello;\n{% temporary_access_button label="Open" %}\nAdiós.'
|
||||
workflow.possible_status[0].items[1].to = ['test@example.net'] # force recipient
|
||||
workflow.possible_status[1].items[1].identifier = 'do-accept'
|
||||
workflow.store()
|
||||
|
||||
formdef = FormDef()
|
||||
formdef.name = 'test email form button'
|
||||
formdef.fields = []
|
||||
formdef.workflow_id = workflow.id
|
||||
formdef.workflow_roles = {'_receiver': role.id}
|
||||
formdef.enable_tracking_codes = True
|
||||
formdef.store()
|
||||
formdef.data_class().wipe()
|
||||
|
||||
formdata = formdef.data_class()()
|
||||
formdata.just_created()
|
||||
formdata.store()
|
||||
formdata.perform_workflow()
|
||||
formdata.store()
|
||||
|
||||
email_data = emails.get('New form')
|
||||
form_url = re.findall(r'\shttp.*\s', email_data['payload'])[0].strip()
|
||||
if docutils:
|
||||
assert len(email_data['payloads']) == 2
|
||||
assert form_url in force_str(email_data['payloads'][1])
|
||||
|
||||
app = get_app(pub)
|
||||
resp = app.get(form_url).follow()
|
||||
assert 'The form has been recorded' in resp.text
|
||||
|
||||
|
||||
def test_manager_public_access(pub):
|
||||
user, manager = create_user_and_admin(pub)
|
||||
|
||||
|
|
|
@ -246,10 +246,14 @@ def email(
|
|||
subject = subject.replace('\n', ' ') # make sure newlines are stripped
|
||||
|
||||
# handle action links/buttons
|
||||
url_button_re = re.compile(r'---===BUTTON:URL:(?P<url>https?:\/\/.*?):(?P<label>.*?)===---')
|
||||
button_re = re.compile(r'---===BUTTON:(?P<token>[a-zA-Z0-9]*):(?P<label>.*?)===---')
|
||||
|
||||
def get_action_url(match):
|
||||
return '%s/actions/%s/' % (get_publisher().get_frontoffice_url(), match.group('token'))
|
||||
match_dict = match.groupdict()
|
||||
if 'url' in match_dict:
|
||||
return match_dict.get('url')
|
||||
return '%s/actions/%s/' % (get_publisher().get_frontoffice_url(), match_dict.get('token'))
|
||||
|
||||
def text_button(match):
|
||||
return '[%s] %s' % (match.group('label'), get_action_url(match))
|
||||
|
@ -262,6 +266,8 @@ def email(
|
|||
return force_str(render_to_string('qommon/email_button_link.html', context))
|
||||
|
||||
has_button = '---===BUTTON' in (text_body or html_body)
|
||||
text_body = url_button_re.sub(text_button, text_body) if text_body else None
|
||||
html_body = url_button_re.sub(html_button, html_body) if html_body else None
|
||||
text_body = button_re.sub(text_button, text_body) if text_body else None
|
||||
html_body = button_re.sub(html_button, html_body) if html_body else None
|
||||
|
||||
|
|
|
@ -526,6 +526,16 @@ def action_button(context, action_id, label, delay=3, message=None, done_message
|
|||
return '---===BUTTON:%s:%s===---' % (token.id, label)
|
||||
|
||||
|
||||
@register.simple_tag(takes_context=True)
|
||||
def temporary_access_button(
|
||||
context, label, days=None, hours=None, minutes=None, seconds=None, bypass_checks=False
|
||||
):
|
||||
url = temporary_access_url(context, days=days, hours=hours, minutes=minutes, bypass_checks=bypass_checks)
|
||||
if not url:
|
||||
return ''
|
||||
return '---===BUTTON:URL:%s:%s===---' % (url, label)
|
||||
|
||||
|
||||
@register.filter
|
||||
def add(term1, term2):
|
||||
'''replace the "add" native django filter'''
|
||||
|
|
Loading…
Reference in New Issue