58 rights['record'] = [('checkHasAny', [ |
58 rights['record'] = [('checkHasAny', [ |
59 [('checkIsAllowedToViewProjectSurveyRecordAs', |
59 [('checkIsAllowedToViewProjectSurveyRecordAs', |
60 [grading_survey_logic, 'mentor', 'id']), |
60 [grading_survey_logic, 'mentor', 'id']), |
61 ('checkIsSurveyReadable', [grading_survey_logic]), |
61 ('checkIsSurveyReadable', [grading_survey_logic]), |
62 ]])] |
62 ]])] |
63 rights['results'] = ['checkIsDeveloper'] # TODO: proper access check |
63 rights['results'] = ['checkIsUser'] |
64 rights['take'] = [('checkIsSurveyTakeable', grading_survey_logic), |
64 rights['take'] = [('checkIsSurveyTakeable', grading_survey_logic), |
65 ('checkIsAllowedToTakeProjectSurveyAs', |
65 ('checkIsAllowedToTakeProjectSurveyAs', |
66 [grading_survey_logic, 'mentor', 'project'])] |
66 [grading_survey_logic, 'mentor', 'project'])] |
67 |
67 |
68 new_params = {} |
68 new_params = {} |
111 # TODO: Ensure that this doesn't break when someone is a mentor for |
111 # TODO: Ensure that this doesn't break when someone is a mentor for |
112 # a lot of organizations. |
112 # a lot of organizations. |
113 |
113 |
114 fields = {'mentor': mentor_entities, |
114 fields = {'mentor': mentor_entities, |
115 'status': 'accepted'} |
115 'status': 'accepted'} |
|
116 |
|
117 return fields |
|
118 |
|
119 def _getResultsViewRecordFields(self, survey, allowed_to_read): |
|
120 """Get the Results View filter for ProjectSurveyRecords. |
|
121 |
|
122 For args see survey.View()._getResultsViewRecordFields() |
|
123 |
|
124 Returns: |
|
125 Returns the dictionary containing the fields to filter on |
|
126 """ |
|
127 |
|
128 from soc.logic.models.mentor import logic as mentor_logic |
|
129 from soc.logic.models.org_admin import logic as org_admin_logic |
|
130 |
|
131 if allowed_to_read: |
|
132 return super(View, self)._getResultsViewRecordFields(survey, |
|
133 allowed_to_read) |
|
134 |
|
135 fields = {'survey': survey} |
|
136 |
|
137 user_entity = user_logic.getForCurrentAccount() |
|
138 program_entity = survey.scope |
|
139 |
|
140 role_fields = {'user': user_entity, |
|
141 'program': program_entity, |
|
142 'status': ['active', 'inactive']} |
|
143 |
|
144 org_admins = org_admin_logic.getForFields(role_fields) |
|
145 mentors = mentor_logic.getForFields(role_fields) |
|
146 |
|
147 organizations = {} |
|
148 |
|
149 if org_admins: |
|
150 for org_admin in org_admins: |
|
151 # for each org admin store the organization |
|
152 org_scope = org_admin.scope |
|
153 org_key_name = org_scope.key().id_or_name() |
|
154 organizations[org_key_name] = org_scope |
|
155 |
|
156 if mentors: |
|
157 for mentor in mentors: |
|
158 # for each mentor store the organization |
|
159 # This will allow the user to view the GradingProjectSurvey Records |
|
160 # listing for projects which he might have no further access to. |
|
161 org_scope = mentor.scope |
|
162 org_key_name = org_scope.key().id_or_name() |
|
163 organizations[org_key_name] = org_scope |
|
164 |
|
165 if organizations: |
|
166 # filter on all the found organizations |
|
167 fields['org'] = organizations.values() |
|
168 else: |
|
169 # This user is no org admin or mentor and should only see |
|
170 # his/her own records. |
|
171 fields['user'] = user_entity |
116 |
172 |
117 return fields |
173 return fields |
118 |
174 |
119 |
175 |
120 class GradeSurveyTakeForm(surveys.SurveyTakeForm): |
176 class GradeSurveyTakeForm(surveys.SurveyTakeForm): |