manager: fix invalid link for templated ICS URL (#68248)
This commit is contained in:
parent
bca73caaea
commit
a2e89316d2
|
@ -2452,9 +2452,12 @@ class TimePeriodExceptionSource(models.Model):
|
|||
self.enabled = False
|
||||
self.save()
|
||||
|
||||
def render_ics_url(self):
|
||||
return Template(self.ics_url).render(Context(settings.TEMPLATE_VARS))
|
||||
|
||||
def _check_ics_content(self):
|
||||
if self.ics_url:
|
||||
ics_url = Template(self.ics_url).render(Context(settings.TEMPLATE_VARS))
|
||||
ics_url = self.render_ics_url()
|
||||
try:
|
||||
response = requests.get(ics_url, proxies=settings.REQUESTS_PROXIES)
|
||||
response.raise_for_status()
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<ul class="objects-list single-links">
|
||||
{% for object in exception_sources %}
|
||||
<li>
|
||||
<a {% if not object.enabled %}class="disabled"{% endif %} title="{{ object }}" {% if object.ics_url %}href="{{ object }}"{% endif %}>{{ object|truncatechars:50 }}</a>
|
||||
<a {% if not object.enabled %}class="disabled"{% endif %} title="{{ object }}" {% if object.ics_url %}href="{{ object.render_ics_url }}"{% endif %}>{{ object|truncatechars:50 }}</a>
|
||||
{% if object.ics_filename %}
|
||||
<a rel="popup" class="link-action-icon refresh" href="{% url 'chrono-manager-time-period-exception-source-replace' object.pk %}">{% trans "replace" %}</a>
|
||||
{% elif object.ics_url %}
|
||||
|
|
|
@ -798,6 +798,11 @@ END:VCALENDAR"""
|
|||
assert mocked_get.call_args.args[0] == 'https://passerelle.publik.love/holidays/test/holidays.ics'
|
||||
|
||||
resp = app.get('/manage/agendas/desk/%s/import-exceptions-from-ics/' % desk.pk)
|
||||
assert (
|
||||
resp.pyquery('a[title="{{ passerelle_url }}holidays/test/holidays.ics"]').attr('href')
|
||||
== 'https://passerelle.publik.love/holidays/test/holidays.ics'
|
||||
)
|
||||
|
||||
resp.form['ics_url'] = '{{ unknown }}holidays/test/holidays.ics'
|
||||
resp = resp.form.submit(status=200)
|
||||
assert 'Enter a valid URL.' in resp.text
|
||||
|
|
Loading…
Reference in New Issue