app/soc/views/models/project_survey.py
changeset 2753 11d510941d2f
parent 2740 4b8aa5b9cb23
child 2754 efbce6839e90
equal deleted inserted replaced
2752:fb3bed3eecd8 2753:11d510941d2f
    56     rights['record'] = [('checkHasAny', [
    56     rights['record'] = [('checkHasAny', [
    57         [('checkIsAllowedToViewProjectSurveyRecordAs',
    57         [('checkIsAllowedToViewProjectSurveyRecordAs',
    58           [project_survey_logic, 'student', 'id']),
    58           [project_survey_logic, 'student', 'id']),
    59         ('checkIsSurveyReadable', [project_survey_logic]),
    59         ('checkIsSurveyReadable', [project_survey_logic]),
    60         ]])]
    60         ]])]
    61     rights['results'] = ['checkIsDeveloper'] # TODO: proper access check
    61     rights['results'] = ['checkIsUser']
    62     rights['take'] = [('checkIsSurveyTakeable', project_survey_logic),
    62     rights['take'] = [('checkIsSurveyTakeable', project_survey_logic),
    63                       ('checkIsAllowedToTakeProjectSurveyAs',
    63                       ('checkIsAllowedToTakeProjectSurveyAs',
    64                        [project_survey_logic, 'student', 'project'])]
    64                        [project_survey_logic, 'student', 'project'])]
    65     rights['send_reminder'] = ['checkIsDeveloper'] #TODO: proper access check
    65     rights['send_reminder'] = ['checkIsDeveloper'] #TODO: proper access check
    66 
    66 
   253 
   253 
   254     content = lists.getListContent(request, student_project_params, fields)
   254     content = lists.getListContent(request, student_project_params, fields)
   255     contents = [content]
   255     contents = [content]
   256 
   256 
   257     return self._list(request, student_project_params, contents, page_name)
   257     return self._list(request, student_project_params, contents, page_name)
       
   258 
       
   259   def _getResultsViewRecordFields(self, survey, allowed_to_read):
       
   260     """Get the Results View filter for ProjectSurveyRecords.
       
   261 
       
   262     For args see survey.View()._getResultsViewRecordFields()
       
   263 
       
   264     Returns:
       
   265       Returns the dictionary containing the fields to filter on
       
   266     """
       
   267 
       
   268     from soc.logic.models.org_admin import logic as org_admin_logic
       
   269     from soc.logic.models.student import logic as student_logic
       
   270 
       
   271     if allowed_to_read:
       
   272       return super(View, self)._getResultsViewRecordFields(survey,
       
   273                                                            allowed_to_read)
       
   274 
       
   275     fields = {'survey': survey}
       
   276 
       
   277     program_entity = survey.scope
       
   278     user_entity = user_logic.getForCurrentAccount()
       
   279 
       
   280     student_fields = {'scope': program_entity,
       
   281                       'user': user_entity,
       
   282                       'status': ['active', 'inactive']}
       
   283     student_entity = student_logic.getForFields(student_fields, unique=True)
       
   284 
       
   285     if student_entity:
       
   286       # just get all records for the current user
       
   287       fields['user'] = user_entity
       
   288       return fields
       
   289 
       
   290     org_admin_fields = {'user': user_entity,
       
   291                         'program': program_entity,
       
   292                         'status': ['active', 'inactive']}
       
   293 
       
   294     org_admins = org_admin_logic.getForFields(org_admin_fields)
       
   295 
       
   296     if org_admins:
       
   297       # filter on all the organizations this user is org admin for
       
   298       organizations = []
       
   299 
       
   300       for org_admin in org_admins:
       
   301         organizations.append(org_admin.scope)
       
   302 
       
   303       # TODO: this might blow up if the user is org admin for too many orgs
       
   304       fields['org'] = organizations
       
   305 
       
   306     return fields
   258 
   307 
   259   @decorators.merge_params
   308   @decorators.merge_params
   260   @decorators.check_access
   309   @decorators.check_access
   261   def sendReminder(self, request, access_type, page_name=None,
   310   def sendReminder(self, request, access_type, page_name=None,
   262                    params=None, **kwargs):
   311                    params=None, **kwargs):