Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Unified Diff: appengine/findit/common/auth_util.py

Issue 2397603002: [Findit] Cloud Endpoints API to receive reports on flakes. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/findit/common/auth_util.py
diff --git a/appengine/findit/common/auth_util.py b/appengine/findit/common/auth_util.py
index 443ed058e82b64103266e72fa89c89f71294ff41..33383890b12595943c8175f8158e7521463cf3f8 100644
--- a/appengine/findit/common/auth_util.py
+++ b/appengine/findit/common/auth_util.py
@@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+from google.appengine.api import oauth
+from google.appengine.api import users
from google.appengine.api.app_identity import app_identity
@@ -12,3 +14,24 @@ def GetAuthToken(scope=_EMAIL_SCOPE): # pragma: no cover
"""Gets auth token for requests to hosts that need authorizations."""
auth_token, _ = app_identity.get_access_token(scope)
return auth_token
+
+
+def GetUserEmail(scope=_EMAIL_SCOPE): # pragma: no cover
+ """Returns the email of the logged-in user or None if not logged-in."""
+ user = users.get_current_user() # Cookie-based authentication.
+ if not user:
+ try:
+ user = oauth.get_current_user(scope) # Oauth-based authentication.
+ except oauth.OAuthRequestError:
+ pass # Not logged-in or invalid oauth token.
+ return user.email() if user else None
+
+
+def IsCurrentUserAdmin(scope=_EMAIL_SCOPE): # pragma: no cover
+ """Returns True if the logged-in user is an admin."""
+ is_admin = users.is_current_user_admin()
+ try:
+ is_admin = is_admin or oauth.is_current_user_admin(scope)
+ except oauth.OAuthRequestError:
+ pass # Not logged-in or invalid oauth token.
+ return is_admin
« no previous file with comments | « no previous file | appengine/findit/common/base_handler.py » ('j') | appengine/findit/model/flake/flake_analysis_request.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698