summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Yves Chibon <pingou@pingoured.fr>2011-11-29 19:01:10 +0100
committerPierre-Yves Chibon <pingou@pingoured.fr>2011-11-29 19:01:10 +0100
commit110345b29f20b160cf1cb283d0c159b5a882871b (patch)
treeefd2324c06bb065af22dea2fc95d21a89a4463f9
parent2142800ce3da00fc98dcbd3897177628047aca95 (diff)
Handle case where fas says a user is logged in while he has never logged in in this app
This will lead to problem while creating a review and trying to display it afterward as the user is not in the local db. Now, as soon as there are information from the FAS (the user is logged in) we check if the user is in the DB and if not we add him.
-rw-r--r--review-srv-tg2/review_srv/controllers/root.py36
1 files changed, 24 insertions, 12 deletions
diff --git a/review-srv-tg2/review_srv/controllers/root.py b/review-srv-tg2/review_srv/controllers/root.py
index 52bdb6c..c0c5921 100644
--- a/review-srv-tg2/review_srv/controllers/root.py
+++ b/review-srv-tg2/review_srv/controllers/root.py
@@ -39,6 +39,23 @@ GIT_DIR = config.get("fedora_review.git_repo",
# Default git url is "http://path/to/git/"
GIT_URL = config.get("fedora_review.git_repo_url", "http://path/to/git")
+
+def check_user():
+ if request.identity:
+ user_fas = request.environ.get('repoze.who.identity')['user']
+ if not model.DBSession.query(User).get(user_fas.user_id):
+ print "Adding user"
+ user = User()
+ user.user_id = user_fas.user_id
+ user.user_name = user_fas.user_name
+ user.email_address = user_fas.email_address
+ user.display_name = user_fas.display_name
+ model.DBSession.add(user)
+ else:
+ flash('Please re-login')
+ redirect('/logout_handler')
+
+
class RootController(BaseController):
"""
The root controller for the review-srv-tg2 application.
@@ -63,6 +80,8 @@ class RootController(BaseController):
request.identity = request.environ.get('repoze.who.identity')
+ check_user()
+
@expose('review_srv.templates.about')
def about(self):
"""Handle the 'about' page."""
@@ -273,7 +292,8 @@ class RootController(BaseController):
@require(not_anonymous("Please log-in"))
def new(self):
"""Handle the 'new' page."""
- branches = model.DBSession.query(Branches).all()
+ check_user()
+ branches = model.DBSession.query(Branches).filter_by(active=True).all()
return dict(page='new', branches=branches)
@expose()
@@ -287,17 +307,9 @@ class RootController(BaseController):
login_counter = request.environ['repoze.who.logins'] + 1
redirect('/login', came_from=came_from, __logins=login_counter)
userid = request.identity['repoze.who.userid']
- user_fas = request.identity['user']
- if not model.DBSession.query(User).get(user_fas.user_id):
- print "Adding user"
- user = User()
- user.user_id = user_fas.user_id
- user.user_name = user_fas.user_name
- user.email_address = user_fas.email_address
- user.display_name = user_fas.display_name
- model.DBSession.add(user)
flash(_('Welcome back, %s!') % userid)
- redirect(came_from)
+ check_user()
+ redirect(url(came_from))
@expose()
def post_logout(self, came_from=url('/')):
@@ -307,7 +319,7 @@ class RootController(BaseController):
"""
flash(_('We hope to see you soon!'))
- redirect(came_from)
+ redirect(url(came_from))
@expose('review_srv.templates.review')
def review(self, review_id):