diff options
author | rubenwardy <rw@rubenwardy.com> | 2020-08-02 18:03:44 +0100 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2020-08-02 18:03:44 +0100 |
commit | d69da8e3ea5347aa1cee0e24e913864b3a1aa337 (patch) | |
tree | 94d75319a8203cf6fca69ac0e9bfcf3637c7351b | |
parent | 9a648095427b4d2bdd6811f5e19a8e5d51a3c6dc (diff) | |
download | cheatdb-d69da8e3ea5347aa1cee0e24e913864b3a1aa337.tar.xz |
Redirect to correct URL when _game is missing from package name
-rw-r--r-- | app/blueprints/packages/packages.py | 2 | ||||
-rw-r--r-- | app/utils.py | 17 |
2 files changed, 16 insertions, 3 deletions
diff --git a/app/blueprints/packages/packages.py b/app/blueprints/packages/packages.py index d612f9e..0076c5c 100644 --- a/app/blueprints/packages/packages.py +++ b/app/blueprints/packages/packages.py @@ -266,6 +266,8 @@ def create_edit(author=None, name=None): else: package = getPackageByInfo(author, name) + if package is None: + abort(404) if not package.checkPerm(current_user, Permission.EDIT_PACKAGE): return redirect(package.getDetailsURL()) diff --git a/app/utils.py b/app/utils.py index ec5fa3a..a47f6d0 100644 --- a/app/utils.py +++ b/app/utils.py @@ -194,11 +194,11 @@ def rank_required(rank): def getPackageByInfo(author, name): user = User.query.filter_by(username=author).first() if user is None: - abort(404) + return None package = Package.query.filter_by(name=name, author_id=user.id, soft_deleted=False).first() if package is None: - abort(404) + return None return package @@ -208,7 +208,18 @@ def is_package_page(f): if not ("author" in kwargs and "name" in kwargs): abort(400) - package = getPackageByInfo(kwargs["author"], kwargs["name"]) + author = kwargs["author"] + name = kwargs["name"] + + package = getPackageByInfo(author, name) + if package is None: + package = getPackageByInfo(author, name + "_game") + if package is None or package.type != PackageType.GAME: + abort(404) + + args = dict(kwargs) + args["name"] = name + "_game" + return redirect(url_for(request.endpoint, **args)) del kwargs["author"] del kwargs["name"] |