howler-api 4.0.0.dev1062__py3-none-any.whl → 4.0.0.dev1069__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. howler/actions/add_to_bundle.py +75 -52
  2. howler/actions/demote.py +2 -2
  3. howler/actions/remove_from_bundle.py +46 -64
  4. howler/actions/transition.py +5 -3
  5. howler/api/__init__.py +1 -2
  6. howler/api/socket.py +6 -36
  7. howler/api/v1/__init__.py +56 -3
  8. howler/api/v1/action.py +2 -1
  9. howler/api/v1/analytic.py +106 -17
  10. howler/api/v1/hit.py +126 -50
  11. howler/api/v1/tool.py +22 -47
  12. howler/api/v1/user.py +1 -1
  13. howler/api/v1/utils/etag.py +43 -65
  14. howler/app.py +0 -15
  15. howler/common/loader.py +5 -4
  16. howler/cronjobs/rules.py +279 -0
  17. howler/datastore/collection.py +25 -40
  18. howler/datastore/howler_store.py +14 -29
  19. howler/datastore/types.py +6 -1
  20. howler/healthz.py +45 -1
  21. howler/helper/discover.py +8 -12
  22. howler/helper/hit.py +4 -4
  23. howler/helper/search.py +3 -13
  24. howler/odm/helper.py +7 -113
  25. howler/odm/models/config.py +1 -14
  26. howler/odm/models/hit.py +336 -4
  27. howler/odm/models/howler_data.py +35 -3
  28. howler/odm/models/view.py +0 -8
  29. howler/odm/random_data.py +50 -372
  30. howler/remote/datatypes/__init__.py +97 -5
  31. howler/remote/datatypes/counters.py +2 -2
  32. howler/remote/datatypes/hash.py +1 -1
  33. howler/remote/datatypes/queues/comms.py +1 -2
  34. howler/remote/datatypes/user_quota_tracker.py +3 -3
  35. howler/services/config_service.py +3 -3
  36. howler/services/event_service.py +40 -78
  37. howler/services/hit_service.py +170 -83
  38. howler/utils/socket_utils.py +25 -4
  39. {howler_api-4.0.0.dev1062.dist-info → howler_api-4.0.0.dev1069.dist-info}/METADATA +3 -3
  40. {howler_api-4.0.0.dev1062.dist-info → howler_api-4.0.0.dev1069.dist-info}/RECORD +42 -59
  41. howler/actions/add_to_case.py +0 -136
  42. howler/api/v2/__init__.py +0 -44
  43. howler/api/v2/case.py +0 -437
  44. howler/api/v2/ingest.py +0 -371
  45. howler/api/v2/search.py +0 -340
  46. howler/cronjobs/correlation.py +0 -36
  47. howler/odm/constants.py +0 -20
  48. howler/odm/mixins.py +0 -97
  49. howler/odm/models/case.py +0 -218
  50. howler/odm/models/observable.py +0 -126
  51. howler/odm/models/record.py +0 -350
  52. howler/services/bundle_compat_service.py +0 -281
  53. howler/services/case_service.py +0 -944
  54. howler/services/correlation_service.py +0 -168
  55. howler/services/docs_service.py +0 -89
  56. howler/services/observable_service.py +0 -142
  57. howler/services/search_service.py +0 -229
  58. howler/services/viewer_service.py +0 -43
  59. {howler_api-4.0.0.dev1062.dist-info → howler_api-4.0.0.dev1069.dist-info}/WHEEL +0 -0
  60. {howler_api-4.0.0.dev1062.dist-info → howler_api-4.0.0.dev1069.dist-info}/entry_points.txt +0 -0
@@ -1,27 +1,28 @@
1
- """Deprecated add_to_bundle action — delegates to add_to_case via bundle_compat_service."""
2
-
3
1
  from typing import Optional
4
2
 
5
3
  from howler.actions import check_hit_limit
