Remove short name from widget urls #546

This commit is contained in:
Daniel Grams 2023-09-12 15:37:20 +02:00
parent e0bcd269ab
commit 4b0cb3c375
5 changed files with 65 additions and 153 deletions

View File

@ -70,7 +70,7 @@
<div class="tab-pane fade py-3" id="embedWidgetModalIframeTab" role="tabpanel" aria-labelledby="embedWidgetModalIframeTabLink"> <div class="tab-pane fade py-3" id="embedWidgetModalIframeTab" role="tabpanel" aria-labelledby="embedWidgetModalIframeTabLink">
<p>Alternativ zur Einbindung per Script kann das Widget direkt per iFrame eingebunden werden.</p> <p>Alternativ zur Einbindung per Script kann das Widget direkt per iFrame eingebunden werden.</p>
<p>Kopiere den unten stehenden Code und füge ihn auf deiner Website ein. Füge den folgenden Code an der Stelle im <code>&lt;body&gt;</code> der Seite ein, wo das Widget dargestellt werden soll.</p> <p>Kopiere den unten stehenden Code und füge ihn auf deiner Website ein. Füge den folgenden Code an der Stelle im <code>&lt;body&gt;</code> der Seite ein, wo das Widget dargestellt werden soll.</p>
<textarea class="form-control text-monospace" style="font-size: 0.7rem;" disabled><iframe src="{{ url_for('widget_event_dates', au_short_name=admin_unit.short_name, _external=True) }}"></iframe></textarea> <textarea class="form-control text-monospace" style="font-size: 0.7rem;" disabled><iframe src="{{ url_for('widget_event_dates', id=admin_unit.id, _external=True) }}"></iframe></textarea>
</div> </div>
</div> </div>
</div> </div>
@ -80,13 +80,13 @@
<div class="btn-group mb-3"> <div class="btn-group mb-3">
<button type="button" class="btn btn-outline-info" data-toggle="modal" data-target="#embedWidgetModal"><i class="fa fa-wrench"></i> Installation</button> <button type="button" class="btn btn-outline-info" data-toggle="modal" data-target="#embedWidgetModal"><i class="fa fa-wrench"></i> Installation</button>
<a class="btn btn-outline-info" href="{{ url_for('widget_event_dates', au_short_name=admin_unit.short_name) }}" target="_blank" rel="noopener noreferrer"><i class="fa fa-external-link-alt"></i> Vorschau</a> <a class="btn btn-outline-info" href="{{ url_for('widget_event_dates', id=admin_unit.id) }}" target="_blank" rel="noopener noreferrer"><i class="fa fa-external-link-alt"></i> Vorschau</a>
</div> </div>
{% if admin_unit.suggestions_enabled %} {% if admin_unit.suggestions_enabled %}
<h2>{{ _('Link, um Veranstaltungen vorzuschlagen') }}</h2> <h2>{{ _('Link, um Veranstaltungen vorzuschlagen') }}</h2>
<input class="form-control text-monospace" style="font-size: 0.7rem;" disabled value="{{ url_for('event_suggestion_create_for_admin_unit', au_short_name=admin_unit.short_name, _external=True) }}" /> <input class="form-control text-monospace" style="font-size: 0.7rem;" disabled value="{{ url_for('event_suggestion_create_for_admin_unit', id=admin_unit.id, _external=True) }}" />
<p><a class="btn btn-outline-info my-2" href="{{ url_for('event_suggestion_create_for_admin_unit', au_short_name=admin_unit.short_name, _external=True) }}" target="_blank" rel="noopener noreferrer"><i class="fa fa-external-link-alt"></i> Vorschau</a></p> <p><a class="btn btn-outline-info my-2" href="{{ url_for('event_suggestion_create_for_admin_unit', id=admin_unit.id, _external=True) }}" target="_blank" rel="noopener noreferrer"><i class="fa fa-external-link-alt"></i> Vorschau</a></p>
{% endif %} {% endif %}

