Acces List library for SQLAlchemy ORM
Project description
SQLAlchemy Acces List
Virtual Environment
To initialize virtual env run following command in project root, pipenv required
$ pipenv shell
Testing ACL
Easiest way to test is creating simple script
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy_acl import ACL
from models import Base, Wage
# creating engine and session, creating tables in db according to models
engine = create_engine('sqlite:///db.sqlite')
Session = sessionmaker(bind=engine, query_cls=ACL.Query)
session = Session()
Base.metadata.create_all(bind=engine)
# attchaing engine to ACL, initializing ACL
ACL.setup(engine)
# example entries for db
# defining few wages and two users, and acl
# admin has access to all entries in wages table, while std_user cannot access 'Prezio`
entries = [
# wages
Wage(id=1, person='Prezio', amount=1000000),
Wage(id=2, person='Programista15k', amount=15000),
Wage(id=3, person='Programista10k', amount=10000),
Wage(id=4, person='Praktykantka', amount=1000),
# users
ACL.UserModel(id=1, username='admin'),
ACL.UserModel(id=2, username='std_user'),
# admin access
ACL.ACLEntry(user_id=1, dest_table='wages', dest_id=1),
ACL.ACLEntry(user_id=1, dest_table='wages', dest_id=2),
ACL.ACLEntry(user_id=1, dest_table='wages', dest_id=3),
ACL.ACLEntry(user_id=1, dest_table='wages', dest_id=4),
# std_user access
ACL.ACLEntry(user_id=2, dest_table='wages', dest_id=2),
ACL.ACLEntry(user_id=2, dest_table='wages', dest_id=3),
ACL.ACLEntry(user_id=2, dest_table='wages', dest_id=4)
]
# adding entries to session and commiting to db
session.add_all(entries)
session.commit()
# retrieving admin and std_user objects
admin = session.query(ACL.UserModel).filter_by(id=1).scalar()
std_user = session.query(ACL.UserModel).filter_by(id=2).scalar()
# when user is not set empty array will be returned
print(session.query(Wage).all())
# []
# setting user before executing query
ACL.set_user(admin)
print(session.query(Wage).all())
# [<Wage 1:Prezio:1000000>, <Wage 2:Programista15k:15000>, <Wage 3:Programista10k:10000>, <Wage 4:Praktykantka:1000>]
# setting user before executing query
ACL.set_user(std_user)
print(session.query(Wage).all())
# [<Wage 2:Programista15k:15000>, <Wage 3:Programista10k:10000>, <Wage 4:Praktykantka:1000>]
# unsetting user
ACL.unset_user()
print(session.query(Wage).all())
# []
ACL.Query
ACL.Query can be used with legacy sqlalchemy project as well as with flask_sqlalchemy project. Due to different usage of those two, connecting ACL may vary, see legacy_sqlalchemy_test.py and flask_sqlalchemy_test.py.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlalchemy-acl-matt-kubica-0.0.1.tar.gz.
File metadata
- Download URL: sqlalchemy-acl-matt-kubica-0.0.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
954199de9a5460e21bbc6a74f4dbdf3d13317185ce63978df8092c4d7edf07fd
|
|
| MD5 |
2aae0b1aff65e31d6efc01ba95cfa1cc
|
|
| BLAKE2b-256 |
0bbd9c1126fcd15f784adf0c0ee767aaa9ba2f03843a700981fba197fc8f8916
|
File details
Details for the file sqlalchemy_acl_matt_kubica-0.0.1-py3-none-any.whl.
File metadata
- Download URL: sqlalchemy_acl_matt_kubica-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c3e97939a6c026940eeacdefe48fc5c602b12cc8651647b987ba61306d5cb74
|
|
| MD5 |
4903aef6938415e4714ea410fd96f799
|
|
| BLAKE2b-256 |
94d9712d86b37a4aac4fd2f4d7604623e27acba5164c03dac035400e40799a3d
|