|
|
|
|
@@ -5,21 +5,29 @@ import pandas as pd
|
|
|
|
|
import json
|
|
|
|
|
import httpx
|
|
|
|
|
import deepdiff
|
|
|
|
|
import app.core.config as c
|
|
|
|
|
import app.core.config as config
|
|
|
|
|
import os
|
|
|
|
|
import sys
|
|
|
|
|
from app.db.session import SessionLocal
|
|
|
|
|
from app.db.crud import get_flows_by_app
|
|
|
|
|
from app.db.crud import get_flows,get_activedomain
|
|
|
|
|
from app.core.auth import get_current_active_user,get_current_user
|
|
|
|
|
|
|
|
|
|
kinton_router = r = APIRouter()
|
|
|
|
|
|
|
|
|
|
def getkintoneenv(user = Depends(get_current_user)):
|
|
|
|
|
db = SessionLocal()
|
|
|
|
|
domain = get_activedomain(db, user.id)
|
|
|
|
|
db.close()
|
|
|
|
|
kintoneevn = config.KINTONE_ENV(domain)
|
|
|
|
|
return kintoneevn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getfieldsfromexcel(df):
|
|
|
|
|
appname = df.iloc[0,2]
|
|
|
|
|
col=[]
|
|
|
|
|
for row in range(5,len(df)):
|
|
|
|
|
if pd.isna(df.iloc[row,1]):
|
|
|
|
|
break
|
|
|
|
|
if not df.iloc[row,3] in c.KINTONE_FIELD_TYPE:
|
|
|
|
|
if not df.iloc[row,3] in config.KINTONE_FIELD_TYPE:
|
|
|
|
|
continue
|
|
|
|
|
p=[]
|
|
|
|
|
for column in range(1,7):
|
|
|
|
|
@@ -42,10 +50,10 @@ def getsettingfromexcel(df):
|
|
|
|
|
des = df.iloc[2,2]
|
|
|
|
|
return {"name":appname,"description":des}
|
|
|
|
|
|
|
|
|
|
def getsettingfromkintone(app:str):
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
def getsettingfromkintone(app:str,c:config.KINTONE_ENV):
|
|
|
|
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
params = {"app":app}
|
|
|
|
|
url = f"{c.BASE_URL}{c.API_V1_STR}/app/settings.json"
|
|
|
|
|
url = f"{c.BASE_URL}{config.API_V1_STR}/app/settings.json"
|
|
|
|
|
r = httpx.get(url,headers=headers,params=params)
|
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
@@ -57,24 +65,24 @@ def analysesettings(excel,kintone):
|
|
|
|
|
updatesettings[key] = excel[key]
|
|
|
|
|
return updatesettings
|
|
|
|
|
|
|
|
|
|
def createkintoneapp(name:str):
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
|
|
|
|
def createkintoneapp(name:str,c:config.KINTONE_ENV):
|
|
|
|
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
|
|
|
|
data = {"name":name}
|
|
|
|
|
url = f"{c.BASE_URL}{c.API_V1_STR}/preview/app.json"
|
|
|
|
|
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app.json"
|
|
|
|
|
r = httpx.post(url,headers=headers,data=json.dumps(data))
|
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
def updateappsettingstokintone(app:str,updates:dict):
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
|
|
|
|
url = f"{c.BASE_URL}{c.API_V1_STR}/preview/app/settings.json"
|
|
|
|
|
def updateappsettingstokintone(app:str,updates:dict,c:config.KINTONE_ENV):
|
|
|
|
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
|
|
|
|
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app/settings.json"
|
|
|
|
|
data = {"app":app}
|
|
|
|
|
data.update(updates)
|
|
|
|
|
r = httpx.put(url,headers=headers,data=json.dumps(data))
|
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
def addfieldstokintone(app:str,fields:dict,revision:str = None):
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
|
|
|
|
url = f"{c.BASE_URL}{c.API_V1_STR}/preview/app/form/fields.json"
|
|
|
|
|
def addfieldstokintone(app:str,fields:dict,c:config.KINTONE_ENV,revision:str = None):
|
|
|
|
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
|
|
|
|
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app/form/fields.json"
|
|
|
|
|
if revision != None:
|
|
|
|
|
data = {"app":app,"revision":revision,"properties":fields}
|
|
|
|
|
else:
|
|
|
|
|
@@ -82,32 +90,32 @@ def addfieldstokintone(app:str,fields:dict,revision:str = None):
|
|
|
|
|
r = httpx.post(url,headers=headers,data=json.dumps(data))
|
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
def updatefieldstokintone(app:str,revision:str,fields:dict):
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
|
|
|
|
url = f"{c.BASE_URL}{c.API_V1_STR}/preview/app/form/fields.json"
|
|
|
|
|
def updatefieldstokintone(app:str,revision:str,fields:dict,c:config.KINTONE_ENV):
|
|
|
|
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
|
|
|
|
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app/form/fields.json"
|
|
|
|
|
data = {"app":app,"properties":fields}
|
|
|
|
|
r = httpx.put(url,headers=headers,data=json.dumps(data))
|
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
def deletefieldsfromkintone(app:str,revision:str,fields:dict):
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
|
|
|
|
url = f"{c.BASE_URL}{c.API_V1_STR}/preview/app/form/fields.json"
|
|
|
|
|
def deletefieldsfromkintone(app:str,revision:str,fields:dict,c:config.KINTONE_ENV):
|
|
|
|
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
|
|
|
|
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app/form/fields.json"
|
|
|
|
|
params = {"app":app,"revision":revision,"fields":fields}
|
|
|
|
|
#r = httpx.delete(url,headers=headers,content=json.dumps(params))
|
|
|
|
|
r = httpx.request(method="DELETE",url=url,headers=headers,content=json.dumps(params))
|
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
def deoployappfromkintone(app:str,revision:str):
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
|
|
|
|
url = f"{c.BASE_URL}{c.API_V1_STR}/preview/app/deploy.json"
|
|
|
|
|
def deoployappfromkintone(app:str,revision:str,c:config.KINTONE_ENV):
|
|
|
|
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
|
|
|
|
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app/deploy.json"
|
|
|
|
|
data = {"apps":[{"app":app,"revision":revision}],"revert": False}
|
|
|
|
|
r = httpx.post(url,headers=headers,data=json.dumps(data))
|
|
|
|
|
return r.json
|
|
|
|
|
|
|
|
|
|
def getfieldsfromkintone(app):
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
def getfieldsfromkintone(app:str,c:config.KINTONE_ENV):
|
|
|
|
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
params = {"app":app}
|
|
|
|
|
url = f"{c.BASE_URL}{c.API_V1_STR}/app/form/fields.json"
|
|
|
|
|
url = f"{c.BASE_URL}{config.API_V1_STR}/app/form/fields.json"
|
|
|
|
|
r = httpx.get(url,headers=headers,params=params)
|
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
@@ -131,10 +139,10 @@ def analysefields(excel,kintone):
|
|
|
|
|
|
|
|
|
|
return {"update":updatefields,"add":addfields,"del":delfields}
|
|
|
|
|
|
|
|
|
|
def getprocessfromkintone(app:str):
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
def getprocessfromkintone(app:str,c:config.KINTONE_ENV):
|
|
|
|
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
params = {"app":app}
|
|
|
|
|
url = f"{c.BASE_URL}{c.API_V1_STR}/app/status.json"
|
|
|
|
|
url = f"{c.BASE_URL}{config.API_V1_STR}/app/status.json"
|
|
|
|
|
r = httpx.get(url,headers=headers,params=params)
|
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
@@ -198,36 +206,36 @@ def analysprocess(excel,kintone):
|
|
|
|
|
# return True
|
|
|
|
|
return diff
|
|
|
|
|
|
|
|
|
|
def updateprocesstokintone(app:str,process:dict):
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
|
|
|
|
url = f"{c.BASE_URL}{c.API_V1_STR}/preview/app/status.json"
|
|
|
|
|
def updateprocesstokintone(app:str,process:dict,c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
|
|
|
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
|
|
|
|
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app/status.json"
|
|
|
|
|
data = {"app":app,"enable":True}
|
|
|
|
|
data.update(process)
|
|
|
|
|
r = httpx.put(url,headers=headers,data=json.dumps(data))
|
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
def getkintoneusers():
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
def getkintoneusers(c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
|
|
|
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
url = f"{c.BASE_URL}/v1/users.json"
|
|
|
|
|
r = httpx.get(url,headers=headers)
|
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
def getkintoneorgs():
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
def getkintoneorgs(c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
|
|
|
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
params = {"code":c.KINTONE_USER}
|
|
|
|
|
url = f"{c.BASE_URL}/v1/user/organizations.json"
|
|
|
|
|
r = httpx.get(url,headers=headers,params=params)
|
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
def uploadkintonefiles(file):
|
|
|
|
|
def uploadkintonefiles(file,c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
|
|
|
|
upload_files = {'file': open(file,'rb')}
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
data ={'name':'file','filename':os.path.basename(file)}
|
|
|
|
|
url = f"{c.BASE_URL}/k/v1/file.json"
|
|
|
|
|
r = httpx.post(url,headers=headers,data=data,files=upload_files)
|
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
def updateappjscss(app,uploads):
|
|
|
|
|
def updateappjscss(app,uploads,c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
|
|
|
|
dsjs = []
|
|
|
|
|
dscss = []
|
|
|
|
|
for upload in uploads:
|
|
|
|
|
@@ -239,24 +247,26 @@ def updateappjscss(app,uploads):
|
|
|
|
|
ds ={'js':dsjs,'css':dscss}
|
|
|
|
|
mb ={'js':[],'css':[]}
|
|
|
|
|
data = {'app':app,'scope':'ALL','desktop':ds,'mobile':mb}
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
|
|
|
|
url = f"{c.BASE_URL}{c.API_V1_STR}/preview/app/customize.json"
|
|
|
|
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
|
|
|
|
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app/customize.json"
|
|
|
|
|
print(data)
|
|
|
|
|
r = httpx.put(url,headers=headers,data=json.dumps(data))
|
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
def createappjs(app):
|
|
|
|
|
db = SessionLocal()
|
|
|
|
|
flows = get_flows_by_app(db,app)
|
|
|
|
|
flows = get_flows(db,app)
|
|
|
|
|
db.close()
|
|
|
|
|
content={}
|
|
|
|
|
for flow in flows:
|
|
|
|
|
content[flow.eventid] = {'flowid':flow.flowid,'name':flow.name,'content':flow.content}
|
|
|
|
|
js = 'const alcflow=' + json.dumps(content)
|
|
|
|
|
fpath = os.path.join("Temp",f"alc_setting_{app}.js")
|
|
|
|
|
with open(fpath,'w') as file:
|
|
|
|
|
file.write(js)
|
|
|
|
|
return fpath
|
|
|
|
|
js = 'const flow=' + json.dumps(content)
|
|
|
|
|
fpath = '{}\\alc_setting_{}.js'.format('Temp',app)
|
|
|
|
|
file = open(fpath,'w',encoding="utf-8")
|
|
|
|
|
file.write(js)
|
|
|
|
|
file.close()
|
|
|
|
|
return fpath
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@r.post("/test",)
|
|
|
|
|
async def test(file:UploadFile= File(...),app:str=None):
|
|
|
|
|
@@ -283,14 +293,14 @@ async def test(file:UploadFile= File(...),app:str=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@r.post("/download",)
|
|
|
|
|
async def download(key):
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
async def download(key,c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
|
|
|
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
params = {"fileKey":key}
|
|
|
|
|
url = f"{c.BASE_URL}/k/v1/file.json"
|
|
|
|
|
r = httpx.get(url,headers=headers,params=params)
|
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
@r.post("/upload",)
|
|
|
|
|
@r.post("/upload")
|
|
|
|
|
async def upload(files:t.List[UploadFile] = File(...)):
|
|
|
|
|
dataframes = []
|
|
|
|
|
for file in files:
|
|
|
|
|
@@ -308,7 +318,7 @@ async def upload(files:t.List[UploadFile] = File(...)):
|
|
|
|
|
return {"files": [file.filename for file in files]}
|
|
|
|
|
|
|
|
|
|
@r.post("/updatejscss")
|
|
|
|
|
async def jscss(app:str,files:t.List[UploadFile] = File(...)):
|
|
|
|
|
async def jscss(app:str,files:t.List[UploadFile] = File(...),env = Depends(getkintoneenv)):
|
|
|
|
|
try:
|
|
|
|
|
jscs=[]
|
|
|
|
|
for file in files:
|
|
|
|
|
@@ -323,56 +333,44 @@ async def jscss(app:str,files:t.List[UploadFile] = File(...)):
|
|
|
|
|
jscs.append({ file.filename:upload['fileKey']})
|
|
|
|
|
appjscs = updateappjscss(app,jscs)
|
|
|
|
|
if appjscs.get("revision") != None:
|
|
|
|
|
deoployappfromkintone(app,appjscs["revision"])
|
|
|
|
|
deoployappfromkintone(app,appjscs["revision"],env)
|
|
|
|
|
return appjscs
|
|
|
|
|
except Exception as e:
|
|
|
|
|
raise HTTPException(status_code=400, detail=f"Error occurred while update file {file.filename}: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@r.get("/allapps",)
|
|
|
|
|
async def allapps():
|
|
|
|
|
try:
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
url = f"{c.BASE_URL}{c.API_V1_STR}/apps.json"
|
|
|
|
|
r = httpx.get(url,headers=headers,timeout=httpx.Timeout(10))
|
|
|
|
|
return r.json()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"異常発生しました。{type(e).__name__},{e}")
|
|
|
|
|
|
|
|
|
|
@r.get("/app")
|
|
|
|
|
async def app(app:str):
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
url = f"{c.BASE_URL}{c.API_V1_STR}/app.json"
|
|
|
|
|
params ={"id":app}
|
|
|
|
|
r = httpx.get(url,headers=headers,params=params)
|
|
|
|
|
@r.get("/allapps")
|
|
|
|
|
async def allapps(c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
|
|
|
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
url = f"{c.BASE_URL}{config.API_V1_STR}/apps.json"
|
|
|
|
|
r = httpx.get(url,headers=headers)
|
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@r.get("/appfields")
|
|
|
|
|
async def appfields(app:str):
|
|
|
|
|
return getfieldsfromkintone(app)
|
|
|
|
|
async def appfields(app:str,env = Depends(getkintoneenv)):
|
|
|
|
|
return getfieldsfromkintone(app,env)
|
|
|
|
|
|
|
|
|
|
@r.get("/appprocess")
|
|
|
|
|
async def appprocess(app:str):
|
|
|
|
|
return getprocessfromkintone(app)
|
|
|
|
|
async def appprocess(app:str,env = Depends(getkintoneenv)):
|
|
|
|
|
return getprocessfromkintone(app,env)
|
|
|
|
|
|
|
|
|
|
@r.get("/alljscss")
|
|
|
|
|
async def alljscs(app:str):
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
url = f"{c.BASE_URL}{c.API_V1_STR}/app/customize.json"
|
|
|
|
|
async def alljscs(app:str,c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
|
|
|
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
|
|
|
|
url = f"{c.BASE_URL}{config.API_V1_STR}/app/customize.json"
|
|
|
|
|
params = {"app":app}
|
|
|
|
|
r = httpx.get(url,headers=headers,params=params)
|
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
@r.post("/createapp",)
|
|
|
|
|
async def createapp(name:str):
|
|
|
|
|
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
|
|
|
|
async def createapp(name:str,c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
|
|
|
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
|
|
|
|
data = {"name":name}
|
|
|
|
|
url = f"{c.BASE_URL}{c.API_V1_STR}/preview/app.json"
|
|
|
|
|
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app.json"
|
|
|
|
|
r = httpx.post(url,headers=headers,data=json.dumps(data))
|
|
|
|
|
result = r.json()
|
|
|
|
|
if result.get("app") != None:
|
|
|
|
|
url = f"{c.BASE_URL}{c.API_V1_STR}/preview/app/deploy.json"
|
|
|
|
|
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app/deploy.json"
|
|
|
|
|
data = {"apps":[result],"revert": False}
|
|
|
|
|
r = httpx.post(url,headers=headers,data=json.dumps(data))
|
|
|
|
|
return r.json
|
|
|
|
|
@@ -380,7 +378,7 @@ async def createapp(name:str):
|
|
|
|
|
property=["label","code","type","required","defaultValue","options"]
|
|
|
|
|
|
|
|
|
|
@r.post("/createappfromexcel",)
|
|
|
|
|
async def createappfromexcel(files:t.List[UploadFile] = File(...)):
|
|
|
|
|
async def createappfromexcel(files:t.List[UploadFile] = File(...),env = Depends(getkintoneenv)):
|
|
|
|
|
for file in files:
|
|
|
|
|
if file.filename.endswith('.xlsx'):
|
|
|
|
|
try:
|
|
|
|
|
@@ -394,18 +392,18 @@ async def createappfromexcel(files:t.List[UploadFile] = File(...)):
|
|
|
|
|
users = getkintoneusers()
|
|
|
|
|
orgs = getkintoneorgs()
|
|
|
|
|
processes = getprocessfromexcel(df,users["users"], orgs["organizationTitles"])
|
|
|
|
|
app = createkintoneapp(appname)
|
|
|
|
|
app = createkintoneapp(appname,env)
|
|
|
|
|
if app.get("app") != None:
|
|
|
|
|
result["app"] = app["app"]
|
|
|
|
|
app = updateappsettingstokintone(result["app"],{"description":desc})
|
|
|
|
|
app = updateappsettingstokintone(result["app"],{"description":desc},env)
|
|
|
|
|
if app.get("revision") != None:
|
|
|
|
|
result["revision"] = app["revision"]
|
|
|
|
|
app = addfieldstokintone(result["app"],fields)
|
|
|
|
|
app = addfieldstokintone(result["app"],env,fields)
|
|
|
|
|
if len(processes)> 0:
|
|
|
|
|
app = updateprocesstokintone(result["app"],processes)
|
|
|
|
|
if app.get("revision") != None:
|
|
|
|
|
result["revision"] = app["revision"]
|
|
|
|
|
deoployappfromkintone(result["app"],result["revision"])
|
|
|
|
|
deoployappfromkintone(result["app"],result["revision"],env)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
raise HTTPException(status_code=400, detail=f"Error occurred while parsing file {file.filename}: {str(e)}")
|
|
|
|
|
else:
|
|
|
|
|
@@ -414,42 +412,42 @@ async def createappfromexcel(files:t.List[UploadFile] = File(...)):
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@r.post("/updateappfromexcel",)
|
|
|
|
|
async def updateappfromexcel(app:str,files:t.List[UploadFile] = File(...)):
|
|
|
|
|
@r.post("/updateappfromexcel")
|
|
|
|
|
async def updateappfromexcel(app:str,files:t.List[UploadFile] = File(...),env = Depends(getkintoneenv)):
|
|
|
|
|
for file in files:
|
|
|
|
|
if file.filename.endswith('.xlsx'):
|
|
|
|
|
try:
|
|
|
|
|
content = await file.read()
|
|
|
|
|
df = pd.read_excel(BytesIO(content))
|
|
|
|
|
excel = getsettingfromexcel(df)
|
|
|
|
|
kintone= getsettingfromkintone(app)
|
|
|
|
|
kintone= getsettingfromkintone(app,env)
|
|
|
|
|
settings = analysesettings(excel,kintone)
|
|
|
|
|
excel = getfieldsfromexcel(df)
|
|
|
|
|
kintone = getfieldsfromkintone(app)
|
|
|
|
|
kintone = getfieldsfromkintone(app,env)
|
|
|
|
|
users = getkintoneusers()
|
|
|
|
|
orgs = getkintoneorgs()
|
|
|
|
|
exp = getprocessfromexcel(df,users["users"], orgs["organizationTitles"])
|
|
|
|
|
#exp = getprocessfromexcel(df)
|
|
|
|
|
kinp = getprocessfromkintone(app)
|
|
|
|
|
kinp = getprocessfromkintone(app,env)
|
|
|
|
|
process = analysprocess(exp,kinp)
|
|
|
|
|
revision = kintone["revision"]
|
|
|
|
|
fields = analysefields(excel,kintone["properties"])
|
|
|
|
|
result = {"app":app,"revision":revision,"msg":"No Update"}
|
|
|
|
|
deploy = False
|
|
|
|
|
if len(fields["update"]) > 0:
|
|
|
|
|
result = updatefieldstokintone(app,revision,fields["update"])
|
|
|
|
|
result = updatefieldstokintone(app,revision,fields["update"],env)
|
|
|
|
|
revision = result["revision"]
|
|
|
|
|
deploy = True
|
|
|
|
|
if len(fields["add"]) > 0:
|
|
|
|
|
result = addfieldstokintone(app,fields["add"],revision)
|
|
|
|
|
result = addfieldstokintone(app,fields["add"],env,revision)
|
|
|
|
|
revision = result["revision"]
|
|
|
|
|
deploy = True
|
|
|
|
|
if len(fields["del"]) > 0:
|
|
|
|
|
result = deletefieldsfromkintone(app,revision,fields["del"])
|
|
|
|
|
result = deletefieldsfromkintone(app,revision,fields["del"],env)
|
|
|
|
|
revision = result["revision"]
|
|
|
|
|
deploy = True
|
|
|
|
|
if len(settings) > 0:
|
|
|
|
|
result = updateappsettingstokintone(app,settings)
|
|
|
|
|
result = updateappsettingstokintone(app,settings,env)
|
|
|
|
|
revision = result["revision"]
|
|
|
|
|
deploy = True
|
|
|
|
|
if len(process)>0:
|
|
|
|
|
@@ -457,7 +455,7 @@ async def updateappfromexcel(app:str,files:t.List[UploadFile] = File(...)):
|
|
|
|
|
revision = result["revision"]
|
|
|
|
|
deploy = True
|
|
|
|
|
if deploy:
|
|
|
|
|
result = deoployappfromkintone(app,revision)
|
|
|
|
|
result = deoployappfromkintone(app,revision,env)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
raise HTTPException(status_code=400, detail=f"Error occurred while parsing file {file.filename}: {str(e)}")
|
|
|
|
|
else:
|
|
|
|
|
@@ -466,11 +464,11 @@ async def updateappfromexcel(app:str,files:t.List[UploadFile] = File(...)):
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
@r.post("/updateprocessfromexcel",)
|
|
|
|
|
async def updateprocessfromexcel(app:str):
|
|
|
|
|
async def updateprocessfromexcel(app:str,env = Depends(getkintoneenv)):
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
excel = getprocessfromexcel()
|
|
|
|
|
kintone = getprocessfromkintone(app)
|
|
|
|
|
kintone = getprocessfromkintone(app,env)
|
|
|
|
|
revision = kintone["revision"]
|
|
|
|
|
#fields = analysefields(excel,kintone["properties"])
|
|
|
|
|
result = {"app":app,"revision":revision,"msg":"No Update"}
|
|
|
|
|
@@ -495,7 +493,7 @@ async def updateprocessfromexcel(app:str):
|
|
|
|
|
revision = result["revision"]
|
|
|
|
|
deploy = True
|
|
|
|
|
if deploy:
|
|
|
|
|
result = deoployappfromkintone(app,revision)
|
|
|
|
|
result = deoployappfromkintone(app,revision,env)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
raise HTTPException(status_code=400, detail=f"Error occurred : {str(e)}")
|
|
|
|
|
|
|
|
|
|
@@ -503,22 +501,20 @@ async def updateprocessfromexcel(app:str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@r.post("/createjstokintone",)
|
|
|
|
|
async def createjstokintone(app:str):
|
|
|
|
|
async def createjstokintone(app:str,env = Depends(getkintoneenv)):
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
jscs=[]
|
|
|
|
|
files=[]
|
|
|
|
|
files.append(createappjs(app))
|
|
|
|
|
base_dir = os.path.abspath('Temp')
|
|
|
|
|
runtimeJs = os.path.join(base_dir, 'alc_runtime.js')
|
|
|
|
|
files.append(runtimeJs)
|
|
|
|
|
files.append('Temp\\alc_runtime.js')
|
|
|
|
|
for file in files:
|
|
|
|
|
upload = uploadkintonefiles(file)
|
|
|
|
|
if upload.get('fileKey') != None:
|
|
|
|
|
jscs.append({ app + '.js':upload['fileKey']})
|
|
|
|
|
appjscs = updateappjscss(app,jscs)
|
|
|
|
|
if appjscs.get("revision") != None:
|
|
|
|
|
deoployappfromkintone(app,appjscs["revision"])
|
|
|
|
|
deoployappfromkintone(app,appjscs["revision"],env)
|
|
|
|
|
return appjscs
|
|
|
|
|
except Exception as e:
|
|
|
|
|
raise HTTPException(status_code=400, detail=f"Error occurred : {str(e)}")
|
|
|
|
|
raise HTTPException(status_code=400, detail=f"Error occurred : {str(e)}")
|
|
|
|
|
|