Exemple #1
0
def get_share_grant_by_token(session: Session,
                             share_token: bytes) -> Optional[ShareGrant]:
    rs = (session.query(
        SQLShareGrant.share_token,
        SQLShareGrant.revoked,
        SQLAccessObject.access_object_name,
        SQLAccessObject.params,
        SQLShareGrant.access_verb_id,
    ).join(
        SQLAccessObject,
        SQLShareGrant.access_object_id == SQLAccessObject.access_object_id,
    ).filter(SQLShareGrant.share_token == share_token).first())
    if rs is None:
        return None
    else:
        share_token, revoked, ao_name, ao_params, av_id = rs
        access_object = BookmarkAccessObject.from_params(ao_params)
        access_verb = Access(av_id)
        return ShareGrant(
            share_token=share_token,
            expiry=None,
            access_object=access_object,
            access_verb=access_verb,
            revoked=revoked,
        )
Exemple #2
0
def test_share_params():
    user_uuid = uuid4()
    url_uuid = uuid4()
    subj = BookmarkAccessObject(user_uuid=user_uuid, url_uuid=url_uuid)
    assert subj.to_params() == {
        "user_uuid": user_uuid.hex,
        "url_uuid": url_uuid.hex,
    }
    assert BookmarkAccessObject.from_params(subj.to_params()) == subj