Skip to content

Commit

Permalink
Merge pull request #246 from phenobarbital/dev
Browse files Browse the repository at this point in the history
list tickets zammad
  • Loading branch information
phenobarbital authored Apr 4, 2024
2 parents 58c9151 + 1eff358 commit 7b9be2f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
28 changes: 22 additions & 6 deletions navigator/actions/zammad.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64
import magic
from urllib.parse import quote_plus
from ..exceptions import ConfigError
from ..conf import (
ZAMMAD_INSTANCE,
Expand All @@ -13,6 +14,8 @@
from .ticket import AbstractTicket
from .rest import RESTAction



class Zammad(AbstractTicket, RESTAction):
"""Zammad.
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion navigator/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 7b9be2f

Please sign in to comment.