Action plugins: typings (WIP)
Fix Bootstrap when token is expired
This commit is contained in:
parent
393096d0b7
commit
3ca56f22a6
4 changed files with 113 additions and 42 deletions
|
@ -16,7 +16,8 @@ from gisaf.models.authentication import (
|
|||
)
|
||||
from gisaf.models.category import Category, CategoryRead
|
||||
from gisaf.models.geo_models_base import GeoModel, PlottableModel
|
||||
from gisaf.models.info import (LegendItem, ModelAction, ModelInfo,
|
||||
from gisaf.models.info import (ActionParam, ActionResult, ActionResults, ActionsResults, ActionsStore, FormFieldInput, LegendItem,
|
||||
ModelAction, ModelInfo,
|
||||
DataProvider, ModelValue, PlotParams,
|
||||
TagActions)
|
||||
from gisaf.models.measures import MeasuresItem
|
||||
|
@ -51,7 +52,8 @@ api = APIRouter(
|
|||
|
||||
@api.get('/bootstrap')
|
||||
async def bootstrap(
|
||||
user: Annotated[UserRead, Depends(get_current_active_user)]) -> BootstrapData:
|
||||
user: Annotated[UserRead, Depends(get_current_active_user)]
|
||||
) -> BootstrapData:
|
||||
return BootstrapData(user=user)
|
||||
|
||||
|
||||
|
@ -100,7 +102,7 @@ async def get_roles(
|
|||
async def get_acls(db_session: db_session,
|
||||
user: Annotated[User, Depends(get_current_active_user)]) -> list[UserRoleLink]:
|
||||
"""New: ACLs returned as UserRoleLink"""
|
||||
if not user or not user.has_role('manager'):
|
||||
if user is not None or not user.has_role('manager'):
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
|
||||
data = await db_session.exec(select(UserRoleLink))
|
||||
return data.all() # type: ignore[return-value]
|
||||
|
@ -355,6 +357,7 @@ async def get_model_info(
|
|||
name=name,
|
||||
icon=action.icon,
|
||||
formFields=action.formFields,
|
||||
roles=action.roles,
|
||||
)
|
||||
for name, actions in plugin_manager.actions_stores.get(store, {}).items()
|
||||
for action in actions
|
||||
|
@ -380,4 +383,36 @@ async def get_plot_params(
|
|||
# *, db_session: AsyncSession = Depends(get_db_session)
|
||||
# ) -> list[UserRoleLink]:
|
||||
# roles = await db_session.exec(select(UserRoleLink))
|
||||
# return roles.all()
|
||||
# return roles.all()
|
||||
|
||||
@api.get('/actions')
|
||||
async def get_actions() -> list[ActionsStore]:
|
||||
# actionsPlugins = List(ActionsStore)
|
||||
return plugin_manager.actionsStores
|
||||
|
||||
@api.post('/execTagAction/{action}')
|
||||
async def execute_tag_action(
|
||||
user: Annotated[UserRead, Depends(get_current_active_user)],
|
||||
stores: list[str],
|
||||
ids: list[list[str]],
|
||||
actionNames: list[str],
|
||||
params: list[ActionParam | None],
|
||||
formFields: list[FormFieldInput],
|
||||
) -> ActionsResults:
|
||||
features = dict(zip(stores, [[int(id) for id in _ids] for _ids in ids]))
|
||||
response = ActionsResults()
|
||||
#formFields = {field['name']: field['value'] for field in formFields}
|
||||
if not params:
|
||||
params = [None] * len(actionNames)
|
||||
for name in actionNames:
|
||||
try:
|
||||
## Give the request from context to execute action, along with the parameters
|
||||
## FIXME: formFields/names?
|
||||
breakpoint()
|
||||
resp = await plugin_manager.execute_action(
|
||||
user, features, name, params, form_fields=formFields)
|
||||
response.actionResults.append(resp)
|
||||
except NoSuchAction:
|
||||
logger.warn(f'Unknown action {name}')
|
||||
response.actionResults.append(ActionResult(message=f'No such action: {name}'))
|
||||
return response
|
Loading…
Add table
Add a link
Reference in a new issue