Ejemplo n.º 1
0
 def testGetForAccountNonMatching(self):
     """Test that non matching returns None.
 """
     email = "*****@*****.**"
     account = users.User(email=email)
     entity = user_logic.getForAccount(account)
     self.failUnlessEqual(entity, None)
Ejemplo n.º 2
0
    def _checkHasStatisticAccess(self, statistic, params=None):
        """Checks that the user has access to the specified statistic.
    """

        logic = params['logic']

        id = accounts.getCurrentAccount()
        user = None
        if id:
            user = user_logic.getForAccount(id)

        checker = access.Checker(None)
        checker.setCurrentUser(id, user)

        access_type = statistic.read_access
        has_access = False

        minimal_rights = logic.ACCESS_TYPES.index(access_type)
        for item in logic.ACCESS_TYPES[minimal_rights:]:
            ref_logic = logic.helper.LOGICS_DICT[item]
            try:
                checker.checkHasActiveRole({}, ref_logic.logic)
                has_access = True
                break
            except Exception:
                pass

        return has_access
Ejemplo n.º 3
0
 def testGetForAccount(self):
     """Test that entity can be retrieved through account.
 """
     email = "*****@*****.**"
     account = users.User(email=email)
     entity = user_logic.getForAccount(account)
     self._compareUsers(self.entity, entity)
Ejemplo n.º 4
0
  def _checkHasStatisticAccess(self, statistic, params=None):
    """Checks that the user has access to the specified statistic.
    """

    logic = params['logic']

    id = accounts.getCurrentAccount()
    user = None
    if id:
      user = user_logic.getForAccount(id)

    checker = access.Checker(None)
    checker.setCurrentUser(id, user)

    access_type = statistic.read_access
    has_access = False

    minimal_rights = logic.ACCESS_TYPES.index(access_type)
    for item in logic.ACCESS_TYPES[minimal_rights:]:
      ref_logic = logic.helper.LOGICS_DICT[item]
      try:
        checker.checkHasActiveRole({}, ref_logic.logic)
        has_access = True
        break
      except Exception:
        pass

    return has_access
Ejemplo n.º 5
0
 def testGetForAccountNonMatching(self):
   """Test that non matching returns None.
   """
   email = "*****@*****.**"
   account = users.User(email=email)
   entity = user_logic.getForAccount(account)
   self.failUnlessEqual(entity, None)
Ejemplo n.º 6
0
 def testGetForAccount(self):
   """Test that entity can be retrieved through account.
   """
   email = "*****@*****.**"
   account = users.User(email=email)
   entity = user_logic.getForAccount(account)
   self._compareUsers(self.entity, entity)
Ejemplo n.º 7
0
def getUniversalContext(request):
  """Constructs a template context dict will many common variables defined.
  
  Args:
    request: the Django HTTP request object

  Returns:
    a new context dict containing:
    
    {
      'request': the Django HTTP request object passed in by the caller
      'account': the logged-in Google Account if there is one
      'user': the User entity corresponding to the Google Account in
        context['account']
      'is_admin': True if users.is_current_user_admin() is True
      'is_debug': True if system.isDebug() is True
      'sign_in': a Google Account login URL
      'sign_out': a Google Account logout URL
      'sidebar_menu_html': an HTML string that renders the sidebar menu
    }
  """

  account = accounts.getCurrentAccount()
  user = None
  is_admin = False

  context = {}
  context['request'] = request

  if account:
    user = user_logic.getForAccount(account)
    is_admin = user_logic.isDeveloper(account=account, user=user)

  context['account'] = account
  context['user'] = user
  context['is_admin'] = is_admin

  context['is_local'] = system.isLocal()
  context['is_debug'] = system.isDebug()
  context['sign_in'] = users.create_login_url(request.path)
  context['sign_out'] = users.create_logout_url(request.path)

  context['sidebar_menu_items'] = callback.getCore().getSidebar(account, user)

  context['gae_version'] = system.getAppVersion()
  context['soc_release'] = system.getMelangeVersion()

  settings = site.logic.getSingleton()

  context['ga_tracking_num'] = settings.ga_tracking_num
  context['gmaps_api_key'] = settings.gmaps_api_key
  context['site_name'] = settings.site_name
  context['site_notice'] = settings.site_notice
  context['tos_link'] = redirects.getToSRedirect(settings)
  context['in_maintenance'] = timeline.isActivePeriod(site, 'maintenance')
 
  return context
Ejemplo n.º 8
0
def getUniversalContext(request):
    """Constructs a template context dict will many common variables defined.

  Args:
    request: the Django HTTP request object

  Returns:
    a new context dict containing:

    {
      'request': the Django HTTP request object passed in by the caller
      'account': the logged-in Google Account if there is one
      'user': the User entity corresponding to the Google Account in
        context['account']
      'is_admin': True if users.is_current_user_admin() is True
      'is_debug': True if system.isDebug() is True
      'sign_in': a Google Account login URL
      'sign_out': a Google Account logout URL
      'sidebar_menu_html': an HTML string that renders the sidebar menu
    }
  """

    core = callback.getCore()

    context = core.getRequestValue('context', {})

    if context:
        return context

    account = accounts.getCurrentAccount()
    user = None
    is_admin = False

    context['request'] = request

    if account:
        user = user_logic.getForAccount(account)
        is_admin = user_logic.isDeveloper(account=account, user=user)

    context['account'] = account
    context['user'] = user
    context['is_admin'] = is_admin

    context['is_local'] = system.isLocal()
    context['is_debug'] = system.isDebug()
    context['sign_in'] = users.create_login_url(request.path)
    context['sign_out'] = users.create_logout_url(request.path)

    context['sidebar_menu_items'] = core.getSidebar(account, user)

    context['gae_version'] = system.getAppVersion()
    context['soc_release'] = system.getMelangeVersion()

    settings = site.logic.getSingleton()

    context['ga_tracking_num'] = settings.ga_tracking_num
    context['gmaps_api_key'] = settings.gmaps_api_key
    context['site_name'] = settings.site_name
    context['site_notice'] = settings.site_notice
    context['tos_link'] = redirects.getToSRedirect(settings)
    context['in_maintenance'] = timeline.isActivePeriod(
        settings, 'maintenance')

    # Only one xsrf_token is generated per request.
    xsrf_secret_key = site.logic.getXsrfSecretKey(settings)
    context['xsrf_token'] = xsrfutil.getGeneratedTokenForCurrentUser(
        xsrf_secret_key)

    core.setRequestValue('context', context)

    return context