1654 # timeline does not exists so deny |
1654 # timeline does not exists so deny |
1655 self.deny(django_args) |
1655 self.deny(django_args) |
1656 |
1656 |
1657 fields = program_logic.getKeyFieldsFromFields(django_args) |
1657 fields = program_logic.getKeyFieldsFromFields(django_args) |
1658 self.checkIsHostForProgram(fields) |
1658 self.checkIsHostForProgram(fields) |
|
1659 |
|
1660 def checkHasSurveyAccess(self, django_args): |
|
1661 """Checks if the survey specified in django_args can be taken. |
|
1662 |
|
1663 Uses survey.taking_access to map that string onto a check. Also checks for |
|
1664 deadline start and end. |
|
1665 |
|
1666 If the prefix is 'program', the scope of the survey is the program and |
|
1667 the taking_acccess attribute means: |
|
1668 mentor: user is mentor for the program |
|
1669 org_admin: user is org_admin for the program |
|
1670 student: user is student for the program |
|
1671 user: valid user on the website |
|
1672 public: anyone can participate in the survey |
|
1673 """ |
|
1674 |
|
1675 if django_args['prefix'] != 'program': |
|
1676 # TODO : update when generic surveys are allowe |
|
1677 return self.deny(django_args) |
|
1678 |
|
1679 survey = survey_logic.getFromKeyFieldsOr404(django_args) |
|
1680 |
|
1681 if not timeline_helper.isActivePeriod(survey, 'survey'): |
|
1682 raise out_of_band.AccessViolation(message_fmt=DEF_PAGE_INACTIVE_MSG) |
|
1683 |
|
1684 role = survey.taking_access |
|
1685 |
|
1686 if role == 'public': |
|
1687 # TODO : are we sure we want public surveys? |
|
1688 return self.allow(django_args) |
|
1689 |
|
1690 if role == 'user': |
|
1691 return self.checkIsUser(django_args) |
|
1692 |
|
1693 django_args = django_args.copy() |
|
1694 |
|
1695 if role == 'mentor' or role == 'org_admin': |
|
1696 django_args['program'] = survey.scope |
|
1697 # program is the 'program' attribute for mentors and org_admins |
|
1698 return self._checkHasActiveRoleFor(django_args, mentor_logic, 'program') |
|
1699 |
|
1700 if role == 'student': |
|
1701 django_args['scope'] = survey.scope |
|
1702 # program is the 'scope' attribute for students |
|
1703 return self.checkHasActiveRoleForScope(django_args, student_logic) |
|
1704 |
|
1705 # unknown role |
|
1706 self.deny(django_args) |