summaryrefslogtreecommitdiffstats
path: root/gitsrht/repos.py
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-11-24 14:23:43 -0500
committerDrew DeVault <sir@cmpwn.com>2018-11-24 14:23:43 -0500
commit31c9eff0540cbd7e0ee727bfcb4118e9ffff0afa (patch)
treec5c78919ba7a3aebb859d7f6d1e7abf05027b339 /gitsrht/repos.py
parente95fbad612e6041dbde5ff1232bc2752f2de4b62 (diff)
Tweaks to contributors page
Diffstat (limited to 'gitsrht/repos.py')
-rw-r--r--gitsrht/repos.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/gitsrht/repos.py b/gitsrht/repos.py
index 8e617e2..2749e10 100644
--- a/gitsrht/repos.py
+++ b/gitsrht/repos.py
@@ -1,7 +1,9 @@
import subprocess
+from flask import redirect, abort, url_for
+from gitsrht.access import get_repo, has_access, UserAccess
+from gitsrht.types import User, Repository, RepoVisibility, Redirect
from srht.database import db
from srht.config import cfg
-from gitsrht.types import Repository, RepoVisibility, Redirect
import shutil
import re
import os
@@ -94,3 +96,20 @@ def delete_repo(repo):
pass
db.session.delete(repo)
db.session.commit()
+
+def get_repo_or_redir(owner, repo):
+ owner, repo = get_repo(owner, repo)
+ if not repo:
+ abort(404)
+ if not has_access(repo, UserAccess.read):
+ abort(401)
+ if isinstance(repo, Redirect):
+ view_args = request.view_args
+ if not "repo" in view_args or not "owner" in view_args:
+ return redirect(url_for(".summary",
+ owner=repo.new_repo.owner.canonical_name,
+ repo=repo.new_repo.name))
+ view_args["owner"] = repo.new_repo.owner.canonical_name
+ view_args["repo"] = repo.new_repo.name
+ abort(redirect(url_for(request.endpoint, **view_args)))
+ return owner, repo