Created update button for workspace settings -- these include TIMEZONE and WORKSPACE NAME
This commit is contained in:
@@ -147,6 +147,34 @@ def delete_task(task_id: str, db: Session = Depends(get_db), current_user: model
|
||||
db.delete(db_task)
|
||||
db.commit()
|
||||
return {"message": "Task deleted"}
|
||||
@app.get("/workspace", response_model=schemas.Workspace)
|
||||
def read_workspace(db: Session = Depends(get_db), current_user: models.User = Depends(auth.get_current_user)):
|
||||
ws = db.query(models.Workspace).first()
|
||||
if not ws:
|
||||
ws = models.Workspace(id="default", name="murchison-auto", timezone="Pacific/Auckland")
|
||||
db.add(ws)
|
||||
db.commit()
|
||||
db.refresh(ws)
|
||||
return ws
|
||||
|
||||
@app.patch("/workspace", response_model=schemas.Workspace)
|
||||
def update_workspace(ws_update: schemas.WorkspaceUpdate, db: Session = Depends(get_db), current_user: models.User = Depends(auth.get_current_user)):
|
||||
if current_user.account_type != "admin":
|
||||
raise HTTPException(status_code=403, detail="Not enough permissions")
|
||||
|
||||
ws = db.query(models.Workspace).first()
|
||||
if not ws:
|
||||
ws = models.Workspace(id="default", name="murchison-auto", timezone="Pacific/Auckland")
|
||||
db.add(ws)
|
||||
|
||||
update_data = ws_update.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(ws, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(ws)
|
||||
return ws
|
||||
|
||||
@app.get("/audit", response_model=List[schemas.AuditLog])
|
||||
def read_audit(db: Session = Depends(get_db), current_user: models.User = Depends(auth.get_current_user)):
|
||||
return db.query(models.AuditLog).order_by(models.AuditLog.at.desc()).all()
|
||||
|
||||
Reference in New Issue
Block a user