1 | ## |
---|
2 | ## interfaces.py |
---|
3 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
4 | from zope import schema |
---|
5 | from zope.catalog.interfaces import ICatalog |
---|
6 | from zope.component import getUtility |
---|
7 | from zope.component.interfaces import IObjectEvent |
---|
8 | from zope.interface import Interface, Attribute, implements |
---|
9 | from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
---|
10 | |
---|
11 | class FatalCSVError(Exception): |
---|
12 | """Some row could not be processed. |
---|
13 | """ |
---|
14 | pass |
---|
15 | |
---|
16 | def 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 | |
---|
23 | class 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 | |
---|
39 | class IWAeUPObject(Interface): |
---|
40 | """A WAeUP object. |
---|
41 | |
---|
42 | This is merely a marker interface. |
---|
43 | """ |
---|
44 | |
---|
45 | class 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 | |
---|
77 | class IWAeUPContainer(IWAeUPObject): |
---|
78 | """A container for WAeUP objects. |
---|
79 | """ |
---|
80 | |
---|
81 | class IWAeUPContained(IWAeUPObject): |
---|
82 | """An item contained in an IWAeUPContainer. |
---|
83 | """ |
---|
84 | |
---|
85 | class IStudentContainer(IWAeUPContainer): |
---|
86 | """A container for StudentObjects. |
---|
87 | """ |
---|
88 | |
---|
89 | |
---|
90 | class 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 | |
---|
99 | class 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 | |
---|
109 | class 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 | |
---|
121 | class 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 | |
---|
133 | class 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 | |
---|
142 | class 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 | |
---|
170 | class ISchemaTypeConverter(Interface): |
---|
171 | """A converter for zope.schema.types. |
---|
172 | """ |
---|
173 | def convert(string): |
---|
174 | """Convert string to certain schema type. |
---|
175 | """ |
---|
176 | |
---|
177 | |
---|
178 | class 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 | |
---|
200 | class 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 | |
---|
214 | class 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 | |
---|
225 | class IDataCenter(IWAeUPObject): |
---|
226 | """A data center. |
---|
227 | |
---|
228 | TODO : declare methods, at least those needed by pages. |
---|
229 | """ |
---|
230 | pass |
---|
231 | |
---|
232 | class 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 | |
---|
260 | class IDataCenterStorageMovedEvent(IObjectEvent): |
---|
261 | """Emitted, when the storage of a datacenter changes. |
---|
262 | """ |
---|
263 | |
---|
264 | class IObjectUpgradeEvent(IObjectEvent): |
---|
265 | """Can be fired, when an object shall be upgraded. |
---|
266 | """ |
---|
267 | |
---|
268 | class 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 | |
---|
278 | class 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 | |
---|
288 | class 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 | |
---|
344 | class 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 | """ |
---|