/usr/share/pyshared/schooltool/group/group.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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | #
# 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
#
"""
Group objects
"""
__docformat__ = 'restructuredtext'
from persistent import Persistent
from zope.annotation.interfaces import IAttributeAnnotatable
from zope.container.contained import Contained
from zope.container.btree import BTreeContainer
from zope.lifecycleevent.interfaces import IObjectAddedEvent
from zope.lifecycleevent.interfaces import IObjectRemovedEvent
from zope.lifecycleevent import ObjectAddedEvent
from zope.app.dependable.interfaces import IDependable
from zope.intid import addIntIdSubscriber
from zope.intid.interfaces import IIntIds
from zope.component import adapter
from zope.component import adapts
from zope.component import getAdapter
from zope.component import getUtility
from zope.interface import implementer
from zope.interface import implements
from schooltool.app.app import Asset
from schooltool.app.app import InitBase
from schooltool.app.interfaces import ICalendarParentCrowd
from schooltool.app.interfaces import ISchoolToolApplication
from schooltool.app.membership import GroupMemberCrowd
from schooltool.app.membership import URIMembership, URIMember, URIGroup
from schooltool.app.security import ConfigurableCrowd
from schooltool.app.security import LeaderCrowd
from schooltool.course.interfaces import ISection
from schooltool.group import interfaces
from schooltool.group.interfaces import IGroupContainer
from schooltool.relationship import RelationshipProperty
from schooltool.schoolyear.interfaces import ISchoolYear
from schooltool.schoolyear.interfaces import ISchoolYearContainer
from schooltool.schoolyear.subscriber import ObjectEventAdapterSubscriber
from schooltool.securitypolicy.crowds import Crowd, AggregateCrowd
from schooltool.securitypolicy.crowds import AggregateCrowdDescription
from schooltool.securitypolicy.metaconfigure import getCrowdsUtility
from schooltool.securitypolicy.interfaces import ICrowd
from schooltool.common import SchoolToolMessage as _
defaultGroups = {"manager" : _("Site Managers"),
"students" : _("Students"),
"teachers" : _("Teachers"),
"clerks" : _("Clerks"),
"administrators": _("School Administrators"),
}
class GroupContainerContainer(BTreeContainer):
"""Container of group containers."""
implements(interfaces.IGroupContainerContainer,
IAttributeAnnotatable)
class GroupContainer(BTreeContainer):
"""Container of groups."""
implements(interfaces.IGroupContainer, IAttributeAnnotatable)
@adapter(ISchoolYear)
@implementer(interfaces.IGroupContainer)
def getGroupContainer(sy):
addIntIdSubscriber(sy, ObjectAddedEvent(sy))
int_ids = getUtility(IIntIds)
sy_id = str(int_ids.getId(sy))
app = ISchoolToolApplication(None)
gc = app['schooltool.group'].get(sy_id, None)
if gc is None:
gc = app['schooltool.group'][sy_id] = GroupContainer()
return gc
@adapter(ISchoolToolApplication)
@implementer(interfaces.IGroupContainer)
def getGroupContainerForApp(app):
syc = ISchoolYearContainer(app)
sy = syc.getActiveSchoolYear()
if sy is None:
return None
return IGroupContainer(sy)
@adapter(ISection)
@implementer(interfaces.IGroupContainer)
def getGroupContainerForSection(section):
sy = ISchoolYear(section)
return IGroupContainer(sy)
@adapter(interfaces.IGroupContainer)
@implementer(ISchoolYear)
def getSchoolYearForGroupContainer(group_container):
container_id = int(group_container.__name__)
int_ids = getUtility(IIntIds)
container = int_ids.getObject(container_id)
return container
class Group(Persistent, Contained, Asset):
"""Group."""
implements(interfaces.IGroup, interfaces.IGroupContained,
IAttributeAnnotatable)
members = RelationshipProperty(URIMembership, URIGroup, URIMember)
def __init__(self, title=None, description=None):
self.title = title
self.description = description
# XXX Unit test ME!
class InitGroupsForNewSchoolYear(ObjectEventAdapterSubscriber):
adapts(IObjectAddedEvent, ISchoolYear)
def initializeGroupContainer(self):
groups = IGroupContainer(self.object)
for id, title in defaultGroups.items():
group = groups[id] = Group(title)
IDependable(group).addDependent('')
def importDefaultGroups(self, activeSchoolyear):
oldGroups = IGroupContainer(activeSchoolyear)
newGroups = IGroupContainer(self.object)
for groupId in defaultGroups:
if groupId in oldGroups:
oldGroup = oldGroups[groupId]
newGroup = Group(oldGroup.title, oldGroup.description)
newGroups[groupId] = newGroup
IDependable(newGroup).addDependent('')
def __call__(self):
app = ISchoolToolApplication(None)
syc = ISchoolYearContainer(app)
activeSchoolyear = syc.getActiveSchoolYear()
if activeSchoolyear is not None:
self.importDefaultGroups(activeSchoolyear)
else:
self.initializeGroupContainer()
class GroupInit(InitBase):
def __call__(self):
self.app['schooltool.group'] = GroupContainerContainer()
class GroupContainerViewersCrowd(ConfigurableCrowd):
setting_key = 'everyone_can_view_group_list'
class GroupViewersCrowd(ConfigurableCrowd):
setting_key = 'everyone_can_view_group_info'
class GroupCalendarSettingCrowd(ConfigurableCrowd):
setting_key = 'everyone_can_view_group_calendar'
class GroupCalendarViewersCrowd(AggregateCrowd):
implements(ICalendarParentCrowd)
adapts(interfaces.IGroup)
def crowdFactories(self):
return [GroupCalendarSettingCrowd, GroupMemberCrowd, LeaderCrowd]
class GroupCalendarMemberSettingCrowd(ConfigurableCrowd):
setting_key = 'members_can_edit_group_calendar'
class GroupCalendarEditorsCrowd(Crowd):
implements(ICalendarParentCrowd)
adapts(interfaces.IGroup)
def contains(self, principal):
"""Return the value of the related setting (True or False)."""
if (GroupCalendarMemberSettingCrowd(self.context).contains(principal) and
GroupMemberCrowd(self.context).contains(principal)):
return True
# Fall back to schooltool.edit for IGroup
crowd = getAdapter(self.context, ICrowd, name='schooltool.edit')
return crowd.contains(principal)
class GroupCalendarEditorsCrowdDescription(AggregateCrowdDescription):
def getFactories(self):
crowd_util = getCrowdsUtility()
crowds = crowd_util.getFactories('schooltool.edit', interfaces.IGroup)
return [GroupCalendarMemberSettingCrowd] + crowds
class RemoveGroupsWhenSchoolYearIsDeleted(ObjectEventAdapterSubscriber):
adapts(IObjectRemovedEvent, ISchoolYear)
def __call__(self):
group_container = IGroupContainer(self.object)
for group_id, group in list(group_container.items()):
IDependable(group).removeDependent('')
del group_container[group_id]
|