source: main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py @ 6207

Last change on this file since 6207 was 6180, checked in by uli, 13 years ago

Add local roles dicts for user accounts. That seems to
need pretty much machinery, but seems also to work. So,
why not?

We have a new event type, that should be fired when
a local role is set or unset somewhere.

We have also two new event subscribers, one listening
to the new event (and then updates the user account
local roles listings), and another one listening to
IObjectRemoved events.

The latter is the trick to keep the local role listings
in user accounts more or less up-to-date. Without it
these lists would grow and grow, not noticing that
the objects they refer to, have gone already.

We now must think about subscribing to other events.
What happens, when an object is moved or copied.
Will the local roles then be copied as well? And would
that fact be reflected in user accounts?

Beside this we have to find all places in sources
where local roles are set/unset and trigger the new
LocalRoleSetEvent? defined in users.py.

Samples for the whole new stuff are in authentication.txt.

  • Property svn:eol-style set to native
File size: 10.2 KB
Line 
1##
2## interfaces.py
3from zc.sourcefactory.basic import BasicSourceFactory
4from zope import schema
5from zope.catalog.interfaces import ICatalog
6from zope.component import getUtility
7from zope.component.interfaces import IObjectEvent
8from zope.interface import Interface, Attribute, implements
9from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
10
11class FatalCSVError(Exception):
12    """Some row could not be processed.
13    """
14    pass
15
16def SimpleWAeUPVocabulary(*terms):
17    """A well-buildt vocabulary provides terms with a value, token and
18       title for each term
19    """
20    return SimpleVocabulary([
21            SimpleTerm(value, value, title) for title, value in terms])
22
23class RoleSource(BasicSourceFactory):
24    def getValues(self):
25        # late import: in interfaces we should not import local modules
26        from waeup.sirp.permissions import getWAeUPRoleNames
27        return getWAeUPRoleNames()
28
29    def getTitle(self, value):
30        # late import: in interfaces we should not import local modules
31        from waeup.sirp.permissions import getRoles
32        roles = dict(getRoles())
33        if value in roles.keys():
34            title = roles[value].title
35        if '.' in title:
36            title = title.split('.', 2)[1]
37        return title
38
39class IWAeUPObject(Interface):
40    """A WAeUP object.
41
42    This is merely a marker interface.
43    """
44
45class IUniversity(IWAeUPObject):
46    """Representation of a university.
47    """
48    name = schema.TextLine(
49        title = u'Name of University',
50        default = u'Unnamed',
51        required = True,
52        )
53
54    title = schema.TextLine(
55        title = u'Title of frontpage',
56        default = u'No Title',
57        required = False,
58        )
59
60    skin = schema.Choice(
61        title = u'Skin',
62        default = u'waeuptheme-gray1.css',
63        vocabulary = 'waeup.sirp.browser.theming.ThemesVocabulary',
64        required = True,
65        )
66
67    frontpage = schema.Text(
68        title = u'Content in reST format',
69        required = False,
70        default = u'This is the SIRP frontpage.'
71        )
72
73    faculties = Attribute("A container for faculties.")
74    students = Attribute("A container for students.")
75    hostels = Attribute("A container for hostels.")
76
77class IWAeUPContainer(IWAeUPObject):
78    """A container for WAeUP objects.
79    """
80
81class IWAeUPContained(IWAeUPObject):
82    """An item contained in an IWAeUPContainer.
83    """
84
85class IStudentContainer(IWAeUPContainer):
86    """A container for StudentObjects.
87    """
88
89
90class IHostelContainer(IWAeUPContainer):
91    """A container for hostels.
92    """
93    def addHostel(hostel):
94        """Add an IHostel object.
95
96        Returns the key, under which the object was stored.
97        """
98
99class IHostel(IWAeUPObject):
100    """Representation of a hostel.
101    """
102    name = schema.TextLine(
103        title = u'Name of Hostel',
104        default = u'Nobody',
105        required = True,
106        )
107
108
109class IWAeUPExporter(Interface):
110    """An exporter for objects.
111    """
112    def export(obj, filepath=None):
113        """Export by pickling.
114
115        Returns a file-like object containing a representation of `obj`.
116
117        This is done using `pickle`. If `filepath` is ``None``, a
118        `cStringIO` object is returned, that contains the saved data.
119        """
120
121class IWAeUPXMLExporter(Interface):
122    """An XML exporter for objects.
123    """
124    def export(obj, filepath=None):
125        """Export as XML.
126
127        Returns an XML representation of `obj`.
128
129        If `filepath` is ``None``, a StringIO` object is returned,
130        that contains the transformed data.
131        """
132
133class IWAeUPXMLImporter(Interface):
134    """An XML import for objects.
135    """
136    def doImport(filepath):
137        """Create Python object from XML.
138
139        Returns a Python object.
140        """
141
142class IBatchProcessor(Interface):
143    """A batch processor that handles mass-operations.
144    """
145    name = schema.TextLine(
146        title = u'Importer name'
147        )
148
149    mode = schema.Choice(
150        title = u'Import mode',
151        values = ['create', 'update', 'remove']
152        )
153
154    def doImport(path, headerfields, mode='create', user='Unknown',
155                 logger=None):
156        """Read data from ``path`` and update connected object.
157
158        `headerfields` is a list of headerfields as read from the file
159        to import.
160
161        `mode` gives the import mode to use (``'create'``,
162        ``'update'``, or ``'remove'``.
163
164        `user` is a string describing the user performing the
165        import. Normally fetched from current principal.
166
167        `logger` is the logger to use during import.
168        """
169
170class ISchemaTypeConverter(Interface):
171    """A converter for zope.schema.types.
172    """
173    def convert(string):
174        """Convert string to certain schema type.
175        """
176
177
178class IUserAccount(IWAeUPObject):
179    """A user account.
180    """
181    name = schema.TextLine(
182        title = u'User ID',
183        description = u'Loginname',
184        required = True,)
185    title = schema.TextLine(
186        title = u'Username',
187        description = u'Real name',
188        required = False,)
189    description = schema.TextLine(
190        title = u'User description',
191        required = False,)
192    password = schema.Password(
193        title = u'Password',
194        required = True,)
195    roles = schema.List(
196        title = u'Roles',
197        value_type = schema.Choice(source=RoleSource()))
198
199
200class IUserContainer(IWAeUPObject):
201    """A container for users (principals).
202
203    These users are used for authentication purposes.
204    """
205
206    def addUser(name, password, title=None, description=None):
207        """Add a user.
208        """
209
210    def delUser(name):
211        """Delete a user if it exists.
212        """
213
214class ILocalRolesAssignable(Interface):
215    """The local roles assignable to an object.
216    """
217    def __call__():
218        """Returns a list of dicts.
219
220        Each dict contains a ``name`` referring to the role assignable
221        for the specified object and a `title` to describe the range
222        of users to which this role can be assigned.
223        """
224
225class IDataCenter(IWAeUPObject):
226    """A data center.
227
228    TODO : declare methods, at least those needed by pages.
229    """
230    pass
231
232class IDataCenterFile(Interface):
233    """A data center file.
234    """
235
236    name = schema.TextLine(
237        title = u'Filename')
238
239    size = schema.TextLine(
240        title = u'Human readable file size')
241
242    uploaddate = schema.TextLine(
243        title = u'Human readable upload datetime')
244
245    lines = schema.Int(
246        title = u'Number of lines in file')
247
248    def getDate():
249        """Get creation timestamp from file in human readable form.
250        """
251
252    def getSize():
253        """Get human readable size of file.
254        """
255
256    def getLinesNumber():
257        """Get number of lines of file.
258        """
259
260class IDataCenterStorageMovedEvent(IObjectEvent):
261    """Emitted, when the storage of a datacenter changes.
262    """
263
264class IObjectUpgradeEvent(IObjectEvent):
265    """Can be fired, when an object shall be upgraded.
266    """
267
268class ILocalRoleSetEvent(IObjectEvent):
269    """A local role was granted/revoked for a principal on an object.
270    """
271    role_id = Attribute(
272        "The role id that was set.")
273    principal_id = Attribute(
274        "The principal id for which the role was granted/revoked.")
275    granted = Attribute(
276        "Boolean. If false, then the role was revoked.")
277
278class IQueryResultItem(Interface):
279    """An item in a search result.
280    """
281    url = schema.TextLine(
282        title = u'URL that links to the found item')
283    title = schema.TextLine(
284        title = u'Title displayed in search results.')
285    description = schema.Text(
286        title = u'Longer description of the item found.')
287
288class IWAeUPSIRPPluggable(Interface):
289    """A component that might be plugged into a WAeUP SIRP app.
290
291    Components implementing this interface are referred to as
292    'plugins'. They are normally called when a new
293    :class:`waeup.sirp.app.University` instance is created.
294
295    Plugins can setup and update parts of the central site without the
296    site object (normally a :class:`waeup.sirp.app.University` object)
297    needing to know about that parts. The site simply collects all
298    available plugins, calls them and the plugins care for their
299    respective subarea like the applicants area or the datacenter
300    area.
301
302    Currently we have no mechanism to define an order of plugins. A
303    plugin should therefore make no assumptions about the state of the
304    site or other plugins being run before and instead do appropriate
305    checks if necessary.
306
307    Updates can be triggered for instance by the respective form in
308    the site configuration. You normally do updates when the
309    underlying software changed.
310    """
311    def setup(site, name, logger):
312        """Create an instance of the plugin.
313
314        The method is meant to be called by the central app (site)
315        when it is created.
316
317        `site`:
318           The site that requests a setup.
319
320        `name`:
321           The name under which the plugin was registered (utility name).
322
323        `logger`:
324           A standard Python logger for the plugins use.
325        """
326
327    def update(site, name, logger):
328        """Method to update an already existing plugin.
329
330        This might be called by a site when something serious
331        changes. It is a poor-man replacement for Zope generations
332        (but probably more comprehensive and better understandable).
333
334        `site`:
335           The site that requests an update.
336
337        `name`:
338           The name under which the plugin was registered (utility name).
339
340        `logger`:
341           A standard Python logger for the plugins use.
342        """
343
344class IAuthPluginUtility(Interface):
345    """A component that cares for authentication setup at site creation.
346
347    Utilities providing this interface are looked up when a Pluggable
348    Authentication Utility (PAU) for any
349    :class:`waeup.sirp.app.University` instance is created and put
350    into ZODB.
351
352    The setup-code then calls the `register` method of the utility and
353    expects a modified (or unmodified) version of the PAU back.
354
355    This allows to define any authentication setup modifications by
356    submodules or third-party modules/packages.
357    """
358
359    def register(pau):
360        """Register any plugins wanted to be in the PAU.
361        """
362
363    def unregister(pau):
364        """Unregister any plugins not wanted to be in the PAU.
365        """
Note: See TracBrowser for help on using the repository browser.