Beispiel #1
0
  def checkIsUser(self, django_args=None):
    """Raises an alternate HTTP response if Google Account has no User entity.

    Args:
      django_args: a dictionary with django's arguments, not used

    Raises:
      AccessViolationResponse:
      * if no User exists for the logged-in Google Account, or
      * if no Google Account is logged in at all
      * if User has not agreed to the site-wide ToS, if one exists
    """

    self.checkIsLoggedIn()

    if not self.user:
      raise out_of_band.LoginRequest(message_fmt=DEF_NO_USER_LOGIN_MSG)

    if user_logic.agreesToSiteToS(self.user):
      return

    # Would not reach this point of site-wide ToS did not exist, since
    # agreesToSiteToS() call above always returns True if no ToS is in effect.
    login_msg_fmt = DEF_AGREE_TO_TOS_MSG_FMT % {
        'tos_link': redirects.getToSRedirect(site_logic.getSingleton())}

    raise out_of_band.LoginRequest(message_fmt=login_msg_fmt)
Beispiel #2
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
Beispiel #3
0
  def _getToSExampleText(self):
    """Returns example_text linking to site-wide ToS, or a warning message.
    """
    tos_link = redirects.getToSRedirect(site_logic.getSingleton())

    if not tos_link:
      return ('<div class="notice">&nbsp;<i>No site-wide</i> Terms of'
              ' Service <i>are currently set!</i>&nbsp;</div>')

    return ('<i>current site-wide <b><a href=%s>Terms of Service</a></b></i>'
            % tos_link)
Beispiel #4
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