6
- from howler.common.exceptions import NotFoundException
7
4
  from howler.common.loader import datastore
5
+ from howler.datastore.operations import OdmHelper
8
6
  from howler.odm.models.action import VALID_TRIGGERS
7
+ from howler.odm.models.hit import Hit
9
8
  from howler.odm.models.user import User
10
- from howler.services import bundle_compat_service, case_service
9
+ from howler.services import hit_service
11
10
  from howler.utils.str_utils import sanitize_lucene_query
12
11
 
12
+ hit_helper = OdmHelper(Hit)
13
+
13
14
  OPERATION_ID = "add_to_bundle"
14
15
  MAX_HITS_BASIC = 10
15
16
  MAX_HITS_ADVANCED = 1000
16
17
  SKIP_CENTRAL_LIMIT = True # This operation transforms the query, handles limit check locally
17
18
 
18
19
 
19
- def execute(query: str, bundle_id: Optional[str] = None, user: Optional[User] = None, **kwargs): # noqa: C901
20
- """Add a set of hits matching the query to the specified bundle (deprecated — uses cases).
20
+ def execute(query: str, bundle_id: Optional[str] = None, user: Optional[User] = None, **kwargs):
21
+ """Add a set of hits matching the query to the specified bundle.
21
22
 
22
23
  Args:
23
24
  query (str): The query containing the matching hits