View File

@ -102,7 +102,7 @@
<small class="text-muted mr-2"><i class="fa fa-server"></i> {{ date.event.organizer.name }}</small> <small class="text-muted mr-2"><i class="fa fa-server"></i> {{ date.event.organizer.name }}</small>
{% endif %} {% endif %}
<small class="text-muted"><i class="fa fa-map-marker"></i> {{ date.event.event_place.name }}</small> <small class="text-muted"><i class="fa fa-map-marker"></i> {{ date.event.event_place.name }}</small>
<a href="{{ url_for('widget_event_date', au_short_name=admin_unit.short_name, id=date.id) }}" target="_blank" rel="noopener noreferrer" class="stretched-link"></a> <a href="{{ url_for('event_date', id=date.id) }}" target="_blank" rel="noopener noreferrer" class="stretched-link"></a>
</div> </div>
<div class="col-sm-4 text-right"> <div class="col-sm-4 text-right">
{% if date.event.photo_id %} {% if date.event.photo_id %}
@ -138,7 +138,7 @@
<small class="text-muted mr-2"><i class="fa fa-server"></i> {{ date.event.organizer.name }}</small> <small class="text-muted mr-2"><i class="fa fa-server"></i> {{ date.event.organizer.name }}</small>
{% endif %} {% endif %}
<small class="text-muted"><i class="fa fa-map-marker"></i> {{ date.event.event_place.name }}</small> <small class="text-muted"><i class="fa fa-map-marker"></i> {{ date.event.event_place.name }}</small>
<a href="{{ url_for('widget_event_date', au_short_name=admin_unit.short_name, id=date.id) }}" target="_blank" rel="noopener noreferrer" class="stretched-link"></a> <a href="{{ url_for('event_date', id=date.id) }}" target="_blank" rel="noopener noreferrer" class="stretched-link"></a>
</div> </div>
</div> </div>
</div> </div>

View File

