/usr/share/pyshared/schooltool/person/person.py is in python-schooltool 1:2.1.0-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | #
# SchoolTool - common information systems platform for school administration
# Copyright (c) 2005 Shuttleworth Foundation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""
Person implementation and support objects
$Id$
"""
import hashlib
from persistent import Persistent
from zope.interface import implements, implementer
from zope.annotation.interfaces import IAttributeAnnotatable
from zope.container import btree
from zope.container.contained import Contained
from zope.component import adapts, adapter
from zope.component import getUtility
from schooltool.app.interfaces import ISchoolToolApplication
from schooltool.app.interfaces import ISchoolToolCalendar
from schooltool.app.membership import URIMembership, URIMember, URIGroup
from schooltool.app.overlay import OverlaidCalendarsProperty
from schooltool.app.catalog import AttributeCatalog
from schooltool.person import interfaces
from schooltool.relationship import RelationshipProperty
from schooltool.securitypolicy.crowds import Crowd
from schooltool.person.interfaces import IPerson
from schooltool.app.security import ICalendarParentCrowd
from schooltool.securitypolicy.crowds import ConfigurableCrowd
from schooltool.person.interfaces import IPersonPreferences
from schooltool.person.interfaces import IPasswordWriter
from schooltool.securitypolicy.crowds import OwnerCrowd, AggregateCrowd
from schooltool.utility.utility import UtilitySetUp
class PersonContainer(btree.BTreeContainer):
"""Container of persons."""
implements(interfaces.IPersonContainer, IAttributeAnnotatable)
super_user = None
def __setitem__(self, key, person):
"""See `IWriteContainer`
Ignores `key` and uses `person.username` as the key.
"""
key = person.username
btree.BTreeContainer.__setitem__(self, key, person)
class Person(Persistent, Contained):
"""Person."""
implements(interfaces.IPersonContained, IAttributeAnnotatable)
photo = None
username = None
_hashed_password = None
groups = RelationshipProperty(URIMembership, URIMember, URIGroup)
overlaid_calendars = OverlaidCalendarsProperty()
def __init__(self, username=None, title=None):
self.title = title
self.username = username
def setPassword(self, password):
self._hashed_password = hash_password(password)
def checkPassword(self, password):
return (self._hashed_password is not None
and hash_password(password) == self._hashed_password)
def hasPassword(self):
return self._hashed_password is not None
def __eq__(self, other):
if not IPerson.providedBy(other):
return False
return self.username == other.username
def hash_password(password):
r"""Compute a SHA-1 hash of a given password.
>>> hash_password('secret')
'\xe5\xe9\xfa\x1b\xa3\x1e\xcd\x1a\xe8Ou\xca\xaaGO:f?\x05\xf4'
Passwords should be ASCII or Unicode strings.
>>> hash_password('\u263B')
'\xe4\x13\xef\x8dv3\xba*P\xbb1\xa2k\x9c|,n\xe3mL'
To avoid problems with a multitude of 8-bit encodings, they are forbidden
>>> hash_password('\xFF') # doctest: +ELLIPSIS
Traceback (most recent call last):
...
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in ...
None means "no password set, account is locked":
>>> hash_password(None) is None
True
Security note: passwords are not salted, so it is possible to detect
users that have the same password.
"""
if password is None:
return None
return hashlib.sha1(password.encode('UTF-8')).digest()
def personAppCalendarOverlaySubscriber(person, event):
"""Add application calendar to overlays of all new persons.
"""
app = ISchoolToolApplication(None, None)
if app is None:
# If we get this we are probably in the initial new-site setup
# or creating a new manager during startup. This should be
# safe to ignore since it will happen very infrequently
# (perhaps only once) and the manager can easily add the site
# calendar to his/her overlay in the overlay selection view.
return
person.overlaid_calendars.add(ISchoolToolCalendar(app))
from schooltool.app.app import InitBase
class PersonInit(InitBase):
def __call__(self):
self.app['persons'] = PersonContainer()
class PublicCalendarCrowd(Crowd):
def contains(self, principal):
cal_public = IPersonPreferences(self.context).cal_public
return cal_public
class PersonCalendarCrowd(AggregateCrowd):
adapts(IPerson)
implements(ICalendarParentCrowd)
def crowdFactories(self):
return [PublicCalendarCrowd, OwnerCrowd]
def getCalendarOwner(calendar):
return IPerson(calendar.__parent__, None)
@adapter(IPerson)
@implementer(interfaces.IPersonContainer)
def getContainerOfPerson(person):
return person.__parent__
class PersonPasswordWriter(object):
"""Adapter of person to IPasswordWriter."""
adapts(IPerson)
implements(IPasswordWriter)
def __init__(self, person):
self.person = person
def setPassword(self, password):
"""See IPasswordWriter."""
self.person.setPassword(password)
class PersonListViewersCrowd(ConfigurableCrowd):
"""The crowd of people who can view the person list."""
setting_key = 'everyone_can_view_person_list'
class PasswordWriterCrowd(ConfigurableCrowd):
setting_key = 'persons_can_change_their_passwords'
def contains(self, principal):
"""Return the value of the related setting (True or False)."""
return (ConfigurableCrowd.contains(self, principal) and
OwnerCrowd(self.context.person).contains(principal))
class PersonCatalog(AttributeCatalog):
version = '1 - replaced catalog utility'
interface = IPerson
attributes = ('__name__', 'title')
getPersonCatalog = PersonCatalog.get
|