source: main/waeup.ikoba/trunk/src/waeup/ikoba/interfaces.py @ 12300

Last change on this file since 12300 was 12260, checked in by Henrik Bettermann, 10 years ago

Validate document and contract ids properly.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 38.6 KB
RevLine 
[7193]1## $Id: interfaces.py 12260 2014-12-19 08:11:12Z henrik $
[3521]2##
[7193]3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
[6361]18import os
[7221]19import re
[7702]20import codecs
[9217]21import zc.async.interfaces
[7670]22import zope.i18nmessageid
[6915]23from datetime import datetime
[7063]24from hurry.file.interfaces import IFileRetrieval
[8394]25from hurry.workflow.interfaces import IWorkflowInfo
[4789]26from zc.sourcefactory.basic import BasicSourceFactory
[6147]27from zope import schema
[7233]28from zope.pluggableauth.interfaces import IPrincipalInfo
29from zope.security.interfaces import IGroupClosureAwarePrincipal as IPrincipal
[4789]30from zope.component import getUtility
[4882]31from zope.component.interfaces import IObjectEvent
[9217]32from zope.configuration.fields import Path
33from zope.container.interfaces import INameChooser, IContainer
[8394]34from zope.interface import Interface, Attribute
[7795]35from zope.schema.interfaces import IObject
[4789]36from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
[11949]37from waeup.ikoba.schema import PhoneNumber
38from waeup.ikoba.sourcefactory import SmartBasicContextualSourceFactory
[3521]39
[11949]40_ = MessageFactory = zope.i18nmessageid.MessageFactory('waeup.ikoba')
[6990]41
[8214]42DELETION_MARKER = 'XXX'
43IGNORE_MARKER = '<IGNORE>'
[11949]44WAEUP_KEY = 'waeup.ikoba'
[9217]45VIRT_JOBS_CONTAINER_NAME = 'jobs'
[8202]46
[12089]47# States for various workflows
48
[7673]49CREATED = 'created'
[12089]50
[11967]51STARTED = 'started'
[11964]52REQUESTED = 'requested'
53APPROVED = 'approved'
[7670]54
[12089]55SUBMITTED = 'submitted'
56VERIFIED = 'verified'
57REJECTED = 'rejected'
58EXPIRED = 'expired'
[12200]59PUBLISHED = 'published'
[12089]60
61
[9217]62#: A dict giving job status as tuple (<STRING>, <TRANSLATED_STRING>),
63#: the latter for UI purposes.
64JOB_STATUS_MAP = {
65    zc.async.interfaces.NEW: ('new', _('new')),
66    zc.async.interfaces.COMPLETED: ('completed', _('completed')),
67    zc.async.interfaces.PENDING: ('pending', _('pending')),
68    zc.async.interfaces.ACTIVE: ('active', _('active')),
69    zc.async.interfaces.ASSIGNED: ('assigned', _('assigned')),
70    zc.async.interfaces.CALLBACKS: ('callbacks', _('callbacks')),
71    }
72
[8361]73#default_rest_frontpage = u'' + codecs.open(os.path.join(
74#        os.path.dirname(__file__), 'frontpage.rst'),
75#        encoding='utf-8', mode='rb').read()
76
77default_html_frontpage = u'' + codecs.open(os.path.join(
78        os.path.dirname(__file__), 'frontpage.html'),
[7702]79        encoding='utf-8', mode='rb').read()
[6361]80
[11949]81def SimpleIkobaVocabulary(*terms):
[6915]82    """A well-buildt vocabulary provides terms with a value, token and
83       title for each term
84    """
85    return SimpleVocabulary([
86            SimpleTerm(value, value, title) for title, value in terms])
87
88
[11450]89class ContextualDictSourceFactoryBase(SmartBasicContextualSourceFactory):
[11949]90    """A base for contextual sources based on IkobaUtils dicts.
[11450]91
92    To create a real source, you have to set the `DICT_NAME` attribute
[11949]93    which should be the name of a dictionary in IkobaUtils.
[11450]94    """
95    def getValues(self, context):
[11949]96        utils = getUtility(IIkobaUtils)
[11664]97        sorted_items = sorted(getattr(utils, self.DICT_NAME).items(),
98                              key=lambda item: item[1])
99        return [item[0] for item in sorted_items]
[11450]100
101    def getToken(self, context, value):
102        return str(value)
103
104    def getTitle(self, context, value):
[11949]105        utils = getUtility(IIkobaUtils)
[11450]106        return getattr(utils, self.DICT_NAME)[value]
107
[7795]108class SubjectSource(BasicSourceFactory):
[7918]109    """A source for school subjects used in exam documentation.
110    """
[7795]111    def getValues(self):
[11949]112        subjects_dict = getUtility(IIkobaUtils).EXAM_SUBJECTS_DICT
[7837]113        return sorted(subjects_dict.keys())
114
[7795]115    def getTitle(self, value):
[11949]116        subjects_dict = getUtility(IIkobaUtils).EXAM_SUBJECTS_DICT
[7837]117        return "%s:" % subjects_dict[value]
[7795]118
119class GradeSource(BasicSourceFactory):
[7918]120    """A source for exam grades.
121    """
[7795]122    def getValues(self):
[11949]123        for entry in getUtility(IIkobaUtils).EXAM_GRADES:
[7918]124            yield entry[0]
[7837]125
[7795]126    def getTitle(self, value):
[11949]127        return dict(getUtility(IIkobaUtils).EXAM_GRADES)[value]
[7795]128
[7850]129# Define a validation method for email addresses
[7221]130class NotAnEmailAddress(schema.ValidationError):
131    __doc__ = u"Invalid email address"
132
[8638]133#: Regular expression to check email-address formats. As these can
134#: become rather complex (nearly everything is allowed by RFCs), we only
135#: forbid whitespaces, commas and dots following onto each other.
[7221]136check_email = re.compile(
[8638]137    r"^[^@\s,]+@[^@\.\s,]+(\.[^@\.\s,]+)*$").match
[7221]138
139def validate_email(value):
140    if not check_email(value):
141        raise NotAnEmailAddress(value)
142    return True
143
[12260]144# Define a validation method for email addresses
145class NotIdValue(schema.ValidationError):
146    __doc__ = u"Invalid id"
147
148#: Regular expressions to check id formats.
149check_id = re.compile(r"^[a-zA-Z0-9_-]{2,6}$").match
150check_uuid = re.compile( r"^[a-zA-Z0-9]{32}$").match
151
152def validate_id(value):
153    if not check_id(value):
154        raise NotIdValue(value)
155    return True
156
157def validate_uuid(value):
158    # We are using also short ids in tests
159    if not check_uuid(value) and not check_id(value):
160        raise NotIdValue(value)
161    return True
162
[7850]163# Define a validation method for international phone numbers
164class InvalidPhoneNumber(schema.ValidationError):
165    __doc__ = u"Invalid phone number"
166
167# represent format +NNN-NNNN-NNNN
168RE_INT_PHONE = re.compile(r"^\+?\d+\-\d+\-[\d\-]+$")
169
170def validate_phone(value):
[7851]171    if not RE_INT_PHONE.match(value):
[7850]172        raise InvalidPhoneNumber(value)
173    return True
174
[4858]175class FatalCSVError(Exception):
176    """Some row could not be processed.
177    """
178    pass
179
[6226]180class DuplicationError(Exception):
181    """An exception that can be raised when duplicates are found.
182
183    When raising :exc:`DuplicationError` you can, beside the usual
184    message, specify a list of objects which are duplicates. These
185    values can be used by catching code to print something helpful or
186    similar.
187    """
188    def __init__(self, msg, entries=[]):
189        self.msg = msg
190        self.entries = entries
191
192    def __str__(self):
193        return '%r' % self.msg
194
[6143]195class RoleSource(BasicSourceFactory):
[7178]196    """A source for site roles.
[6508]197    """
[6143]198    def getValues(self):
[6157]199        # late import: in interfaces we should not import local modules
[11949]200        from waeup.ikoba.permissions import get_waeup_role_names
[7186]201        return get_waeup_role_names()
[6157]202
203    def getTitle(self, value):
204        # late import: in interfaces we should not import local modules
[11949]205        from waeup.ikoba.permissions import get_all_roles
[7186]206        roles = dict(get_all_roles())
[6157]207        if value in roles.keys():
208            title = roles[value].title
[6569]209            if '.' in title:
210                title = title.split('.', 2)[1]
[6157]211        return title
[6143]212
[7313]213class CaptchaSource(BasicSourceFactory):
214    """A source for captchas.
215    """
216    def getValues(self):
[7323]217        captchas = ['No captcha', 'Testing captcha', 'ReCaptcha']
[7313]218        try:
219            # we have to 'try' because IConfiguration can only handle
[7817]220            # interfaces from w.k.interface.
[11949]221            from waeup.ikoba.browser.interfaces import ICaptchaManager
[7313]222        except:
223            return captchas
224        return sorted(getUtility(ICaptchaManager).getAvailCaptchas().keys())
225
226    def getTitle(self, value):
227        return value
228
[7795]229class IResultEntry(Interface):
230    """A school grade entry.
231    """
232    subject = schema.Choice(
233        title = _(u'Subject'),
234        source = SubjectSource(),
235        )
236    grade = schema.Choice(
237        title = _(u'Grade'),
238        source = GradeSource(),
239        )
240
241class IResultEntryField(IObject):
242    """A zope.schema-like field for usage in interfaces.
243
244    Marker interface to distuingish result entries from ordinary
245    object fields. Needed for registration of widgets.
246    """
247
[11949]248class IIkobaUtils(Interface):
[7358]249    """A collection of methods which are subject to customization.
250    """
[7568]251
[7841]252    PORTAL_LANGUAGE = Attribute("Dict of global language setting")
253    PREFERRED_LANGUAGES_DICT = Attribute("Dict of preferred languages")
254    EXAM_SUBJECTS_DICT = Attribute("Dict of examination subjects")
[11799]255    EXAM_GRADES = Attribute("Dict of examination grades")
256    SYSTEM_MAX_LOAD = Attribute("Dict of maximum system loads.")
[7568]257
[7404]258    def sendContactForm(
259          from_name,from_addr,rcpt_name,rcpt_addr,
260          from_username,usertype,portal,body,subject):
[7358]261        """Send an email with data provided by forms.
262        """
263
[7475]264    def fullname(firstname,lastname,middlename):
265        """Full name constructor.
266        """
267
[8853]268    def sendCredentials(user, password, url_info, msg):
[7475]269        """Send credentials as email.
270
[11947]271        Input is the customer for which credentials are sent and the
[7475]272        password.
273
274        Returns True or False to indicate successful operation.
275        """
276
277    def genPassword(length, chars):
278        """Generate a random password.
279        """
280
[11949]281class IIkobaObject(Interface):
282    """A Ikoba object.
[5663]283
284    This is merely a marker interface.
[4789]285    """
286
[11954]287class ICompany(IIkobaObject):
288    """Representation of an company.
[3521]289    """
[5955]290
[6065]291
[11949]292class IIkobaContainer(IIkobaObject):
293    """A container for Ikoba objects.
[4789]294    """
295
[11949]296class IIkobaContained(IIkobaObject):
297    """An item contained in an IIkobaContainer.
[4789]298    """
[6136]299
[7726]300class ICSVExporter(Interface):
301    """A CSV file exporter for objects.
302    """
303    fields = Attribute("""List of fieldnames in resulting CSV""")
[7907]304
305    title = schema.TextLine(
306        title = u'Title',
307        description = u'Description to be displayed in selections.',
308        )
[7726]309    def mangle_value(value, name, obj):
310        """Mangle `value` extracted from `obj` or suobjects thereof.
311
[8394]312        This is called by export before actually writing to the result
313        file.
[7726]314        """
315
[9797]316    def get_filtered(site, **kw):
317        """Get datasets in `site` to be exported.
318
319        The set of data is specified by keywords, which might be
320        different for any implementaion of exporter.
321
322        Returns an iterable.
323        """
324
[7730]325    def export(iterable, filepath=None):
326        """Export iterables as rows in a CSV file.
[7726]327
[8394]328        If `filepath` is not given, a string with the data should be
329        returned.
[7730]330
331        What kind of iterables are acceptable depends on the specific
332        exporter implementation.
[7726]333        """
334
[9766]335    def export_all(site, filepath=None):
[7726]336        """Export all items in `site` as CSV file.
337
[8394]338        if `filepath` is not given, a string with the data should be
339        returned.
[7726]340        """
341
[9797]342    def export_filtered(site, filepath=None, **kw):
343        """Export those items in `site` specified by `args` and `kw`.
344
345        If `filepath` is not given, a string with the data should be
346        returned.
347
348        Which special keywords are supported is up to the respective
349        exporter.
350        """
351
[11949]352class IIkobaExporter(Interface):
[4789]353    """An exporter for objects.
354    """
355    def export(obj, filepath=None):
356        """Export by pickling.
357
358        Returns a file-like object containing a representation of `obj`.
359
360        This is done using `pickle`. If `filepath` is ``None``, a
361        `cStringIO` object is returned, that contains the saved data.
362        """
363
[11949]364class IIkobaXMLExporter(Interface):
[4789]365    """An XML exporter for objects.
366    """
367    def export(obj, filepath=None):
368        """Export as XML.
369
370        Returns an XML representation of `obj`.
371
372        If `filepath` is ``None``, a StringIO` object is returned,
373        that contains the transformed data.
374        """
375
[11949]376class IIkobaXMLImporter(Interface):
[4789]377    """An XML import for objects.
378    """
379    def doImport(filepath):
380        """Create Python object from XML.
381
382        Returns a Python object.
383        """
384
[4858]385class IBatchProcessor(Interface):
386    """A batch processor that handles mass-operations.
387    """
388    name = schema.TextLine(
[7933]389        title = _(u'Processor name')
[4858]390        )
391
[5476]392    def doImport(path, headerfields, mode='create', user='Unknown',
[8218]393                 logger=None, ignore_empty=True):
[4858]394        """Read data from ``path`` and update connected object.
[5476]395
396        `headerfields` is a list of headerfields as read from the file
397        to import.
398
399        `mode` gives the import mode to use (``'create'``,
400        ``'update'``, or ``'remove'``.
401
402        `user` is a string describing the user performing the
403        import. Normally fetched from current principal.
404
405        `logger` is the logger to use during import.
[8218]406
407        `ignore_emtpy` in update mode ignores empty fields if true.
[4858]408        """
409
[11949]410class IContactForm(IIkobaObject):
[7225]411    """A contact form.
412    """
413
414    email_from = schema.ASCIILine(
[7828]415        title = _(u'Email Address:'),
[7225]416        default = None,
417        required = True,
418        constraint=validate_email,
419        )
420
421    email_to = schema.ASCIILine(
[7828]422        title = _(u'Email to:'),
[7225]423        default = None,
424        required = True,
425        constraint=validate_email,
426        )
427
428    subject = schema.TextLine(
[7828]429        title = _(u'Subject:'),
[7225]430        required = True,)
431
432    fullname = schema.TextLine(
[7828]433        title = _(u'Full Name:'),
[7225]434        required = True,)
435
436    body = schema.Text(
[7828]437        title = _(u'Text:'),
[7225]438        required = True,)
439
[11949]440class IIkobaPrincipalInfo(IPrincipalInfo):
441    """Infos about principals that are users of Ikoba Ikoba.
[7233]442    """
443    email = Attribute("The email address of a user")
444    phone = Attribute("The phone number of a user")
[8757]445    public_name = Attribute("The public name of a user")
[7225]446
[7233]447
[11949]448class IIkobaPrincipal(IPrincipal):
449    """A principle for Ikoba Ikoba.
[7233]450
451    This interface extends zope.security.interfaces.IPrincipal and
452    requires also an `id` and other attributes defined there.
453    """
454
455    email = schema.TextLine(
[7828]456        title = _(u'Email Address'),
[7233]457        description = u'',
458        required=False,)
459
[8176]460    phone = PhoneNumber(
[7828]461        title = _(u'Phone'),
[7233]462        description = u'',
463        required=False,)
464
[8757]465    public_name = schema.TextLine(
466        title = _(u'Public Name'),
467        required = False,)
468
[11949]469class IFailedLoginInfo(IIkobaObject):
[10055]470    """Info about failed logins.
471
472    Timestamps are supposed to be stored as floats using time.time()
473    or similar.
474    """
475    num = schema.Int(
476        title = _(u'Number of failed logins'),
477        description = _(u'Number of failed logins'),
478        required = True,
479        default = 0,
480        )
481
482    last = schema.Float(
483        title = _(u'Timestamp'),
484        description = _(u'Timestamp of last failed login or `None`'),
485        required = False,
486        default = None,
487        )
488
489    def as_tuple():
490        """Get login info as tuple ``<NUM>, <TIMESTAMP>``.
491        """
492
493    def set_values(num=0, last=None):
494        """Set number of failed logins and timestamp of last one.
495        """
496
497    def increase():
498        """Increase the current number of failed logins and set timestamp.
499        """
500
501    def reset():
502        """Set failed login counters back to zero.
503        """
504
505
[11949]506class IUserAccount(IIkobaObject):
[4789]507    """A user account.
508    """
[10055]509
510    failed_logins = Attribute("""FailedLoginInfo for this account""")
511
[4789]512    name = schema.TextLine(
[7828]513        title = _(u'User Id'),
[6512]514        description = u'Login name of user',
[4789]515        required = True,)
[7221]516
[4789]517    title = schema.TextLine(
[7828]518        title = _(u'Full Name'),
[8759]519        required = True,)
[7221]520
[8756]521    public_name = schema.TextLine(
522        title = _(u'Public Name'),
[8759]523        description = u"Substitute for officer's real name "
[11947]524                       "in object histories.",
[8756]525        required = False,)
526
[7197]527    description = schema.Text(
[7828]528        title = _(u'Description/Notice'),
[4789]529        required = False,)
[7221]530
531    email = schema.ASCIILine(
[7828]532        title = _(u'Email Address'),
[7221]533        default = None,
[7222]534        required = True,
[7221]535        constraint=validate_email,
536        )
537
[8176]538    phone = PhoneNumber(
[7828]539        title = _(u'Phone'),
[7233]540        default = None,
[8062]541        required = False,
[7233]542        )
543
[4789]544    roles = schema.List(
[8486]545        title = _(u'Portal Roles'),
[8079]546        value_type = schema.Choice(source=RoleSource()),
547        required = False,
548        )
[6136]549
[10055]550
551
[7147]552class IPasswordValidator(Interface):
553    """A password validator utility.
554    """
[6136]555
[7147]556    def validate_password(password, password_repeat):
557        """Validates a password by comparing it with
558        control password and checking some other requirements.
559        """
560
561
[11949]562class IUsersContainer(IIkobaObject):
[4789]563    """A container for users (principals).
564
565    These users are used for authentication purposes.
566    """
567
568    def addUser(name, password, title=None, description=None):
569        """Add a user.
570        """
571
572    def delUser(name):
573        """Delete a user if it exists.
574        """
575
[6141]576class ILocalRolesAssignable(Interface):
577    """The local roles assignable to an object.
578    """
579    def __call__():
580        """Returns a list of dicts.
581
582        Each dict contains a ``name`` referring to the role assignable
583        for the specified object and a `title` to describe the range
584        of users to which this role can be assigned.
585        """
586
[11949]587class IConfigurationContainer(IIkobaObject):
[6907]588    """A container for session configuration objects.
589    """
590
591    name = schema.TextLine(
[11954]592        title = _(u'Name of Company'),
593        default = _(u'Sample Company'),
[6907]594        required = True,
595        )
596
[7459]597    acronym = schema.TextLine(
[11954]598        title = _(u'Abbreviated Title of Company'),
[11949]599        default = u'WAeUP.Ikoba',
[7459]600        required = True,
601        )
602
[6907]603    frontpage = schema.Text(
[8361]604        title = _(u'Content in HTML format'),
[6907]605        required = False,
[8361]606        default = default_html_frontpage,
[6907]607        )
608
[7702]609    frontpage_dict = schema.Dict(
610        title = u'Content as language dictionary with values in html format',
[7485]611        required = False,
[7702]612        default = {},
[7485]613        )
614
[7223]615    name_admin = schema.TextLine(
[7828]616        title = _(u'Name of Administrator'),
[7223]617        default = u'Administrator',
[8230]618        required = True,
[7223]619        )
620
[7221]621    email_admin = schema.ASCIILine(
[7828]622        title = _(u'Email Address of Administrator'),
[7221]623        default = 'contact@waeup.org',
[8230]624        required = True,
[7221]625        constraint=validate_email,
626        )
627
628    email_subject = schema.TextLine(
[7828]629        title = _(u'Subject of Email to Administrator'),
[11949]630        default = _(u'Ikoba Contact'),
[8230]631        required = True,
[7221]632        )
633
[7470]634    smtp_mailer = schema.Choice(
[7828]635        title = _(u'SMTP mailer to use when sending mail'),
[7470]636        vocabulary = 'Mail Delivery Names',
637        default = 'No email service',
638        required = True,
639        )
640
[7313]641    captcha = schema.Choice(
[7828]642        title = _(u'Captcha used for public registration pages'),
[7313]643        source = CaptchaSource(),
644        default = u'No captcha',
645        required = True,
646        )
[7221]647
[7664]648
[11949]649class IDataCenter(IIkobaObject):
[4789]650    """A data center.
651
[8394]652    A data center manages files (uploads, downloads, etc.).
653
654    Beside providing the bare paths needed to keep files, it also
655    provides some helpers to put results of batch processing into
656    well-defined final locations (with well-defined filenames).
657
658    The main use-case is managing of site-related files, i.e. files
659    for import, export etc.
660
661    DataCenters are _not_ meant as storages for object-specific files
662    like passport photographs and similar.
663
664    It is up to the datacenter implementation how to organize data
665    (paths) inside its storage path.
[4789]666    """
[8394]667    storage = schema.Bytes(
668        title = u'Path to directory where everything is kept.'
669        )
[4789]670
[8394]671    deleted_path = schema.Bytes(
672        title = u'Path were data about deleted objects should be stored.'
673        )
674
[9023]675    def getPendingFiles(sort='name'):
[8394]676        """Get a list of files stored in `storage` sorted by basename.
677        """
[9023]678
[9074]679    def getFinishedFiles():
680        """Get a list of files stored in `finished` subfolder of `storage`.
[9023]681        """
682
[8394]683    def setStoragePath(path, move=False, overwrite=False):
684        """Set the path where to store files.
685
686        If `move` is True, move over files from the current location
687        to the new one.
688
689        If `overwrite` is also True, overwrite any already existing
690        files of same name in target location.
691
692        Triggers a DataCenterStorageMovedEvent.
693        """
694
695    def distProcessedFiles(successful, source_path, finished_file,
696                           pending_file, mode='create', move_orig=True):
697        """Distribute processed files over final locations.
698        """
699
700
[4789]701class IDataCenterFile(Interface):
702    """A data center file.
703    """
[4858]704
705    name = schema.TextLine(
706        title = u'Filename')
707
708    size = schema.TextLine(
709        title = u'Human readable file size')
710
711    uploaddate = schema.TextLine(
712        title = u'Human readable upload datetime')
713
714    lines = schema.Int(
715        title = u'Number of lines in file')
[6136]716
[4789]717    def getDate():
718        """Get creation timestamp from file in human readable form.
719        """
720
721    def getSize():
722        """Get human readable size of file.
723        """
[4858]724
725    def getLinesNumber():
726        """Get number of lines of file.
727        """
[4882]728
729class IDataCenterStorageMovedEvent(IObjectEvent):
730    """Emitted, when the storage of a datacenter changes.
731    """
[5007]732
[6136]733class IObjectUpgradeEvent(IObjectEvent):
734    """Can be fired, when an object shall be upgraded.
735    """
736
[6180]737class ILocalRoleSetEvent(IObjectEvent):
738    """A local role was granted/revoked for a principal on an object.
739    """
740    role_id = Attribute(
741        "The role id that was set.")
742    principal_id = Attribute(
743        "The principal id for which the role was granted/revoked.")
744    granted = Attribute(
745        "Boolean. If false, then the role was revoked.")
746
[5007]747class IQueryResultItem(Interface):
748    """An item in a search result.
749    """
750    url = schema.TextLine(
751        title = u'URL that links to the found item')
752    title = schema.TextLine(
753        title = u'Title displayed in search results.')
754    description = schema.Text(
755        title = u'Longer description of the item found.')
[6136]756
[11949]757class IIkobaPluggable(Interface):
758    """A component that might be plugged into a Ikoba Ikoba app.
[5658]759
760    Components implementing this interface are referred to as
761    'plugins'. They are normally called when a new
[11954]762    :class:`waeup.ikoba.app.Company` instance is created.
[5658]763
764    Plugins can setup and update parts of the central site without the
[11954]765    site object (normally a :class:`waeup.ikoba.app.Company` object)
[5658]766    needing to know about that parts. The site simply collects all
767    available plugins, calls them and the plugins care for their
[11947]768    respective subarea like the cutomers area or the datacenter
[5658]769    area.
770
771    Currently we have no mechanism to define an order of plugins. A
772    plugin should therefore make no assumptions about the state of the
773    site or other plugins being run before and instead do appropriate
774    checks if necessary.
775
776    Updates can be triggered for instance by the respective form in
777    the site configuration. You normally do updates when the
778    underlying software changed.
[5013]779    """
[5069]780    def setup(site, name, logger):
781        """Create an instance of the plugin.
[5013]782
[5658]783        The method is meant to be called by the central app (site)
784        when it is created.
785
786        `site`:
787           The site that requests a setup.
788
789        `name`:
790           The name under which the plugin was registered (utility name).
791
792        `logger`:
793           A standard Python logger for the plugins use.
[5069]794        """
795
796    def update(site, name, logger):
797        """Method to update an already existing plugin.
798
799        This might be called by a site when something serious
[5658]800        changes. It is a poor-man replacement for Zope generations
801        (but probably more comprehensive and better understandable).
802
803        `site`:
804           The site that requests an update.
805
806        `name`:
807           The name under which the plugin was registered (utility name).
808
809        `logger`:
810           A standard Python logger for the plugins use.
[5069]811        """
[5898]812
[5899]813class IAuthPluginUtility(Interface):
[5898]814    """A component that cares for authentication setup at site creation.
815
816    Utilities providing this interface are looked up when a Pluggable
817    Authentication Utility (PAU) for any
[11954]818    :class:`waeup.ikoba.app.Company` instance is created and put
[5898]819    into ZODB.
820
821    The setup-code then calls the `register` method of the utility and
822    expects a modified (or unmodified) version of the PAU back.
823
824    This allows to define any authentication setup modifications by
825    submodules or third-party modules/packages.
826    """
827
828    def register(pau):
829        """Register any plugins wanted to be in the PAU.
830        """
831
832    def unregister(pau):
833        """Unregister any plugins not wanted to be in the PAU.
834        """
[6273]835
836class IObjectConverter(Interface):
837    """Object converters are available as simple adapters, adapting
838       interfaces (not regular instances).
839
840    """
841
[6277]842    def fromStringDict(self, data_dict, context, form_fields=None):
843        """Convert values in `data_dict`.
[6273]844
[6277]845        Converts data in `data_dict` into real values based on
846        `context` and `form_fields`.
[6273]847
[6277]848        `data_dict` is a mapping (dict) from field names to values
849        represented as strings.
[6273]850
[6277]851        The fields (keys) to convert can be given in optional
852        `form_fields`. If given, form_fields should be an instance of
853        :class:`zope.formlib.form.Fields`. Suitable instances are for
854        example created by :class:`grok.AutoFields`.
[6273]855
[6277]856        If no `form_fields` are given, a default is computed from the
857        associated interface.
[6273]858
[6277]859        The `context` can be an existing object (implementing the
860        associated interface) or a factory name. If it is a string, we
861        try to create an object using
862        :func:`zope.component.createObject`.
863
864        Returns a tuple ``(<FIELD_ERRORS>, <INVARIANT_ERRORS>,
865        <DATA_DICT>)`` where
866
867        ``<FIELD_ERRORS>``
868           is a list of tuples ``(<FIELD_NAME>, <ERROR>)`` for each
869           error that happened when validating the input data in
870           `data_dict`
871
872        ``<INVARIANT_ERRORS>``
873           is a list of invariant errors concerning several fields
874
875        ``<DATA_DICT>``
876           is a dict with the values from input dict converted.
877
878        If errors happen, i.e. the error lists are not empty, always
879        an empty ``<DATA_DICT>`` is returned.
880
881        If ``<DATA_DICT>` is non-empty, there were no errors.
[6273]882        """
[6293]883
[7932]884class IFieldConverter(Interface):
[8214]885    def request_data(name, value, schema_field, prefix='', mode='create'):
[7932]886        """Create a dict with key-value mapping as created by a request.
887
888        `name` and `value` are expected to be parsed from CSV or a
889        similar input and represent an attribute to be set to a
890        representation of value.
891
[8214]892        `mode` gives the mode of import.
893
[7932]894        :meth:`update_request_data` is then requested to turn this
895        name and value into vars as they would be sent by a regular
896        form submit. This means we do not create the real values to be
897        set but we only define the values that would be sent in a
898        browser request to request the creation of those values.
899
900        The returned dict should contain names and values of a faked
901        browser request for the given `schema_field`.
902
903        Field converters are normally registered as adapters to some
904        specific zope.schema field.
905        """
906
[6338]907class IObjectHistory(Interface):
908
909    messages = schema.List(
910        title = u'List of messages stored',
911        required = True,
912        )
913
914    def addMessage(message):
915        """Add a message.
916        """
[6353]917
[11949]918class IIkobaWorkflowInfo(IWorkflowInfo):
[6353]919    """A :class:`hurry.workflow.workflow.WorkflowInfo` with additional
920       methods for convenience.
921    """
922    def getManualTransitions():
923        """Get allowed manual transitions.
924
925        Get a sorted list of tuples containing the `transition_id` and
926        `title` of each allowed transition.
927        """
[6481]928
929class ISiteLoggers(Interface):
930
[11949]931    loggers = Attribute("A list or generator of registered IkobaLoggers")
[6481]932
933    def register(name, filename=None, site=None, **options):
934        """Register a logger `name` which logs to `filename`.
935
936        If `filename` is not given, logfile will be `name` with
937        ``.log`` as filename extension.
938        """
939
940    def unregister(name):
941        """Unregister a once registered logger.
942        """
943
944class ILogger(Interface):
945    """A logger cares for setup, update and restarting of a Python logger.
946    """
947
948    logger = Attribute("""A :class:`logging.Logger` instance""")
949
950
951    def __init__(name, filename=None, site=None, **options):
[11949]952        """Create a Ikoba logger instance.
[6481]953        """
954
955    def setup():
956        """Create a Python :class:`logging.Logger` instance.
957
958        The created logger is based on the params given by constructor.
959        """
960
961    def update(**options):
962        """Update the logger.
963
964        Updates the logger respecting modified `options` and changed
965        paths.
966        """
[6754]967
968class ILoggerCollector(Interface):
969
970    def getLoggers(site):
971        """Return all loggers registered for `site`.
972        """
973
974    def registerLogger(site, logging_component):
975        """Register a logging component residing in `site`.
976        """
977
978    def unregisterLogger(site, logging_component):
979        """Unregister a logger.
980        """
[7063]981
982#
983# External File Storage and relatives
984#
985class IFileStoreNameChooser(INameChooser):
986    """See zope.container.interfaces.INameChooser for base methods.
987    """
[7066]988    def checkName(name, attr=None):
[7063]989        """Check whether an object name is valid.
990
991        Raises a user error if the name is not valid.
992        """
993
[7066]994    def chooseName(name, attr=None):
995        """Choose a unique valid file id for the object.
[7063]996
[7066]997        The given name may be taken into account when choosing the
998        name (file id).
[7063]999
[7066]1000        chooseName is expected to always choose a valid file id (that
1001        would pass the checkName test) and never raise an error.
1002
1003        If `attr` is not ``None`` it might been taken into account as
1004        well when generating the file id. Usual behaviour is to
1005        interpret `attr` as a hint for what type of file for a given
1006        context should be stored if there are several types
[11947]1007        possible. For instance for a certain customer some file could
[7066]1008        be the connected passport photograph or some certificate scan
1009        or whatever. Each of them has to be stored in a different
1010        location so setting `attr` to a sensible value should give
1011        different file ids returned.
[7063]1012        """
1013
1014class IExtFileStore(IFileRetrieval):
1015    """A file storage that stores files in filesystem (not as blobs).
1016    """
1017    root = schema.TextLine(
1018        title = u'Root path of file store.',
1019        )
1020
1021    def getFile(file_id):
1022        """Get raw file data stored under file with `file_id`.
1023
1024        Returns a file descriptor open for reading or ``None`` if the
1025        file cannot be found.
1026        """
1027
[7071]1028    def getFileByContext(context, attr=None):
[7063]1029        """Get raw file data stored for the given context.
1030
1031        Returns a file descriptor open for reading or ``None`` if no
1032        such file can be found.
1033
[7071]1034        Both, `context` and `attr` might be used to find (`context`)
1035        and feed (`attr`) an appropriate file name chooser.
1036
[7063]1037        This is a convenience method.
1038        """
1039
[7090]1040    def deleteFile(file_id):
1041        """Delete file stored under `file_id`.
1042
1043        Remove file from filestore so, that it is not available
1044        anymore on next call to getFile for the same file_id.
1045
1046        Should not complain if no such file exists.
1047        """
1048
1049    def deleteFileByContext(context, attr=None):
1050        """Delete file for given `context` and `attr`.
1051
1052        Both, `context` and `attr` might be used to find (`context`)
1053        and feed (`attr`) an appropriate file name chooser.
1054
1055        This is a convenience method.
1056        """
1057
[7063]1058    def createFile(filename, f):
1059        """Create file given by f with filename `filename`
1060
1061        Returns a hurry.file.File-based object.
1062        """
1063
1064class IFileStoreHandler(Interface):
1065    """Filestore handlers handle specific files for file stores.
1066
1067    If a file to store/get provides a specific filename, a file store
1068    looks up special handlers for that type of file.
1069
1070    """
1071    def pathFromFileID(store, root, filename):
1072        """Turn file id into path to store.
1073
1074        Returned path should be absolute.
1075        """
1076
1077    def createFile(store, root, filename, file_id, file):
1078        """Return some hurry.file based on `store` and `file_id`.
1079
1080        Some kind of callback method called by file stores to create
1081        file objects from file_id.
1082
1083        Returns a tuple ``(raw_file, path, file_like_obj)`` where the
[11949]1084        ``file_like_obj`` should be a HurryFile, a IkobaImageFile or
[7063]1085        similar. ``raw_file`` is the (maybe changed) input file and
1086        ``path`` the relative internal path to store the file at.
1087
1088        Please make sure the ``raw_file`` is opened for reading and
1089        the file descriptor set at position 0 when returned.
1090
1091        This method also gets the raw input file object that is about
1092        to be stored and is expected to raise any exceptions if some
1093        kind of validation or similar fails.
1094        """
[7389]1095
1096class IPDF(Interface):
1097    """A PDF representation of some context.
1098    """
1099
[8257]1100    def __call__(view=None, note=None):
[7389]1101        """Create a bytestream representing a PDF from context.
1102
1103        If `view` is passed in additional infos might be rendered into
1104        the document.
[8257]1105
1106        `note` is optional HTML rendered at bottom of the created
1107        PDF. Please consider the limited reportlab support for HTML,
1108        but using font-tags and friends you certainly can get the
1109        desired look.
[7389]1110        """
[7473]1111
1112class IMailService(Interface):
1113    """A mail service.
1114    """
1115
1116    def __call__():
1117        """Get the default mail delivery.
1118        """
[7576]1119
[9217]1120
[7576]1121class IDataCenterConfig(Interface):
1122    path = Path(
1123        title = u'Path',
[7828]1124        description = u"Directory where the datacenter should store "
1125                      u"files by default (adjustable in web UI).",
[7576]1126        required = True,
1127        )
[8346]1128
[12060]1129
1130class IPayPalConfig(Interface):
1131    path = Path(
1132        title = u'Path',
1133        description = u"Path to config file for PayPal REST API.",
1134        required = True,
1135        )
1136
1137
[9217]1138#
1139# Asynchronous job handling and related
1140#
[11949]1141class IJobManager(IIkobaObject):
[9217]1142    """A manager for asynchronous running jobs (tasks).
1143    """
1144    def put(job, site=None):
1145        """Put a job into task queue.
[8346]1146
[9217]1147        If no `site` is given, queue job in context of current local
1148        site.
1149
1150        Returns a job_id to identify the put job. This job_id is
1151        needed for further references to the job.
1152        """
1153
1154    def jobs(site=None):
1155        """Get an iterable of jobs stored.
1156        """
1157
1158    def get(job_id, site=None):
1159        """Get the job with id `job_id`.
1160
1161        For the `site` parameter see :meth:`put`.
1162        """
1163
1164    def remove(job_id, site=None):
1165        """Remove job with `job_id` from stored jobs.
1166        """
1167
1168    def start_test_job(site=None):
1169        """Start a test job.
1170        """
1171
1172class IProgressable(Interface):
1173    """A component that can indicate its progress status.
[8346]1174    """
[9217]1175    percent = schema.Float(
1176        title = u'Percent of job done already.',
[8346]1177        )
1178
[9217]1179class IJobContainer(IContainer):
1180    """A job container contains IJob objects.
1181    """
1182
1183class IExportJob(zc.async.interfaces.IJob):
1184    def __init__(site, exporter_name):
1185        pass
1186
[9816]1187    finished = schema.Bool(
1188        title = u'`True` if the job finished.`',
1189        default = False,
1190        )
1191
1192    failed = schema.Bool(
1193        title = u"`True` iff the job finished and didn't provide a file.",
1194        default = None,
1195        )
1196
[11949]1197class IExportJobContainer(IIkobaObject):
[9217]1198    """A component that contains (maybe virtually) export jobs.
1199    """
[9718]1200    def start_export_job(exporter_name, user_id, *args, **kwargs):
[9217]1201        """Start asynchronous export job.
1202
1203        `exporter_name` is the name of an exporter utility to be used.
1204
1205        `user_id` is the ID of the user that triggers the export.
1206
[9718]1207        `args` positional arguments passed to the export job created.
1208
1209        `kwargs` keyword arguments passed to the export job.
1210
[9217]1211        The job_id is stored along with exporter name and user id in a
1212        persistent list.
1213
1214        Returns the job ID of the job started.
1215        """
1216
1217    def get_running_export_jobs(user_id=None):
1218        """Get export jobs for user with `user_id` as list of tuples.
1219
1220        Each tuples holds ``<job_id>, <exporter_name>, <user_id>`` in
1221        that order. The ``<exporter_name>`` is the utility name of the
1222        used exporter.
1223
1224        If `user_id` is ``None``, all running jobs are returned.
1225        """
1226
1227    def get_export_jobs_status(user_id=None):
1228        """Get running/completed export jobs for `user_id` as list of tuples.
1229
1230        Each tuple holds ``<raw status>, <status translated>,
1231        <exporter title>`` in that order, where ``<status
1232        translated>`` and ``<exporter title>`` are translated strings
1233        representing the status of the job and the human readable
1234        title of the exporter used.
1235        """
1236
1237    def delete_export_entry(entry):
1238        """Delete the export denoted by `entry`.
1239
1240        Removes `entry` from the local `running_exports` list and also
1241        removes the regarding job via the local job manager.
1242
1243        `entry` is a tuple ``(<job id>, <exporter name>, <user id>)``
1244        as created by :meth:`start_export_job` or returned by
1245        :meth:`get_running_export_jobs`.
1246        """
1247
1248    def entry_from_job_id(job_id):
1249        """Get entry tuple for `job_id`.
1250
1251        Returns ``None`` if no such entry can be found.
1252        """
[9726]1253
1254class IExportContainerFinder(Interface):
1255    """A finder for the central export container.
1256    """
1257    def __call__():
1258        """Return the currently used global or site-wide IExportContainer.
1259        """
[9766]1260
[11949]1261class IFilteredQuery(IIkobaObject):
[9766]1262    """A query for objects.
1263    """
1264
1265    defaults = schema.Dict(
1266        title = u'Default Parameters',
1267        required = True,
1268        )
1269
1270    def __init__(**parameters):
1271        """Instantiate a filtered query by passing in parameters.
1272        """
1273
1274    def query():
1275        """Get an iterable of objects denoted by the set parameters.
1276
1277        The search should be applied to objects inside current
1278        site. It's the caller's duty to set the correct site before.
1279
1280        Result can be any iterable like a catalog result set, a list,
1281        or similar.
1282        """
1283
1284class IFilteredCatalogQuery(IFilteredQuery):
1285    """A catalog-based query for objects.
1286    """
1287
1288    cat_name = schema.TextLine(
1289        title = u'Registered name of the catalog to search.',
1290        required = True,
1291        )
1292
1293    def query_catalog(catalog):
1294        """Query catalog with the parameters passed to constructor.
1295        """
[12251]1296
1297
1298class IIDSource(Interface):
1299    """A source for unique IDs, according to RFC 4122.
1300    """
1301    def get_uuid():
1302        """Get a random unique ID.
1303
1304        Get a 'Universially Unique IDentifier'. The result string
1305        might contain any printable characters.
1306        """
1307
1308    def get_hex_uuid():
1309        """Get a random unique ID as a string representing a hex number.
1310        """
Note: See TracBrowser for help on using the repository browser.