2
# SchoolTool - common information systems platform for school administration
3
# Copyright (c) 2005 Shuttleworth Foundation
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
from zope.authentication.interfaces import IUnauthenticatedPrincipal
21
from zope.component import getUtility
22
from zope.intid.interfaces import IIntIds
23
from zope.security.proxy import removeSecurityProxy
25
from schooltool.app.membership import URIGroup
26
from schooltool.contact.interfaces import IContact
27
from schooltool.course.interfaces import ISection
28
from schooltool.person.interfaces import IPerson
29
from schooltool.relationship.relationship import getRelatedObjects
30
from schooltool.securitypolicy import crowds
32
from schooltool.intervention import InterventionGettext as _
36
class InterventionInstructorsCrowd(crowds.Crowd):
37
"""Crowd of instructors of the student indicated by the given
38
intervention object."""
40
title = _(u'Instructors')
41
description = _(u'Instructors of a student in any of his sections.')
43
def _getSections(self, ob):
44
return [section for section in getRelatedObjects(ob, URIGroup)
45
if ISection.providedBy(section)]
47
def contains(self, principal):
48
if IUnauthenticatedPrincipal.providedBy(principal):
50
teacher = IPerson(principal)
51
student = removeSecurityProxy(IPerson(self.context))
52
for section in self._getSections(student):
53
if teacher in section.instructors:
58
class InterventionAdvisorsCrowd(crowds.Crowd):
59
"""Crowd of advisors of the student indicated by the given
60
intervention object."""
62
title = _(u'Advisors')
63
description = _(u'Advisors of a student.')
65
def contains(self, principal):
66
if IUnauthenticatedPrincipal.providedBy(principal):
68
teacher = IPerson(principal)
69
student = removeSecurityProxy(IPerson(self.context))
70
return teacher in student.advisors
73
class BaseResponsibleCrowd(crowds.Crowd):
74
"""Crowd of any user who is on the list of persons responsible for the
77
def contains(self, principal):
78
if IUnauthenticatedPrincipal.providedBy(principal):
80
if not interfaces.IInterventionMarker.providedBy(self.context):
82
responsible = interfaces.IInterventionPersonsResponsible(self.context)
83
contact_id = getUtility(IIntIds).getId(IContact(IPerson(principal)))
84
return contact_id in responsible
87
class StaffResponsibleCrowd(BaseResponsibleCrowd):
88
"""Crowd of school staff who are on the list of persons responsible for the
91
title = _(u'Staff responsible')
92
description = _(u'Staff members responsible for the message or goal.')
94
def contains(self, principal):
95
if not super(StaffResponsibleCrowd, self).contains(principal):
97
student = removeSecurityProxy(IPerson(self.context))
98
return IPerson(principal).username != student.username
101
class StudentResponsibleCrowd(BaseResponsibleCrowd):
102
"""Crowd containing the student who is in the list of persons responsible
103
for the message or goal."""
105
title = _(u'Students responsible')
106
description = _(u'Students responsible for the message or goal.')
108
def contains(self, principal):
109
if not super(StudentResponsibleCrowd, self).contains(principal):
111
student = removeSecurityProxy(IPerson(self.context))
112
return IPerson(principal).username == student.username