Merge pull request #547 from eventcally/issues/546

Remove short name from widget urls #546
This commit is contained in:
Daniel Grams 2023-09-12 16:28:54 +02:00 committed by GitHub
commit 2183fc96cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 67 additions and 155 deletions

View File

@ -2,7 +2,7 @@ describe("Widget", () => {
it("event dates", () => {
cy.createAdminUnit().then(function (adminUnitId) {
cy.createEvent(adminUnitId).then(function (eventId) {
cy.visit("/meinecrew/widget/eventdates");
cy.visit("/organizations/" + adminUnitId + "/widget/eventdates");
cy.screenshotDatepicker("#date_from-user");
cy.screenshot("eventdates");
@ -34,7 +34,7 @@ describe("Widget", () => {
() => {
cy.createAdminUnit().then(function (adminUnitId) {
// Start
cy.visit("/meinecrew/widget/event_suggestions/create");
cy.visit("/organizations/" + adminUnitId + "/widget/event_suggestions/create");
cy.wait(1000); // Wait for jQuery to load
cy.get(".wizard-next:visible").click();

View File

@ -70,7 +70,7 @@
<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>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>
@ -80,13 +80,13 @@
<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>
<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>
{% if admin_unit.suggestions_enabled %}
<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) }}" />
<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>
<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', id=admin_unit.id, _external=True) }}" target="_blank" rel="noopener noreferrer"><i class="fa fa-external-link-alt"></i> Vorschau</a></p>
{% endif %}

View File

@ -102,7 +102,7 @@
<small class="text-muted mr-2"><i class="fa fa-server"></i> {{ date.event.organizer.name }}</small>
{% endif %}
<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 class="col-sm-4 text-right">
{% 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>
{% endif %}
<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>

View File

@ -25,7 +25,7 @@
var req_data = form.serialize();
$.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",
data: req_data,
error: function(xhr, status, error) {

View File

@ -7,18 +7,13 @@ from sqlalchemy.sql import func
from project import app, db
from project.access import (
admin_unit_suggestions_enabled_or_404,
can_read_event_or_401,
get_admin_unit_members_with_permission,
)
from project.dateutils import get_next_full_hour
from project.forms.event_date import FindEventDateWidgetForm
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.services.event import (
get_event_date_with_details_or_404,
get_event_dates_query,
)
from project.services.event import get_event_dates_query
from project.services.event_suggestion import insert_event_suggestion
from project.services.place import get_event_places
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 (
flash_errors,
flash_message,
get_calendar_links_for_event_date,
get_pagination_urls,
get_share_links,
handleSqlError,
send_mails_async,
)
@app.route("/<string:au_short_name>/widget/eventdates")
def widget_event_dates(au_short_name):
admin_unit = AdminUnit.query.filter(
AdminUnit.short_name == au_short_name
).first_or_404()
@app.route("/organizations/<int:id>/widget/eventdates")
def widget_event_dates(id):
admin_unit = AdminUnit.query.get_or_404(id)
params = EventSearchParams()
params.set_default_date_range()
@ -63,41 +54,15 @@ def widget_event_dates(au_short_name):
admin_unit=admin_unit,
params=params,
dates=dates.items,
pagination=get_pagination_urls(dates, au_short_name=au_short_name),
)
@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,
pagination=get_pagination_urls(dates, id=id),
)
@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):
admin_unit = AdminUnit.query.filter(
AdminUnit.short_name == au_short_name
).first_or_404()
def event_suggestion_create_for_admin_unit(id):
admin_unit = AdminUnit.query.get_or_404(id)
admin_unit_suggestions_enabled_or_404(admin_unit)
form = CreateEventSuggestionForm()

View File

@ -1,36 +1,34 @@
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()
seeder.create_event(admin_unit_id)
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)
utils.assert_response_contains(response, "widget.css")
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)
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)
url = utils.get_url(
"widget_event_dates", au_short_name=au_short_name, keyword="name"
)
url = utils.get_url("widget_event_dates", id=admin_unit_id, keyword="name")
utils.get_ok(url)
url = utils.get_url(
"widget_event_dates", au_short_name=au_short_name, category_id=1
)
url = utils.get_url("widget_event_dates", id=admin_unit_id, category_id=1)
utils.get_ok(url)
url = utils.get_url(
"widget_event_dates",
au_short_name=au_short_name,
id=admin_unit_id,
coordinate="51.9077888,10.4333312",
distance=500,
)
@ -38,7 +36,7 @@ def test_event_dates(client, seeder, utils):
url = utils.get_url(
"widget_event_dates",
au_short_name=au_short_name,
id=admin_unit_id,
date_from="2020-10-03",
date_to="2021-10-03",
)
@ -46,7 +44,7 @@ def test_event_dates(client, seeder, utils):
url = utils.get_url(
"widget_event_dates",
au_short_name=au_short_name,
id=admin_unit_id,
s_ft="Verdana",
s_bg="#eceef0",
s_pr="#b09641",
@ -55,15 +53,12 @@ def test_event_dates(client, seeder, utils):
utils.get_ok(url)
# Unverified
au_short_name = "unverifiedcrew"
_, _, unverified_id = seeder.create_event_unverified()
url = utils.get_url("widget_event_dates", au_short_name=au_short_name)
_, unverified_admin_unit_id, unverified_id = seeder.create_event_unverified()
url = utils.get_url("widget_event_dates", id=unverified_admin_unit_id)
response = utils.get_ok(url)
unverified_date_id = seeder.get_event_date_id(unverified_id)
unverified_url = utils.get_url(
"widget_event_date", au_short_name=au_short_name, id=unverified_date_id
)
unverified_url = utils.get_url("event_date", id=unverified_date_id)
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
user_id, admin_unit_id = seeder.setup_base()
au_short_name = "meinecrew"
start = create_berlin_date(2020, 10, 3, 10)
end = create_berlin_date(2020, 10, 3, 11)
@ -80,7 +74,7 @@ def test_event_dates_oneDay(client, seeder, utils):
url = utils.get_url(
"widget_event_dates",
au_short_name=au_short_name,
id=admin_unit_id,
date_from="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):
_, admin_unit_id = seeder.setup_base()
au_short_name = "meinecrew"
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)
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():
return {
"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("free_text", [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()
admin_unit_id = seeder.create_admin_unit(user_id, "Meine Crew")
au_short_name = "meinecrew"
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_ok(url)
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()
admin_unit_id = seeder.create_admin_unit(user_id, "Meine Crew")
au_short_name = "meinecrew"
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_ok(url)
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(
client, app, seeder, utils, mocker
client, app, seeder: Seeder, utils: UtilActions, mocker
):
user_id = seeder.create_user()
seeder.create_admin_unit(user_id, "Meine Crew")
au_short_name = "meinecrew"
admin_unit_id = seeder.create_admin_unit(user_id, "Meine Crew")
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_ok(url)
data = get_create_data()
@ -314,12 +268,9 @@ def test_event_suggestion_create_for_admin_unit_emptyFreeText(
client, app, seeder, utils, mocker
):
user_id = seeder.create_user()
seeder.create_admin_unit(user_id, "Meine Crew")
au_short_name = "meinecrew"
admin_unit_id = seeder.create_admin_unit(user_id, "Meine Crew")
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_ok(url)
data = get_create_data()
@ -338,12 +289,9 @@ def test_event_suggestion_create_for_admin_unit_invalidEventPlaceId(
client, app, seeder, utils, mocker
):
user_id = seeder.create_user()
seeder.create_admin_unit(user_id, "Meine Crew")
au_short_name = "meinecrew"
admin_unit_id = seeder.create_admin_unit(user_id, "Meine Crew")
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_ok(url)
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):
user_id = seeder.create_user()
seeder.create_admin_unit(user_id, "Meine Crew", suggestions_enabled=False)
au_short_name = "meinecrew"
url = utils.get_url(
"event_suggestion_create_for_admin_unit", au_short_name=au_short_name
admin_unit_id = seeder.create_admin_unit(
user_id, "Meine Crew", suggestions_enabled=False
)
url = utils.get_url("event_suggestion_create_for_admin_unit", id=admin_unit_id)
response = utils.get(url)
utils.assert_response_notFound(response)