aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2020-08-02 18:03:44 +0100
committerrubenwardy <rw@rubenwardy.com>2020-08-02 18:03:44 +0100
commitd69da8e3ea5347aa1cee0e24e913864b3a1aa337 (patch)
tree94d75319a8203cf6fca69ac0e9bfcf3637c7351b
parent9a648095427b4d2bdd6811f5e19a8e5d51a3c6dc (diff)
downloadcheatdb-d69da8e3ea5347aa1cee0e24e913864b3a1aa337.tar.xz
Redirect to correct URL when _game is missing from package name
-rw-r--r--app/blueprints/packages/packages.py2
-rw-r--r--app/utils.py17
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"]