From 1eff358e7a961dc21d4a5cbcd15e0a3c4545fae9 Mon Sep 17 00:00:00 2001 From: Jesus Lara Date: Fri, 5 Apr 2024 00:02:35 +0200 Subject: [PATCH] list tickets zammad --- navigator/actions/zammad.py | 28 ++++++++++++++++++++++------ navigator/version.py | 2 +- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/navigator/actions/zammad.py b/navigator/actions/zammad.py index 93761ece..572d068b 100644 --- a/navigator/actions/zammad.py +++ b/navigator/actions/zammad.py @@ -1,5 +1,6 @@ import base64 import magic +from urllib.parse import quote_plus from ..exceptions import ConfigError from ..conf import ( ZAMMAD_INSTANCE, @@ -13,6 +14,8 @@ from .ticket import AbstractTicket from .rest import RESTAction + + class Zammad(AbstractTicket, RESTAction): """Zammad. @@ -67,13 +70,25 @@ async def get_user_token(self): ) return result['token'] - async def list_tickets(self): + async def list_tickets(self, **kwargs): """list_tickets. Getting a List of all opened tickets by User. """ self.method = 'get' - self.url = f"{self.zammad_instance}api/v1/tickets/search?query=state_id:%201%20OR%20state_id:%202%20OR%20state_id:%203" + states = kwargs.pop('state_id', [1, 2, 3]) # Open by Default + if ',' in states: + states = states.split(',') + + if states: + # Then, after getting the states, we can join them with a delimiter + # state_id: 1 OR state_id: 2 OR state_id: 3 + state_id_parts = ["state_id:{}".format(state) for state in states[1:]] + query_string = "state_id:{} OR ".format(states[0]) + " OR ".join(state_id_parts) + qs = quote_plus(query_string) + else: + qs = "state_id:%201%20OR%20state_id:%202%20OR%20state_id:%203" + self.url = f"{self.zammad_instance}api/v1/tickets/search?query={qs}" try: result, _ = await self.request( self.url, self.method @@ -84,10 +99,10 @@ async def list_tickets(self): f"Error getting Zammad Tickets: {e}" ) from e - async def update(self, ticket: int): - """list_tickets. + async def update(self, ticket: int, **kwargs): + """update. - Getting a List of all opened tickets by User. + Update an Existing Ticket. """ self.method = 'post' title = self._kwargs.pop('title', None) @@ -118,7 +133,8 @@ async def update(self, ticket: int): "group": group, "customer": customer, "service_catalog": service_catalog, - "article": article + "article": article, + **kwargs } try: result, _ = await self.request( diff --git a/navigator/version.py b/navigator/version.py index 4ccbb32f..c623e92a 100644 --- a/navigator/version.py +++ b/navigator/version.py @@ -4,7 +4,7 @@ __description__ = ( "Navigator Web Framework based on aiohttp, " "with batteries included." ) -__version__ = "2.8.38" +__version__ = "2.8.39" __author__ = "Jesus Lara" __author_email__ = "jesuslarag@gmail.com" __license__ = "BSD"