Merge pull request #137 from nvrthles/dev

Fix: client app self hosting installation steps request parameters and runtime errors.
This commit is contained in:
Badr B 2024-01-04 23:06:40 +01:00 committed by GitHub
commit becf0a5c2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 29 deletions

11
apps/api/.gitignore vendored
View file

@ -163,9 +163,8 @@ dmypy.json
# Cython debug symbols
cython_debug/
.idea/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
Pipfile
Pipfile.lock
run.py

View file

@ -16,4 +16,5 @@ httpx
faker
requests
pyyaml
sentry-sdk[fastapi]
sentry-sdk[fastapi]
pydantic[email]>=1.8.0,<2.0.0

View file

@ -1,5 +1,5 @@
from typing import Optional
from pydantic import BaseModel
from pydantic import BaseModel, EmailStr
from sqlmodel import Field, SQLModel
from src.db.roles import RoleRead
@ -10,12 +10,14 @@ class UserBase(SQLModel):
username: str
first_name: str
last_name: str
email: str
email: EmailStr
avatar_image: Optional[str] = ""
bio: Optional[str] = ""
class UserCreate(UserBase):
first_name: str = ""
last_name: str = ""
password: str

View file

@ -41,33 +41,30 @@ async def api_get_latest_install_instance(
@router.post("/default_elements")
async def api_install_def_elements(
request: Request,
db_session=Depends(get_db_session),
):
elements = await install_default_elements(request, {}, db_session)
elements = await install_default_elements(db_session)
return elements
@router.post("/org")
async def api_install_org(
request: Request,
org: OrganizationCreate,
db_session=Depends(get_db_session),
org: OrganizationCreate,
db_session=Depends(get_db_session),
):
organization = await install_create_organization(request, org, db_session)
organization = await install_create_organization(org, db_session)
return organization
@router.post("/user")
async def api_install_user(
request: Request,
data: UserCreate,
org_slug: str,
db_session=Depends(get_db_session),
):
user = await install_create_organization_user(request, data, org_slug, db_session)
user = await install_create_organization_user(data, org_slug, db_session)
return user

View file

@ -31,7 +31,7 @@ async def create_install_instance(request: Request, data: dict, db_session: Sess
install.install_uuid = str(f"install_{uuid4()}")
install.update_date = str(datetime.now())
install.creation_date = str(datetime.now())
install.step = 1
# insert install instance
db_session.add(install)
@ -93,7 +93,9 @@ async def update_install_instance(
# Install Default roles
async def install_default_elements( data: dict, db_session: Session):
async def install_default_elements(db_session: Session):
"""
"""
# remove all default roles
statement = select(Role).where(Role.role_type == RoleTypeEnum.TYPE_GLOBAL)
roles = db_session.exec(statement).all()
@ -315,7 +317,7 @@ async def install_create_organization_user(
if not org.first():
raise HTTPException(
status_code=400,
status_code=409,
detail="Organization does not exist",
)
@ -325,7 +327,7 @@ async def install_create_organization_user(
if result.first():
raise HTTPException(
status_code=400,
status_code=409,
detail="Username already exists",
)
@ -335,7 +337,7 @@ async def install_create_organization_user(
if result.first():
raise HTTPException(
status_code=400,
status_code=409,
detail="Email already exists",
)

View file

@ -61,14 +61,12 @@ function AccountCreation() {
username: '',
},
validate,
onSubmit: values => {
onSubmit: async values => {
let finalvalues = { ...values, org_slug: install.data[1].slug }
let finalvalueswithoutpasswords = { ...values, password: '', confirmPassword: '', org_slug: install.data[1].slug }
let install_data = { ...install.data, 3: finalvalues }
let install_data_without_passwords = { ...install.data, 3: finalvalueswithoutpasswords }
updateInstall({ ...install_data_without_passwords }, 4)
createNewUserInstall(finalvalues)
await updateInstall({ ...install_data_without_passwords }, 4)
await createNewUserInstall({email:values.email,username:values.username,password:values.password},install.data[1].slug)
// await 2 seconds
setTimeout(() => {

View file

@ -13,8 +13,8 @@ export async function createNewOrgInstall(body: any) {
return res;
}
export async function createNewUserInstall(body: any) {
const result = await fetch(`${getAPIUrl()}install/user?org_slug=${body.org_slug}`, RequestBody("POST", body, null));
export async function createNewUserInstall(body: any,org_slug:string) {
const result = await fetch(`${getAPIUrl()}install/user?org_slug=${org_slug}`, RequestBody("POST", body, null));
const res = await errorHandling(result);
return res;
}