24
- bundle_id (str): The ``howler.id`` of the bundle to add the hits to.
25
+ bundle_id (str): The `howler.id` of the bundle to add the hits to.
25
26
  """
26
27
  report = []
27
28
 
@@ -36,81 +37,96 @@ def execute(query: str, bundle_id: Optional[str] = None, user: Optional[User] =
36
37
  ]
37
38
 
38
39
  try:
39
- case_id = bundle_compat_service.find_case_for_bundle(bundle_id)
40
- if case_id is None:
40
+ bundle_hit = hit_service.get_hit(bundle_id, as_odm=True)
41
+ if not bundle_hit or not bundle_hit.howler.is_bundle:
41
42
  report.append(
42
43
  {
43
44
  "query": query,
44
45
  "outcome": "error",
45
46
  "title": "Invalid Bundle",
46
- "message": f"Either a hit with ID {bundle_id} does not exist, or it has no associated case.",
47
+ "message": f"Either a hit with ID {bundle_id} does not exist, or it is not a bundle.",
47
48
  }
48
49
  )
49
50
  return report
50
51
 
51
52
  ds = datastore()
52
53
 
53
- # Check hit limit against the query before searching
54
- if user:
55
- limit_error = check_hit_limit(query, user, MAX_HITS_BASIC, MAX_HITS_ADVANCED)
56
- if limit_error:
57
- return [limit_error]
58
-
59
- matching_hits = ds.hit.search(query, rows=MAX_HITS_ADVANCED)["items"]
54
+ skipped_hits_bundles = ds.hit.search(
55
+ f"({query}) AND howler.is_bundle:true",
56
+ fl="howler.id",
57
+ )["items"]
60
58
 
61
- if not matching_hits:
59
+ if len(skipped_hits_bundles) > 0:
62
60
  report.append(
63
61
  {
64
- "query": query,
62
+ "query": f"({query}) AND howler.is_bundle:true",
65
63
  "outcome": "skipped",
66
- "title": "No Matching Hits",
67
- "message": "There were no hits matching this query.",
64
+ "title": "Skipped Bundles",
65
+ "message": "Bundles cannot be added to a bundle.",
68
66
  }
69
67
  )
70
- return report
71
68
 
72
- added = []
73
- skipped = []
74
- for hit in matching_hits:
75
- child_label = f"hits/{hit.howler.analytic} ({hit.howler.id})"
76
- try:
77
- case_service.append_case_item(
78
- case_id,
79
- item_type="hit",
80
- item_value=hit.howler.id,
81
- item_path=child_label,
82
- )
83
- added.append(hit.howler.id)
84
- except Exception:
85
- skipped.append(hit.howler.id)
86
-
87
- if skipped:
69
+ skipped_hits_already_added = ds.hit.search(
70
+ f"({query}) AND (howler.bundles:{sanitize_lucene_query(bundle_id)})",
71
+ fl="howler.id",
72
+ )["items"]
73
+
74
+ if len(skipped_hits_already_added) > 0:
88
75
  report.append(
89
76
  {
90
- "query": f"howler.id:({' OR '.join(sanitize_lucene_query(h) for h in skipped)})",
77
+ "query": f"({query}) AND (howler.bundles:{sanitize_lucene_query(bundle_id)})",
91
78
  "outcome": "skipped",
92
79
  "title": "Skipped Hits",
93
- "message": "These hits could not be added (already present or invalid).",
80
+ "message": "These hits have already been added to the specified bundle.",
94
81
  }
95
82
  )
96
83
 
97
- if added:
84
+ safe_query = f"({query}) AND (-howler.bundles:({sanitize_lucene_query(bundle_id)}) AND howler.is_bundle:false)"
85
+
86
+ # Check hit limit against the effective query (not raw query)
87
+ if user:
88
+ limit_error = check_hit_limit(safe_query, user, MAX_HITS_BASIC, MAX_HITS_ADVANCED)
89
+ if limit_error:
90
+ return [limit_error]
91
+
92
+ matching_hits = ds.hit.search(safe_query, rows=MAX_HITS_ADVANCED, fl="howler.id")["items"]
93
+ if len(matching_hits) < 1:
98
94
  report.append(
99
95
  {
100
- "query": f"howler.id:({' OR '.join(sanitize_lucene_query(h) for h in added)})",
101
- "outcome": "success",
102
- "title": "Executed Successfully",
103
- "message": "The specified bundle has had all matching hits added.",
96
+ "query": safe_query,
97
+ "outcome": "skipped",
98
+ "title": "No Matching Hits",
99
+ "message": "There were no hits matching this query.",
104
100
  }
105
101
  )
102
+ return report
103
+
104
+ ds.hit.update_by_query(
105
+ safe_query,
106
+ [hit_helper.list_add("howler.bundles", sanitize_lucene_query(bundle_id), if_missing=True)],
107
+ )
108
+
109
+ operations = [
110
+ hit_helper.list_add(
111
+ "howler.hits",
112
+ hit["howler"]["id"],
113
+ if_missing=True,
114
+ )
115
+ for hit in matching_hits
116
+ ]
106
117
 
107
- except NotFoundException as e:
118
+ operations.append(hit_helper.update("howler.bundle_size", len(operations)))
119
+ hit_service.update_hit(
120
+ bundle_id,
121
+ operations,
122
+ )
123
+ bundle_hit = hit_service.get_hit(bundle_id, as_odm=True)
108
124
  report.append(
109
125
  {
110
- "query": query,
111
- "outcome": "error",
112
- "title": "Failed to Execute",
113
- "message": str(e),
126
+ "query": safe_query.replace("-howler.bundles", "howler.bundles"),
127
+ "outcome": "success",
128
+ "title": "Executed Successfully",
129
+ "message": "The specified bundle has had all matching hits added.",
114
130
  }
115
131
  )
116
132
  except Exception as e:
@@ -130,11 +146,11 @@ def specification():
130
146
  """Specify various properties of the action, such as title, descriptions, permissions and input steps."""
131
147
  return {
132
148
  "id": OPERATION_ID,
133
- "title": "Add to Bundle (Deprecated)",
149
+ "title": "Add to Bundle",
134
150
  "priority": 6,
135
151
  "i18nKey": f"operations.{OPERATION_ID}",
136
152
  "description": {
137
- "short": "Add a set of hits to a bundle (deprecated — uses cases)",
153
+ "short": "Add a set of hits to a bundle",
138
154
  "long": execute.__doc__,
139
155
  },
140
156
  "roles": ["automation_basic", "actionrunner_basic"],
@@ -142,6 +158,13 @@ def specification():
142
158
  {
143
159
  "args": {"bundle_id": []},
144
160
  "options": {},
161
+ "validation": {
162
+ "warn": {"query": "howler.bundles:($bundle_id) OR howler.is_bundle:true"},
163
+ "error": {
164
+ "query": "howler.id:$bundle_id AND howler.is_bundle:false",
165
+ "message": "The bundle id given must be a bundle.",
166
+ },
167
+ },
145
168
  }
146
169
  ],
147
170
  "triggers": VALID_TRIGGERS,
howler/actions/demote.py CHANGED
@@ -9,7 +9,7 @@ from howler.odm.models.howler_data import (
9
9
  Assessment,
10
10
  AssessmentEscalationMap,
11
11
  Escalation,
12
- Status,
12
+ HitStatus,
13
13
  )
14
14
  from howler.odm.models.user import User
15
15
  from howler.utils.str_utils import sanitize_lucene_query
@@ -99,7 +99,7 @@ def execute(
99
99
  "howler.assignment",
100
100
  user.get("uname", "automation") if user else "automation",
101
101
  ),
102
- odm_helper.update("howler.status", Status.RESOLVED),
102
+ odm_helper.update("howler.status", HitStatus.RESOLVED),
103
103
  ],
104
104
  )
105
105
 
@@ -1,27 +1,29 @@
1
- """Deprecated remove_from_bundle action — delegates to case_service for item removal."""
2
-
3
1
  from typing import Optional
4
2
 
5
3
  from howler.actions import check_hit_limit
6
- from howler.common.exceptions import NotFoundException
4
+ from howler.common.exceptions import HowlerException
7
5
  from howler.common.loader import datastore
6
+ from howler.datastore.operations import OdmHelper
8
7
  from howler.odm.models.action import VALID_TRIGGERS
8
+ from howler.odm.models.hit import Hit
9
9
  from howler.odm.models.user import User
10
- from howler.services import bundle_compat_service, case_service
10
+ from howler.services import hit_service
11
11
  from howler.utils.str_utils import sanitize_lucene_query
12
12
 
13
+ hit_helper = OdmHelper(Hit)
14
+
13
15
  OPERATION_ID = "remove_from_bundle"
14
16
  MAX_HITS_BASIC = 10
15
17
  MAX_HITS_ADVANCED = 1000
16
18
  SKIP_CENTRAL_LIMIT = True # This operation transforms the query, handles limit check locally
17
19
 
18
20
 
19
- def execute(query: str, bundle_id: Optional[str] = None, user: Optional[User] = None, **kwargs): # noqa: C901
20
- """Remove a set of hits matching the query from the specified bundle (deprecated — uses cases).
21
+ def execute(query: str, bundle_id: Optional[str] = None, user: Optional[User] = None, **kwargs):
22
+ """Remove a set of hits matching the query from the specified bundle.
21
23
 
22
24
  Args:
23
25
  query (str): The query containing the matching hits
24
- bundle_id (str): The ``howler.id`` of the bundle to remove the hits from.
26
+ bundle_id (str): The `howler.id` of the bundle to remove the hits from.
25
27
  """
