145 'Please <a href="%(sign_out)s">sign out</a> in order to view this page.') |
145 'Please <a href="%(sign_out)s">sign out</a> in order to view this page.') |
146 |
146 |
147 DEF_GROUP_NOT_FOUND_MSG = ugettext( |
147 DEF_GROUP_NOT_FOUND_MSG = ugettext( |
148 'The requested Group can not be found.') |
148 'The requested Group can not be found.') |
149 |
149 |
150 DEF_NO_ACTIVE_STUDENT_PROJECT_MSG = ugettext( |
150 DEF_NOT_ALLOWED_PROJECT_FOR_SURVEY_MSG = ugettext( |
151 'There is no active student project that would allow you to take this survey.') |
151 'You are not allowed to take this Survey for the specified Student Project') |
152 |
152 |
153 DEF_USER_ACCOUNT_INVALID_MSG_FMT = ugettext( |
153 DEF_USER_ACCOUNT_INVALID_MSG_FMT = ugettext( |
154 'The <b><i>%(email)s</i></b> account cannot be used with this site, for' |
154 'The <b><i>%(email)s</i></b> account cannot be used with this site, for' |
155 ' one or more of the following reasons:' |
155 ' one or more of the following reasons:' |
156 '<ul>' |
156 '<ul>' |
157 ' <li>the account is invalid</li>' |
157 ' <li>the account is invalid</li>' |
158 ' <li>the account is already attached to a User profile and cannot be' |
158 ' <li>the account is already attached to a User profile and cannot be' |
159 ' used to create another one</li>' |
159 ' used to create another one</li>' |
160 ' <li>the account is a former account that cannot be used again</li>' |
160 ' <li>the account is a former account that cannot be used again</li>' |
161 '</ul>') |
161 '</ul>') |
|
162 |
|
163 |
|
164 class Error(Exception): |
|
165 """Base class for all exceptions raised by this module. |
|
166 """ |
|
167 |
|
168 pass |
|
169 |
|
170 |
|
171 class InvalidArgumentError(Error): |
|
172 """Raised when an invalid argument is passed to a method. |
|
173 |
|
174 For example, if an argument is None, but must always be non-False. |
|
175 """ |
|
176 |
|
177 pass |
162 |
178 |
163 |
179 |
164 def allowSidebar(fun): |
180 def allowSidebar(fun): |
165 """Decorator that allows access if the sidebar is calling. |
181 """Decorator that allows access if the sidebar is calling. |
166 """ |
182 """ |
1633 role_name: String containing either "student" or "mentor" |
1649 role_name: String containing either "student" or "mentor" |
1634 project_key_location: String containing the key entry in the GET dict |
1650 project_key_location: String containing the key entry in the GET dict |
1635 where the key for the project can be located. |
1651 where the key for the project can be located. |
1636 """ |
1652 """ |
1637 |
1653 |
1638 # TODO(ljvderijk) implement this check |
1654 if not role_name in ['mentor', 'student']: |
1639 #raise out_of_band.AccessViolation(message_fmt=DEF_NO_ACTIVE_STUDENT_PROJECT_MSG) |
1655 raise InvalidArgumentError('role_name is not mentor or student') |
1640 |
1656 |
1641 self.allow(django_args) |
1657 # get the project keyname from the GET dictionary |
|
1658 get_dict= django_args['GET'] |
|
1659 key_name = get_dict.get(project_key_location) |
|
1660 |
|
1661 if not key_name: |
|
1662 # no key name present so no need to deny access |
|
1663 return |
|
1664 |
|
1665 # retrieve the Student Project for the key |
|
1666 entity = student_project_logic.getFromKeyNameOr404(key_name) |
|
1667 |
|
1668 # TODO(ljvderijk) change this to cope with multiple surveys for one project |
|
1669 # check if a survey can be conducted about this project |
|
1670 if entity.status != 'accepted': |
|
1671 raise out_of_band.AccessViolation( |
|
1672 message_fmt=DEF_NOT_ALLOWED_PROJECT_FOR_SURVEY_MSG) |
|
1673 |
|
1674 # get the correct role depending on the role_name |
|
1675 role_entity = getattr(entity, role_name) |
|
1676 user_entity = user_logic.getForCurrentAccount() |
|
1677 |
|
1678 # check if the role matches the current user |
|
1679 if (not user_entity) or (role_entity.user.key() != user_entity.key()): |
|
1680 raise out_of_band.AccessViolation( |
|
1681 message_fmt=DEF_NOT_ALLOWED_PROJECT_FOR_SURVEY_MSG) |
|
1682 |
|
1683 # check if the role is active |
|
1684 if role_entity.status != 'active': |
|
1685 raise out_of_band.AccessViolation(message_fmt=DEF_NEED_ROLE_MSG) |
|
1686 |
|
1687 return |
1642 |
1688 |
1643 @allowSidebar |
1689 @allowSidebar |
1644 @allowDeveloper |
1690 @allowDeveloper |
1645 def checkIsDocumentReadable(self, django_args, key_name_field=None): |
1691 def checkIsDocumentReadable(self, django_args, key_name_field=None): |
1646 """Checks whether a document is readable by the current user. |
1692 """Checks whether a document is readable by the current user. |