app/soc/views/helper/access.py
changeset 887 b8c1a6bc913e
parent 884 ded4850776c8
child 888 a75ae24f04cb
equal deleted inserted replaced
886:f5847f24c56e 887:b8c1a6bc913e
    36 from django.core import urlresolvers
    36 from django.core import urlresolvers
    37 from django.utils.translation import ugettext_lazy
    37 from django.utils.translation import ugettext_lazy
    38 
    38 
    39 from soc.logic import accounts
    39 from soc.logic import accounts
    40 from soc.logic import dicts
    40 from soc.logic import dicts
    41 from soc.logic.models import host as host_logic
    41 from soc.logic.models.host import logic as host_logic
    42 from soc.logic.models import notification as notification_logic
    42 from soc.logic.models.notification import logic as notification_logic
    43 from soc.logic.models import user as user_logic
    43 from soc.logic.models.request import logic as request_logic
    44 from soc.logic.models import request as request_logic
    44 from soc.logic.models.user import logic as user_logic
    45 from soc.views import helper
    45 from soc.views import helper
    46 from soc.views import out_of_band
    46 from soc.views import out_of_band
    47 
    47 
    48 
    48 
    49 DEF_NO_USER_LOGIN_MSG_FMT = ugettext_lazy(
    49 DEF_NO_USER_LOGIN_MSG_FMT = ugettext_lazy(
   184     should be returned by the calling view.
   184     should be returned by the calling view.
   185   """
   185   """
   186 
   186 
   187   checkIsLoggedIn(request, args, kwargs)
   187   checkIsLoggedIn(request, args, kwargs)
   188 
   188 
   189   user = user_logic.logic.getForFields(
   189   user = user_logic.getForFields({'account': users.get_current_user()},
   190       {'account': users.get_current_user()}, unique=True)
   190                                  unique=True)
   191 
   191 
   192   if user:
   192   if user:
   193     return
   193     return
   194 
   194 
   195   raise out_of_band.LoginRequest(message_fmt=DEF_NO_USER_LOGIN_MSG_FMT)
   195   raise out_of_band.LoginRequest(message_fmt=DEF_NO_USER_LOGIN_MSG_FMT)
   244   except out_of_band.Error:
   244   except out_of_band.Error:
   245     pass
   245     pass
   246 
   246 
   247   checkIsUser(request, args, kwargs)
   247   checkIsUser(request, args, kwargs)
   248 
   248 
   249   user = user_logic.logic.getForFields(
   249   user = user_logic.getForFields({'account': users.get_current_user()},
   250       {'account': users.get_current_user()}, unique=True)
   250                                  unique=True)
   251 
   251 
   252   host = host_logic.logic.getForFields(
   252   host = host_logic.getForFields({'user': user}, unique=True)
   253       {'user': user}, unique=True)
       
   254 
   253 
   255   if host:
   254   if host:
   256     return
   255     return
   257 
   256 
   258   login_message_fmt = DEF_DEV_LOGOUT_LOGIN_MSG_FMT % {
   257   login_message_fmt = DEF_DEV_LOGOUT_LOGIN_MSG_FMT % {
   331 
   330 
   332   role = splitpath[0]
   331   role = splitpath[0]
   333   group_id = splitpath[2]
   332   group_id = splitpath[2]
   334   user_id = splitpath[3]
   333   user_id = splitpath[3]
   335 
   334 
   336   user = user_logic.logic.getForFields(
   335   user = user_logic.getForFields({'account': users.get_current_user()},
   337       {'account': users.get_current_user()}, unique=True)
   336                                  unique=True)
   338 
   337 
   339   if user_id != user.link_id:
   338   if user_id != user.link_id:
   340     # TODO: perhaps this needs a better explanation?
   339     # TODO: perhaps this needs a better explanation?
   341     deny(request, args, kwargs)
   340     deny(request, args, kwargs)
   342 
   341 
   345       'role': role,
   344       'role': role,
   346       'scope_path': group_id,
   345       'scope_path': group_id,
   347       'group_accepted': True,
   346       'group_accepted': True,
   348       }
   347       }
   349 
   348 
   350   request = request_logic.logic.getForFields(properties, unique=True)
   349   request = request_logic.getForFields(properties, unique=True)
   351 
   350 
   352   if request:
   351   if request:
   353     return
   352     return
   354 
   353 
   355   raise out_of_band.LoginRequest(message_fmt=login_message_fmt)
   354   raise out_of_band.LoginRequest(message_fmt=login_message_fmt)
   379     except out_of_band.Error:
   378     except out_of_band.Error:
   380       pass
   379       pass
   381 
   380 
   382     checkIsUser(request, args, kwargs)
   381     checkIsUser(request, args, kwargs)
   383 
   382 
   384     user = user_logic.logic.getForCurrentAccount()
   383     user = user_logic.getForCurrentAccount()
   385 
   384 
   386     properties = {
   385     properties = {
   387         'applicant': user,
   386         'applicant': user,
   388         'reviewed': True,
   387         'reviewed': True,
   389         'accepted': True,
   388         'accepted': True,
   430   except Exception:
   429   except Exception:
   431     deny(request, args, kwargs)
   430     deny(request, args, kwargs)
   432 
   431 
   433   properties = dicts.filter(kwargs, ['link_id', 'scope_path'])
   432   properties = dicts.filter(kwargs, ['link_id', 'scope_path'])
   434 
   433 
   435   notification = notification_logic.logic.getForFields(properties, unique=True)
   434   notification = notification_logic.getForFields(properties, unique=True)
   436   user = user_logic.logic.getForCurrentAccount()
   435   user = user_logic.getForCurrentAccount()
   437 
   436 
   438   # We need to check to see if the key's are equal since the User
   437   # We need to check to see if the key's are equal since the User
   439   # objects are different and the default __eq__ method does not check
   438   # objects are different and the default __eq__ method does not check
   440   # if the keys are equal (which is what we want).
   439   # if the keys are equal (which is what we want).
   441   if user.key() == notification.scope.key():
   440   if user.key() == notification.scope.key():
   474     application = app_logic.logic.getForFields(properties, unique=True)
   473     application = app_logic.logic.getForFields(properties, unique=True)
   475     
   474     
   476     if not application:
   475     if not application:
   477       deny(request, args, kwargs)
   476       deny(request, args, kwargs)
   478     
   477     
   479     user = user_logic.logic.getForCurrentAccount()
   478     user = user_logic.getForCurrentAccount()
   480 
   479 
   481     # We need to check to see if the key's are equal since the User
   480     # We need to check to see if the key's are equal since the User
   482     # objects are different and the default __eq__ method does not check
   481     # objects are different and the default __eq__ method does not check
   483     # if the keys are equal (which is what we want).
   482     # if the keys are equal (which is what we want).
   484     if user.key() == application.applicant.key():
   483     if user.key() == application.applicant.key():