app/soc/views/helper/access.py
changeset 508 2b90baceac88
parent 481 94834a1e6c01
child 525 1dc62d570eff
equal deleted inserted replaced
507:3603fdafabf7 508:2b90baceac88
    34 
    34 
    35 from django.utils.translation import ugettext_lazy
    35 from django.utils.translation import ugettext_lazy
    36 
    36 
    37 from soc.logic import accounts
    37 from soc.logic import accounts
    38 from soc.logic import models
    38 from soc.logic import models
       
    39 from soc.views import helper
    39 from soc.views.simple import requestLogin
    40 from soc.views.simple import requestLogin
    40 
    41 
    41 import soc.views.out_of_band
    42 import soc.views.out_of_band
    42 
    43 
    43 
    44 
    53 DEF_DEV_LOGOUT_LOGIN_MSG_FMT = ugettext_lazy(
    54 DEF_DEV_LOGOUT_LOGIN_MSG_FMT = ugettext_lazy(
    54   'Please <a href="%%(sign_out)s">sign out</a>'
    55   'Please <a href="%%(sign_out)s">sign out</a>'
    55   ' and <a href="%%(sign_in)s">sign in</a>'
    56   ' and <a href="%%(sign_in)s">sign in</a>'
    56   ' again as %(role)s to view this page.')
    57   ' again as %(role)s to view this page.')
    57 
    58 
       
    59 DEF_PAGE_DENIED_MSG = ugettext_lazy(
       
    60   'Access to this page has been restricted')
       
    61 
       
    62 
       
    63 def allow(request):
       
    64   """Never returns an alternate HTTP response
       
    65 
       
    66   Args:
       
    67     request: a django HTTP request
       
    68   """
       
    69 
       
    70   return
       
    71 
       
    72 def deny(request):
       
    73   """Returns an alternate HTTP response
       
    74 
       
    75   Args:
       
    76     request: a django HTTP request
       
    77 
       
    78   Returns: a subclass of django.http.HttpResponse which contains the
       
    79   alternate response that should be returned by the calling view.
       
    80   """
       
    81 
       
    82   context = helper.responses.getUniversalContext(request)
       
    83   context['login_title'] = 'Access denied'
       
    84   context['login_header'] = 'Access denied'
       
    85   context['login_message'] = DEF_PAGE_DENIED_MSG
       
    86 
       
    87   denied_response = helper.responses.respond(request, DEF_LOGIN_TMPL, context=context)
       
    88 
       
    89   raise soc.views.out_of_band.AccessViolationResponse(denied_response)
    58 
    90 
    59 def checkIsLoggedIn(request):
    91 def checkIsLoggedIn(request):
    60   """Returns an alternate HTTP response if Google Account is not logged in.
    92   """Returns an alternate HTTP response if Google Account is not logged in.
    61 
    93 
    62   Args:
    94   Args: