Fix tg actions
This commit is contained in:
parent
3ca56f22a6
commit
8b7081df67
2 changed files with 13 additions and 32 deletions
|
@ -16,7 +16,8 @@ from gisaf.models.authentication import (
|
||||||
)
|
)
|
||||||
from gisaf.models.category import Category, CategoryRead
|
from gisaf.models.category import Category, CategoryRead
|
||||||
from gisaf.models.geo_models_base import GeoModel, PlottableModel
|
from gisaf.models.geo_models_base import GeoModel, PlottableModel
|
||||||
from gisaf.models.info import (ActionParam, ActionResult, ActionResults, ActionsResults, ActionsStore, FormFieldInput, LegendItem,
|
from gisaf.models.info import (ActionParam, ActionsResults, ActionsStore,
|
||||||
|
FormFieldInput, LegendItem,
|
||||||
ModelAction, ModelInfo,
|
ModelAction, ModelInfo,
|
||||||
DataProvider, ModelValue, PlotParams,
|
DataProvider, ModelValue, PlotParams,
|
||||||
TagActions)
|
TagActions)
|
||||||
|
@ -37,7 +38,7 @@ from gisaf.custom_store_base import BaseStore
|
||||||
from gisaf.redis_tools import store as redis_store
|
from gisaf.redis_tools import store as redis_store
|
||||||
from gisaf.models.info import FeatureInfo
|
from gisaf.models.info import FeatureInfo
|
||||||
from gisaf.live_utils import get_live_feature_info
|
from gisaf.live_utils import get_live_feature_info
|
||||||
from gisaf.plugins import manager as plugin_manager, NoSuchAction
|
from gisaf.plugins import manager as plugin_manager
|
||||||
from gisaf.utils import gisTypeSymbolMap
|
from gisaf.utils import gisTypeSymbolMap
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -390,7 +391,7 @@ async def get_actions() -> list[ActionsStore]:
|
||||||
# actionsPlugins = List(ActionsStore)
|
# actionsPlugins = List(ActionsStore)
|
||||||
return plugin_manager.actionsStores
|
return plugin_manager.actionsStores
|
||||||
|
|
||||||
@api.post('/execTagAction/{action}')
|
@api.post('/execTagActions')
|
||||||
async def execute_tag_action(
|
async def execute_tag_action(
|
||||||
user: Annotated[UserRead, Depends(get_current_active_user)],
|
user: Annotated[UserRead, Depends(get_current_active_user)],
|
||||||
stores: list[str],
|
stores: list[str],
|
||||||
|
@ -405,14 +406,9 @@ async def execute_tag_action(
|
||||||
if not params:
|
if not params:
|
||||||
params = [None] * len(actionNames)
|
params = [None] * len(actionNames)
|
||||||
for name in actionNames:
|
for name in actionNames:
|
||||||
try:
|
## Give the request from context to execute action, along with the parameters
|
||||||
## Give the request from context to execute action, along with the parameters
|
## FIXME: formFields/names?
|
||||||
## FIXME: formFields/names?
|
resp = await plugin_manager.execute_action(
|
||||||
breakpoint()
|
user, features, name, params, form_fields=formFields)
|
||||||
resp = await plugin_manager.execute_action(
|
response.actionResults.append(resp)
|
||||||
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
|
return response
|
|
@ -25,7 +25,6 @@ from gisaf.models.reconcile import StatusChange
|
||||||
from gisaf.models.info import (
|
from gisaf.models.info import (
|
||||||
ActionResults,
|
ActionResults,
|
||||||
ActionResult,
|
ActionResult,
|
||||||
ActionsResults,
|
|
||||||
Downloader,
|
Downloader,
|
||||||
TagAction, ActionAction,
|
TagAction, ActionAction,
|
||||||
TagActions,
|
TagActions,
|
||||||
|
@ -38,15 +37,8 @@ from gisaf.models.info import (
|
||||||
)
|
)
|
||||||
from gisaf.registry import NotInRegistry, registry
|
from gisaf.registry import NotInRegistry, registry
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('Gisaf plugin manager')
|
logger = logging.getLogger('Gisaf plugin manager')
|
||||||
|
|
||||||
|
|
||||||
class NoSuchAction(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ActionPlugin:
|
class ActionPlugin:
|
||||||
"""
|
"""
|
||||||
Base class for all actions plugins.
|
Base class for all actions plugins.
|
||||||
|
@ -66,7 +58,7 @@ class ActionPlugin:
|
||||||
user: UserRead,
|
user: UserRead,
|
||||||
features: dict[str, list],
|
features: dict[str, list],
|
||||||
params: list,
|
params: list,
|
||||||
form_fields: list[FormFieldInput]) -> ActionResults:
|
form_fields: list[FormFieldInput]) -> ActionResult:
|
||||||
raise NotImplementedError('Action plugins must implement execute')
|
raise NotImplementedError('Action plugins must implement execute')
|
||||||
|
|
||||||
|
|
||||||
|
@ -180,7 +172,6 @@ class PluginManager:
|
||||||
self.executors = defaultdict(list)
|
self.executors = defaultdict(list)
|
||||||
self.downloaders = defaultdict(list)
|
self.downloaders = defaultdict(list)
|
||||||
self.downloaders_stores = defaultdict(list)
|
self.downloaders_stores = defaultdict(list)
|
||||||
self.actions_names = defaultdict(list)
|
|
||||||
|
|
||||||
registered_models = registry.geom
|
registered_models = registry.geom
|
||||||
registered_stores = registered_models.keys()
|
registered_stores = registered_models.keys()
|
||||||
|
@ -230,7 +221,6 @@ class PluginManager:
|
||||||
logger.warning(err)
|
logger.warning(err)
|
||||||
continue
|
continue
|
||||||
self.executors[action.name].append(action)
|
self.executors[action.name].append(action)
|
||||||
#self.actions_names[action.name].append(plugin)
|
|
||||||
stores = action.stores
|
stores = action.stores
|
||||||
for _action in action.stores_by_re:
|
for _action in action.stores_by_re:
|
||||||
_re = re.compile(_action)
|
_re = re.compile(_action)
|
||||||
|
@ -377,7 +367,7 @@ class PluginManager:
|
||||||
name: str,
|
name: str,
|
||||||
params: list[ActionParam | None],
|
params: list[ActionParam | None],
|
||||||
form_fields: list[FormFieldInput]
|
form_fields: list[FormFieldInput]
|
||||||
) -> ActionsResults:
|
) -> ActionResults:
|
||||||
"""
|
"""
|
||||||
Execute the plugin action by calling the executor's execute function.
|
Execute the plugin action by calling the executor's execute function.
|
||||||
It is up to the plugin action to check for security, using eg:
|
It is up to the plugin action to check for security, using eg:
|
||||||
|
@ -386,20 +376,15 @@ class PluginManager:
|
||||||
...
|
...
|
||||||
await check_permission(request, 'role')
|
await check_permission(request, 'role')
|
||||||
"""
|
"""
|
||||||
results = ActionsResults()
|
results = ActionResults(name=name)
|
||||||
try:
|
|
||||||
plugins = self.actions_names[name]
|
|
||||||
except KeyError:
|
|
||||||
raise NoSuchAction
|
|
||||||
for executor in self.executors[name]:
|
for executor in self.executors[name]:
|
||||||
## TODO: get features from DB?
|
## TODO: get features from DB?
|
||||||
result: ActionResults
|
|
||||||
## Check permission
|
## Check permission
|
||||||
if executor.roles:
|
if executor.roles:
|
||||||
if user is None or not any([user.has_role(role) for role in executor.roles]):
|
if user is None or not any([user.has_role(role) for role in executor.roles]):
|
||||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
|
||||||
|
result: ActionResult
|
||||||
result = await executor.execute(user, features, params, form_fields)
|
result = await executor.execute(user, features, params, form_fields)
|
||||||
result.name = name
|
|
||||||
results.actionResults.append(result)
|
results.actionResults.append(result)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue