fedora_elections/elections.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
New commits:
commit 86578361f7e9dbb40fabbe4f08bfdc78d13202ea
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Fri Jul 25 15:45:04 2014 +0200
Rely on the is_authenticated() where it makes sense
diff --git a/fedora_elections/elections.py b/fedora_elections/elections.py
index 5227ddb..355eabb 100644
--- a/fedora_elections/elections.py
+++ b/fedora_elections/elections.py
@@ -309,7 +309,7 @@ def election_results(election_alias):
return election
elif election.embargoed:
- if not hasattr(flask.g, 'fas_user') or not flask.g.fas_user:
+ if not is_authenticated():
flask.flash("We are sorry. The results for this election "
"cannot be viewed because they are currently "
"embargoed pending formal announcement.")
commit 950db261e90a6244f667dcc6b5bc00836b3f8354
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Fri Jul 25 15:44:14 2014 +0200
Optimization: by using `and` instead of `or` will stop the condition at the first
False
diff --git a/fedora_elections/elections.py b/fedora_elections/elections.py
index e7b9893..5227ddb 100644
--- a/fedora_elections/elections.py
+++ b/fedora_elections/elections.py
@@ -364,8 +364,8 @@ def election_results_text(election_alias):
if not isinstance(election, models.Election): # pragma: no cover
return election
- if not is_authenticated() or not is_admin(flask.g.fas_user) \
- or not is_election_admin(flask.g.fas_user, election.id):
+ if not (is_authenticated() and is_admin(flask.g.fas_user)
+ and is_election_admin(flask.g.fas_user, election.id)):
flask.flash(
"The text results are only available to the admins",
"error")
return safe_redirect_back()
commit 0d63467564d94d5497ac2da10002ba3d1438bc6d
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Fri Jul 25 15:43:43 2014 +0200
Check is the user is authenticated before checking if he/she is an admin
diff --git a/fedora_elections/elections.py b/fedora_elections/elections.py
index a4ca812..e7b9893 100644
--- a/fedora_elections/elections.py
+++ b/fedora_elections/elections.py
@@ -330,8 +330,8 @@ def election_results(election_alias):
"embargoed pending formal announcement.")
return safe_redirect_back()
- if is_admin(flask.g.fas_user) \
- or is_election_admin(flask.g.fas_user, election.id):
+ if is_authenticated() and (is_admin(flask.g.fas_user) \
+ or is_election_admin(flask.g.fas_user, election.id)):
flask.flash(
"Check out the <a href='%s'>Text version</a> "
"to send the annoucement" % flask.url_for(
Show replies by date