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