Пример #1
0
def update_domain(data):
    """
    Updates a domain.

    Field ``tenant``, if given, can be ID (int), principal (str) or
    an instance of a Principal.

    Data fields:
    ``id``:     Required. ID of domain to update
    ``editor``: Required. ID of Principal
    ``mtime``:  Required

    :param data: Dict with data fields
    :returns: Instance of updated domain
    """
    # If 'tenant' is set, it may be ID, name or instance of a principal.
    if 'tenant' in data:
        if not isinstance(data['tenant'], Principal):
            data['tenant'] = Principal.find_one(data['tenant'])
        data['tenant_id'] = data['tenant'].id
        del data['tenant']
    sess = DbSession()
    dom = sess.query(Domain).filter(Domain.id==data['id']).one()
    for k, v in data.items():
        setattr(dom, k, v)
    sess.flush()
    return dom
Пример #2
0
def create_domain(data):
    """
    Creates a new domain record.

    Field ``tenant`` can be ID (int), principal (str) or
    an instance of a Principal.

    Data fields:
    - ``owner``: Required
    - ``tenant``: Principal

    :param data: Dict with data fields
    :returns: Instance of created domain
    """
    # If 'tenant' is set, it may be ID, name or instance of a principal.
    if 'tenant' in data:
        if not isinstance(data['tenant'], Principal):
            data['tenant'] = Principal.find_one(data['tenant'])
        data['tenant_id'] = data['tenant'].id
        del data['tenant']
    # Set defaults
    if not 'max_mailboxes' in data:
        data['max_mailboxes'] = MAX_MAILBOXES
    if not 'max_aliases' in data:
        data['max_aliases'] = MAX_ALIASES
    if not 'quota' in data:
        data['quota'] = QUOTA
    
    sess = DbSession()
    dom = Domain()
    for k, v in data.items():
        setattr(dom, k, v)
    sess.add(dom)
    sess.flush() # to get ID of domain
    return dom
Пример #3
0
Файл: app.py Проект: dmdm/PySite
 def delete_fixtures(self):
     from pysite.authmgr.models import Principal, Role
     from pysite.vmailmgr.models import Domain, Mailbox, Alias
     sess = pysite.models.DbSession()
     transaction.begin()
     try:
         # 1. Delete principals. This should cascade to rolemembers,
         #    domains (via tenant), and domain cascades to mailbox and
         #    alias.
         # 2. Delete the roles
         for it in self.fixtures['principals']:
             ent = Principal.find_one(it['principal'])
             ent.dump()
             sess.delete(ent)
         for it in self.fixtures['roles']:
             ent = Role.find_one(it['name'])
             ent.dump()
             sess.delete(ent)
         transaction.commit()
     except Exception as e:
         transaction.abort()
         raise e