Skip to content

Commit

Permalink
Merge pull request #220 from ynput/enhancement/use-statuses-for-event…
Browse files Browse the repository at this point in the history
…-filtering

Events: Use statuses for events filtering
  • Loading branch information
iLLiCiTiT authored Nov 29, 2024
2 parents 4682928 + 2abb1e4 commit 5da44b5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 28 deletions.
28 changes: 16 additions & 12 deletions ayon_api/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,16 +871,17 @@ def get_event(


def get_events(
topics=None,
event_ids=None,
project_names=None,
states=None,
users=None,
include_logs=None,
has_children=None,
newer_than=None,
older_than=None,
fields=None,
topics: Optional[Iterable[str]] = None,
event_ids: Optional[Iterable[str]] = None,
project_names: Optional[Iterable[str]] = None,
statuses: Optional[Iterable[str]] = None,
users: Optional[Iterable[str]] = None,
include_logs: Optional[bool] = None,
has_children: Optional[bool] = None,
newer_than: Optional[str] = None,
older_than: Optional[str] = None,
fields: Optional[Iterable[str]] = None,
states: Optional[Iterable[str]] = None,
):
"""Get events from server with filtering options.
Expand All @@ -892,7 +893,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 @@ -904,6 +905,8 @@ 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.
Expand All @@ -914,13 +917,14 @@ def get_events(
topics=topics,
event_ids=event_ids,
project_names=project_names,
states=states,
statuses=statuses,
users=users,
include_logs=include_logs,
has_children=has_children,
newer_than=newer_than,
older_than=older_than,
fields=fields,
states=states,
)


Expand Down
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
43 changes: 30 additions & 13 deletions ayon_api/server_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1455,16 +1455,17 @@ def get_event(self, event_id):

def get_events(
self,
topics=None,
event_ids=None,
project_names=None,
states=None,
users=None,
include_logs=None,
has_children=None,
newer_than=None,
older_than=None,
fields=None
topics: Optional[Iterable[str]] = None,
event_ids: Optional[Iterable[str]] = None,
project_names: Optional[Iterable[str]] = None,
statuses: Optional[Iterable[str]] = None,
users: Optional[Iterable[str]] = None,
include_logs: Optional[bool] = None,
has_children: Optional[bool] = None,
newer_than: Optional[str] = None,
older_than: Optional[str] = None,
fields: Optional[Iterable[str]] = None,
states: Optional[Iterable[str]] = 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 5da44b5

Please sign in to comment.