Skip to content

Commit

Permalink
Merge pull request #630 from hotosm/hotfixes
Browse files Browse the repository at this point in the history
Hotfixes
  • Loading branch information
nrjadkry authored Jul 24, 2023
2 parents 8f1bdaf + edab306 commit 8356314
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
13 changes: 10 additions & 3 deletions src/backend/app/auth/auth_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def callback(request: Request, osm_auth=Depends(init_osm_auth)):


@router.get("/me/", response_model=AuthUser)
def my_data(user_data: AuthUser = Depends(login_required)):
def my_data(
db: Session = Depends(database.get_db),
user_data: AuthUser = Depends(login_required)
):
"""Read the access token and provide user details from OSM user's API endpoint,
also integrated with underpass .
Expand All @@ -87,7 +90,11 @@ def my_data(user_data: AuthUser = Depends(login_required)):
"""

# Save user info in User table
db_user = DbUser(id=user_data['id'], username=user_data['username'])
db_user.commit()
user = user_crud.get_user_by_id(db, user_data['id'])
if not user:
db_user = DbUser(id=user_data['id'], username=user_data['username'])
db.add(db_user)
db.commit()


return JSONResponse(content={"user_data": user_data}, status_code=200)
10 changes: 5 additions & 5 deletions src/backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@

logger = logging.getLogger(__name__)


sentry_sdk.init(
dsn=settings.SENTRY_DSN,
traces_sample_rate=0.1,
)
if not settings.DEBUG:
sentry_sdk.init(
dsn=settings.SENTRY_DSN,
traces_sample_rate=0.1,
)


def get_application() -> FastAPI:
Expand Down
2 changes: 2 additions & 0 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ async def create_project(
else:
raise HTTPException(status_code=404, detail="Project not found")


@router.post("/update_odk_credentials")
async def update_odk_credentials(
background_task: BackgroundTasks,
Expand Down Expand Up @@ -485,6 +486,7 @@ async def generate_files(
if file_ext not in allowed_extensions:
raise HTTPException(status_code=400, detail="Provide a valid .xls file")
xform_title = file_name[0]
await upload.seek(0)
contents = await upload.read()

project.form_xls = contents
Expand Down
5 changes: 5 additions & 0 deletions src/backend/app/users/user_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,8 @@ async def create_user_roles(user_role: user_schemas.UserRoles, db: Session):
db.commit()
db.refresh(db_user_role)
return db_user_role


def get_user_by_id(db: Session, user_id: int):
db_user = db.query(db_models.DbUser).filter(db_models.DbUser.id == user_id).first()
return db_user

0 comments on commit 8356314

Please sign in to comment.