def create(petition: PetitionIn, expand: bool = False, token: str = Security(security)):
    if not allowed_to_control_petition(token):
        raise HTTPException(
            status_code=HTTP_401_UNAUTHORIZED,
            detail="Not authorized to control this petition",
        )
    try:
        petition_object, ci_uid = _generate_petition_object(petition)
    except FileNotFoundError:
        raise HTTPException(
            status_code=HTTP_404_NOT_FOUND,
            detail="Credential issuer is not validated, missing info/keys/credentials",
        )
    except ConnectionError:
        raise HTTPException(
            status_code=HTTP_424_FAILED_DEPENDENCY,
            detail="Credential issuer server is not available",
        )

    p = Petition(
        petition=petition_object,
        petition_id=petition.petition_id,
        credential_issuer_uid=ci_uid,
        credential_issuer_url=petition.credential_issuer_url,
    )

    try:
        DBSession.add(p)
        DBSession.commit()
    except IntegrityError:
        DBSession.rollback()
        raise HTTPException(
            status_code=HTTP_409_CONFLICT, detail="Duplicate Petition Id"
        )
    return p.publish(expand)
Beispiel #2
0
def create_user(data):
    time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')

    db_session = DBSession()
    print(data)
    user = db_session.query(User).filter(
        User.email == data['email']).first()
    if user:
        return {'status': 'error',
                'message': 'message'}
    password = sha512(data['password'].encode('utf-8')).hexdigest()
    new_user = User(
        username=data['username'], password=password,
        email=data['email'], confirmed_at=time, is_active=True,
        is_admin=data['is_admin'])

    try:
        db_session.add(new_user)
        db_session.commit()

        result = {'status': 'OK',
                  'user': data['username']}
    except:
        db_session.rollback()
        result = {'status': 'error'}

    db_session.close()
    return result
Beispiel #3
0
 def setup(self):
     try:
         new_attrs = {}
         new_attrs.update(self.attrs)
         new_attrs.update(self.do_get_dependencies())
         setup()
         self.obj = self.klass(**new_attrs)
         DBSession.add(self.obj)
         DBSession.flush()
         return self.obj
     except:
         DBSession.rollback()
         raise
Beispiel #4
0
def create_author(data):
    db_session = DBSession()
    new_author = Authors(**data)

    try:
        db_session.add(new_author)
        db_session.commit()

        result = {'status': 'OK',
                  'author': data['fullname']}
    except:
        db_session.rollback()
        result = {'status': 'error'}

    db_session.close()
    return result
Beispiel #5
0
def create_book(data):
    db_session = DBSession()

    new_book = Books(name=data['name'],
                     type_id=data['type_id'],
                     author_id=data['author_id'],
                     book_translator=data['book_translator'])

    try:
        db_session.add(new_book)
        db_session.commit()

        result = {'status': 'OK', 'book': data['name']}
    except:
        db_session.rollback()
        result = {'status': 'error'}

    db_session.close()
    return result
Beispiel #6
0
def create_type(data):
    db_session = DBSession()

    book_type = db_session.query(Types).filter(
        Types.name == data['name']).first()
    if book_type:
        return {'status': 'error', 'message': 'message'}

    new_type = Types(name=data['name'])

    try:
        db_session.add(new_type)
        db_session.commit()

        result = {'status': 'OK', 'type': data['name']}
    except:
        db_session.rollback()
        result = {'status': 'error'}

    db_session.close()
    return result
Beispiel #7
0
 def tearDown(self):
     DBSession.rollback()