Merge lp:~aelkner/schooltool/january_fixes into lp:schooltool/1.7

Proposed by Alan Elkner
Status: Superseded
Proposed branch: lp:~aelkner/schooltool/january_fixes
Merge into: lp:schooltool/1.7
Diff against target: 127 lines (+88/-2)
3 files modified
src/schooltool/basicperson/security.py (+18/-2)
src/schooltool/basicperson/security.zcml (+9/-0)
src/schooltool/basicperson/tests/test_security.py (+61/-0)
To merge this branch: bzr merge lp:~aelkner/schooltool/january_fixes
Reviewer Review Type Date Requested Status
SchoolTool Owners Pending
Review via email: mp+18296@code.launchpad.net

This proposal has been superseded by a proposal from 2010-02-09.

To post a comment you must log in.
lp:~aelkner/schooltool/january_fixes updated
2626. By Alan Elkner <aelkner@ubuntu>

created split and fieldset widget rows for schooltool.intervention views

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/schooltool/basicperson/security.py'
2--- src/schooltool/basicperson/security.py 2009-11-06 14:49:44 +0000
3+++ src/schooltool/basicperson/security.py 2010-01-30 09:23:15 +0000
4@@ -24,10 +24,12 @@
5 """
6 from zope.traversing.api import getParent
7
8+from schooltool.app.interfaces import ISchoolToolApplication
9 from schooltool.basicperson.interfaces import IBasicPerson
10+from schooltool.common import SchoolToolMessage as _
11 from schooltool.group.interfaces import IGroupContainer
12-from schooltool.securitypolicy.crowds import ConfigurableCrowd
13-from schooltool.app.interfaces import ISchoolToolApplication
14+from schooltool.person.interfaces import IPerson
15+from schooltool.securitypolicy.crowds import Crowd, ConfigurableCrowd
16
17
18 class PersonInfoViewersCrowd(ConfigurableCrowd):
19@@ -56,3 +58,17 @@
20 return (ConfigurableCrowd.contains(self, principal) or
21 teachers in groups)
22
23+
24+class PersonAdvisorsCrowd(Crowd):
25+ """Crowd of advisors of a person."""
26+
27+ title = _(u'Advisors')
28+ description = _(u'Advisors of a person.')
29+
30+ def contains(self, principal):
31+ user = IPerson(principal, None)
32+ person = self.context
33+ if not IBasicPerson.providedBy(person):
34+ return False
35+ return user in person.advisors
36+
37
38=== modified file 'src/schooltool/basicperson/security.zcml'
39--- src/schooltool/basicperson/security.zcml 2009-11-02 13:45:40 +0000
40+++ src/schooltool/basicperson/security.zcml 2010-01-30 09:23:15 +0000
41@@ -3,11 +3,20 @@
42 xmlns:zope="http://namespaces.zope.org/zope"
43 i18n_domain="schooltool">
44
45+ <crowd
46+ name="person_advisors"
47+ factory="schooltool.basicperson.security.PersonAdvisorsCrowd" />
48+
49 <allow
50 interface="schooltool.basicperson.interfaces.IFieldDescription"
51 crowds="administration"
52 permission="schooltool.edit" />
53
54+ <allow
55+ interface="schooltool.person.interfaces.IPerson"
56+ crowds="person_advisors"
57+ permission="schooltool.view" />
58+
59 <!-- Security descriptions -->
60
61 <describe_group
62
63=== added file 'src/schooltool/basicperson/tests/test_security.py'
64--- src/schooltool/basicperson/tests/test_security.py 1970-01-01 00:00:00 +0000
65+++ src/schooltool/basicperson/tests/test_security.py 2010-01-30 09:23:15 +0000
66@@ -0,0 +1,61 @@
67+#
68+# SchoolTool - common information systems platform for school administration
69+# Copyright (c) 2007 Shuttleworth Foundation
70+#
71+# This program is free software; you can redistribute it and/or modify
72+# it under the terms of the GNU General Public License as published by
73+# the Free Software Foundation; either version 2 of the License, or
74+# (at your option) any later version.
75+#
76+# This program is distributed in the hope that it will be useful,
77+# but WITHOUT ANY WARRANTY; without even the implied warranty of
78+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
79+# GNU General Public License for more details.
80+#
81+# You should have received a copy of the GNU General Public License
82+# along with this program; if not, write to the Free Software
83+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
84+#
85+"""
86+Unit tests for basic person security.
87+"""
88+import unittest
89+import doctest
90+
91+from schooltool.relationship.tests import setUp, tearDown
92+
93+
94+def doctest_PersonAdvisorsCrowd():
95+ """Tests for PersonAdvisorsCrowd.
96+
97+ We'll create an advisor and two students.
98+
99+ >>> from schooltool.basicperson.person import BasicPerson
100+ >>> student1 = BasicPerson("student", "Student", "One")
101+ >>> student2 = BasicPerson("student", "Student", "Two")
102+ >>> advisor = BasicPerson("advisor", "Advisor", "One")
103+
104+ The advisor will only advise the first student.
105+
106+ >>> student1.advisors.add(advisor)
107+
108+ Hence, the advisor will belong to the first student's advisors crowd and
109+ not the second.
110+
111+ >>> from schooltool.basicperson.security import PersonAdvisorsCrowd
112+ >>> PersonAdvisorsCrowd(student1).contains(advisor)
113+ True
114+ >>> PersonAdvisorsCrowd(student2).contains(advisor)
115+ False
116+
117+ """
118+
119+
120+def test_suite():
121+ optionflags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
122+ return doctest.DocTestSuite(optionflags=optionflags,
123+ setUp=setUp, tearDown=tearDown)
124+
125+
126+if __name__ == '__main__':
127+ unittest.main(defaultTest='test_suite')

Subscribers

People subscribed via source and target branches