domain bug fix
This commit is contained in:
@@ -29,18 +29,19 @@ async def login(
|
|||||||
else:
|
else:
|
||||||
permissions = "user"
|
permissions = "user"
|
||||||
access_token = security.create_access_token(
|
access_token = security.create_access_token(
|
||||||
data={"sub": user.email, "permissions": permissions},
|
data={"sub": user.id, "permissions": permissions},
|
||||||
expires_delta=access_token_expires,
|
expires_delta=access_token_expires,
|
||||||
)
|
)
|
||||||
|
|
||||||
return {"access_token": access_token, "token_type": "bearer"}
|
return {"access_token": access_token, "token_type": "bearer","user_name":user.first_name + " " + user.last_name}
|
||||||
|
|
||||||
|
|
||||||
@r.post("/signup")
|
@r.post("/signup")
|
||||||
async def signup(
|
async def signup(
|
||||||
|
firstname:str, lastname:str,
|
||||||
db=Depends(get_db), form_data: OAuth2PasswordRequestForm = Depends()
|
db=Depends(get_db), form_data: OAuth2PasswordRequestForm = Depends()
|
||||||
):
|
):
|
||||||
user = sign_up_new_user(db, form_data.username, form_data.password)
|
user = sign_up_new_user(db, form_data.username, form_data.password,firstname,lastname)
|
||||||
if not user:
|
if not user:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_409_CONFLICT,
|
status_code=status.HTTP_409_CONFLICT,
|
||||||
@@ -56,8 +57,8 @@ async def signup(
|
|||||||
else:
|
else:
|
||||||
permissions = "user"
|
permissions = "user"
|
||||||
access_token = security.create_access_token(
|
access_token = security.create_access_token(
|
||||||
data={"sub": user.email, "permissions": permissions},
|
data={"sub": user.id, "permissions": permissions},
|
||||||
expires_delta=access_token_expires,
|
expires_delta=access_token_expires,
|
||||||
)
|
)
|
||||||
|
|
||||||
return {"access_token": access_token, "token_type": "bearer"}
|
return {"access_token": access_token, "token_type": "bearer","user_name":user.first_name + " " + user.last_name}
|
||||||
|
|||||||
@@ -5,21 +5,29 @@ import pandas as pd
|
|||||||
import json
|
import json
|
||||||
import httpx
|
import httpx
|
||||||
import deepdiff
|
import deepdiff
|
||||||
import app.core.config as c
|
import app.core.config as config
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
from app.db.session import SessionLocal
|
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()
|
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):
|
def getfieldsfromexcel(df):
|
||||||
appname = df.iloc[0,2]
|
appname = df.iloc[0,2]
|
||||||
col=[]
|
col=[]
|
||||||
for row in range(5,len(df)):
|
for row in range(5,len(df)):
|
||||||
if pd.isna(df.iloc[row,1]):
|
if pd.isna(df.iloc[row,1]):
|
||||||
break
|
break
|
||||||
if not df.iloc[row,3] in c.KINTONE_FIELD_TYPE:
|
if not df.iloc[row,3] in config.KINTONE_FIELD_TYPE:
|
||||||
continue
|
continue
|
||||||
p=[]
|
p=[]
|
||||||
for column in range(1,7):
|
for column in range(1,7):
|
||||||
@@ -42,10 +50,10 @@ def getsettingfromexcel(df):
|
|||||||
des = df.iloc[2,2]
|
des = df.iloc[2,2]
|
||||||
return {"name":appname,"description":des}
|
return {"name":appname,"description":des}
|
||||||
|
|
||||||
def getsettingfromkintone(app:str):
|
def getsettingfromkintone(app:str,c:config.KINTONE_ENV):
|
||||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
||||||
params = {"app":app}
|
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)
|
r = httpx.get(url,headers=headers,params=params)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
@@ -57,24 +65,24 @@ def analysesettings(excel,kintone):
|
|||||||
updatesettings[key] = excel[key]
|
updatesettings[key] = excel[key]
|
||||||
return updatesettings
|
return updatesettings
|
||||||
|
|
||||||
def createkintoneapp(name:str):
|
def createkintoneapp(name:str,c:config.KINTONE_ENV):
|
||||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
||||||
data = {"name":name}
|
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))
|
r = httpx.post(url,headers=headers,data=json.dumps(data))
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
def updateappsettingstokintone(app:str,updates:dict):
|
def updateappsettingstokintone(app:str,updates:dict,c:config.KINTONE_ENV):
|
||||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
headers={config.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"
|
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app/settings.json"
|
||||||
data = {"app":app}
|
data = {"app":app}
|
||||||
data.update(updates)
|
data.update(updates)
|
||||||
r = httpx.put(url,headers=headers,data=json.dumps(data))
|
r = httpx.put(url,headers=headers,data=json.dumps(data))
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
def addfieldstokintone(app:str,fields:dict,revision:str = None):
|
def addfieldstokintone(app:str,fields:dict,c:config.KINTONE_ENV,revision:str = None):
|
||||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
headers={config.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"
|
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app/form/fields.json"
|
||||||
if revision != None:
|
if revision != None:
|
||||||
data = {"app":app,"revision":revision,"properties":fields}
|
data = {"app":app,"revision":revision,"properties":fields}
|
||||||
else:
|
else:
|
||||||
@@ -82,32 +90,32 @@ def addfieldstokintone(app:str,fields:dict,revision:str = None):
|
|||||||
r = httpx.post(url,headers=headers,data=json.dumps(data))
|
r = httpx.post(url,headers=headers,data=json.dumps(data))
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
def updatefieldstokintone(app:str,revision:str,fields:dict):
|
def updatefieldstokintone(app:str,revision:str,fields:dict,c:config.KINTONE_ENV):
|
||||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
headers={config.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"
|
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app/form/fields.json"
|
||||||
data = {"app":app,"properties":fields}
|
data = {"app":app,"properties":fields}
|
||||||
r = httpx.put(url,headers=headers,data=json.dumps(data))
|
r = httpx.put(url,headers=headers,data=json.dumps(data))
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
def deletefieldsfromkintone(app:str,revision:str,fields:dict):
|
def deletefieldsfromkintone(app:str,revision:str,fields:dict,c:config.KINTONE_ENV):
|
||||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
headers={config.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"
|
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app/form/fields.json"
|
||||||
params = {"app":app,"revision":revision,"fields":fields}
|
params = {"app":app,"revision":revision,"fields":fields}
|
||||||
#r = httpx.delete(url,headers=headers,content=json.dumps(params))
|
#r = httpx.delete(url,headers=headers,content=json.dumps(params))
|
||||||
r = httpx.request(method="DELETE",url=url,headers=headers,content=json.dumps(params))
|
r = httpx.request(method="DELETE",url=url,headers=headers,content=json.dumps(params))
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
def deoployappfromkintone(app:str,revision:str):
|
def deoployappfromkintone(app:str,revision:str,c:config.KINTONE_ENV):
|
||||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
headers={config.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"
|
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app/deploy.json"
|
||||||
data = {"apps":[{"app":app,"revision":revision}],"revert": False}
|
data = {"apps":[{"app":app,"revision":revision}],"revert": False}
|
||||||
r = httpx.post(url,headers=headers,data=json.dumps(data))
|
r = httpx.post(url,headers=headers,data=json.dumps(data))
|
||||||
return r.json
|
return r.json
|
||||||
|
|
||||||
def getfieldsfromkintone(app):
|
def getfieldsfromkintone(app:str,c:config.KINTONE_ENV):
|
||||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
||||||
params = {"app":app}
|
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)
|
r = httpx.get(url,headers=headers,params=params)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
@@ -131,10 +139,10 @@ def analysefields(excel,kintone):
|
|||||||
|
|
||||||
return {"update":updatefields,"add":addfields,"del":delfields}
|
return {"update":updatefields,"add":addfields,"del":delfields}
|
||||||
|
|
||||||
def getprocessfromkintone(app:str):
|
def getprocessfromkintone(app:str,c:config.KINTONE_ENV):
|
||||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
||||||
params = {"app":app}
|
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)
|
r = httpx.get(url,headers=headers,params=params)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
@@ -198,36 +206,36 @@ def analysprocess(excel,kintone):
|
|||||||
# return True
|
# return True
|
||||||
return diff
|
return diff
|
||||||
|
|
||||||
def updateprocesstokintone(app:str,process:dict):
|
def updateprocesstokintone(app:str,process:dict,c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
||||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
headers={config.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"
|
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app/status.json"
|
||||||
data = {"app":app,"enable":True}
|
data = {"app":app,"enable":True}
|
||||||
data.update(process)
|
data.update(process)
|
||||||
r = httpx.put(url,headers=headers,data=json.dumps(data))
|
r = httpx.put(url,headers=headers,data=json.dumps(data))
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
def getkintoneusers():
|
def getkintoneusers(c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
||||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
||||||
url = f"{c.BASE_URL}/v1/users.json"
|
url = f"{c.BASE_URL}/v1/users.json"
|
||||||
r = httpx.get(url,headers=headers)
|
r = httpx.get(url,headers=headers)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
def getkintoneorgs():
|
def getkintoneorgs(c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
||||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
||||||
params = {"code":c.KINTONE_USER}
|
params = {"code":c.KINTONE_USER}
|
||||||
url = f"{c.BASE_URL}/v1/user/organizations.json"
|
url = f"{c.BASE_URL}/v1/user/organizations.json"
|
||||||
r = httpx.get(url,headers=headers,params=params)
|
r = httpx.get(url,headers=headers,params=params)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
def uploadkintonefiles(file):
|
def uploadkintonefiles(file,c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
||||||
upload_files = {'file': open(file,'rb')}
|
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)}
|
data ={'name':'file','filename':os.path.basename(file)}
|
||||||
url = f"{c.BASE_URL}/k/v1/file.json"
|
url = f"{c.BASE_URL}/k/v1/file.json"
|
||||||
r = httpx.post(url,headers=headers,data=data,files=upload_files)
|
r = httpx.post(url,headers=headers,data=data,files=upload_files)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
def updateappjscss(app,uploads):
|
def updateappjscss(app,uploads,c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
||||||
dsjs = []
|
dsjs = []
|
||||||
dscss = []
|
dscss = []
|
||||||
for upload in uploads:
|
for upload in uploads:
|
||||||
@@ -239,25 +247,27 @@ def updateappjscss(app,uploads):
|
|||||||
ds ={'js':dsjs,'css':dscss}
|
ds ={'js':dsjs,'css':dscss}
|
||||||
mb ={'js':[],'css':[]}
|
mb ={'js':[],'css':[]}
|
||||||
data = {'app':app,'scope':'ALL','desktop':ds,'mobile':mb}
|
data = {'app':app,'scope':'ALL','desktop':ds,'mobile':mb}
|
||||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
headers={config.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"
|
url = f"{c.BASE_URL}{config.API_V1_STR}/preview/app/customize.json"
|
||||||
print(data)
|
print(data)
|
||||||
r = httpx.put(url,headers=headers,data=json.dumps(data))
|
r = httpx.put(url,headers=headers,data=json.dumps(data))
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
def createappjs(app):
|
def createappjs(app):
|
||||||
db = SessionLocal()
|
db = SessionLocal()
|
||||||
flows = get_flows_by_app(db,app)
|
flows = get_flows(db,app)
|
||||||
db.close()
|
db.close()
|
||||||
content={}
|
content={}
|
||||||
for flow in flows:
|
for flow in flows:
|
||||||
content[flow.eventid] = {'flowid':flow.flowid,'name':flow.name,'content':flow.content}
|
content[flow.eventid] = {'flowid':flow.flowid,'name':flow.name,'content':flow.content}
|
||||||
js = 'const alcflow=' + json.dumps(content)
|
js = 'const flow=' + json.dumps(content)
|
||||||
fpath = os.path.join("Temp",f"alc_setting_{app}.js")
|
fpath = '{}\\alc_setting_{}.js'.format('Temp',app)
|
||||||
with open(fpath,'w') as file:
|
file = open(fpath,'w',encoding="utf-8")
|
||||||
file.write(js)
|
file.write(js)
|
||||||
|
file.close()
|
||||||
return fpath
|
return fpath
|
||||||
|
|
||||||
|
|
||||||
@r.post("/test",)
|
@r.post("/test",)
|
||||||
async def test(file:UploadFile= File(...),app:str=None):
|
async def test(file:UploadFile= File(...),app:str=None):
|
||||||
if file.filename.endswith('.xlsx'):
|
if file.filename.endswith('.xlsx'):
|
||||||
@@ -283,14 +293,14 @@ async def test(file:UploadFile= File(...),app:str=None):
|
|||||||
|
|
||||||
|
|
||||||
@r.post("/download",)
|
@r.post("/download",)
|
||||||
async def download(key):
|
async def download(key,c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
||||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
||||||
params = {"fileKey":key}
|
params = {"fileKey":key}
|
||||||
url = f"{c.BASE_URL}/k/v1/file.json"
|
url = f"{c.BASE_URL}/k/v1/file.json"
|
||||||
r = httpx.get(url,headers=headers,params=params)
|
r = httpx.get(url,headers=headers,params=params)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
@r.post("/upload",)
|
@r.post("/upload")
|
||||||
async def upload(files:t.List[UploadFile] = File(...)):
|
async def upload(files:t.List[UploadFile] = File(...)):
|
||||||
dataframes = []
|
dataframes = []
|
||||||
for file in files:
|
for file in files:
|
||||||
@@ -308,7 +318,7 @@ async def upload(files:t.List[UploadFile] = File(...)):
|
|||||||
return {"files": [file.filename for file in files]}
|
return {"files": [file.filename for file in files]}
|
||||||
|
|
||||||
@r.post("/updatejscss")
|
@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:
|
try:
|
||||||
jscs=[]
|
jscs=[]
|
||||||
for file in files:
|
for file in files:
|
||||||
@@ -318,61 +328,49 @@ async def jscss(app:str,files:t.List[UploadFile] = File(...)):
|
|||||||
fout = open(fpath,'wb')
|
fout = open(fpath,'wb')
|
||||||
fout.write(fbytes)
|
fout.write(fbytes)
|
||||||
fout.close()
|
fout.close()
|
||||||
upload = uploadkintonefiles(fpath)
|
upload = uploadkintonefiles(fpath,env)
|
||||||
if upload.get('fileKey') != None:
|
if upload.get('fileKey') != None:
|
||||||
jscs.append({ file.filename:upload['fileKey']})
|
jscs.append({ file.filename:upload['fileKey']})
|
||||||
appjscs = updateappjscss(app,jscs)
|
appjscs = updateappjscss(app,jscs)
|
||||||
if appjscs.get("revision") != None:
|
if appjscs.get("revision") != None:
|
||||||
deoployappfromkintone(app,appjscs["revision"])
|
deoployappfromkintone(app,appjscs["revision"],env)
|
||||||
return appjscs
|
return appjscs
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=400, detail=f"Error occurred while update file {file.filename}: {str(e)}")
|
raise HTTPException(status_code=400, detail=f"Error occurred while update file {file.filename}: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
@r.get("/allapps",)
|
@r.get("/allapps")
|
||||||
async def allapps():
|
async def allapps(c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
||||||
try:
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
||||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
url = f"{c.BASE_URL}{config.API_V1_STR}/apps.json"
|
||||||
url = f"{c.BASE_URL}{c.API_V1_STR}/apps.json"
|
r = httpx.get(url,headers=headers)
|
||||||
r = httpx.get(url,headers=headers,timeout=httpx.Timeout(10))
|
|
||||||
return r.json()
|
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)
|
|
||||||
return r.json()
|
|
||||||
|
|
||||||
|
|
||||||
@r.get("/appfields")
|
@r.get("/appfields")
|
||||||
async def appfields(app:str):
|
async def appfields(app:str,env = Depends(getkintoneenv)):
|
||||||
return getfieldsfromkintone(app)
|
return getfieldsfromkintone(app,env)
|
||||||
|
|
||||||
@r.get("/appprocess")
|
@r.get("/appprocess")
|
||||||
async def appprocess(app:str):
|
async def appprocess(app:str,env = Depends(getkintoneenv)):
|
||||||
return getprocessfromkintone(app)
|
return getprocessfromkintone(app,env)
|
||||||
|
|
||||||
@r.get("/alljscss")
|
@r.get("/alljscss")
|
||||||
async def alljscs(app:str):
|
async def alljscs(app:str,c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
||||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE}
|
||||||
url = f"{c.BASE_URL}{c.API_V1_STR}/app/customize.json"
|
url = f"{c.BASE_URL}{config.API_V1_STR}/app/customize.json"
|
||||||
params = {"app":app}
|
params = {"app":app}
|
||||||
r = httpx.get(url,headers=headers,params=params)
|
r = httpx.get(url,headers=headers,params=params)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
@r.post("/createapp",)
|
@r.post("/createapp",)
|
||||||
async def createapp(name:str):
|
async def createapp(name:str,c:config.KINTONE_ENV=Depends(getkintoneenv)):
|
||||||
headers={c.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
headers={config.API_V1_AUTH_KEY:c.API_V1_AUTH_VALUE,"Content-Type": "application/json"}
|
||||||
data = {"name":name}
|
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))
|
r = httpx.post(url,headers=headers,data=json.dumps(data))
|
||||||
result = r.json()
|
result = r.json()
|
||||||
if result.get("app") != None:
|
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}
|
data = {"apps":[result],"revert": False}
|
||||||
r = httpx.post(url,headers=headers,data=json.dumps(data))
|
r = httpx.post(url,headers=headers,data=json.dumps(data))
|
||||||
return r.json
|
return r.json
|
||||||
@@ -380,7 +378,7 @@ async def createapp(name:str):
|
|||||||
property=["label","code","type","required","defaultValue","options"]
|
property=["label","code","type","required","defaultValue","options"]
|
||||||
|
|
||||||
@r.post("/createappfromexcel",)
|
@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:
|
for file in files:
|
||||||
if file.filename.endswith('.xlsx'):
|
if file.filename.endswith('.xlsx'):
|
||||||
try:
|
try:
|
||||||
@@ -394,18 +392,18 @@ async def createappfromexcel(files:t.List[UploadFile] = File(...)):
|
|||||||
users = getkintoneusers()
|
users = getkintoneusers()
|
||||||
orgs = getkintoneorgs()
|
orgs = getkintoneorgs()
|
||||||
processes = getprocessfromexcel(df,users["users"], orgs["organizationTitles"])
|
processes = getprocessfromexcel(df,users["users"], orgs["organizationTitles"])
|
||||||
app = createkintoneapp(appname)
|
app = createkintoneapp(appname,env)
|
||||||
if app.get("app") != None:
|
if app.get("app") != None:
|
||||||
result["app"] = app["app"]
|
result["app"] = app["app"]
|
||||||
app = updateappsettingstokintone(result["app"],{"description":desc})
|
app = updateappsettingstokintone(result["app"],{"description":desc},env)
|
||||||
if app.get("revision") != None:
|
if app.get("revision") != None:
|
||||||
result["revision"] = app["revision"]
|
result["revision"] = app["revision"]
|
||||||
app = addfieldstokintone(result["app"],fields)
|
app = addfieldstokintone(result["app"],env,fields)
|
||||||
if len(processes)> 0:
|
if len(processes)> 0:
|
||||||
app = updateprocesstokintone(result["app"],processes)
|
app = updateprocesstokintone(result["app"],processes)
|
||||||
if app.get("revision") != None:
|
if app.get("revision") != None:
|
||||||
result["revision"] = app["revision"]
|
result["revision"] = app["revision"]
|
||||||
deoployappfromkintone(result["app"],result["revision"])
|
deoployappfromkintone(result["app"],result["revision"],env)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=400, detail=f"Error occurred while parsing file {file.filename}: {str(e)}")
|
raise HTTPException(status_code=400, detail=f"Error occurred while parsing file {file.filename}: {str(e)}")
|
||||||
else:
|
else:
|
||||||
@@ -414,42 +412,42 @@ async def createappfromexcel(files:t.List[UploadFile] = File(...)):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@r.post("/updateappfromexcel",)
|
@r.post("/updateappfromexcel")
|
||||||
async def updateappfromexcel(app:str,files:t.List[UploadFile] = File(...)):
|
async def updateappfromexcel(app:str,files:t.List[UploadFile] = File(...),env = Depends(getkintoneenv)):
|
||||||
for file in files:
|
for file in files:
|
||||||
if file.filename.endswith('.xlsx'):
|
if file.filename.endswith('.xlsx'):
|
||||||
try:
|
try:
|
||||||
content = await file.read()
|
content = await file.read()
|
||||||
df = pd.read_excel(BytesIO(content))
|
df = pd.read_excel(BytesIO(content))
|
||||||
excel = getsettingfromexcel(df)
|
excel = getsettingfromexcel(df)
|
||||||
kintone= getsettingfromkintone(app)
|
kintone= getsettingfromkintone(app,env)
|
||||||
settings = analysesettings(excel,kintone)
|
settings = analysesettings(excel,kintone)
|
||||||
excel = getfieldsfromexcel(df)
|
excel = getfieldsfromexcel(df)
|
||||||
kintone = getfieldsfromkintone(app)
|
kintone = getfieldsfromkintone(app,env)
|
||||||
users = getkintoneusers()
|
users = getkintoneusers()
|
||||||
orgs = getkintoneorgs()
|
orgs = getkintoneorgs()
|
||||||
exp = getprocessfromexcel(df,users["users"], orgs["organizationTitles"])
|
exp = getprocessfromexcel(df,users["users"], orgs["organizationTitles"])
|
||||||
#exp = getprocessfromexcel(df)
|
#exp = getprocessfromexcel(df)
|
||||||
kinp = getprocessfromkintone(app)
|
kinp = getprocessfromkintone(app,env)
|
||||||
process = analysprocess(exp,kinp)
|
process = analysprocess(exp,kinp)
|
||||||
revision = kintone["revision"]
|
revision = kintone["revision"]
|
||||||
fields = analysefields(excel,kintone["properties"])
|
fields = analysefields(excel,kintone["properties"])
|
||||||
result = {"app":app,"revision":revision,"msg":"No Update"}
|
result = {"app":app,"revision":revision,"msg":"No Update"}
|
||||||
deploy = False
|
deploy = False
|
||||||
if len(fields["update"]) > 0:
|
if len(fields["update"]) > 0:
|
||||||
result = updatefieldstokintone(app,revision,fields["update"])
|
result = updatefieldstokintone(app,revision,fields["update"],env)
|
||||||
revision = result["revision"]
|
revision = result["revision"]
|
||||||
deploy = True
|
deploy = True
|
||||||
if len(fields["add"]) > 0:
|
if len(fields["add"]) > 0:
|
||||||
result = addfieldstokintone(app,fields["add"],revision)
|
result = addfieldstokintone(app,fields["add"],env,revision)
|
||||||
revision = result["revision"]
|
revision = result["revision"]
|
||||||
deploy = True
|
deploy = True
|
||||||
if len(fields["del"]) > 0:
|
if len(fields["del"]) > 0:
|
||||||
result = deletefieldsfromkintone(app,revision,fields["del"])
|
result = deletefieldsfromkintone(app,revision,fields["del"],env)
|
||||||
revision = result["revision"]
|
revision = result["revision"]
|
||||||
deploy = True
|
deploy = True
|
||||||
if len(settings) > 0:
|
if len(settings) > 0:
|
||||||
result = updateappsettingstokintone(app,settings)
|
result = updateappsettingstokintone(app,settings,env)
|
||||||
revision = result["revision"]
|
revision = result["revision"]
|
||||||
deploy = True
|
deploy = True
|
||||||
if len(process)>0:
|
if len(process)>0:
|
||||||
@@ -457,7 +455,7 @@ async def updateappfromexcel(app:str,files:t.List[UploadFile] = File(...)):
|
|||||||
revision = result["revision"]
|
revision = result["revision"]
|
||||||
deploy = True
|
deploy = True
|
||||||
if deploy:
|
if deploy:
|
||||||
result = deoployappfromkintone(app,revision)
|
result = deoployappfromkintone(app,revision,env)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=400, detail=f"Error occurred while parsing file {file.filename}: {str(e)}")
|
raise HTTPException(status_code=400, detail=f"Error occurred while parsing file {file.filename}: {str(e)}")
|
||||||
else:
|
else:
|
||||||
@@ -466,11 +464,11 @@ async def updateappfromexcel(app:str,files:t.List[UploadFile] = File(...)):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
@r.post("/updateprocessfromexcel",)
|
@r.post("/updateprocessfromexcel",)
|
||||||
async def updateprocessfromexcel(app:str):
|
async def updateprocessfromexcel(app:str,env = Depends(getkintoneenv)):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
excel = getprocessfromexcel()
|
excel = getprocessfromexcel()
|
||||||
kintone = getprocessfromkintone(app)
|
kintone = getprocessfromkintone(app,env)
|
||||||
revision = kintone["revision"]
|
revision = kintone["revision"]
|
||||||
#fields = analysefields(excel,kintone["properties"])
|
#fields = analysefields(excel,kintone["properties"])
|
||||||
result = {"app":app,"revision":revision,"msg":"No Update"}
|
result = {"app":app,"revision":revision,"msg":"No Update"}
|
||||||
@@ -495,7 +493,7 @@ async def updateprocessfromexcel(app:str):
|
|||||||
revision = result["revision"]
|
revision = result["revision"]
|
||||||
deploy = True
|
deploy = True
|
||||||
if deploy:
|
if deploy:
|
||||||
result = deoployappfromkintone(app,revision)
|
result = deoployappfromkintone(app,revision,env)
|
||||||
except Exception as e:
|
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)}")
|
||||||
|
|
||||||
@@ -503,22 +501,20 @@ async def updateprocessfromexcel(app:str):
|
|||||||
|
|
||||||
|
|
||||||
@r.post("/createjstokintone",)
|
@r.post("/createjstokintone",)
|
||||||
async def createjstokintone(app:str):
|
async def createjstokintone(app:str,env = Depends(getkintoneenv)):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
jscs=[]
|
jscs=[]
|
||||||
files=[]
|
files=[]
|
||||||
files.append(createappjs(app))
|
files.append(createappjs(app))
|
||||||
base_dir = os.path.abspath('Temp')
|
files.append('Temp\\alc_runtime.js')
|
||||||
runtimeJs = os.path.join(base_dir, 'alc_runtime.js')
|
|
||||||
files.append(runtimeJs)
|
|
||||||
for file in files:
|
for file in files:
|
||||||
upload = uploadkintonefiles(file)
|
upload = uploadkintonefiles(file,env)
|
||||||
if upload.get('fileKey') != None:
|
if upload.get('fileKey') != None:
|
||||||
jscs.append({ app + '.js':upload['fileKey']})
|
jscs.append({ app + '.js':upload['fileKey']})
|
||||||
appjscs = updateappjscss(app,jscs)
|
appjscs = updateappjscss(app,jscs)
|
||||||
if appjscs.get("revision") != None:
|
if appjscs.get("revision") != None:
|
||||||
deoployappfromkintone(app,appjscs["revision"])
|
deoployappfromkintone(app,appjscs["revision"],env)
|
||||||
return appjscs
|
return appjscs
|
||||||
except Exception as e:
|
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)}")
|
||||||
@@ -4,6 +4,7 @@ from app.db.session import get_db
|
|||||||
from app.db.crud import *
|
from app.db.crud import *
|
||||||
from app.db.schemas import *
|
from app.db.schemas import *
|
||||||
from typing import List
|
from typing import List
|
||||||
|
from app.core.auth import get_current_active_user,get_current_user
|
||||||
|
|
||||||
platform_router = r = APIRouter()
|
platform_router = r = APIRouter()
|
||||||
|
|
||||||
@@ -140,19 +141,18 @@ async def flow_delete(
|
|||||||
return delete_flow(db, flowid)
|
return delete_flow(db, flowid)
|
||||||
|
|
||||||
@r.get(
|
@r.get(
|
||||||
"/domain/{userid}",
|
"/domains/{tenantid}",
|
||||||
response_model=List[Domain],
|
response_model=List[Domain],
|
||||||
response_model_exclude_none=True,
|
response_model_exclude_none=True,
|
||||||
)
|
)
|
||||||
async def domain_details(
|
async def domain_details(
|
||||||
request: Request,
|
request: Request,
|
||||||
userid: str,
|
tenantid:str,
|
||||||
db=Depends(get_db),
|
db=Depends(get_db),
|
||||||
):
|
):
|
||||||
domains = get_domain(db, userid)
|
domains = get_domains(db,tenantid)
|
||||||
return domains
|
return domains
|
||||||
|
|
||||||
|
|
||||||
@r.post("/domain", response_model=Domain, response_model_exclude_none=True)
|
@r.post("/domain", response_model=Domain, response_model_exclude_none=True)
|
||||||
async def domain_create(
|
async def domain_create(
|
||||||
request: Request,
|
request: Request,
|
||||||
@@ -174,13 +174,105 @@ async def domain_edit(
|
|||||||
|
|
||||||
|
|
||||||
@r.delete(
|
@r.delete(
|
||||||
"/domain/{userid}/{id}", response_model=Domain, response_model_exclude_none=True
|
"/domain/{id}", response_model=Domain, response_model_exclude_none=True
|
||||||
)
|
)
|
||||||
async def domain_delete(
|
async def domain_delete(
|
||||||
request: Request,
|
request: Request,
|
||||||
userid: int,
|
|
||||||
id: int,
|
id: int,
|
||||||
db=Depends(get_db),
|
db=Depends(get_db),
|
||||||
):
|
):
|
||||||
|
|
||||||
return delete_domain(db, userid,id)
|
return delete_domain(db,id)
|
||||||
|
|
||||||
|
@r.get(
|
||||||
|
"/domain",
|
||||||
|
response_model=List[Domain],
|
||||||
|
response_model_exclude_none=True,
|
||||||
|
)
|
||||||
|
async def userdomain_details(
|
||||||
|
request: Request,
|
||||||
|
user=Depends(get_current_user),
|
||||||
|
db=Depends(get_db),
|
||||||
|
):
|
||||||
|
domains = get_domain(db, user.id)
|
||||||
|
return domains
|
||||||
|
|
||||||
|
@r.post(
|
||||||
|
"/domain/{userid}",
|
||||||
|
response_model_exclude_none=True,
|
||||||
|
)
|
||||||
|
async def create_userdomain(
|
||||||
|
request: Request,
|
||||||
|
userid: int,
|
||||||
|
domainids:list,
|
||||||
|
db=Depends(get_db),
|
||||||
|
):
|
||||||
|
domain = add_userdomain(db, userid,domainids)
|
||||||
|
return domain
|
||||||
|
|
||||||
|
@r.delete(
|
||||||
|
"/domain/{domainid}/{userid}", response_model_exclude_none=True
|
||||||
|
)
|
||||||
|
async def userdomain_delete(
|
||||||
|
request: Request,
|
||||||
|
domainid:int,
|
||||||
|
userid: int,
|
||||||
|
db=Depends(get_db),
|
||||||
|
):
|
||||||
|
return delete_userdomain(db, userid,domainid)
|
||||||
|
|
||||||
|
|
||||||
|
@r.get(
|
||||||
|
"/activedomain",
|
||||||
|
response_model=Domain,
|
||||||
|
response_model_exclude_none=True,
|
||||||
|
)
|
||||||
|
async def get_useractivedomain(
|
||||||
|
request: Request,
|
||||||
|
user=Depends(get_current_user),
|
||||||
|
db=Depends(get_db),
|
||||||
|
):
|
||||||
|
domain = get_activedomain(db, user.id)
|
||||||
|
return domain
|
||||||
|
|
||||||
|
@r.put(
|
||||||
|
"/activedomain/{domainid}",
|
||||||
|
response_model_exclude_none=True,
|
||||||
|
)
|
||||||
|
async def update_activeuserdomain(
|
||||||
|
request: Request,
|
||||||
|
domainid:int,
|
||||||
|
user=Depends(get_current_user),
|
||||||
|
db=Depends(get_db),
|
||||||
|
):
|
||||||
|
domain = active_userdomain(db, user.id,domainid)
|
||||||
|
return domain
|
||||||
|
|
||||||
|
|
||||||
|
@r.get(
|
||||||
|
"/events",
|
||||||
|
response_model=t.List[Event],
|
||||||
|
response_model_exclude={"id"},
|
||||||
|
response_model_exclude_none=True,
|
||||||
|
)
|
||||||
|
async def event_data(
|
||||||
|
request: Request,
|
||||||
|
db=Depends(get_db),
|
||||||
|
):
|
||||||
|
events = get_events(db)
|
||||||
|
return events
|
||||||
|
|
||||||
|
|
||||||
|
@r.get(
|
||||||
|
"/eventactions/{eventid}",
|
||||||
|
response_model=t.List[Action],
|
||||||
|
response_model_exclude={"id"},
|
||||||
|
response_model_exclude_none=True,
|
||||||
|
)
|
||||||
|
async def eventactions_data(
|
||||||
|
request: Request,
|
||||||
|
eventid: str,
|
||||||
|
db=Depends(get_db),
|
||||||
|
):
|
||||||
|
actions = get_eventactions(db,eventid)
|
||||||
|
return actions
|
||||||
@@ -3,7 +3,7 @@ from fastapi import Depends, HTTPException, status
|
|||||||
from jwt import PyJWTError
|
from jwt import PyJWTError
|
||||||
|
|
||||||
from app.db import models, schemas, session
|
from app.db import models, schemas, session
|
||||||
from app.db.crud import get_user_by_email, create_user
|
from app.db.crud import get_user_by_email, create_user,get_user
|
||||||
from app.core import security
|
from app.core import security
|
||||||
|
|
||||||
|
|
||||||
@@ -19,14 +19,14 @@ async def get_current_user(
|
|||||||
payload = jwt.decode(
|
payload = jwt.decode(
|
||||||
token, security.SECRET_KEY, algorithms=[security.ALGORITHM]
|
token, security.SECRET_KEY, algorithms=[security.ALGORITHM]
|
||||||
)
|
)
|
||||||
email: str = payload.get("sub")
|
id: int = payload.get("sub")
|
||||||
if email is None:
|
if id is None:
|
||||||
raise credentials_exception
|
raise credentials_exception
|
||||||
permissions: str = payload.get("permissions")
|
permissions: str = payload.get("permissions")
|
||||||
token_data = schemas.TokenData(email=email, permissions=permissions)
|
token_data = schemas.TokenData(id = id, permissions=permissions)
|
||||||
except PyJWTError:
|
except PyJWTError:
|
||||||
raise credentials_exception
|
raise credentials_exception
|
||||||
user = get_user_by_email(db, token_data.email)
|
user = get_user(db, token_data.id)
|
||||||
if user is None:
|
if user is None:
|
||||||
raise credentials_exception
|
raise credentials_exception
|
||||||
return user
|
return user
|
||||||
@@ -58,7 +58,7 @@ def authenticate_user(db, email: str, password: str):
|
|||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
def sign_up_new_user(db, email: str, password: str):
|
def sign_up_new_user(db, email: str, password: str, firstname: str,lastname: str):
|
||||||
user = get_user_by_email(db, email)
|
user = get_user_by_email(db, email)
|
||||||
if user:
|
if user:
|
||||||
return False # User already exists
|
return False # User already exists
|
||||||
@@ -67,6 +67,8 @@ def sign_up_new_user(db, email: str, password: str):
|
|||||||
schemas.UserCreate(
|
schemas.UserCreate(
|
||||||
email=email,
|
email=email,
|
||||||
password=password,
|
password=password,
|
||||||
|
firstname = firstname,
|
||||||
|
lastname = lastname,
|
||||||
is_active=True,
|
is_active=True,
|
||||||
is_superuser=False,
|
is_superuser=False,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,18 +1,26 @@
|
|||||||
import os
|
import os
|
||||||
|
import base64
|
||||||
|
|
||||||
PROJECT_NAME = "KintoneAppBuilder"
|
PROJECT_NAME = "KintoneAppBuilder"
|
||||||
|
|
||||||
SQLALCHEMY_DATABASE_URI = "postgres://maxz64:m@xz1205@alicornkintone.postgres.database.azure.com/postgres"
|
SQLALCHEMY_DATABASE_URI = "postgres://maxz64:m@xz1205@alicornkintone.postgres.database.azure.com/postgres"
|
||||||
|
#SQLALCHEMY_DATABASE_URI = "postgres://kabAdmin:P@ssw0rd!@kintonetooldb.postgres.database.azure.com/postgres"
|
||||||
BASE_URL = "https://mfu07rkgnb7c.cybozu.com"
|
|
||||||
|
|
||||||
API_V1_STR = "/k/v1"
|
API_V1_STR = "/k/v1"
|
||||||
|
|
||||||
API_V1_AUTH_KEY = "X-Cybozu-Authorization"
|
API_V1_AUTH_KEY = "X-Cybozu-Authorization"
|
||||||
|
|
||||||
API_V1_AUTH_VALUE = "TVhaOm1heHoxMjA1"
|
|
||||||
|
|
||||||
KINTONE_USER = "MXZ"
|
|
||||||
|
|
||||||
KINTONE_FIELD_TYPE=["GROUP","GROUP_SELECT","CHECK_BOX","SUBTABLE","DROP_DOWN","USER_SELECT","RADIO_BUTTON","RICH_TEXT","LINK","REFERENCE_TABLE","CALC","TIME","NUMBER","ORGANIZATION_SELECT","FILE","DATETIME","DATE","MULTI_SELECT","SINGLE_LINE_TEXT","MULTI_LINE_TEXT"]
|
KINTONE_FIELD_TYPE=["GROUP","GROUP_SELECT","CHECK_BOX","SUBTABLE","DROP_DOWN","USER_SELECT","RADIO_BUTTON","RICH_TEXT","LINK","REFERENCE_TABLE","CALC","TIME","NUMBER","ORGANIZATION_SELECT","FILE","DATETIME","DATE","MULTI_SELECT","SINGLE_LINE_TEXT","MULTI_LINE_TEXT"]
|
||||||
|
|
||||||
|
class KINTONE_ENV:
|
||||||
|
|
||||||
|
BASE_URL = ""
|
||||||
|
|
||||||
|
API_V1_AUTH_VALUE = ""
|
||||||
|
|
||||||
|
KINTONE_USER = ""
|
||||||
|
|
||||||
|
def __init__(self,domain) -> None:
|
||||||
|
self.BASE_URL = domain.url
|
||||||
|
self.KINTONE_USER = domain.kintoneuser
|
||||||
|
self.API_V1_AUTH_VALUE = base64.b64encode(bytes(f"{domain.kintoneuser}:{domain.kintonepwd}","utf-8"))
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
from fastapi import HTTPException, status
|
from fastapi import HTTPException, status
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
from sqlalchemy import and_
|
||||||
import typing as t
|
import typing as t
|
||||||
|
|
||||||
from . import models, schemas
|
from . import models, schemas
|
||||||
@@ -182,8 +183,8 @@ def get_flows_by_app(db: Session, appid: str):
|
|||||||
return flows
|
return flows
|
||||||
|
|
||||||
def create_domain(db: Session, domain: schemas.DomainBase):
|
def create_domain(db: Session, domain: schemas.DomainBase):
|
||||||
db_domain = models.UserDomain(
|
db_domain = models.Domain(
|
||||||
userid=domain.userid,
|
tenantid = domain.tenantid,
|
||||||
name=domain.name,
|
name=domain.name,
|
||||||
url=domain.url,
|
url=domain.url,
|
||||||
kintoneuser=domain.kintoneuser,
|
kintoneuser=domain.kintoneuser,
|
||||||
@@ -194,9 +195,9 @@ def create_domain(db: Session, domain: schemas.DomainBase):
|
|||||||
db.refresh(db_domain)
|
db.refresh(db_domain)
|
||||||
return db_domain
|
return db_domain
|
||||||
|
|
||||||
def delete_domain(db: Session, userid: int,id: int):
|
def delete_domain(db: Session,id: int):
|
||||||
db_domain = db.query(models.UserDomain).get(id)
|
db_domain = db.query(models.Domain).get(id)
|
||||||
if not db_domain or db_domain.userid != userid:
|
if not db_domain:
|
||||||
raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Domain not found")
|
raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Domain not found")
|
||||||
db.delete(db_domain)
|
db.delete(db_domain)
|
||||||
db.commit()
|
db.commit()
|
||||||
@@ -206,8 +207,8 @@ def delete_domain(db: Session, userid: int,id: int):
|
|||||||
def edit_domain(
|
def edit_domain(
|
||||||
db: Session, domain: schemas.DomainBase
|
db: Session, domain: schemas.DomainBase
|
||||||
) -> schemas.Domain:
|
) -> schemas.Domain:
|
||||||
db_domain = db.query(models.UserDomain).get(domain.id)
|
db_domain = db.query(models.Domain).get(domain.id)
|
||||||
if not db_domain or db_domain.userid != domain.userid:
|
if not db_domain:
|
||||||
raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Domain not found")
|
raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Domain not found")
|
||||||
update_data = domain.dict(exclude_unset=True)
|
update_data = domain.dict(exclude_unset=True)
|
||||||
|
|
||||||
@@ -220,8 +221,64 @@ def edit_domain(
|
|||||||
db.refresh(db_domain)
|
db.refresh(db_domain)
|
||||||
return db_domain
|
return db_domain
|
||||||
|
|
||||||
|
def add_userdomain(db: Session, userid:int,domainids:list):
|
||||||
|
for domainid in domainids:
|
||||||
|
db_domain = models.UserDomain(
|
||||||
|
userid = userid,
|
||||||
|
domainid = domainid
|
||||||
|
)
|
||||||
|
db.add(db_domain)
|
||||||
|
db.commit()
|
||||||
|
db.refresh(db_domain)
|
||||||
|
return db_domain
|
||||||
|
|
||||||
|
def delete_userdomain(db: Session, userid: int,domainid: int):
|
||||||
|
db_domain = db.query(models.UserDomain).filter(and_(models.UserDomain.userid == userid,models.UserDomain.domainid == domainid)).first()
|
||||||
|
if not db_domain:
|
||||||
|
raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Domain not found")
|
||||||
|
db.delete(db_domain)
|
||||||
|
db.commit()
|
||||||
|
return db_domain
|
||||||
|
|
||||||
|
def active_userdomain(db: Session, userid: int,domainid: int):
|
||||||
|
db_userdomains = db.query(models.UserDomain).filter(models.UserDomain.userid == userid).all()
|
||||||
|
if not db_userdomains:
|
||||||
|
raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Domain not found")
|
||||||
|
for domain in db_userdomains:
|
||||||
|
if domain.domainid == domainid:
|
||||||
|
domain.active = True
|
||||||
|
else:
|
||||||
|
domain.active = False
|
||||||
|
db.add(domain)
|
||||||
|
db.commit()
|
||||||
|
return db_userdomains
|
||||||
|
|
||||||
|
def get_activedomain(db: Session, userid: int):
|
||||||
|
db_domain = db.query(models.Domain).join(models.UserDomain,models.UserDomain.domainid == models.Domain.id ).filter(and_(models.UserDomain.userid == userid,models.UserDomain.active == True)).first()
|
||||||
|
if not db_domain:
|
||||||
|
raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Domain not found")
|
||||||
|
return db_domain
|
||||||
|
|
||||||
def get_domain(db: Session, userid: str):
|
def get_domain(db: Session, userid: str):
|
||||||
domains = db.query(models.UserDomain).filter(models.UserDomain.userid == userid).all()
|
domains = db.query(models.Domain).join(models.UserDomain,models.UserDomain.domainid == models.Domain.id ).filter(models.UserDomain.userid == userid).all()
|
||||||
if not domains:
|
if not domains:
|
||||||
raise HTTPException(status_code=404, detail="Data not found")
|
raise HTTPException(status_code=404, detail="Data not found")
|
||||||
return domains
|
return domains
|
||||||
|
|
||||||
|
def get_domains(db: Session,tenantid:str):
|
||||||
|
domains = db.query(models.Domain).filter(models.Domain.tenantid == tenantid ).all()
|
||||||
|
if not domains:
|
||||||
|
raise HTTPException(status_code=404, detail="Data not found")
|
||||||
|
return domains
|
||||||
|
|
||||||
|
def get_events(db: Session):
|
||||||
|
events = db.query(models.Event).all()
|
||||||
|
if not events:
|
||||||
|
raise HTTPException(status_code=404, detail="Data not found")
|
||||||
|
return events
|
||||||
|
|
||||||
|
def get_eventactions(db: Session,eventid: str):
|
||||||
|
eveactions = db.query(models.Action).join(models.EventAction,models.EventAction.actionid == models.Action.id ).join(models.Event,models.Event.id == models.EventAction.eventid).filter(models.Event.eventid == eventid).all()
|
||||||
|
if not eveactions:
|
||||||
|
raise HTTPException(status_code=404, detail="Data not found")
|
||||||
|
return eveactions
|
||||||
@@ -50,12 +50,43 @@ class Flow(Base):
|
|||||||
name = Column(String(200))
|
name = Column(String(200))
|
||||||
content = Column(String)
|
content = Column(String)
|
||||||
|
|
||||||
class UserDomain(Base):
|
class Tenant(Base):
|
||||||
__tablename__ = "userdomain"
|
__tablename__ = "tenant"
|
||||||
|
|
||||||
userid = Column(Integer,ForeignKey("user.id"))
|
tenantid = Column(String(100), index=True, nullable=False)
|
||||||
|
name = Column(String(200))
|
||||||
|
licence = Column(String(200))
|
||||||
|
startdate = Column(DateTime)
|
||||||
|
enddate = Column(DateTime)
|
||||||
|
|
||||||
|
class Domain(Base):
|
||||||
|
__tablename__ = "domain"
|
||||||
|
|
||||||
|
tenantid = Column(String(100), index=True, nullable=False)
|
||||||
name = Column(String(100), nullable=False)
|
name = Column(String(100), nullable=False)
|
||||||
url = Column(String(200), nullable=False)
|
url = Column(String(200), nullable=False)
|
||||||
kintoneuser = Column(String(100), nullable=False)
|
kintoneuser = Column(String(100), nullable=False)
|
||||||
kintonepwd = Column(String(100), nullable=False)
|
kintonepwd = Column(String(100), nullable=False)
|
||||||
|
|
||||||
|
|
||||||
|
class UserDomain(Base):
|
||||||
|
__tablename__ = "userdomain"
|
||||||
|
|
||||||
|
userid = Column(Integer,ForeignKey("user.id"))
|
||||||
|
domainid = Column(Integer,ForeignKey("domain.id"))
|
||||||
active = Column(Boolean, default=False)
|
active = Column(Boolean, default=False)
|
||||||
|
|
||||||
|
class Event(Base):
|
||||||
|
__tablename__ = "event"
|
||||||
|
|
||||||
|
category = Column(String(100), nullable=False)
|
||||||
|
type = Column(String(100), nullable=False)
|
||||||
|
eventid= Column(String(100), nullable=False)
|
||||||
|
function = Column(String(500), nullable=False)
|
||||||
|
mobile = Column(Boolean, default=False)
|
||||||
|
|
||||||
|
class EventAction(Base):
|
||||||
|
__tablename__ = "eventaction"
|
||||||
|
|
||||||
|
eventid = Column(Integer,ForeignKey("event.id"))
|
||||||
|
actionid = Column(Integer,ForeignKey("action.id"))
|
||||||
@@ -21,6 +21,8 @@ class UserOut(UserBase):
|
|||||||
|
|
||||||
class UserCreate(UserBase):
|
class UserCreate(UserBase):
|
||||||
password: str
|
password: str
|
||||||
|
first_name: str
|
||||||
|
last_name: str
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
@@ -46,6 +48,7 @@ class Token(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class TokenData(BaseModel):
|
class TokenData(BaseModel):
|
||||||
|
id:int = 0
|
||||||
email: str = None
|
email: str = None
|
||||||
permissions: str = "user"
|
permissions: str = "user"
|
||||||
|
|
||||||
@@ -106,21 +109,30 @@ class Flow(Base):
|
|||||||
|
|
||||||
class DomainBase(BaseModel):
|
class DomainBase(BaseModel):
|
||||||
id: int
|
id: int
|
||||||
userid: int
|
tenantid: str
|
||||||
name: str
|
name: str
|
||||||
url: str
|
url: str
|
||||||
kintoneuser: str
|
kintoneuser: str
|
||||||
kintonepwd: str
|
kintonepwd: str
|
||||||
active:bool = False
|
|
||||||
|
|
||||||
class Domain(Base):
|
class Domain(Base):
|
||||||
id: int
|
id: int
|
||||||
userid: str
|
tenantid: str
|
||||||
name: str
|
name: str
|
||||||
url: str
|
url: str
|
||||||
kintoneuser: str
|
kintoneuser: str
|
||||||
kintonepwd: str
|
kintonepwd: str
|
||||||
active:bool
|
|
||||||
|
class Config:
|
||||||
|
orm_mode = True
|
||||||
|
|
||||||
|
class Event(Base):
|
||||||
|
id: int
|
||||||
|
category: str
|
||||||
|
type: str
|
||||||
|
eventid: str
|
||||||
|
function: str
|
||||||
|
mobile: bool
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
42
frontend/src/components/DomainSelect.vue
Normal file
42
frontend/src/components/DomainSelect.vue
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<template>
|
||||||
|
<div class="q-pa-md">
|
||||||
|
<q-table :title="name+'一覧'" :selection="type" v-model:selected="selected" :columns="columns" :rows="rows" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
import { ref,onMounted,reactive } from 'vue'
|
||||||
|
import { api } from 'boot/axios';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'DomainSelect',
|
||||||
|
props: {
|
||||||
|
name: String,
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
setup() {
|
||||||
|
const columns = [
|
||||||
|
{ name: 'id'},
|
||||||
|
{ name: 'tenantid', required: true,label: 'テナント',align: 'left',field: 'tenantid',sortable: true},
|
||||||
|
{ name: 'name', align: 'center', label: 'ドメイン', field: 'name', sortable: true },
|
||||||
|
{ name: 'url', label: 'URL', field: 'url', sortable: true },
|
||||||
|
{ name: 'kintoneuser', label: 'アカウント', field: 'kintoneuser' }
|
||||||
|
]
|
||||||
|
const rows = reactive([])
|
||||||
|
onMounted( () => {
|
||||||
|
api.get(`http://127.0.0.1:8000/api/domains/testtenant`).then(res =>{
|
||||||
|
res.data.forEach((item) =>
|
||||||
|
{
|
||||||
|
rows.push({id:item.id,tenantid:item.tenantid,name:item.name,url:item.url,kintoneuser:item.kintoneuser});
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
columns,
|
||||||
|
rows,
|
||||||
|
selected: ref([]),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
no-caps
|
no-caps
|
||||||
icon="share"
|
icon="share"
|
||||||
size="md"
|
size="md"
|
||||||
:label="`${userStore.currentDomain.domainName}.cybozu.com`"
|
:label="userStore.currentDomain.domainName"
|
||||||
>
|
>
|
||||||
<q-list>
|
<q-list>
|
||||||
<q-item v-for="domain in domains" :key="domain.domainName"
|
<q-item v-for="domain in domains" :key="domain.domainName"
|
||||||
@@ -15,7 +15,8 @@
|
|||||||
<q-icon name="share" size="sm" color="orange" text-color="white"></q-icon>
|
<q-icon name="share" size="sm" color="orange" text-color="white"></q-icon>
|
||||||
</q-item-section>
|
</q-item-section>
|
||||||
<q-item-section>
|
<q-item-section>
|
||||||
<q-item-label>{{ `${domain.domainName}.cybozu.com` }}</q-item-label>
|
<q-item-label>{{domain.domainName}}</q-item-label>
|
||||||
|
<q-item-label caption>{{domain.kintoneUrl}}</q-item-label>
|
||||||
</q-item-section>
|
</q-item-section>
|
||||||
</q-item>
|
</q-item>
|
||||||
</q-list>
|
</q-list>
|
||||||
|
|||||||
225
frontend/src/pages/TenantDomain.vue
Normal file
225
frontend/src/pages/TenantDomain.vue
Normal file
@@ -0,0 +1,225 @@
|
|||||||
|
<template>
|
||||||
|
<div class="q-pa-md">
|
||||||
|
<q-table
|
||||||
|
title="Treats"
|
||||||
|
:rows="rows"
|
||||||
|
:columns="columns"
|
||||||
|
row-key="id"
|
||||||
|
selection="single"
|
||||||
|
:filter="filter"
|
||||||
|
:loading="loading"
|
||||||
|
v-model:selected="selected"
|
||||||
|
>
|
||||||
|
|
||||||
|
<template v-slot:top>
|
||||||
|
<q-btn color="primary" :disable="loading" label="新規" @click="addRow" />
|
||||||
|
<q-btn class="q-ml-sm" color="primary" :disable="loading" label="編集" @click="editRow" />
|
||||||
|
<q-btn class="q-ml-sm" color="primary" :disable="loading" label="削除" @click="removeRow" />
|
||||||
|
<q-space />
|
||||||
|
<q-input borderless dense debounce="300" color="primary" v-model="filter">
|
||||||
|
<template v-slot:append>
|
||||||
|
<q-icon name="search" />
|
||||||
|
</template>
|
||||||
|
</q-input>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
</q-table>
|
||||||
|
|
||||||
|
<q-dialog :model-value="show" persistent>
|
||||||
|
<q-card style="min-width: 400px">
|
||||||
|
<q-card-section>
|
||||||
|
<div class="text-h6">Kintone Account</div>
|
||||||
|
</q-card-section>
|
||||||
|
|
||||||
|
<q-card-section class="q-pt-none">
|
||||||
|
<q-form class="q-gutter-md">
|
||||||
|
<q-input filled v-model="tenantid" label="Tenant" hint="Tenant ID" lazy-rules
|
||||||
|
:rules="[val => val && val.length > 0 || 'Please type something']" />
|
||||||
|
|
||||||
|
<q-input filled v-model="name" label="Your name *" hint="Kintone envirment name" lazy-rules
|
||||||
|
:rules="[val => val && val.length > 0 || 'Please type something']" />
|
||||||
|
|
||||||
|
<q-input filled type="url" v-model="url" label="Kintone url" hint="Kintone domain address" lazy-rules
|
||||||
|
:rules="[val => val && val.length > 0, isDomain || 'Please type something']" />
|
||||||
|
|
||||||
|
<q-input filled v-model="kintoneuser" label="Login user " hint="Kintone user name" lazy-rules
|
||||||
|
:rules="[val => val && val.length > 0 || 'Please type something']" />
|
||||||
|
|
||||||
|
<q-input v-model="kintonepwd" filled :type="isPwd ? 'password' : 'text'" hint="Password with toggle"
|
||||||
|
label="User password">
|
||||||
|
<template v-slot:append>
|
||||||
|
<q-icon :name="isPwd ? 'visibility_off' : 'visibility'" class="cursor-pointer" @click="isPwd = !isPwd" />
|
||||||
|
</template>
|
||||||
|
</q-input>
|
||||||
|
</q-form>
|
||||||
|
</q-card-section>
|
||||||
|
<q-card-actions align="right" class="text-primary">
|
||||||
|
<q-btn label="Save" type="submit" color="primary" @click="onSubmit"/>
|
||||||
|
<q-btn label="Cancel" type="cancel" color="primary" flat class="q-ml-sm" @click="closeDg()"/>
|
||||||
|
</q-card-actions>
|
||||||
|
</q-card>
|
||||||
|
|
||||||
|
</q-dialog>
|
||||||
|
|
||||||
|
<q-dialog v-model="confirm" persistent>
|
||||||
|
<q-card>
|
||||||
|
<q-card-section class="row items-center">
|
||||||
|
<q-avatar icon="confirm" color="primary" text-color="white" />
|
||||||
|
<span class="q-ml-sm">削除してもよろしいですか?</span>
|
||||||
|
</q-card-section>
|
||||||
|
|
||||||
|
<q-card-actions align="right">
|
||||||
|
<q-btn flat label="Cancel" color="primary" v-close-popup />
|
||||||
|
<q-btn flat label="OK" color="primary" v-close-popup @click = "deleteDomain()"/>
|
||||||
|
</q-card-actions>
|
||||||
|
</q-card>
|
||||||
|
</q-dialog>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref,onMounted, reactive} from 'vue';
|
||||||
|
import { useQuasar } from 'quasar'
|
||||||
|
import { api } from 'boot/axios';
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{ name: 'id'},
|
||||||
|
{
|
||||||
|
name: 'tenantid',
|
||||||
|
required: true,
|
||||||
|
label: 'Tenant',
|
||||||
|
align: 'left',
|
||||||
|
field: row => row.tenantid,
|
||||||
|
format: val => `${val}`,
|
||||||
|
sortable: true
|
||||||
|
},
|
||||||
|
{ name: 'name', align: 'center', label: 'Name', field: 'name', sortable: true },
|
||||||
|
{ name: 'url', align: 'left',label: 'URL', field: 'url', sortable: true },
|
||||||
|
{ name: 'user', label: 'Account', field: 'user' },
|
||||||
|
{ name: 'password', label: 'Password', field: 'password' }
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
const loading = ref(false)
|
||||||
|
const filter = ref('')
|
||||||
|
const rows = reactive([])
|
||||||
|
const show = ref(false);
|
||||||
|
const confirm = ref(false);
|
||||||
|
const selected = ref([])
|
||||||
|
const tenantid = ref('')
|
||||||
|
const name = ref('')
|
||||||
|
const url =ref('')
|
||||||
|
const isPwd =ref(true)
|
||||||
|
const kintoneuser =ref('')
|
||||||
|
const kintonepwd =ref('')
|
||||||
|
|
||||||
|
const $q = useQuasar()
|
||||||
|
|
||||||
|
let editId = ref(0);
|
||||||
|
|
||||||
|
const getDomain = () => {
|
||||||
|
loading.value = true;
|
||||||
|
api.get(`http://127.0.0.1:8000/api/domains/testtenant`).then(res => {
|
||||||
|
rows.length = 0;
|
||||||
|
res.data.forEach((item) => {
|
||||||
|
rows.push({ id:item.id,tenantid: item.tenantid,name: item.name, url: item.url, user: item.kintoneuser, password: item.kintonepwd });
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}).finally(()=>{ loading.value = false; });
|
||||||
|
|
||||||
|
}
|
||||||
|
onMounted(() => {
|
||||||
|
getDomain();
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// emulate fetching data from server
|
||||||
|
const addRow = () => {
|
||||||
|
editId.value
|
||||||
|
show.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeRow = () => {
|
||||||
|
//loading.value = true
|
||||||
|
confirm.value = true;
|
||||||
|
let row = JSON.parse(JSON.stringify(selected.value[0]));
|
||||||
|
if(selected.value.length === 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
editId.value = row.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteDomain = () => {
|
||||||
|
api.delete(`http://127.0.0.1:8000/api/domain/`+ editId.value).then(() =>{
|
||||||
|
getDomain();
|
||||||
|
})
|
||||||
|
editId.value = 0;
|
||||||
|
selected.value=[];
|
||||||
|
};
|
||||||
|
|
||||||
|
const editRow = () => {
|
||||||
|
if(selected.value.length === 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let row = JSON.parse(JSON.stringify(selected.value[0]));
|
||||||
|
editId.value = row.id;
|
||||||
|
tenantid.value = row.tenantid;
|
||||||
|
name.value = row.name;
|
||||||
|
url.value = row.url;
|
||||||
|
kintoneuser.value = row.user;
|
||||||
|
kintonepwd.value = row.password;
|
||||||
|
isPwd.value = true;
|
||||||
|
show.value = true;
|
||||||
|
};
|
||||||
|
const closeDg = () => {
|
||||||
|
show.value = false;
|
||||||
|
onReset();
|
||||||
|
}
|
||||||
|
|
||||||
|
const onSubmit = () => {
|
||||||
|
if(editId.value !== 0)
|
||||||
|
{
|
||||||
|
api.put(`http://127.0.0.1:8000/api/domain`,{
|
||||||
|
'id': editId.value,
|
||||||
|
'tenantid': tenantid.value,
|
||||||
|
'name': name.value,
|
||||||
|
'url': url.value,
|
||||||
|
'kintoneuser': kintoneuser.value,
|
||||||
|
'kintonepwd': kintonepwd.value
|
||||||
|
}).then(() =>{
|
||||||
|
getDomain();
|
||||||
|
closeDg();
|
||||||
|
onReset();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
api.post(`http://127.0.0.1:8000/api/domain`,{
|
||||||
|
'id': 0,
|
||||||
|
'tenantid': tenantid.value,
|
||||||
|
'name': name.value,
|
||||||
|
'url': url.value,
|
||||||
|
'kintoneuser': kintoneuser.value,
|
||||||
|
'kintonepwd': kintonepwd.value
|
||||||
|
}).then(() =>{
|
||||||
|
getDomain();
|
||||||
|
closeDg();
|
||||||
|
onReset();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
selected.value=[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const onReset = () => {
|
||||||
|
name.value = '';
|
||||||
|
url.value = '';
|
||||||
|
kintoneuser.value = '';
|
||||||
|
kintonepwd.value ='';
|
||||||
|
isPwd.value = true;
|
||||||
|
editId.value = 0;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -111,7 +111,7 @@ export default {
|
|||||||
<q-table grid grid-header title="Domain" selection="single" :rows="rows" :columns="columns" v-model:selected="selected" row-key="name" :filter="filter" hide-header>
|
<q-table grid grid-header title="Domain" selection="single" :rows="rows" :columns="columns" v-model:selected="selected" row-key="name" :filter="filter" hide-header>
|
||||||
<template v-slot:top>
|
<template v-slot:top>
|
||||||
<div class="q-pa-md q-gutter-sm">
|
<div class="q-pa-md q-gutter-sm">
|
||||||
<q-btn color="primary" size="sm" label=" 新規 " @click="newDomain()" dense />
|
<q-btn color="primary" label="追加" @click="newDomain()" dense />
|
||||||
</div>
|
</div>
|
||||||
<q-space />
|
<q-space />
|
||||||
<q-input borderless dense debounce="300" v-model="filter" placeholder="Search">
|
<q-input borderless dense debounce="300" v-model="filter" placeholder="Search">
|
||||||
@@ -125,21 +125,24 @@ export default {
|
|||||||
<q-card>
|
<q-card>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<div class="q-table__grid-item-row">
|
<div class="q-table__grid-item-row">
|
||||||
<div class="q-table__grid-item-title">Name</div>
|
<div class="q-table__grid-item-title">Domain</div>
|
||||||
<div class="q-table__grid-item-value">{{ props.row.name }}</div>
|
<div class="q-table__grid-item-value">{{ props.row.name }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="q-table__grid-item-row">
|
<div class="q-table__grid-item-row">
|
||||||
<div class="q-table__grid-item-title">Domain</div>
|
<div class="q-table__grid-item-title">URL</div>
|
||||||
<div class="q-table__grid-item-value">{{ props.row.url }}</div>
|
<div class="q-table__grid-item-value">{{ props.row.url }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="q-table__grid-item-row">
|
<div class="q-table__grid-item-row">
|
||||||
<div class="q-table__grid-item-title">Account</div>
|
<div class="q-table__grid-item-title">Account</div>
|
||||||
<div class="q-table__grid-item-value">{{ props.row.kintoneuser }}</div>
|
<div class="q-table__grid-item-value">{{ props.row.kintoneuser }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="q-table__grid-item-row">
|
||||||
|
<div class="q-table__grid-item-value">{{isActive(props.row.id) }}</div>
|
||||||
|
</div>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-separator />
|
<q-separator />
|
||||||
<q-card-actions align="right">
|
<q-card-actions align="right">
|
||||||
<q-btn flat @click = "editDomain(props.row)">編集</q-btn>
|
<q-btn flat @click = "activeDomain(props.row.id)">有効</q-btn>
|
||||||
<q-btn flat @click = "deleteConfirm(props.row)">削除</q-btn>
|
<q-btn flat @click = "deleteConfirm(props.row)">削除</q-btn>
|
||||||
</q-card-actions>
|
</q-card-actions>
|
||||||
</q-card>
|
</q-card>
|
||||||
@@ -147,40 +150,9 @@ export default {
|
|||||||
</template>
|
</template>
|
||||||
</q-table>
|
</q-table>
|
||||||
|
|
||||||
<q-dialog :model-value="show" persistent>
|
<show-dialog v-model:visible="show" name="ドメイン" @close="closeDg">
|
||||||
<q-card style="min-width: 400px">
|
<domain-select ref="domainDg" name="ドメイン" type="multiple"></domain-select>
|
||||||
<q-card-section>
|
</show-dialog>
|
||||||
<div class="text-h6">Kintone Account</div>
|
|
||||||
</q-card-section>
|
|
||||||
|
|
||||||
<q-card-section class="q-pt-none">
|
|
||||||
<q-form class="q-gutter-md">
|
|
||||||
<q-input filled v-model="name" label="Your name *" hint="Kintone envirment name" lazy-rules
|
|
||||||
:rules="[val => val && val.length > 0 || 'Please type something']" />
|
|
||||||
|
|
||||||
<q-input filled type="url" v-model="url" label="Kintone url" hint="Kintone domain address" lazy-rules
|
|
||||||
:rules="[val => val && val.length > 0, isDomain || 'Please type something']" />
|
|
||||||
|
|
||||||
<q-input filled v-model="kintoneuser" label="Login user " hint="Kintone user name" lazy-rules
|
|
||||||
:rules="[val => val && val.length > 0 || 'Please type something']" />
|
|
||||||
|
|
||||||
<q-input v-model="kintonepwd" filled :type="isPwd ? 'password' : 'text'" hint="Password with toggle"
|
|
||||||
label="User password">
|
|
||||||
<template v-slot:append>
|
|
||||||
<q-icon :name="isPwd ? 'visibility_off' : 'visibility'" class="cursor-pointer" @click="isPwd = !isPwd" />
|
|
||||||
</template>
|
|
||||||
</q-input>
|
|
||||||
|
|
||||||
<q-toggle v-model="active" label="Active Domain" />
|
|
||||||
</q-form>
|
|
||||||
</q-card-section>
|
|
||||||
<q-card-actions align="right" class="text-primary">
|
|
||||||
<q-btn label="Save" type="submit" color="primary" @click="onSubmit"/>
|
|
||||||
<q-btn label="Cancel" type="cancel" color="primary" flat class="q-ml-sm" @click="closeDg()"/>
|
|
||||||
</q-card-actions>
|
|
||||||
</q-card>
|
|
||||||
|
|
||||||
</q-dialog>
|
|
||||||
|
|
||||||
<q-dialog v-model="confirm" persistent>
|
<q-dialog v-model="confirm" persistent>
|
||||||
<q-card>
|
<q-card>
|
||||||
@@ -201,23 +173,23 @@ export default {
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useQuasar } from 'quasar'
|
import { useQuasar } from 'quasar'
|
||||||
import { ref, onMounted, reactive } from 'vue'
|
import { ref, onMounted, reactive } from 'vue'
|
||||||
import { api } from 'boot/axios';
|
import ShowDialog from 'components/ShowDialog.vue';
|
||||||
|
import DomainSelect from 'components/DomainSelect.vue';
|
||||||
|
import { useAuthStore } from 'stores/useAuthStore';
|
||||||
|
|
||||||
|
const authStore = useAuthStore();
|
||||||
|
import { api } from 'boot/axios';
|
||||||
|
|
||||||
const $q = useQuasar()
|
const $q = useQuasar()
|
||||||
|
|
||||||
|
const domainDg = ref();
|
||||||
const selected = ref([])
|
const selected = ref([])
|
||||||
const name = ref('')
|
|
||||||
const active = ref(false)
|
|
||||||
const isPwd =ref(true)
|
|
||||||
const url =ref('')
|
|
||||||
const kintoneuser =ref('')
|
|
||||||
const kintonepwd =ref('')
|
|
||||||
|
|
||||||
const show = ref(false);
|
const show = ref(false);
|
||||||
const confirm = ref(false)
|
const confirm = ref(false)
|
||||||
|
|
||||||
let editId = ref(0);
|
let editId = ref(0);
|
||||||
|
let activedomainid = ref(0);
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{ name: 'id'},
|
{ name: 'id'},
|
||||||
@@ -231,25 +203,29 @@ const columns = [
|
|||||||
},
|
},
|
||||||
{ name: 'url', align: 'center', label: 'Domain', field: 'url', sortable: true },
|
{ name: 'url', align: 'center', label: 'Domain', field: 'url', sortable: true },
|
||||||
{ name: 'kintoneuser', label: 'User', field: 'kintoneuser', sortable: true },
|
{ name: 'kintoneuser', label: 'User', field: 'kintoneuser', sortable: true },
|
||||||
{ name: 'kintonepwd' }
|
{ name: 'kintonepwd' },
|
||||||
|
{ name: 'active', field: 'active'}
|
||||||
]
|
]
|
||||||
|
|
||||||
const rows = reactive([])
|
const rows = reactive([])
|
||||||
|
|
||||||
|
const isActive = (id:number) =>{
|
||||||
|
if(id == activedomainid.value)
|
||||||
|
return "Active";
|
||||||
|
else
|
||||||
|
return "Inactive";
|
||||||
|
}
|
||||||
|
|
||||||
const newDomain = () => {
|
const newDomain = () => {
|
||||||
editId.value = 0;
|
editId.value = 0;
|
||||||
show.value = true;
|
show.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const editDomain = (row:object) => {
|
|
||||||
editId.value = row.id;
|
const activeDomain = (id:number) => {
|
||||||
name.value = row.name;
|
api.put(`http://127.0.0.1:8000/api/activedomain/`+ id).then(() =>{
|
||||||
url.value = row.url;
|
getDomain();
|
||||||
kintoneuser.value = row.kintoneuser;
|
})
|
||||||
kintonepwd.value = row.kintonepwd;
|
|
||||||
isPwd.value = true;
|
|
||||||
active.value = false;
|
|
||||||
show.value = true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteConfirm = (row:object) => {
|
const deleteConfirm = (row:object) => {
|
||||||
@@ -258,18 +234,30 @@ const deleteConfirm = (row:object) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const deleteDomain = () => {
|
const deleteDomain = () => {
|
||||||
api.delete(`http://127.0.0.1:8000/api/domain/1/`+ editId.value).then(() =>{
|
api.delete(`http://127.0.0.1:8000/api/domain/`+ editId.value+'/1').then(() =>{
|
||||||
getDomain();
|
getDomain();
|
||||||
})
|
})
|
||||||
editId.value = 0;
|
editId.value = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeDg = () => {
|
const closeDg = (val:string) => {
|
||||||
show.value = false;
|
if (val == 'OK') {
|
||||||
onReset();
|
let dodmainids =[];
|
||||||
|
let domains = JSON.parse(JSON.stringify(domainDg.value.selected));
|
||||||
|
for(var key in domains)
|
||||||
|
{
|
||||||
|
dodmainids.push(domains[key].id);
|
||||||
|
}
|
||||||
|
api.post(`http://127.0.0.1:8000/api/domain`, dodmainids).then(() =>{getDomain();});
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
const getDomain = () => {
|
const getDomain = () => {
|
||||||
api.get(`http://127.0.0.1:8000/api/domain/1`).then(res => {
|
api.get(`http://127.0.0.1:8000/api/activedomain`).then(res => {
|
||||||
|
activedomainid.value = res.data.id;
|
||||||
|
authStore.changedomain(res.data.name);
|
||||||
|
});
|
||||||
|
api.get(`http://127.0.0.1:8000/api/domain`).then(res => {
|
||||||
rows.length = 0;
|
rows.length = 0;
|
||||||
res.data.forEach((item) => {
|
res.data.forEach((item) => {
|
||||||
rows.push({ id:item.id,name: item.name, url: item.url, kintoneuser: item.kintoneuser, kintonepwd: item.kintonepwd});
|
rows.push({ id:item.id,name: item.name, url: item.url, kintoneuser: item.kintoneuser, kintonepwd: item.kintonepwd});
|
||||||
@@ -286,68 +274,6 @@ const isDomain = (val) =>{
|
|||||||
// return (domainPattern.test(val) || '無効なURL')
|
// return (domainPattern.test(val) || '無効なURL')
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = () =>{
|
|
||||||
if(editId.value !== 0)
|
|
||||||
{
|
|
||||||
api.put(`http://127.0.0.1:8000/api/domain`,{
|
|
||||||
'id': editId.value,
|
|
||||||
'userid': 1,
|
|
||||||
'name': name.value,
|
|
||||||
'url': url.value,
|
|
||||||
'kintoneuser': kintoneuser.value,
|
|
||||||
'kintonepwd': kintonepwd.value,
|
|
||||||
'active': active.value
|
|
||||||
}).then(() =>{
|
|
||||||
getDomain();
|
|
||||||
closeDg();
|
|
||||||
onReset();
|
|
||||||
})
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
api.post(`http://127.0.0.1:8000/api/domain`,{
|
|
||||||
'id': 0,
|
|
||||||
'userid': 1,
|
|
||||||
'name': name.value,
|
|
||||||
'url': url.value,
|
|
||||||
'kintoneuser': kintoneuser.value,
|
|
||||||
'kintonepwd': kintonepwd.value,
|
|
||||||
'active': active.value
|
|
||||||
}).then(() =>{
|
|
||||||
getDomain();
|
|
||||||
closeDg();
|
|
||||||
onReset();
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// if (accept.value !== true) {
|
|
||||||
// $q.notify({
|
|
||||||
// color: 'red-5',
|
|
||||||
// textColor: 'white',
|
|
||||||
// icon: 'warning',
|
|
||||||
// message: 'You need to accept the license and terms first'
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// $q.notify({
|
|
||||||
// color: 'green-4',
|
|
||||||
// textColor: 'white',
|
|
||||||
// icon: 'cloud_done',
|
|
||||||
// message: 'Submitted'
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
};
|
|
||||||
|
|
||||||
const onReset = () => {
|
|
||||||
name.value = '';
|
|
||||||
url.value = '';
|
|
||||||
kintoneuser.value = '';
|
|
||||||
kintonepwd.value ='';
|
|
||||||
isPwd.value = true;
|
|
||||||
active.value = false;
|
|
||||||
editId.value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ const routes: RouteRecordRaw[] = [
|
|||||||
{ path: 'flowEditor2', component: () => import('pages/FlowChart.vue') },
|
{ path: 'flowEditor2', component: () => import('pages/FlowChart.vue') },
|
||||||
{ path: 'flowChart2', component: () => import('pages/FlowEditorPage2.vue') },
|
{ path: 'flowChart2', component: () => import('pages/FlowEditorPage2.vue') },
|
||||||
{ path: 'right', component: () => import('pages/testRight.vue') },
|
{ path: 'right', component: () => import('pages/testRight.vue') },
|
||||||
{ path: 'domain', component: () => import('pages/UserDomain.vue') }
|
{ path: 'domain', component: () => import('pages/TenantDomain.vue') },
|
||||||
|
{ path: 'userdomain', component: () => import('pages/UserDomain.vue') }
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
// Always leave this as last one,
|
// Always leave this as last one,
|
||||||
|
|||||||
@@ -11,11 +11,17 @@ export interface IUserState{
|
|||||||
|
|
||||||
export const useAuthStore = defineStore({
|
export const useAuthStore = defineStore({
|
||||||
id: 'auth',
|
id: 'auth',
|
||||||
state: () :IUserState => ({
|
state: ():IUserState =>{
|
||||||
token: localStorage.getItem('token')||'',
|
const token=localStorage.getItem('token')||'';
|
||||||
|
if(token!==''){
|
||||||
|
api.defaults.headers["Authorization"]='Bearer ' + token;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
token,
|
||||||
returnUrl: '',
|
returnUrl: '',
|
||||||
currentDomain: JSON.parse(localStorage.getItem('currentDomain')||"{}")
|
currentDomain: JSON.parse(localStorage.getItem('currentDomain')||"{}")
|
||||||
}),
|
}
|
||||||
|
},
|
||||||
actions: {
|
actions: {
|
||||||
async login(username:string, password:string) {
|
async login(username:string, password:string) {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
@@ -26,6 +32,7 @@ export const useAuthStore = defineStore({
|
|||||||
console.info(result);
|
console.info(result);
|
||||||
this.token =result.data.access_token;
|
this.token =result.data.access_token;
|
||||||
localStorage.setItem('token', result.data.access_token);
|
localStorage.setItem('token', result.data.access_token);
|
||||||
|
api.defaults.headers["Authorization"]='Bearer ' + this.token;
|
||||||
this.currentDomain=await this.getCurrentDomain();
|
this.currentDomain=await this.getCurrentDomain();
|
||||||
localStorage.setItem('currentDomain',JSON.stringify(this.currentDomain));
|
localStorage.setItem('currentDomain',JSON.stringify(this.currentDomain));
|
||||||
Router.push(this.returnUrl || '/');
|
Router.push(this.returnUrl || '/');
|
||||||
@@ -37,22 +44,23 @@ export const useAuthStore = defineStore({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async getCurrentDomain():Promise<IDomainInfo>{
|
async getCurrentDomain():Promise<IDomainInfo>{
|
||||||
|
const activedomain = await api.get(`http://127.0.0.1:8000/api/activedomain`);
|
||||||
return {
|
return {
|
||||||
domainName:'mfu07rkgnb7c',
|
id:activedomain.data.id,
|
||||||
kintoneUrl:'https://mfu07rkgnb7c.cybozu.com'
|
domainName:activedomain.data.name,
|
||||||
|
kintoneUrl:activedomain.data.url
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async getUserDomains():Promise<IDomainInfo[]>{
|
async getUserDomains():Promise<IDomainInfo[]>{
|
||||||
return [
|
const resp = await api.get(`http://127.0.0.1:8000/api/domain`);
|
||||||
{
|
const domains =resp.data as any[];
|
||||||
domainName:'mfu07rkgnb7c',
|
return domains.map(data=>{
|
||||||
kintoneUrl:'https://mfu07rkgnb7c.cybozu.com'
|
return {
|
||||||
},
|
id:data.id,
|
||||||
{
|
domainName:data.name,
|
||||||
domainName:'alicorn',
|
kintoneUrl:data.url
|
||||||
kintoneUrl:'https://alicorn.cybozu.com'
|
|
||||||
}
|
}
|
||||||
]
|
});
|
||||||
},
|
},
|
||||||
logout() {
|
logout() {
|
||||||
this.token = undefined;
|
this.token = undefined;
|
||||||
@@ -60,7 +68,11 @@ export const useAuthStore = defineStore({
|
|||||||
localStorage.removeItem('currentDomain');
|
localStorage.removeItem('currentDomain');
|
||||||
Router.push('/login');
|
Router.push('/login');
|
||||||
},
|
},
|
||||||
setCurrentDomain(domain:IDomainInfo){
|
async setCurrentDomain(domain:IDomainInfo){
|
||||||
|
if(domain.id===this.currentDomain.id){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await api.put(`http://127.0.0.1:8000/api/activedomain/${domain.id}`);
|
||||||
this.currentDomain=domain;
|
this.currentDomain=domain;
|
||||||
localStorage.setItem('currentDomain',JSON.stringify(this.currentDomain));
|
localStorage.setItem('currentDomain',JSON.stringify(this.currentDomain));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
export interface IDomainInfo{
|
export interface IDomainInfo{
|
||||||
|
id:number;
|
||||||
domainName:string;
|
domainName:string;
|
||||||
kintoneUrl:string;
|
kintoneUrl:string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user