app/soc/views/helper/access.py
changeset 2112 9a2c9354468c
parent 2101 d6250eac3ab0
child 2116 68d7679a2af2
equal deleted inserted replaced
2111:dfe684de7f92 2112:9a2c9354468c
    49 from soc.logic.models.request import logic as request_logic
    49 from soc.logic.models.request import logic as request_logic
    50 from soc.logic.models.role import logic as role_logic
    50 from soc.logic.models.role import logic as role_logic
    51 from soc.logic.models.site import logic as site_logic
    51 from soc.logic.models.site import logic as site_logic
    52 from soc.logic.models.sponsor import logic as sponsor_logic
    52 from soc.logic.models.sponsor import logic as sponsor_logic
    53 from soc.logic.models.student import logic as student_logic
    53 from soc.logic.models.student import logic as student_logic
       
    54 from soc.logic.models.student_project import logic as student_project_logic
    54 from soc.logic.models.student_proposal import logic as student_proposal_logic
    55 from soc.logic.models.student_proposal import logic as student_proposal_logic
    55 from soc.logic.models.timeline import logic as timeline_logic
    56 from soc.logic.models.timeline import logic as timeline_logic
    56 from soc.logic.models.user import logic as user_logic
    57 from soc.logic.models.user import logic as user_logic
    57 from soc.views.helper import redirects
    58 from soc.views.helper import redirects
    58 from soc.views import out_of_band
    59 from soc.views import out_of_band
  1371       self.deny(django_args)
  1372       self.deny(django_args)
  1372 
  1373 
  1373     return
  1374     return
  1374 
  1375 
  1375   @allowDeveloper
  1376   @allowDeveloper
       
  1377   def checkIsMyStudentProject(self, django_args):
       
  1378     """Checks whether the project belongs to the current user.
       
  1379 
       
  1380     Args:
       
  1381       django_args: a dictionary with django's arguments
       
  1382 
       
  1383      Raises:
       
  1384        AccessViolationResponse:
       
  1385          - If there is no project found
       
  1386          - If the project does not belong to the current user
       
  1387     """
       
  1388 
       
  1389     self.checkIsUser()
       
  1390 
       
  1391     project_entity = student_project_logic.getFromKeyFieldsOr404(django_args)
       
  1392 
       
  1393     if project_entity.student.user.key() != self.user.key():
       
  1394       raise out_of_band.AccessViolation(
       
  1395           message_fmt=DEF_NOT_YOUR_ENTITY_MSG)
       
  1396 
       
  1397     return
       
  1398 
       
  1399   @allowDeveloper
       
  1400   def checkStudentProjectHasStatus(self, django_args, allowed_status):
       
  1401     """Checks whether the Project has one of the given statusses.
       
  1402 
       
  1403     Args:
       
  1404       django_args: a dictionary with django's arguments
       
  1405       allowed_status: list with the allowed statusses for the entity
       
  1406 
       
  1407      Raises:
       
  1408        AccessViolationResponse:
       
  1409          - If there is no project found
       
  1410          - If the project is not in the requested status
       
  1411     """
       
  1412 
       
  1413     project_entity = student_project_logic.getFromKeyFieldsOr404(django_args)
       
  1414 
       
  1415     if not project_entity.status in allowed_status:
       
  1416       raise out_of_band.AccessViolation(
       
  1417           message_fmt=DEF_NO_ACTIVE_ENTITY_MSG)
       
  1418 
       
  1419     return
       
  1420 
       
  1421   @allowDeveloper
  1376   def checkIsMyEntity(self, django_args, logic,
  1422   def checkIsMyEntity(self, django_args, logic,
  1377                       field_name='user', user=False):
  1423                       field_name='user', user=False):
  1378     """Checks whether the entity belongs to the user.
  1424     """Checks whether the entity belongs to the user.
  1379 
  1425 
  1380     Args:
  1426     Args: