Skip to content

Commit

Permalink
Fix #1364 load plan share urls by plan name when uuid fallsback
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsimpson committed Jun 23, 2024
1 parent 353bc02 commit 4308628
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions subscribie/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
import pycountry
from types import SimpleNamespace
from flask_babel import Domain
from urllib.parse import urlparse
from pathlib import PurePosixPath
from urllib.parse import unquote
from sqlalchemy import func

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -390,13 +394,23 @@ def get_translations():
@bp.route("/plan/<uuid>/<plan_title>")
def view_plan(uuid, plan_title=None):
"""
Note: "plan_name" is not used, and is also
optional. It's just there to make
urls look 'pretty'
when humans share them.
Match on plan uuid, or fallback to plan name.
Note: "uuid" may refer to an archived plan for backward
compatibility with published links.
See https://github.com/Subscribie/subscribie/issues/1364
"""
# fetch plan from db
plan = Plan.query.filter_by(uuid=uuid).first()
if plan is None:
# Try to locate plan by title only
url = urlparse(request.url)
request_path = PurePosixPath(url.path).parts
requested_plan_name_slug = unquote(request_path[3])
plan = Plan.query.filter(
func.lower(Plan.title) == requested_plan_name_slug.lower()
).first()

if plan is None:
return "Plan not found. Visit <a href='/'>home</a>"
elif plan.archived:
Expand Down

0 comments on commit 4308628

Please sign in to comment.