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

1"""Admin action.""" 

2 

3import gws 

4import gws.base.action 

5 

6from . import inspector, mapcache 

7 

8 

9@gws.ext.config.action('admin') 

10class Config(gws.base.action.Config): 

11 """Administration tools. (added in 8.5)""" 

12 

13 pass 

14 

15 

16@gws.ext.props.action('admin') 

17class Props(gws.base.action.Props): 

18 pass 

19 

20 

21class ViewCacheRequest(gws.Request): 

22 """Request for the cache viewer.""" 

23 

24 path: str = '' 

25 """Page or tile path: empty, ``<cache>``, ``<cache>/<z>``, ``<cache>/<z>/<x>/<y>.<ext>`` or an asset name.""" 

26 

27 

28class InspectorRequest(gws.Request): 

29 """Request for the object inspector.""" 

30 

31 path: str = '' 

32 """Object path, or an asset name.""" 

33 search: str = '' 

34 """Search text, ``text`` or ``prop=text``.""" 

35 

36 

37@gws.ext.object.action('admin') 

38class Object(gws.base.action.Object): 

39 """Admin action. 

40 

41 Serves the administration tools: the object inspector and the tile cache viewer. 

42 """ 

43 

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.""" 

47 

48 self._ensure_admin(req) 

49 return mapcache.get_content(self.root, p.path) 

50 

51 @gws.ext.command.get('adminInspector') 

52 def admin_inspector(self, req: gws.WebRequester, p: InspectorRequest) -> gws.ContentResponse: 

53 """Display the object inspector.""" 

54 

55 self._ensure_admin(req) 

56 return inspector.get_content(self.root, p.path, p.search) 

57 

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()