26
28
  report = []
27
29
 
@@ -36,78 +38,67 @@ def execute(query: str, bundle_id: Optional[str] = None, user: Optional[User] =
36
38
  ]
37
39
 
38
40
  try:
39
- case_id = bundle_compat_service.find_case_for_bundle(bundle_id)
40
- if case_id is None:
41
+ bundle_hit = hit_service.get_hit(bundle_id, as_odm=True)
42
+ if not bundle_hit or not bundle_hit.howler.is_bundle:
41
43
  report.append(
42
44
  {
43
45
  "query": query,
44
46
  "outcome": "error",
45
47
  "title": "Invalid Bundle",
46
- "message": f"Either a hit with ID {bundle_id} does not exist, or it has no associated case.",
48
+ "message": f"Either a hit with ID {bundle_id} does not exist, or it is not a bundle.",
47
49
  }
48
50
  )
49
51
  return report
50
52
 
51
53
  ds = datastore()
52
54
 
53
- # Check hit limit against the query before searching
54
- if user:
55
- limit_error = check_hit_limit(query, user, MAX_HITS_BASIC, MAX_HITS_ADVANCED)
56
- if limit_error:
57
- return [limit_error]
58
-
59
- matching_hits = ds.hit.search(query, rows=MAX_HITS_ADVANCED)["items"]
55
+ skipped_hits = ds.hit.search(
56
+ f"({query}) AND -howler.bundles:{sanitize_lucene_query(bundle_id)}",
57
+ fl="howler.id",
58
+ )["items"]
60
59
 
