~sircmpwn/sr.ht-dev

todo.sr.ht: Do not allow ommission of tilde v1 PROPOSED

This makes todo.sr.ht's behavior consistent with other sr.ht services
by returning a 404 if you try to omit the tilde in a tracker URL. The
second commit also fixes the "Create & configure tracker" button
redirecting you to https://todo.sr.ht/username/tracker without a tilde.
Fixes https://todo.sr.ht/~sircmpwn/todo.sr.ht/198

Benjamin Lowry (2):
  get_tracker: return None if tilde is ommitted
  redirect to correct page when creating & configuring tracker

 todosrht/access.py             | 36 +++++++++++++++++-----------------
 todosrht/blueprints/tracker.py |  2 +-
 2 files changed, 19 insertions(+), 19 deletions(-)

-- 
2.26.2
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/10942/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH todo.sr.ht 1/2] get_tracker: return None if tilde is ommitted Export this patch

This makes the behavior consistent with other sr.ht services

Signed-off-by: Benjamin Lowry <ben@ben.gmbh>
---
 todosrht/access.py | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/todosrht/access.py b/todosrht/access.py
index 3d5eadd..06e3e86 100644
--- a/todosrht/access.py
+++ b/todosrht/access.py
@@ -39,26 +39,26 @@ def get_tracker(owner, name, with_for_update=False, user=None):
    if not owner:
        return None, None

    if not isinstance(owner, User):
        if owner.startswith("~"):
            owner = owner[1:]
        owner = User.query.filter(User.username == owner).one_or_none()
        if not owner:
    if owner[0] == "~":
        owner = owner[1:]
        if not isinstance(owner, User):
            owner = User.query.filter(User.username == owner).one_or_none()
            if not owner:
                return None, None
        tracker = (Tracker.query
            .filter(Tracker.owner_id == owner.id)
            .filter(Tracker.name.ilike(name)))
        if with_for_update:
            tracker = tracker.with_for_update()
        tracker = tracker.one_or_none()
        if not tracker:
            return None, None
    tracker = (Tracker.query
        .filter(Tracker.owner_id == owner.id)
        .filter(Tracker.name.ilike(name)))
    if with_for_update:
        tracker = tracker.with_for_update()
    tracker = tracker.one_or_none()
    if not tracker:
        access = get_access(tracker, None, user=user)
        if access:
            return tracker, access
    else:
        # TODO: org trackers
        return None, None
    access = get_access(tracker, None, user=user)
    if access:
        return tracker, access

    # TODO: org trackers
    return None, None

def get_ticket(tracker, ticket_id, user=None):
    ticket = (Ticket.query
-- 
2.26.2

[PATCH todo.sr.ht 2/2] redirect to correct page when creating & configuring tracker Export this patch

Use canonical_name to redirect to the tracker page with
a tilde before the username.

Signed-off-by: Benjamin Lowry <ben@ben.gmbh>
---
 todosrht/blueprints/tracker.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/todosrht/blueprints/tracker.py b/todosrht/blueprints/tracker.py
index 68cde2c..4d3a5ae 100644
--- a/todosrht/blueprints/tracker.py
+++ b/todosrht/blueprints/tracker.py
@@ -53,7 +53,7 @@ def create_POST():

    if "create-configure" in valid:
        return redirect(url_for("settings.details_GET",
                owner=current_user.username,
                owner=current_user.canonical_name,
                name=tracker.name))

    return redirect(tracker_url(tracker))
-- 
2.26.2