Skip to content

Commit

Permalink
Merge pull request #155 from UpstreamDataInc/dev_dt_error
Browse files Browse the repository at this point in the history
Reload page when datatables show auth error from BFF
  • Loading branch information
b-rowan authored Oct 4, 2024
2 parents b097993 + 65895dd commit 94060ae
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
6 changes: 4 additions & 2 deletions goosebit/ui/bff/routes.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations

from fastapi import APIRouter
from fastapi import APIRouter, Depends

from goosebit.auth import validate_current_user

from . import devices, download, rollouts, software

router = APIRouter(prefix="/bff", tags=["bff"])
router = APIRouter(prefix="/bff", tags=["bff"], dependencies=[Depends(validate_current_user)])
router.include_router(devices.router)
router.include_router(software.router)
router.include_router(rollouts.router)
Expand Down
12 changes: 6 additions & 6 deletions goosebit/ui/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="login")

router = APIRouter(prefix="/ui", dependencies=[Depends(redirect_if_unauthenticated)], include_in_schema=False)
router = APIRouter(prefix="/ui", include_in_schema=False)
router.include_router(bff.router)


@router.get("")
@router.get("", dependencies=[Depends(redirect_if_unauthenticated)])
async def ui_root(request: Request):
return RedirectResponse(request.url_for("devices_ui"))


@router.get(
"/devices",
dependencies=[Security(validate_user_permissions, scopes=["device.read"])],
dependencies=[Depends(redirect_if_unauthenticated), Security(validate_user_permissions, scopes=["device.read"])],
)
@nav.route("Devices", permissions="device.read")
async def devices_ui(request: Request):
Expand All @@ -31,7 +31,7 @@ async def devices_ui(request: Request):

@router.get(
"/software",
dependencies=[Security(validate_user_permissions, scopes=["software.read"])],
dependencies=[Depends(redirect_if_unauthenticated), Security(validate_user_permissions, scopes=["software.read"])],
)
@nav.route("Software", permissions="software.read")
async def software_ui(request: Request):
Expand All @@ -40,7 +40,7 @@ async def software_ui(request: Request):

@router.get(
"/rollouts",
dependencies=[Security(validate_user_permissions, scopes=["rollout.read"])],
dependencies=[Depends(redirect_if_unauthenticated), Security(validate_user_permissions, scopes=["rollout.read"])],
)
@nav.route("Rollouts", permissions="rollout.read")
async def rollouts_ui(request: Request):
Expand All @@ -49,7 +49,7 @@ async def rollouts_ui(request: Request):

@router.get(
"/logs/{dev_id}",
dependencies=[Security(validate_user_permissions, scopes=["device.read"])],
dependencies=[Depends(redirect_if_unauthenticated), Security(validate_user_permissions, scopes=["device.read"])],
)
async def logs_ui(request: Request, dev_id: str):
return templates.TemplateResponse(request, "logs.html.jinja", context={"title": "Log", "device": dev_id})
13 changes: 12 additions & 1 deletion goosebit/ui/templates/nav.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,18 @@
box-shadow: none!important;
}
</style>
<script>const TABLE_UPDATE_TIME = 3000;</script>
<script>
const TABLE_UPDATE_TIME = 3000;
DataTable.ext.errMode = function ( e, settings, helpPage, message ) {
if (e.jqXHR.status == 401) {
window.location.reload();
} else if (e.jqXHR.status >= 200 && e.jqXHR.status < 300) {
console.error("AJAX query error when reloading datatable");
}
console.error("Unknown error when reloading datatable");
};
</script>
<script src="{{ url_for('static', path='js/util.js') }}"></script>
</head>
<body data-bs-theme="dark">
Expand Down

0 comments on commit 94060ae

Please sign in to comment.