ADD: Integrated Permissions Module - Starting prototype and proof of concept
parent
8902a4d49a
commit
8d1f7ffcfc
@ -0,0 +1,16 @@
|
||||
from settings.config import SQLACHEMY
|
||||
from sqlalchemy import Table
|
||||
from sqlalchemy.orm import declarative_base
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
class Ipm(Base):
|
||||
"""
|
||||
IPM model class.
|
||||
"""
|
||||
__table__ = Table(
|
||||
"ipm",
|
||||
Base.metadata,
|
||||
autoload=True,
|
||||
autoload_with=SQLACHEMY
|
||||
)
|
@ -0,0 +1,24 @@
|
||||
## IPM (Integrated Permissions Module)
|
||||
# The Integrated Permissions Module will allow for individual sets of rules for individual users
|
||||
|
||||
import MySQLdb
|
||||
from models.ipm import Ipm
|
||||
from settings.config import MYSQL_CONFIG, SQLACHEMY
|
||||
from sqlalchemy.orm import Session
|
||||
import json
|
||||
|
||||
def ipm_check(user: str, ipmstring: str) -> bool:
|
||||
|
||||
ipmjson = {}
|
||||
ipmstring = ipmstring.split('.')
|
||||
with Session(SQLACHEMY) as session:
|
||||
ipmlist = session.query(Ipm).filter(Ipm.user==user)
|
||||
ipmlist = session.execute(ipmlist)
|
||||
ipmlist = [obj.ipmlist for obj in ipmlist.scalars()]
|
||||
ipmjson = json.loads(str(ipmlist[0])) if ipmlist else None
|
||||
if ipmjson is None:
|
||||
return False
|
||||
if ipmstring[1] in ipmjson[ipmstring[0]] or "*" in ipmjson[ipmstring[0]]:
|
||||
return True
|
||||
else:
|
||||
return False
|
Loading…
Reference in New Issue