~ubuntu-branches/ubuntu/raring/schooltool.intervention/raring

« back to all changes in this revision

Viewing changes to src/schooltool/intervention/security.py

  • Committer: Gediminas Paulauskas
  • Date: 2011-09-19 16:56:45 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: menesis@pov.lt-20110919165645-718diuud5tc4mjsx
Tags: 0.5.0-0ubuntu1
* New upstream release.
* debian/rules: move gradebook to Suggests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# SchoolTool - common information systems platform for school administration
 
3
# Copyright (c) 2005 Shuttleworth Foundation
 
4
#
 
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.
 
9
#
 
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.
 
14
#
 
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
 
18
#
 
19
 
 
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
 
24
 
 
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
 
31
 
 
32
from schooltool.intervention import InterventionGettext as _
 
33
import interfaces
 
34
 
 
35
 
 
36
class InterventionInstructorsCrowd(crowds.Crowd):
 
37
    """Crowd of instructors of the student indicated by the given 
 
38
       intervention object."""
 
39
 
 
40
    title = _(u'Instructors')
 
41
    description = _(u'Instructors of a student in any of his sections.')
 
42
 
 
43
    def _getSections(self, ob):
 
44
        return [section for section in getRelatedObjects(ob, URIGroup)
 
45
                if ISection.providedBy(section)]
 
46
 
 
47
    def contains(self, principal):
 
48
        if IUnauthenticatedPrincipal.providedBy(principal):
 
49
            return False
 
50
        teacher = IPerson(principal)
 
51
        student = removeSecurityProxy(IPerson(self.context))
 
52
        for section in self._getSections(student):
 
53
            if teacher in section.instructors:
 
54
                return True
 
55
        return False
 
56
 
 
57
 
 
58
class InterventionAdvisorsCrowd(crowds.Crowd):
 
59
    """Crowd of advisors of the student indicated by the given 
 
60
       intervention object."""
 
61
 
 
62
    title = _(u'Advisors')
 
63
    description = _(u'Advisors of a student.')
 
64
 
 
65
    def contains(self, principal):
 
66
        if IUnauthenticatedPrincipal.providedBy(principal):
 
67
            return False
 
68
        teacher = IPerson(principal)
 
69
        student = removeSecurityProxy(IPerson(self.context))
 
70
        return teacher in student.advisors
 
71
 
 
72
 
 
73
class BaseResponsibleCrowd(crowds.Crowd):
 
74
    """Crowd of any user who is on the list of persons responsible for the
 
75
       message or goal."""
 
76
 
 
77
    def contains(self, principal):
 
78
        if IUnauthenticatedPrincipal.providedBy(principal):
 
79
            return False
 
80
        if not interfaces.IInterventionMarker.providedBy(self.context):
 
81
            return False
 
82
        responsible = interfaces.IInterventionPersonsResponsible(self.context)
 
83
        contact_id = getUtility(IIntIds).getId(IContact(IPerson(principal)))
 
84
        return contact_id in responsible
 
85
 
 
86
 
 
87
class StaffResponsibleCrowd(BaseResponsibleCrowd):
 
88
    """Crowd of school staff who are on the list of persons responsible for the
 
89
       message or goal."""
 
90
 
 
91
    title = _(u'Staff responsible')
 
92
    description = _(u'Staff members responsible for the message or goal.')
 
93
 
 
94
    def contains(self, principal):
 
95
        if not super(StaffResponsibleCrowd, self).contains(principal):
 
96
            return False
 
97
        student = removeSecurityProxy(IPerson(self.context))
 
98
        return IPerson(principal).username != student.username
 
99
 
 
100
 
 
101
class StudentResponsibleCrowd(BaseResponsibleCrowd):
 
102
    """Crowd containing the student who is in the list of persons responsible
 
103
       for the message or goal."""
 
104
 
 
105
    title = _(u'Students responsible')
 
106
    description = _(u'Students responsible for the message or goal.')
 
107
 
 
108
    def contains(self, principal):
 
109
        if not super(StudentResponsibleCrowd, self).contains(principal):
 
110
            return False
 
111
        student = removeSecurityProxy(IPerson(self.context))
 
112
        return IPerson(principal).username == student.username
 
113