cubicweb/server/test/data-migractions/cubes/fakeemail/schema.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Sat, 16 Jan 2016 13:48:51 +0100
changeset 11057 0b59724cb3f2
parent 10907 server/test/data-migractions/cubes/fakeemail/schema.py@9ae707db5265
child 11767 432f87a63057
permissions -rw-r--r--
Reorganize source tree to have a "cubicweb" top-level package Basically: mkdir cubicweb hg mv *.py -X setup.py cubicweb hg mv dataimport devtools entities etwist ext hooks i18n misc schemas server skeleton sobjects test web wsgi cubicweb Other changes: * adjust path to cubicweb-ctl in devtools tests * update setup.py to avoid importing __pkginfo__ (exec it instead), replace os.path.walk by os.walk and prepend `modname` here and there * update tox.ini to account for new test locations * update doc/conf.py so that it still finds __pkginfo__.py and CWDIR in doc/Makefile

"""entity/relation schemas to store email in an cubicweb instance

:organization: Logilab
:copyright: 2006-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
"""
__docformat__ = "restructuredtext en"
from cubicweb import _

# pylint: disable-msg=E0611,F0401
from yams.buildobjs import (SubjectRelation, RelationType, EntityType,
                            String, Datetime, Int, RelationDefinition)
from yams.reader import context

from cubicweb.schema import ERQLExpression


class Email(EntityType):
    """electronic mail"""
    subject   = String(fulltextindexed=True)
    date      = Datetime(description=_('UTC time on which the mail was sent'))
    messageid = String(required=True, indexed=True)
    headers   = String(description=_('raw headers'))

    sender     = SubjectRelation('EmailAddress', cardinality='?*')
    # an email with only Bcc is acceptable, don't require any recipients
    recipients = SubjectRelation('EmailAddress')
    cc         = SubjectRelation('EmailAddress')

    parts       = SubjectRelation('EmailPart', cardinality='*1', composite='subject')
    attachment  = SubjectRelation('File')

    reply_to    = SubjectRelation('Email', cardinality='?*')
    cites       = SubjectRelation('Email')
    in_thread   = SubjectRelation('EmailThread', cardinality='?*')


class EmailPart(EntityType):
    """an email attachment"""
    __permissions__ = {
        'read':   ('managers', 'users', 'guests',), # XXX if E parts X, U has_read_permission E
        'add':    ('managers', ERQLExpression('E parts X, U has_update_permission E'),),
        'delete': ('managers', ERQLExpression('E parts X, U has_update_permission E')),
        'update': ('managers', 'owners',),
        }

    content  = String(fulltextindexed=True)
    content_format = String(required=True, maxsize=50)
    ordernum = Int(required=True)
    alternative = SubjectRelation('EmailPart', symmetric=True)


class EmailThread(EntityType):
    """discussion thread"""
    title = String(required=True, indexed=True, fulltextindexed=True)
    see_also = SubjectRelation('EmailThread')
    forked_from = SubjectRelation('EmailThread', cardinality='?*')

class parts(RelationType):
    """ """
    fulltext_container = 'subject'

class sender(RelationType):
    """ """
    inlined = True

class in_thread(RelationType):
    """ """
    inlined = True

class reply_to(RelationType):
    """ """
    inlined = True

class generated_by(RelationType):
    """mark an entity as generated from an email"""
    cardinality = '?*'
    subject = ('TrInfo',)
    object = 'Email'

# if comment is installed
if 'Comment' in context.defined:
    class comment_generated_by(RelationDefinition):
        subject = 'Comment'
        name = 'generated_by'
        object = 'Email'