flow domainid->domainurl add app flowhistory
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
from fastapi import Query, Request,Depends, APIRouter, UploadFile,HTTPException,File
|
from fastapi import Query, Request,Depends, APIRouter, UploadFile,HTTPException,File
|
||||||
|
from app.core.operation import log_operation
|
||||||
from app.db import Base,engine
|
from app.db import Base,engine
|
||||||
from app.db.session import get_db
|
from app.db.session import get_db
|
||||||
from app.db.crud import *
|
from app.db.crud import *
|
||||||
@@ -7,6 +8,9 @@ from typing import List, Optional
|
|||||||
from app.core.auth import get_current_active_user,get_current_user
|
from app.core.auth import get_current_active_user,get_current_user
|
||||||
from app.core.apiexception import APIException
|
from app.core.apiexception import APIException
|
||||||
|
|
||||||
|
import httpx
|
||||||
|
import app.core.config as config
|
||||||
|
|
||||||
platform_router = r = APIRouter()
|
platform_router = r = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@@ -17,11 +21,40 @@ platform_router = r = APIRouter()
|
|||||||
)
|
)
|
||||||
async def apps_list(
|
async def apps_list(
|
||||||
request: Request,
|
request: Request,
|
||||||
|
user = Depends(get_current_user),
|
||||||
db=Depends(get_db),
|
db=Depends(get_db),
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
app = get_apps(db)
|
platformapps = get_apps(db)
|
||||||
return app
|
domain = get_activedomain(db, user.id)
|
||||||
|
|
||||||
|
kintoneevn = config.KINTONE_ENV(domain)
|
||||||
|
headers={config.API_V1_AUTH_KEY:kintoneevn.API_V1_AUTH_VALUE}
|
||||||
|
url = f"{kintoneevn.BASE_URL}{config.API_V1_STR}/apps.json"
|
||||||
|
offset = 0
|
||||||
|
limit = 100
|
||||||
|
all_apps = []
|
||||||
|
|
||||||
|
while True:
|
||||||
|
r = httpx.get(f"{url}?limit={limit}&offset={offset}", headers=headers)
|
||||||
|
json_data = r.json()
|
||||||
|
apps = json_data.get("apps",[])
|
||||||
|
all_apps.extend(apps)
|
||||||
|
if len(apps)<limit:
|
||||||
|
break
|
||||||
|
offset += limit
|
||||||
|
|
||||||
|
tempapps = platformapps.copy()
|
||||||
|
for papp in tempapps:
|
||||||
|
exist = False
|
||||||
|
for kapp in all_apps:
|
||||||
|
if kapp['appId'] == papp.appid:
|
||||||
|
exist = True
|
||||||
|
break
|
||||||
|
if not exist:
|
||||||
|
platformapps.remove(papp)
|
||||||
|
|
||||||
|
return platformapps
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise APIException('platform:apps',request.url._url,f"Error occurred while get apps:",e)
|
raise APIException('platform:apps',request.url._url,f"Error occurred while get apps:",e)
|
||||||
|
|
||||||
@@ -158,7 +191,7 @@ async def flow_list(
|
|||||||
try:
|
try:
|
||||||
domain = get_activedomain(db, user.id)
|
domain = get_activedomain(db, user.id)
|
||||||
print("domain=>",domain)
|
print("domain=>",domain)
|
||||||
flows = get_flows_by_app(db, domain.id, appid)
|
flows = get_flows_by_app(db, domain.url, appid)
|
||||||
return flows
|
return flows
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise APIException('platform:flow',request.url._url,f"Error occurred while get flow by appid:",e)
|
raise APIException('platform:flow',request.url._url,f"Error occurred while get flow by appid:",e)
|
||||||
@@ -173,7 +206,7 @@ async def flow_create(
|
|||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
domain = get_activedomain(db, user.id)
|
domain = get_activedomain(db, user.id)
|
||||||
return create_flow(db, domain.id, flow)
|
return create_flow(db, domain.url, flow)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise APIException('platform:flow',request.url._url,f"Error occurred while create flow:",e)
|
raise APIException('platform:flow',request.url._url,f"Error occurred while create flow:",e)
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import base64
|
|||||||
PROJECT_NAME = "KintoneAppBuilder"
|
PROJECT_NAME = "KintoneAppBuilder"
|
||||||
|
|
||||||
#SQLALCHEMY_DATABASE_URI = "postgres://kabAdmin:P@ssw0rd!@kintonetooldb.postgres.database.azure.com/dev"
|
#SQLALCHEMY_DATABASE_URI = "postgres://kabAdmin:P@ssw0rd!@kintonetooldb.postgres.database.azure.com/dev"
|
||||||
SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://kabAdmin:P%40ssw0rd!@kintonetooldb.postgres.database.azure.com/postgres"
|
SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://kabAdmin:P%40ssw0rd!@kintonetooldb.postgres.database.azure.com/dev_v2"
|
||||||
#SQLALCHEMY_DATABASE_URI = "postgres://kabAdmin:P@ssw0rd!@kintonetooldb.postgres.database.azure.com/test"
|
#SQLALCHEMY_DATABASE_URI = "postgres://kabAdmin:P@ssw0rd!@kintonetooldb.postgres.database.azure.com/test"
|
||||||
#SQLALCHEMY_DATABASE_URI = "postgres://kabAdmin:P@ssw0rd!@ktune-prod-db.postgres.database.azure.com/postgres"
|
#SQLALCHEMY_DATABASE_URI = "postgres://kabAdmin:P@ssw0rd!@ktune-prod-db.postgres.database.azure.com/postgres"
|
||||||
API_V1_STR = "/k/v1"
|
API_V1_STR = "/k/v1"
|
||||||
|
|||||||
@@ -79,16 +79,33 @@ def update_appversion(db: Session, appedit: schemas.AppVersion,userid:int):
|
|||||||
if app:
|
if app:
|
||||||
app.version = app.version + 1
|
app.version = app.version + 1
|
||||||
db_app = app
|
db_app = app
|
||||||
|
appver = app.version
|
||||||
else:
|
else:
|
||||||
|
appver = 1
|
||||||
db_app = models.App(
|
db_app = models.App(
|
||||||
domainurl = appedit.domainurl,
|
domainurl = appedit.domainurl,
|
||||||
appid=appedit.appid,
|
appid=appedit.appid,
|
||||||
appname=appedit.appname,
|
appname=appedit.appname,
|
||||||
version = 1,
|
version = 1,
|
||||||
updateuser= userid
|
updateuser= userid
|
||||||
)
|
)
|
||||||
|
|
||||||
db.add(db_app)
|
db.add(db_app)
|
||||||
|
|
||||||
|
flows = db.query(models.Flow).filter(and_(models.Flow.domainurl == appedit.domainurl,models.App.appid == appedit.appid))
|
||||||
|
for flow in flows:
|
||||||
|
db_flowhistory = models.FlowHistory(
|
||||||
|
flowid = flow.flowid,
|
||||||
|
appid = flow.appid,
|
||||||
|
eventid = flow.eventid,
|
||||||
|
domainurl = flow.domainurl,
|
||||||
|
name = flow.name,
|
||||||
|
content = flow.content,
|
||||||
|
createuser = userid,
|
||||||
|
version = appver
|
||||||
|
)
|
||||||
|
db.add(db_flowhistory)
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(db_app)
|
db.refresh(db_app)
|
||||||
return db_app
|
return db_app
|
||||||
@@ -148,12 +165,12 @@ def get_actions(db: Session):
|
|||||||
return actions
|
return actions
|
||||||
|
|
||||||
|
|
||||||
def create_flow(db: Session, domainid: int, flow: schemas.FlowBase):
|
def create_flow(db: Session, domainurl: str, flow: schemas.FlowBase):
|
||||||
db_flow = models.Flow(
|
db_flow = models.Flow(
|
||||||
flowid=flow.flowid,
|
flowid=flow.flowid,
|
||||||
appid=flow.appid,
|
appid=flow.appid,
|
||||||
eventid=flow.eventid,
|
eventid=flow.eventid,
|
||||||
domainid=domainid,
|
domainurl=domainurl,
|
||||||
name=flow.name,
|
name=flow.name,
|
||||||
content=flow.content
|
content=flow.content
|
||||||
)
|
)
|
||||||
@@ -200,8 +217,8 @@ def get_flow(db: Session, flowid: str):
|
|||||||
raise HTTPException(status_code=404, detail="Data not found")
|
raise HTTPException(status_code=404, detail="Data not found")
|
||||||
return flow
|
return flow
|
||||||
|
|
||||||
def get_flows_by_app(db: Session, domainid: int, appid: str):
|
def get_flows_by_app(db: Session,domainurl: str, appid: str):
|
||||||
flows = db.query(models.Flow).filter(and_(models.Flow.domainid == domainid,models.Flow.appid == appid)).all()
|
flows = db.query(models.Flow).filter(and_(models.Flow.domainurl == domainurl,models.Flow.appid == appid)).all()
|
||||||
if not flows:
|
if not flows:
|
||||||
raise Exception("Data not found")
|
raise Exception("Data not found")
|
||||||
return flows
|
return flows
|
||||||
|
|||||||
@@ -62,10 +62,22 @@ class Flow(Base):
|
|||||||
flowid = Column(String(100), index=True, nullable=False)
|
flowid = Column(String(100), index=True, nullable=False)
|
||||||
appid = Column(String(100), index=True, nullable=False)
|
appid = Column(String(100), index=True, nullable=False)
|
||||||
eventid = Column(String(100), index=True, nullable=False)
|
eventid = Column(String(100), index=True, nullable=False)
|
||||||
domainid = Column(Integer,ForeignKey("domain.id"))
|
domainurl = Column(String(200))
|
||||||
name = Column(String(200))
|
name = Column(String(200))
|
||||||
content = Column(String)
|
content = Column(String)
|
||||||
|
|
||||||
|
class FlowHistory(Base):
|
||||||
|
__tablename__ = "flowhistory"
|
||||||
|
|
||||||
|
flowid = Column(String(100), index=True, nullable=False)
|
||||||
|
appid = Column(String(100), index=True, nullable=False)
|
||||||
|
eventid = Column(String(100), index=True, nullable=False)
|
||||||
|
domainurl = Column(String(200))
|
||||||
|
name = Column(String(200))
|
||||||
|
content = Column(String)
|
||||||
|
createuser = Column(Integer,ForeignKey("user.id"))
|
||||||
|
version = Column(Integer)
|
||||||
|
|
||||||
class Tenant(Base):
|
class Tenant(Base):
|
||||||
__tablename__ = "tenant"
|
__tablename__ = "tenant"
|
||||||
|
|
||||||
@@ -119,6 +131,17 @@ class ErrorLog(Base):
|
|||||||
location = Column(String(500))
|
location = Column(String(500))
|
||||||
content = Column(String(5000))
|
content = Column(String(5000))
|
||||||
|
|
||||||
|
class OperationLog(Base):
|
||||||
|
__tablename__ = "operationlog"
|
||||||
|
|
||||||
|
tenantid = Column(String(100))
|
||||||
|
domainurl = Column(String(200))
|
||||||
|
userid = Column(Integer,ForeignKey("user.id"))
|
||||||
|
operation = Column(String(200))
|
||||||
|
function = Column(String(200))
|
||||||
|
detail = Column(String(200))
|
||||||
|
user = relationship('User')
|
||||||
|
|
||||||
class KintoneFormat(Base):
|
class KintoneFormat(Base):
|
||||||
__tablename__ = "kintoneformat"
|
__tablename__ = "kintoneformat"
|
||||||
|
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ class Flow(Base):
|
|||||||
flowid: str
|
flowid: str
|
||||||
appid: str
|
appid: str
|
||||||
eventid: str
|
eventid: str
|
||||||
domainid: int
|
domainurl: str
|
||||||
name: str = None
|
name: str = None
|
||||||
content: str = None
|
content: str = None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user