Пример #1
0
async def add(domain_id: str,
              owner_uid: int,
              roles=builtin.DOMAIN_SYSTEM['roles'],
              name: str = None,
              gravatar: str = None,
              bulletin: str = ''):
    validator.check_domain_id(domain_id)
    validator.check_name(name)
    validator.check_bulletin(bulletin)
    for domain in builtin.DOMAINS:
        if domain['_id'] == domain_id:
            raise error.DomainAlreadyExistError(domain_id)
    coll = db.coll('domain')
    try:
        result = await coll.insert_one({
            '_id': domain_id,
            'pending': True,
            'owner_uid': owner_uid,
            'roles': roles,
            'name': name,
            'gravatar': gravatar,
            'bulletin': bulletin
        })
        domain_id = result.inserted_id
    except errors.DuplicateKeyError:
        raise error.DomainAlreadyExistError(domain_id) from None
    # grant root role to owner by default
    await add_user_role(domain_id, owner_uid, builtin.ROLE_ROOT)
    await coll.update_one({'_id': domain_id}, {'$unset': {'pending': ''}})
    return domain_id
Пример #2
0
async def add(domain_id: str,
              owner_uid: int,
              roles=builtin.DOMAIN_SYSTEM['roles'],
              name: str = None,
              gravatar: str = None):
    validator.check_domain_id(domain_id)
    validator.check_name(name)
    for domain in builtin.DOMAINS:
        if domain['_id'] == domain_id:
            raise error.DomainAlreadyExistError(domain_id)
    coll = db.coll('domain')
    try:
        return (await coll.insert_one({
            '_id': domain_id,
            'owner_uid': owner_uid,
            'roles': roles,
            'name': name,
            'gravatar': gravatar
        })).inserted_id
    except errors.DuplicateKeyError:
        raise error.DomainAlreadyExistError(domain_id) from None
Пример #3
0
async def add(domain_id: str, owner_uid: int,
              roles=builtin.DOMAIN_SYSTEM['roles'],
              name: str=None, gravatar: str=None, bulletin: str=''):
  validator.check_domain_id(domain_id)
  validator.check_name(name)
  validator.check_bulletin(bulletin)
  for domain in builtin.DOMAINS:
    if domain['_id'] == domain_id:
      raise error.DomainAlreadyExistError(domain_id)
  coll = db.coll('domain')
  try:
    result = await coll.insert_one({'_id': domain_id,
                                    'pending': True, 'owner_uid': owner_uid,
                                    'roles': roles, 'name': name,
                                    'gravatar': gravatar, 'bulletin': bulletin})
    domain_id = result.inserted_id
  except errors.DuplicateKeyError:
    raise error.DomainAlreadyExistError(domain_id) from None
  # grant root role to owner by default
  await add_user_role(domain_id, owner_uid, builtin.ROLE_ROOT)
  await coll.update_one({'_id': domain_id},
                        {'$unset': {'pending': ''}})
  return domain_id