本文整理匯總了Python中google.appengine.api.users.is_current_user_admin方法的典型用法代碼示例。如果您正苦於以下問題:Python users.is_current_user_admin方法的具體用法?Python users.is_current_user_admin怎麽用?Python users.is_current_user_admin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類google.appengine.api.users
的用法示例。
在下文中一共展示了users.is_current_user_admin方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: GetStatsDataTemplatized
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import is_current_user_admin [as 別名]
def GetStatsDataTemplatized(params, template='table'):
"""Returns the stats table run through a template.
Args:
params: Example:
params = {
'v': one of the keys in user_agent.BROWSER_NAV,
'current_user_agent': a user agent entity,
'user_agents': list_of user agents,
'tests': list of test names,
'stats': dict - stats[test_name][user_agent],
'total_runs': total_runs[test_name],
'request_path': request.path,
'params': result_parent.params, #optional
}
"""
params['browser_nav'] = result_stats.BROWSER_NAV
params['is_admin'] = users.is_current_user_admin()
if not re.search('\?', params['request_path']):
params['request_path'] = params['request_path'] + '?'
t = loader.get_template('stats_%s.html' % template)
template_rendered = t.render(Context(params))
return template_rendered
示例2: get
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import is_current_user_admin [as 別名]
def get(self, resource=''):
import pipeline # Break circular dependency
if pipeline._ENFORCE_AUTH:
if users.get_current_user() is None:
self.redirect(users.create_login_url(self.request.url))
return
if not users.is_current_user_admin():
self.response.out.write('Forbidden')
self.response.set_status(403)
return
if resource not in self._RESOURCE_MAP:
logging.info('Could not find: %s', resource)
self.response.set_status(404)
self.response.out.write("Resource not found.")
self.response.headers['Content-Type'] = 'text/plain'
return
relative_path, content_type = self._RESOURCE_MAP[resource]
path = os.path.join(os.path.dirname(__file__), relative_path)
if not pipeline._DEBUG:
self.response.headers["Cache-Control"] = "public, max-age=300"
self.response.headers["Content-Type"] = content_type
self.response.out.write(open(path, 'rb').read())
示例3: retrieve_user_from_gae
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import is_current_user_admin [as 別名]
def retrieve_user_from_gae(gae_user):
auth_id = 'federated_%s' % gae_user.user_id()
user_db = model.User.get_by('auth_ids', auth_id)
if user_db:
if not user_db.admin and users.is_current_user_admin():
user_db.admin = True
user_db.put()
return user_db
return auth.create_user_db(
auth_id=auth_id,
name=util.create_name_from_email(gae_user.email()),
username=gae_user.email(),
email=gae_user.email(),
verified=True,
admin=users.is_current_user_admin(),
)
示例4: retrieve_user_from_google
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import is_current_user_admin [as 別名]
def retrieve_user_from_google(google_user):
auth_id = 'federated_%s' % google_user.user_id()
user_db = model.User.get_by('auth_ids', auth_id)
if user_db:
if not user_db.admin and users.is_current_user_admin():
user_db.admin = True
user_db.put()
return user_db
return auth.create_or_get_user_db(
auth_id=auth_id,
name=util.create_name_from_email(google_user.email()),
username=google_user.email(),
email=google_user.email(),
verified=True,
admin=users.is_current_user_admin(),
)
示例5: HasProjectReadAccess
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import is_current_user_admin [as 別名]
def HasProjectReadAccess(environ):
"""Assert that the current user has project read permissions.
Args:
environ: the current WSGI environ
Returns:
True if the current user has read access to the current project.
"""
project = environ['playground.project']
if not project:
Abort(httplib.NOT_FOUND, 'requested read access to non-existent project')
access_key = environ.get('mimic.access_key')
if access_key and access_key == project.access_key:
return True
if users.is_current_user_admin():
return True
user = environ.get('playground.user', None)
if user and user.key.id() in project.writers:
return True
if settings.PUBLIC_PROJECT_TEMPLATE_OWNER in project.writers:
return True
if settings.MANUAL_PROJECT_TEMPLATE_OWNER in project.writers:
return True
return False
示例6: HasProjectWriteAccess
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import is_current_user_admin [as 別名]
def HasProjectWriteAccess(environ):
"""Assert that the current user has project write permissions.
Args:
environ: the current WSGI environ
Returns:
True if the current user as write access to the current project.
"""
project = environ['playground.project']
if not project:
Abort(httplib.NOT_FOUND, 'requested write access to non-existent project')
if users.is_current_user_admin():
return True
user = environ.get('playground.user')
if user and user.key.id() in project.writers:
return True
return False
示例7: post
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import is_current_user_admin [as 別名]
def post(self): # pylint:disable-msg=invalid-name
"""Handles HTTP POST requests."""
if not users.is_current_user_admin():
self.response.set_status(httplib.UNAUTHORIZED)
return
key = self.request.data['key']
url = self.request.data['url']
client_id = self.request.data.get('client_id')
client_secret = self.request.data.get('client_secret')
if client_id and client_secret:
credential = model.SetOAuth2Credential(key, client_id, client_secret)
else:
credential = model.GetOAuth2Credential(key) or model.OAuth2Credential()
r = {
'key': key,
'url': url,
'client_id': credential.client_id,
'client_secret': credential.client_secret,
}
return r
示例8: check_credentials
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import is_current_user_admin [as 別名]
def check_credentials(request, other_application='admin',
expiration=60 * 60, gae_login=True):
""" checks that user is authorized to access other_application"""
if request.env.web2py_runtime_gae:
from google.appengine.api import users
if users.is_current_user_admin():
return True
elif gae_login:
login_html = '<a href="%s">Sign in with your google account</a>.' \
% users.create_login_url(request.env.path_info)
raise HTTP(200, '<html><body>%s</body></html>' % login_html)
else:
return False
else:
t0 = time.time()
dt = t0 - expiration
s = get_session(request, other_application)
r = (s.authorized and s.last_time and s.last_time > dt)
if r:
s.last_time = t0
set_session(request,s,other_application)
return r
示例9: get
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import is_current_user_admin [as 別名]
def get(self, param):
user = users.get_current_user()
if not user:
self.redirect(users.create_login_url(self.request.path))
return
sign_out_link = users.create_logout_url('/')
is_admin = users.is_current_user_admin()
if param == "all" and is_admin:
links = Link.query().fetch()
else:
links = Link.query(Link.owner_id == user.user_id()).fetch()
context = {
"links": links,
"is_admin": is_admin,
"sign_out_link": sign_out_link,
"fqdn": config.GOLINKS_FQDN,
"hostname": config.GOLINKS_HOSTNAME
}
self.response.write(render("template/list.html", context))
示例10: post
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import is_current_user_admin [as 別名]
def post(self, link):
user = users.get_current_user()
if not user:
self.redirect(users.create_login_url(self.request.path))
return
key = link.rstrip("/")
l = Link.get_by_id(key)
if l.owner_id:
if l.owner_id != user.user_id() and not users.is_current_user_admin():
logging.info("%s tried to delete /%s but doesn't have permission" %
(user.email(), key))
errorPage(self.response, 403, "Access denied")
return
l.key.delete()
logging.info("%s deleted /%s" % (user.email(), key))
self.redirect("/links/my")
示例11: get_current_user
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import is_current_user_admin [as 別名]
def get_current_user(self):
user = users.get_current_user()
if user: user.administrator = users.is_current_user_admin()
return user
示例12: requires_admin
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import is_current_user_admin [as 別名]
def requires_admin(f):
"""A decorator that requires a currently logged in administrator."""
@functools.wraps(f)
def wrapper(self, *args, **kwargs):
if not users.is_current_user_admin():
self.DenyAccess()
else:
return f(self, *args, **kwargs)
return wrapper
示例13: admin_required
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import is_current_user_admin [as 別名]
def admin_required(func):
"""Tests to make sure the current user is an admin."""
def _wrapper(request, *args, **kw):
user = users.get_current_user()
if user:
if users.is_current_user_admin():
return func(request, *args, **kw)
else:
return HttpResponse('You need to be an admin. <a href="%s">login</a>.'
% users.create_login_url(request.get_full_path()))
else:
return HttpResponseRedirect(
users.create_login_url(request.get_full_path()))
return _wrapper
示例14: process_exception
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import is_current_user_admin [as 別名]
def process_exception(self, request, exception):
error = traceback.format_exc()
logging.error('Traceback: %s', error)
if users.is_current_user_admin():
return util.Render(request, '500.html', params={'traceback': error})
else:
return None
示例15: Settings
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import is_current_user_admin [as 別名]
def Settings(request):
if request.POST:
current_user = users.get_current_user()
u = models.user_test.User.get_or_insert(current_user.user_id())
u.email = request.POST.get('email', current_user.email())
u.save()
return http.HttpResponseRedirect('/user/settings')
# Regular GET.
current_user = users.get_current_user()
user = models.user_test.User.get_or_insert(
current_user.user_id(),
email=current_user.email())
tests = db.Query(models.user_test.Test)
tests.filter('user', user)
# Only admins can see deleted tests.
if not users.is_current_user_admin():
tests.filter('deleted', False)
tests.order('-created')
if tests.count() == 0:
tests = None
params = {
'api_key': user.key().name(),
'tests': tests,
'csrf_token': request.session.get('csrf_token')
}
return util.Render(request, 'user_settings.html', params)
# Decorators are inherited by TestEdit