@ -25,7 +25,7 @@
var req_data = form.serialize(); var req_data = form.serialize();
$.ajax({ $.ajax({
url: "{{ url_for('event_suggestion_create_for_admin_unit', au_short_name=admin_unit.short_name) }}?preview=true", url: "{{ url_for('event_suggestion_create_for_admin_unit', id=admin_unit.id) }}?preview=true",
type: "post", type: "post",
data: req_data, data: req_data,
error: function(xhr, status, error) { error: function(xhr, status, error) {

View File

@ -7,18 +7,13 @@ from sqlalchemy.sql import func
from project import app, db from project import app, db
from project.access import ( from project.access import (
admin_unit_suggestions_enabled_or_404, admin_unit_suggestions_enabled_or_404,
can_read_event_or_401,
get_admin_unit_members_with_permission, get_admin_unit_members_with_permission,
) )
from project.dateutils import get_next_full_hour from project.dateutils import get_next_full_hour
from project.forms.event_date import FindEventDateWidgetForm from project.forms.event_date import FindEventDateWidgetForm
from project.forms.event_suggestion import CreateEventSuggestionForm from project.forms.event_suggestion import CreateEventSuggestionForm
from project.jsonld import get_sd_for_event_date
from project.models import AdminUnit, EventOrganizer, EventReviewStatus, EventSuggestion from project.models import AdminUnit, EventOrganizer, EventReviewStatus, EventSuggestion
from project.services.event import ( from project.services.event import get_event_dates_query
get_event_date_with_details_or_404,
get_event_dates_query,
)
from project.services.event_suggestion import insert_event_suggestion from project.services.event_suggestion import insert_event_suggestion
from project.services.place import get_event_places from project.services.place import get_event_places
from project.services.search_params import EventSearchParams from project.services.search_params import EventSearchParams
@ -26,19 +21,15 @@ from project.views.event import get_event_category_choices
from project.views.utils import ( from project.views.utils import (
flash_errors, flash_errors,
flash_message, flash_message,
get_calendar_links_for_event_date,
get_pagination_urls, get_pagination_urls,
get_share_links,
handleSqlError, handleSqlError,
send_mails_async, send_mails_async,
) )
@app.route("/<string:au_short_name>/widget/eventdates") @app.route("/organizations/<int:id>/widget/eventdates")
def widget_event_dates(au_short_name): def widget_event_dates(id):
admin_unit = AdminUnit.query.filter( admin_unit = AdminUnit.query.get_or_404(id)
AdminUnit.short_name == au_short_name
).first_or_404()
params = EventSearchParams() params = EventSearchParams()
params.set_default_date_range() params.set_default_date_range()
@ -63,41 +54,15 @@ def widget_event_dates(au_short_name):
admin_unit=admin_unit, admin_unit=admin_unit,
params=params, params=params,
dates=dates.items, dates=dates.items,
pagination=get_pagination_urls(dates, au_short_name=au_short_name), pagination=get_pagination_urls(dates, id=id),
)
@app.route("/<string:au_short_name>/widget/eventdate/<int:id>")
def widget_event_date(au_short_name, id):
admin_unit = AdminUnit.query.filter(
AdminUnit.short_name == au_short_name
).first_or_404()
event_date = get_event_date_with_details_or_404(id)
can_read_event_or_401(event_date.event)
structured_data = app.json.dumps(get_sd_for_event_date(event_date), indent=2)
url = url_for("event_date", id=id, _external=True)
share_links = get_share_links(url, event_date.event.name)
calendar_links = get_calendar_links_for_event_date(event_date)
return render_template(
"widget/event_date/read.html",
event_date=event_date,
styles=get_styles(admin_unit),
structured_data=structured_data,
share_links=share_links,
calendar_links=calendar_links,
) )
@app.route( @app.route(
"/<string:au_short_name>/widget/event_suggestions/create", methods=("GET", "POST") "/organizations/<int:id>/widget/event_suggestions/create", methods=("GET", "POST")
) )
def event_suggestion_create_for_admin_unit(au_short_name): def event_suggestion_create_for_admin_unit(id):
admin_unit = AdminUnit.query.filter( admin_unit = AdminUnit.query.get_or_404(id)
AdminUnit.short_name == au_short_name
).first_or_404()
admin_unit_suggestions_enabled_or_404(admin_unit) admin_unit_suggestions_enabled_or_404(admin_unit)
form = CreateEventSuggestionForm() form = CreateEventSuggestionForm()

View File

@ -1,36 +1,34 @@
import pytest import pytest
from tests.seeder import Seeder
from tests.utils import UtilActions
def test_event_dates(client, seeder, utils):
def test_event_dates(client, seeder: Seeder, utils: UtilActions):
user_id, admin_unit_id = seeder.setup_base() user_id, admin_unit_id = seeder.setup_base()
seeder.create_event(admin_unit_id) seeder.create_event(admin_unit_id)
seeder.create_event(admin_unit_id, draft=True) seeder.create_event(admin_unit_id, draft=True)
au_short_name = "meinecrew"
url = utils.get_url("widget_event_dates", au_short_name=au_short_name) url = utils.get_url("widget_event_dates", id=admin_unit_id)
response = utils.get_ok(url) response = utils.get_ok(url)
utils.assert_response_contains(response, "widget.css") utils.assert_response_contains(response, "widget.css")
assert "X-Frame-Options" not in response.headers assert "X-Frame-Options" not in response.headers
event_url = utils.get_url("widget_event_date", au_short_name=au_short_name, id=1) event_url = utils.get_url("event_date", id=1)
utils.assert_response_contains(response, event_url) utils.assert_response_contains(response, event_url)
draft_url = utils.get_url("widget_event_date", au_short_name=au_short_name, id=2) draft_url = utils.get_url("event_date", id=2)
utils.assert_response_contains_not(response, draft_url) utils.assert_response_contains_not(response, draft_url)
url = utils.get_url( url = utils.get_url("widget_event_dates", id=admin_unit_id, keyword="name")
"widget_event_dates", au_short_name=au_short_name, keyword="name"
)
utils.get_ok(url) utils.get_ok(url)
url = utils.get_url( url = utils.get_url("widget_event_dates", id=admin_unit_id, category_id=1)
"widget_event_dates", au_short_name=au_short_name, category_id=1
)
utils.get_ok(url) utils.get_ok(url)
url = utils.get_url( url = utils.get_url(
"widget_event_dates", "widget_event_dates",
au_short_name=au_short_name, id=admin_unit_id,
coordinate="51.9077888,10.4333312", coordinate="51.9077888,10.4333312",
distance=500, distance=500,
) )
@ -38,7 +36,7 @@ def test_event_dates(client, seeder, utils):
url = utils.get_url( url = utils.get_url(
"widget_event_dates", "widget_event_dates",
au_short_name=au_short_name, id=admin_unit_id,
date_from="2020-10-03", date_from="2020-10-03",
date_to="2021-10-03", date_to="2021-10-03",
) )
@ -46,7 +44,7 @@ def test_event_dates(client, seeder, utils):
url = utils.get_url( url = utils.get_url(
"widget_event_dates", "widget_event_dates",
au_short_name=au_short_name, id=admin_unit_id,
s_ft="Verdana", s_ft="Verdana",
s_bg="#eceef0", s_bg="#eceef0",
s_pr="#b09641", s_pr="#b09641",
@ -55,15 +53,12 @@ def test_event_dates(client, seeder, utils):
utils.get_ok(url) utils.get_ok(url)
# Unverified # Unverified
au_short_name = "unverifiedcrew" _, unverified_admin_unit_id, unverified_id = seeder.create_event_unverified()
_, _, unverified_id = seeder.create_event_unverified() url = utils.get_url("widget_event_dates", id=unverified_admin_unit_id)
url = utils.get_url("widget_event_dates", au_short_name=au_short_name)
response = utils.get_ok(url) response = utils.get_ok(url)
unverified_date_id = seeder.get_event_date_id(unverified_id) unverified_date_id = seeder.get_event_date_id(unverified_id)
unverified_url = utils.get_url( unverified_url = utils.get_url("event_date", id=unverified_date_id)
"widget_event_date", au_short_name=au_short_name, id=unverified_date_id
)
utils.assert_response_contains_not(response, unverified_url) utils.assert_response_contains_not(response, unverified_url)
@ -71,7 +66,6 @@ def test_event_dates_oneDay(client, seeder, utils):
from project.dateutils import create_berlin_date from project.dateutils import create_berlin_date
user_id, admin_unit_id = seeder.setup_base() user_id, admin_unit_id = seeder.setup_base()
au_short_name = "meinecrew"
start = create_berlin_date(2020, 10, 3, 10) start = create_berlin_date(2020, 10, 3, 10)
end = create_berlin_date(2020, 10, 3, 11) end = create_berlin_date(2020, 10, 3, 11)
@ -80,7 +74,7 @@ def test_event_dates_oneDay(client, seeder, utils):
url = utils.get_url( url = utils.get_url(
"widget_event_dates", "widget_event_dates",
au_short_name=au_short_name, id=admin_unit_id,
date_from="2020-10-03", date_from="2020-10-03",
date_to="2020-10-03", date_to="2020-10-03",
) )
@ -90,63 +84,12 @@ def test_event_dates_oneDay(client, seeder, utils):
def test_event_dates_noneDescription(client, seeder, utils): def test_event_dates_noneDescription(client, seeder, utils):
_, admin_unit_id = seeder.setup_base() _, admin_unit_id = seeder.setup_base()
au_short_name = "meinecrew"
seeder.create_event(admin_unit_id, description=None) seeder.create_event(admin_unit_id, description=None)
url = utils.get_url("widget_event_dates", au_short_name=au_short_name) url = utils.get_url("widget_event_dates", id=admin_unit_id)
utils.get_ok(url) utils.get_ok(url)
def test_event_date(client, seeder, utils, app, db):
user_id, admin_unit_id = seeder.setup_base(log_in=False)
seeder.create_event(admin_unit_id)
au_short_name = "meinecrew"
with app.app_context():
from colour import Color
from project.models import AdminUnit
admin_unit = db.session.get(AdminUnit, admin_unit_id)
admin_unit.widget_font = "Verdana"
admin_unit.widget_background_color = Color("#eceef0")
admin_unit.widget_primary_color = Color("#b09641")
admin_unit.widget_link_color = Color("#7b2424")
db.session.commit()
url = utils.get_url("widget_event_date", au_short_name=au_short_name, id=1)
response = utils.get_ok(url)
utils.assert_response_contains(response, "widget.css")
seeder.create_event(admin_unit_id, draft=True)
url = utils.get_url("widget_event_date", au_short_name=au_short_name, id=2)
response = utils.get(url)
utils.assert_response_unauthorized(response)
# Unverified
au_short_name = "unverifiedcrew"
_, _, unverified_id = seeder.create_event_unverified()
unverified_date_id = seeder.get_event_date_id(unverified_id)
url = utils.get_url(
"widget_event_date", au_short_name=au_short_name, id=unverified_date_id
)
utils.assert_response_unauthorized(response)
def test_event_date_co_organizers(client, seeder, utils, app, db):
user_id, admin_unit_id = seeder.setup_base(log_in=False)
event_id, organizer_a_id, organizer_b_id = seeder.create_event_with_co_organizers(
admin_unit_id
)
au_short_name = "meinecrew"
url = utils.get_url("widget_event_date", au_short_name=au_short_name, id=event_id)
response = utils.get(url)
response = utils.get_ok(url)
utils.assert_response_contains(response, "Organizer A")
utils.assert_response_contains(response, "Organizer B")
def get_create_data(): def get_create_data():
return { return {
"accept_tos": "y", "accept_tos": "y",
@ -160,6 +103,26 @@ def get_create_data():
} }
def test_event_dates_colors(client, seeder, utils, app, db):
user_id, admin_unit_id = seeder.setup_base(log_in=False)
seeder.create_event(admin_unit_id)
with app.app_context():
from colour import Color
from project.models import AdminUnit
admin_unit = db.session.get(AdminUnit, admin_unit_id)
admin_unit.widget_font = "Verdana"
admin_unit.widget_background_color = Color("#eceef0")
admin_unit.widget_primary_color = Color("#b09641")
admin_unit.widget_link_color = Color("#7b2424")
db.session.commit()
url = utils.get_url("widget_event_dates", id=admin_unit_id)
utils.get_ok(url)
@pytest.mark.parametrize("db_error", [True, False]) @pytest.mark.parametrize("db_error", [True, False])
@pytest.mark.parametrize("free_text", [True, False]) @pytest.mark.parametrize("free_text", [True, False])
@pytest.mark.parametrize("free_text_suffix", [True, False]) @pytest.mark.parametrize("free_text_suffix", [True, False])
@ -177,11 +140,8 @@ def test_event_suggestion_create_for_admin_unit(
): ):
user_id = seeder.create_user() user_id = seeder.create_user()
admin_unit_id = seeder.create_admin_unit(user_id, "Meine Crew") admin_unit_id = seeder.create_admin_unit(user_id, "Meine Crew")
au_short_name = "meinecrew"
url = utils.get_url( url = utils.get_url("event_suggestion_create_for_admin_unit", id=admin_unit_id)
"event_suggestion_create_for_admin_unit", au_short_name=au_short_name
)
response = utils.get_ok(url) response = utils.get_ok(url)
utils.assert_response_contains(response, "widget.css") utils.assert_response_contains(response, "widget.css")
@ -252,11 +212,8 @@ def test_event_suggestion_create_for_admin_unit_allday(
): ):
user_id = seeder.create_user() user_id = seeder.create_user()
admin_unit_id = seeder.create_admin_unit(user_id, "Meine Crew") admin_unit_id = seeder.create_admin_unit(user_id, "Meine Crew")
au_short_name = "meinecrew"
url = utils.get_url( url = utils.get_url("event_suggestion_create_for_admin_unit", id=admin_unit_id)
"event_suggestion_create_for_admin_unit", au_short_name=au_short_name
)
response = utils.get_ok(url) response = utils.get_ok(url)
data = get_create_data() data = get_create_data()
@ -285,15 +242,12 @@ def test_event_suggestion_create_for_admin_unit_allday(
def test_event_suggestion_create_for_admin_unit_startAfterEnd( def test_event_suggestion_create_for_admin_unit_startAfterEnd(
client, app, seeder, utils, mocker client, app, seeder: Seeder, utils: UtilActions, mocker
): ):
user_id = seeder.create_user() user_id = seeder.create_user()
seeder.create_admin_unit(user_id, "Meine Crew") admin_unit_id = seeder.create_admin_unit(user_id, "Meine Crew")
au_short_name = "meinecrew"
url = utils.get_url( url = utils.get_url("event_suggestion_create_for_admin_unit", id=admin_unit_id)
"event_suggestion_create_for_admin_unit", au_short_name=au_short_name
)
response = utils.get_ok(url) response = utils.get_ok(url)
data = get_create_data() data = get_create_data()
@ -314,12 +268,9 @@ def test_event_suggestion_create_for_admin_unit_emptyFreeText(
client, app, seeder, utils, mocker client, app, seeder, utils, mocker
): ):
user_id = seeder.create_user() user_id = seeder.create_user()
seeder.create_admin_unit(user_id, "Meine Crew") admin_unit_id = seeder.create_admin_unit(user_id, "Meine Crew")
au_short_name = "meinecrew"
url = utils.get_url( url = utils.get_url("event_suggestion_create_for_admin_unit", id=admin_unit_id)
"event_suggestion_create_for_admin_unit", au_short_name=au_short_name
)
response = utils.get_ok(url) response = utils.get_ok(url)
data = get_create_data() data = get_create_data()
@ -338,12 +289,9 @@ def test_event_suggestion_create_for_admin_unit_invalidEventPlaceId(
client, app, seeder, utils, mocker client, app, seeder, utils, mocker
): ):
user_id = seeder.create_user() user_id = seeder.create_user()
seeder.create_admin_unit(user_id, "Meine Crew") admin_unit_id = seeder.create_admin_unit(user_id, "Meine Crew")
au_short_name = "meinecrew"
url = utils.get_url( url = utils.get_url("event_suggestion_create_for_admin_unit", id=admin_unit_id)
"event_suggestion_create_for_admin_unit", au_short_name=au_short_name
)
response = utils.get_ok(url) response = utils.get_ok(url)
data = get_create_data() data = get_create_data()
@ -359,11 +307,10 @@ def test_event_suggestion_create_for_admin_unit_invalidEventPlaceId(
def test_event_suggestion_create_for_admin_unit_notEnabled(client, app, seeder, utils): def test_event_suggestion_create_for_admin_unit_notEnabled(client, app, seeder, utils):
user_id = seeder.create_user() user_id = seeder.create_user()
seeder.create_admin_unit(user_id, "Meine Crew", suggestions_enabled=False) admin_unit_id = seeder.create_admin_unit(
au_short_name = "meinecrew" user_id, "Meine Crew", suggestions_enabled=False
url = utils.get_url(
"event_suggestion_create_for_admin_unit", au_short_name=au_short_name
) )
url = utils.get_url("event_suggestion_create_for_admin_unit", id=admin_unit_id)
response = utils.get(url) response = utils.get(url)
utils.assert_response_notFound(response) utils.assert_response_notFound(response)