Coverage for gws-app/gws/plugin/admin_action/action.py: 0%
30 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
1"""Admin action."""
3import gws
4import gws.base.action
6from . import inspector, mapcache
9@gws.ext.config.action('admin')
10class Config(gws.base.action.Config):
11 """Administration tools. (added in 8.5)"""
13 pass
16@gws.ext.props.action('admin')
17class Props(gws.base.action.Props):
18 pass
21class ViewCacheRequest(gws.Request):
22 """Request for the cache viewer."""
24 path: str = ''
25 """Page or tile path: empty, ``<cache>``, ``<cache>/<z>``, ``<cache>/<z>/<x>/<y>.<ext>`` or an asset name."""
28class InspectorRequest(gws.Request):
29 """Request for the object inspector."""
31 path: str = ''
32 """Object path, or an asset name."""
33 search: str = ''
34 """Search text, ``text`` or ``prop=text``."""
37@gws.ext.object.action('admin')
38class Object(gws.base.action.Object):
39 """Admin action.
41 Serves the administration tools: the object inspector and the tile cache viewer.
42 """
44 @gws.ext.command.get('adminMapCache')
45 def admin_map_cache(self, req: gws.WebRequester, p: ViewCacheRequest) -> gws.ContentResponse:
46 """Display the tile cache viewer."""
48 self._ensure_admin(req)
49 return mapcache.get_content(self.root, p.path)
51 @gws.ext.command.get('adminInspector')
52 def admin_inspector(self, req: gws.WebRequester, p: InspectorRequest) -> gws.ContentResponse:
53 """Display the object inspector."""
55 self._ensure_admin(req)
56 return inspector.get_content(self.root, p.path, p.search)
58 def _ensure_admin(self, req: gws.WebRequester):
59 """Raise ``ForbiddenError`` unless the user has the ``admin`` role."""
60 if not req.user.has_role('admin'):
61 raise gws.ForbiddenError()