61
- if not matching_hits:
60
+ if len(skipped_hits) > 0:
62
61
  report.append(
63
62
  {
64
- "query": query,
63
+ "query": f"howler.id:({' OR '.join(h.howler.id for h in skipped_hits)})",
65
64
  "outcome": "skipped",
66
- "title": "No Matching Hits",
67
- "message": "There were no hits matching this query.",
68
- }
69
- )
70
- return report
71
-
72
- # Get the case to check which hits are actually in it
73
- case = ds.case.get(case_id)
74
- if case is None:
75
- report.append(
76
- {
77
- "query": query,
78
- "outcome": "error",
79
- "title": "Case Not Found",
80
- "message": f"Associated case {case_id} no longer exists.",
65
+ "title": "Skipped Hit not in Bundle",
66
+ "message": "These hits already are not in the bundle.",
81
67
  }
82
68
  )
83
- return report
84
69
 
85
- case_item_values = {item.value for item in case.items}
86
- values_to_remove = [h.howler.id for h in matching_hits if h.howler.id in case_item_values]
87
- skipped_ids = [h.howler.id for h in matching_hits if h.howler.id not in case_item_values]
70
+ safe_query = f"{query} AND (howler.bundles:{sanitize_lucene_query(bundle_id)})"
88
71
 
89
- if skipped_ids:
90
- report.append(
91
- {
92
- "query": f"howler.id:({' OR '.join(sanitize_lucene_query(h) for h in skipped_ids)})",
93
- "outcome": "skipped",
94
- "title": "Skipped Hits Not in Bundle",
95
- "message": "These hits are not in the bundle.",
96
- }
97
- )
72
+ # Check hit limit against the effective query (not raw query)
73
+ if user:
74
+ limit_error = check_hit_limit(safe_query, user, MAX_HITS_BASIC, MAX_HITS_ADVANCED)
75
+ if limit_error:
76
+ return [limit_error]
98
77
 
99
- if not values_to_remove:
78
+ matching_hits = ds.hit.search(safe_query, rows=MAX_HITS_ADVANCED, fl="howler.id")["items"]
79
+ if len(matching_hits) < 1:
100
80
  report.append(
101
81
  {
102
- "query": query,
82
+ "query": safe_query,
103
83
  "outcome": "skipped",
104
84
  "title": "No Matching Hits",
105
- "message": "None of the matching hits were found in the bundle.",
85
+ "message": "There were no hits matching this query.",
106
86
  }
107
87
  )
108
88
  return report
109
89
 
110
- case_service.remove_case_items(case_id, values_to_remove)
90
+ ds.hit.update_by_query(
91
+ safe_query,
92
+ [hit_helper.list_remove("howler.bundles", bundle_id)],
93
+ )
94
+
95
+ hit_service.update_hit(
96
+ bundle_id,
97
+ [hit_helper.list_remove("howler.hits", h["howler"]["id"]) for h in matching_hits],
98
+ )
99
+
100
+ if len(ds.hit.get(bundle_id).howler.hits) < 1:
101
+ hit_service.update_hit(bundle_id, [hit_helper.update("howler.is_bundle", False)])
111
102
 
