当前位置: 首页>>代码示例>>Python>>正文


Python users.is_current_user_admin方法代码示例

本文整理汇总了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 
开发者ID:elsigh,项目名称:browserscope,代码行数:26,代码来源:util.py

示例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()) 
开发者ID:elsigh,项目名称:browserscope,代码行数:27,代码来源:status_ui.py

示例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(),
  ) 
开发者ID:lipis,项目名称:github-stats,代码行数:19,代码来源:gae.py

示例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(),
    ) 
开发者ID:madvas,项目名称:gae-angular-material-starter,代码行数:19,代码来源:google.py

示例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 
开发者ID:googlearchive,项目名称:cloud-playground,代码行数:27,代码来源:shared.py

示例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 
开发者ID:googlearchive,项目名称:cloud-playground,代码行数:20,代码来源:shared.py

示例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 
开发者ID:googlearchive,项目名称:cloud-playground,代码行数:22,代码来源:playground.py

示例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 
开发者ID:uwdata,项目名称:termite-visualizations,代码行数:24,代码来源:fileutils.py

示例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)) 
开发者ID:adamyi,项目名称:golinks,代码行数:21,代码来源:appengine_main.py

示例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") 
开发者ID:adamyi,项目名称:golinks,代码行数:18,代码来源:appengine_main.py

示例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 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:6,代码来源:blog.py

示例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 
开发者ID:google,项目名称:gae-secure-scaffold-python,代码行数:11,代码来源:handlers.py

示例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 
开发者ID:elsigh,项目名称:browserscope,代码行数:16,代码来源:decorators.py

示例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 
开发者ID:elsigh,项目名称:browserscope,代码行数:9,代码来源:middleware.py

示例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 
开发者ID:elsigh,项目名称:browserscope,代码行数:33,代码来源:user_tests.py


注:本文中的google.appengine.api.users.is_current_user_admin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。