Skip to content

Commit

Permalink
Merge pull request #106 from DNO-inc/bodya
Browse files Browse the repository at this point in the history
added the ability to filter tickets by 'scope' and 'queues'
  • Loading branch information
m-o-d-e-r authored Jul 29, 2023
2 parents 151e184 + 2ee37f4 commit 0c99053
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
4 changes: 3 additions & 1 deletion burrito/apps/admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
q_is_valid_faculty,
q_is_valid_queue,
q_is_valid_status_list,
q_scope_is,
q_is_hidden,
)
from burrito.utils.users_util import get_user_by_id
Expand Down Expand Up @@ -157,8 +158,9 @@ async def admin__get_ticket_list_by_filter(
"hidden": q_is_hidden(filters.hidden),
"anonymous": q_is_anonymous(filters.anonymous),
"faculty": q_is_valid_faculty(filters.faculty) if filters.faculty else None,
"status": q_is_valid_status_list(filters.status),
"scope": q_scope_is(filters.scope) if filters.scope else None,
"queue": q_is_valid_queue(filters.queue) if filters.queue else None,
"status": q_is_valid_status_list(filters.status)
}
final_filters = select_filters(available_filters, filters)

Expand Down
4 changes: 3 additions & 1 deletion burrito/apps/anon/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
q_is_anonymous,
q_is_valid_faculty,
q_is_valid_queue,
q_scope_is,
q_is_valid_status_list,
q_not_hidden,
q_protected_statuses
Expand All @@ -35,8 +36,9 @@ async def anon__get_ticket_list_by_filter(filters: AnonTicketListRequestSchema):
available_filters = {
"anonymous": q_is_anonymous(filters.anonymous),
"faculty": q_is_valid_faculty(filters.faculty) if filters.faculty else None,
"status": q_is_valid_status_list(filters.status),
"scope": q_scope_is(filters.scope) if filters.scope else None,
"queue": q_is_valid_queue(filters.queue) if filters.queue else None,
"status": q_is_valid_status_list(filters.status)
}
final_filters = select_filters(available_filters, filters) + [
q_not_hidden(),
Expand Down
21 changes: 13 additions & 8 deletions burrito/apps/tickets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
q_is_anonymous,
q_is_valid_faculty,
q_is_valid_queue,
q_scope_is,
q_is_valid_status_list,
q_protected_statuses,
q_not_hidden,
Expand Down Expand Up @@ -349,8 +350,9 @@ async def tickets__show_tickets_list_by_filter(
"hidden": q_is_hidden(filters.hidden),
"anonymous": q_is_anonymous(filters.anonymous),
"faculty": q_is_valid_faculty(filters.faculty) if filters.faculty else None,
"queue": q_is_valid_queue(filters.queue) if filters.queue else None,
"status": q_is_valid_status_list(filters.status)
"status": q_is_valid_status_list(filters.status),
"scope": q_scope_is(filters.scope) if filters.scope else None,
"queue": q_is_valid_queue(filters.queue) if filters.queue else None
}
final_filters = select_filters(available_filters, filters) + (
[
Expand Down Expand Up @@ -528,8 +530,9 @@ async def tickets__get_liked_tickets(
"hidden": q_is_hidden(_filters.hidden),
"anonymous": q_is_anonymous(_filters.anonymous),
"faculty": q_is_valid_faculty(_filters.faculty) if _filters.faculty else None,
"queue": q_is_valid_queue(_filters.queue) if _filters.queue else None,
"status": q_is_valid_status_list(_filters.status)
"status": q_is_valid_status_list(_filters.status),
"scope": q_scope_is(_filters.scope) if _filters.scope else None,
"queue": q_is_valid_queue(_filters.queue) if _filters.queue else None
}
final_filters = select_filters(available_filters, _filters) + [
q_not_deleted(token_payload.user_id),
Expand Down Expand Up @@ -595,9 +598,10 @@ async def tickets__get_bookmarked_tickets(
"hidden": q_is_hidden(_filters.hidden),
"anonymous": q_is_anonymous(_filters.anonymous),
"faculty": q_is_valid_faculty(_filters.faculty) if _filters.faculty else None,
"queue": q_is_valid_queue(_filters.queue) if _filters.queue else None,
"status": q_is_valid_status_list(_filters.status),
"bookmarks_type": q_bookmarked(token_payload.user_id, _filters.bookmarks_type)
"bookmarks_type": q_bookmarked(token_payload.user_id, _filters.bookmarks_type),
"scope": q_scope_is(_filters.scope) if _filters.scope else None,
"queue": q_is_valid_queue(_filters.queue) if _filters.queue else None
}
final_filters = select_filters(available_filters, _filters) + [
q_not_deleted(token_payload.user_id)
Expand Down Expand Up @@ -659,8 +663,9 @@ async def tickets__get_deleted_tickets(
"hidden": q_is_hidden(_filters.hidden),
"anonymous": q_is_anonymous(_filters.anonymous),
"faculty": q_is_valid_faculty(_filters.faculty) if _filters.faculty else None,
"queue": q_is_valid_queue(_filters.queue) if _filters.queue else None,
"status": q_is_valid_status_list(_filters.status)
"status": q_is_valid_status_list(_filters.status),
"scope": q_scope_is(_filters.scope) if _filters.scope else None,
"queue": q_is_valid_queue(_filters.queue) if _filters.queue else None
}
final_filters = select_filters(available_filters, _filters) + [
q_deleted(token_payload.user_id)
Expand Down
3 changes: 2 additions & 1 deletion burrito/schemas/filters_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
class BaseFilterSchema(BurritoPagination):
anonymous: bool | None
faculty: int | None
queue: int | None
status: list[int] | None
scope: str | None
queue: list[int] | None
11 changes: 9 additions & 2 deletions burrito/utils/query_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from burrito.models.statuses_model import Statuses
from burrito.models.tickets_model import Tickets
from burrito.models.deleted_model import Deleted
from burrito.models.queues_model import Queues
from burrito.models.liked_model import Liked

from burrito.utils.converter import (
Expand Down Expand Up @@ -58,8 +59,14 @@ def q_is_valid_faculty(value: int) -> Expression:
return Tickets.faculty == FacultyConverter.convert(value)


def q_is_valid_queue(queue: int) -> Expression:
return Tickets.queue == QueueConverter.convert(queue)
def q_scope_is(scope: str) -> Expression:
return Tickets.queue.in_(
Queues.select(Queues.queue_id).where(Queues.scope == scope)
)


def q_is_valid_queue(queues: list[int]) -> Expression:
return Tickets.queue.in_(queues)


def q_is_valid_status(value: int) -> Expression:
Expand Down
8 changes: 5 additions & 3 deletions tests/admin_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ def test_002_admin_ticket_list_view(self):
"Authorization": f"Bearer {AuthTestCase.access_token}"
},
json={
"status": [1],
# "hidden": True,
# "anonymous": True
"scope": 'Reports',
"queue": [2],
"status": [6],
"hidden": True,
"anonymous": True
},
timeout=TIMEOUT
)
Expand Down

0 comments on commit 0c99053

Please sign in to comment.