Skip to content

Commit

Permalink
use statuses for events filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
iLLiCiTiT committed Nov 28, 2024
1 parent 7e2b9b4 commit f1e4d82
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
9 changes: 6 additions & 3 deletions ayon_api/graphql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,23 +570,26 @@ def workfiles_info_graphql_query(fields):
return query


def events_graphql_query(fields):
def events_graphql_query(fields, use_states=False):
query = GraphQlQuery("Events")
topics_var = query.add_variable("eventTopics", "[String!]")
ids_var = query.add_variable("eventIds", "[String!]")
projects_var = query.add_variable("projectNames", "[String!]")
states_var = query.add_variable("eventStates", "[String!]")
statuses_var = query.add_variable("eventStatuses", "[String!]")
users_var = query.add_variable("eventUsers", "[String!]")
include_logs_var = query.add_variable("includeLogsFilter", "Boolean!")
has_children_var = query.add_variable("hasChildrenFilter", "Boolean!")
newer_than_var = query.add_variable("newerThanFilter", "String!")
older_than_var = query.add_variable("olderThanFilter", "String!")

statuses_filter_name = "statuses"
if use_states:
statuses_filter_name = "states"
events_field = query.add_field_with_edges("events")
events_field.set_filter("ids", ids_var)
events_field.set_filter("topics", topics_var)
events_field.set_filter("projects", projects_var)
events_field.set_filter("states", states_var)
events_field.set_filter(statuses_filter_name, statuses_var)
events_field.set_filter("users", users_var)
events_field.set_filter("includeLogs", include_logs_var)
events_field.set_filter("hasChildren", has_children_var)
Expand Down
27 changes: 22 additions & 5 deletions ayon_api/server_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1458,13 +1458,14 @@ def get_events(
topics=None,
event_ids=None,
project_names=None,
states=None,
statuses=None,
users=None,
include_logs=None,
has_children=None,
newer_than=None,
older_than=None,
fields=None
fields=None,
states=None,
):
"""Get events from server with filtering options.
Expand All @@ -1476,7 +1477,7 @@ def get_events(
event_ids (Optional[Iterable[str]]): Event ids.
project_names (Optional[Iterable[str]]): Project on which
event happened.
states (Optional[Iterable[str]]): Filtering by states.
statuses (Optional[Iterable[str]]): Filtering by statuses.
users (Optional[Iterable[str]]): Filtering by users
who created/triggered an event.
include_logs (Optional[bool]): Query also log events.
Expand All @@ -1488,18 +1489,31 @@ def get_events(
iso datetime string.
fields (Optional[Iterable[str]]): Fields that should be received
for each event.
states (Optional[Iterable[str]]): DEPRECATED Filtering by states.
Use 'statuses' instead.
Returns:
Generator[dict[str, Any]]: Available events matching filters.
"""
if statuses is None and states is not None:
warnings.warn(
(
"Used deprecated argument 'states' in 'get_events'."
" Use 'statuses' instead."
),
DeprecationWarning
)
statuses = states


filters = {}
if not _prepare_list_filters(
filters,
("eventTopics", topics),
("eventIds", event_ids),
("projectNames", project_names),
("eventStates", states),
("eventStatuses", statuses),
("eventUsers", users),
):
return
Expand All @@ -1519,7 +1533,10 @@ def get_events(
if not fields:
fields = self.get_default_fields_for_type("event")

query = events_graphql_query(set(fields))
major, minor, patch, _, _ = self.server_version_tuple
use_states = (major, minor, patch) <= (1, 5, 6)

query = events_graphql_query(set(fields), use_states)
for attr, filter_value in filters.items():
query.set_variable_value(attr, filter_value)

Expand Down

0 comments on commit f1e4d82

Please sign in to comment.