112
103
  report.append(
113
104
  {
@@ -117,17 +108,7 @@ def execute(query: str, bundle_id: Optional[str] = None, user: Optional[User] =
117
108
  "message": f"Matching hits removed from bundle with id {bundle_id}",
118
109
  }
119
110
  )
120
-
121
- except NotFoundException as e:
122
- report.append(
123
- {
124
- "query": query,
125
- "outcome": "error",
126
- "title": "Failed to Execute",
127
- "message": str(e),
128
- }
129
- )
130
- except Exception as e:
111
+ except HowlerException as e:
131
112
  report.append(
132
113
  {
133
114
  "query": query,
@@ -144,11 +125,11 @@ def specification():
144
125
  """Specify various properties of the action, such as title, descriptions, permissions and input steps."""
145
126
  return {
146
127
  "id": OPERATION_ID,
147
- "title": "Remove from Bundle (Deprecated)",
128
+ "title": "Remove from Bundle",
148
129
  "priority": 5,
149
130
  "i18nKey": f"operations.{OPERATION_ID}",
150
131
  "description": {
151
- "short": "Remove a set of hits from a bundle (deprecated — uses cases)",
132
+ "short": "Remove a set of hits from a bundle",
152
133
  "long": execute.__doc__,
153
134
  },
154
135
  "roles": ["automation_basic", "actionrunner_basic"],
@@ -156,6 +137,7 @@ def specification():
156
137
  {
157
138
  "args": {"bundle_id": []},
158
139
  "options": {},
140
+ "validation": {"error": {"query": "-howler.bundles:$bundle_id"}},
159
141
  }
160
142
  ],
161
143
  "triggers": VALID_TRIGGERS,
@@ -9,8 +9,8 @@ from howler.helper.workflow import Workflow, WorkflowException
9
9
  from howler.odm.models.action import VALID_TRIGGERS
10
10
  from howler.odm.models.howler_data import (
11
11
  Assessment,
12
+ HitStatus,
12
13
  HitStatusTransition,
13
- Status,
14
14
  Vote,
15
15
  )
16
16
  from howler.odm.models.user import User
@@ -193,13 +193,15 @@ def specification():
193
193
  "steps": [
194
194
  {
195
195
  "args": {"status": []},
196
- "options": {"status": Status.list()},
196
+ "options": {"status": HitStatus.list()},
197
197
  "validation": {"error": {"query": "-howler.status:$status"}},
198
198
  },
199
199
  {
200
200
  "args": {"transition": []},
201
201
  "options": {
202
- "transition": {f"status:{status}": hit_service.get_transitions(status) for status in Status.list()},
202
+ "transition": {
203
+ f"status:{status}": hit_service.get_transitions(status) for status in HitStatus.list()
204
+ },
203
205
  },
204
206
  },
205
207
  {
howler/api/__init__.py CHANGED
@@ -25,8 +25,7 @@ logger = get_logger(__file__)
25
25
 
26
26
  def make_subapi_blueprint(name, api_version=1):
27
27
  """Create a flask Blueprint for a subapi in a standard way."""
28
- full_name = f"v{api_version}_{name}"
29
- return Blueprint(full_name, full_name, url_prefix="/".join([API_PREFIX, f"v{api_version}", name]))
28
+ return Blueprint(name, name, url_prefix="/".join([API_PREFIX, f"v{api_version}", name]))
30
29
 
31
30
 
32
31
  def _make_api_response(
howler/api/socket.py CHANGED
@@ -7,11 +7,11 @@ from flask import Blueprint, request
7
7
  from opentelemetry import trace
8
8
 
9
9
  import howler.services.event_service as event_service
10
- import howler.services.viewer_service as viewer_service
11
10
  from howler.api import ok, unauthorized
12
11
  from howler.common.logging import get_logger
12
+ from howler.datastore.operations import OdmHelper
13
13
  from howler.helper.ws import ConnectionClosed, Server
14
- from howler.security import api_login
14
+ from howler.odm.models.hit import Hit
15
15
  from howler.security.socket import websocket_auth, ws_response
16
16
  from howler.utils.socket_utils import check_action
17
17
 
@@ -24,16 +24,13 @@ socket_api._doc = "Endpoints concerning websocket connectivity between the clien
24
24
  logger = get_logger(__file__)
25
25
  tracer = trace.get_tracer(__name__)
26
26
 
27
+ hit_helper = OdmHelper(Hit)
28
+
27
29
 
28
30
  @tracer.start_as_current_span(f"{__name__}.emit")
29
31
  @socket_api.route("/emit/<event>", methods=["POST"])
30
32
  def emit(event: str):
31
- """Emit an event to all listening websockets.
32
-
33
- .. deprecated::
34
- This endpoint is deprecated. Events are now propagated via Redis pubsub
35
- and no longer require a dedicated websocket pod.
36
- """
33
+ """Emit an event to all listening websockets"""
37
34
  if "Authorization" not in request.headers:
38
35
  return unauthorized(err="Missing authorization header")
39
36
 
@@ -52,25 +49,10 @@ def emit(event: str):
52
49
  return ok()
53
50
 
54
51
 
55
- @tracer.start_as_current_span(f"{__name__}.get_viewers")
56
- @socket_api.route("/viewers/<entity_id>", methods=["GET"])
57
- @api_login(audit=False, required_priv=["R"])
58
- def get_viewers(entity_id: str, **kwargs):
59
- """Get the list of users currently viewing the specified entity
60
-
61
- Variables:
62
- entity_id => The ID of the entity to get viewers for
63
-
64
- Result Example:
65
- ["user1", "user2"]
66
- """
67
- return ok(viewer_service.get_viewers(entity_id))
68
-
69
-
70
52
  @tracer.start_as_current_span(f"{__name__}.connect")
71
53
  @socket_api.route("/connect", websocket=True) # type: ignore
72
54
  @websocket_auth(required_priv=["R"])
73
- def connect(ws: Server, *args: Any, ws_id: str, **kwargs): # noqa: C901
55
+ def connect(ws: Server, *args: Any, ws_id: str, **kwargs):
74
56
  """Connect to the server to monitor for updates via websocket
75
57
 
76
58
  Variables:
@@ -96,20 +78,10 @@ def connect(ws: Server, *args: Any, ws_id: str, **kwargs): # noqa: C901
96
78
  logger.debug("Sending action: %s", data)
97
79
  ws.send(ws_response("action", data))
98
80
 
99
- def send_case(data: dict[str, Any]):
100
- logger.debug("Sending case update: %s", data.get("case", {}).get("case_id", "unknown"))
101
- ws.send(ws_response("cases", data))
102
-
103
- def send_viewers_update(data: dict[str, Any]):
104
- logger.debug("Sending viewers update: %s", data.get("id", "unknown"))
105
- ws.send(ws_response("viewers_update", data))
106
-
107
81
  try:
108
82
  event_service.on("hits", send_hit)
109
83
  event_service.on("broadcast", send_broadcast)
110
84
  event_service.on("action", send_action)
111
- event_service.on("cases", send_case)
112
- event_service.on("viewers_update", send_viewers_update)
113
85
  while ws.connected:
114
86
  data = ws.receive(10)
115
87
  if data:
@@ -141,8 +113,6 @@ def connect(ws: Server, *args: Any, ws_id: str, **kwargs): # noqa: C901
141
113
  event_service.off("hits", send_hit)
142
114
  event_service.off("broadcast", send_broadcast)
143
115
  event_service.off("action", send_action)
144
- event_service.off("cases", send_case)
145
- event_service.off("viewers_update", send_viewers_update)
146
116
 
147
117
  for id, action, broadcast in outstanding_actions:
148
118
  outstanding_actions = check_action(id, action, broadcast, outstanding_actions=outstanding_actions, **kwargs)
howler/api/v1/__init__.py CHANGED
@@ -1,8 +1,9 @@
1
- from flask import Blueprint
1
+ from textwrap import dedent
2
+
3
+ from flask import Blueprint, current_app, request
2
4
 
3
5
  from howler.api import ok
4
6
  from howler.security import api_login
5
- from howler.services import docs_service
6
7
 
7
8
  API_PREFIX = "/api/v1"
8
9
  apiv1 = Blueprint("apiv1", __name__, url_prefix=API_PREFIX)
@@ -41,4 +42,56 @@ def get_api_documentation(**kwargs):
41
42
  """
42
43
  user_types = kwargs["user"]["type"]
43
44
 
44
- return ok(docs_service.build_route_docs("v1", user_types))
45
+ api_blueprints = {}
46
+ api_list = []
47
+ for rule in current_app.url_map.iter_rules():
48
+ if rule.rule.startswith(request.path):
49
+ methods = [item for item in (rule.methods or []) if item != "OPTIONS" and item != "HEAD"]
50
+
51
+ func = current_app.view_functions[rule.endpoint]
52
+ required_type = func.__dict__.get("required_type", ["user"])
53
+
54
+ for u_type in user_types:
55
+ if u_type in required_type:
56
+ doc_string = func.__doc__
57
+ func_title = " ".join(
58
+ [x.capitalize() for x in rule.endpoint[rule.endpoint.rindex(".") + 1 :].split("_")]
59
+ )
60
+ blueprint = rule.endpoint[: rule.endpoint.rindex(".")]
61
+ if blueprint == "apiv1":
62
+ blueprint = "documentation"
63
+
64
+ if blueprint not in api_blueprints:
65
+ try:
66
+ doc = current_app.blueprints[rule.endpoint[: rule.endpoint.rindex(".")]]._doc # type: ignore[attr-defined]
67
+ except Exception:
68
+ doc = ""
69
+
70
+ api_blueprints[blueprint] = doc
71
+
72
+ if doc_string:
73
+ description = dedent(doc_string)
74
+ else:
75
+ description = "[INCOMPLETE]\n\nTHIS API HAS NOT BEEN DOCUMENTED YET!"
76
+
77
+ api_id = rule.endpoint.replace("apiv1.", "").replace(".", "_")
78
+
79
+ api_list.append(
80
+ {
81
+ "protected": func.__dict__.get("protected", False),
82
+ "required_type": sorted(required_type),
83
+ "name": func_title,
84
+ "id": api_id,
85
+ "function": f"api.v1.{rule.endpoint}",
86
+ "path": rule.rule,
87
+ "ui_only": rule.rule.startswith("%sui/" % request.path),
88
+ "methods": sorted(methods),
89
+ "description": description,
90
+ "complete": "[INCOMPLETE]" not in description,
91
+ "required_priv": func.__dict__.get("required_priv", []),
92
+ }
93
+ )
94
+
95
+ break
96
+
97
+ return ok({"apis": api_list, "blueprints": api_blueprints})
howler/api/v1/action.py CHANGED
@@ -249,7 +249,8 @@ def execute_action(id: str, **kwargs) -> Response:
249
249
  if not isinstance(execute_req, dict):
250
250
  return bad_request(err="Incorrect data structure!")
251
251
 
252
- action = datastore().action.get(id)
252
+ action: Action = datastore().action.get(id)
253
+
253
254
  if not action:
254
255
  return not_found(err="The specified action does not exist")
255
256