Skip to content

Commit

Permalink
Merge pull request #79 from DNO-inc/bodya
Browse files Browse the repository at this point in the history
 replaced str values of groups, statuses, and faculties with int-based values
  • Loading branch information
m-o-d-e-r authored Jun 25, 2023
2 parents 48f3511 + b3517ce commit a5da007
Show file tree
Hide file tree
Showing 35 changed files with 541 additions and 281 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ _delete_docker_container:

docker_run: _delete_docker_container Dockerfile
docker run --env-file .env --name burrito_love burrito

rmi:
docker rmi $(docker images -q) 2> /dev/null
2 changes: 1 addition & 1 deletion burrito/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.5 indev"
__version__ = "0.5.6 indev"
7 changes: 7 additions & 0 deletions burrito/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

init_manager.run_cycle()

#from burrito.utils.db_preprocessor import LocalDataBasePreprocessor
#db_preprocessor = LocalDataBasePreprocessor(
# {"filename": "./preprocessor_config.json"}
#)
#db_preprocessor.apply_data()


if not init_manager.critical:
import uvicorn
from prometheus_fastapi_instrumentator import Instrumentator, metrics
Expand Down
30 changes: 15 additions & 15 deletions burrito/apps/admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
)
from burrito.utils.auth import get_auth_core
from burrito.utils.converter import (
StatusStrToModel,
FacultyStrToModel,
QueueStrToModel
StatusConverter,
FacultyConverter,
QueueConverter
)

from .utils import (
Expand All @@ -69,22 +69,22 @@ async def admin__update_ticket_data(
admin_updates.ticket_id
)

faculty_object = FacultyStrToModel.convert(admin_updates.faculty)
faculty_object = FacultyConverter.convert(admin_updates.faculty)
if faculty_object: # faculty_id must be > 1
create_ticket_action(
ticket_id=admin_updates.ticket_id,
author_id=token_payload.user_id,
user_id=token_payload.user_id,
field_name="faculty",
old_value=ticket.faculty.name,
new_value=faculty_object.name
)
ticket.faculty = faculty_object

queue_object = QueueStrToModel.convert(admin_updates.queue, admin_updates.faculty)
queue_object = QueueConverter.convert(admin_updates.queue) if admin_updates.queue else None
if queue_object: # queue_id must be > 1
create_ticket_action(
ticket_id=admin_updates.ticket_id,
author_id=token_payload.user_id,
user_id=token_payload.user_id,
field_name="queue",
old_value=ticket.queue.name,
new_value=queue_object.name
Expand All @@ -94,11 +94,11 @@ async def admin__update_ticket_data(
current_admin: Users | None = get_user_by_id(token_payload.user_id)
status_object = None
if ticket.assignee == current_admin:
status_object = StatusStrToModel.convert(admin_updates.status)
status_object = StatusConverter.convert(admin_updates.status)
if status_object: # status_id must be > 1
create_ticket_action(
ticket_id=admin_updates.ticket_id,
author_id=token_payload.user_id,
user_id=token_payload.user_id,
field_name="status",
old_value=ticket.status.name,
new_value=status_object.name
Expand Down Expand Up @@ -128,8 +128,8 @@ async def admin__get_ticket_list_by_filter(
available_filters = {
"hidden": q_is_hidden(filters.hidden),
"anonymous": q_is_anonymous(filters.anonymous),
"faculty": q_is_valid_faculty(filters.faculty),
"queue": q_is_valid_queue(filters.queue, filters.faculty),
"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)
}
final_filters = select_filters(available_filters, filters)
Expand Down Expand Up @@ -326,17 +326,17 @@ async def admin__become_an_assignee(
)
create_ticket_action(
ticket_id=ticket_data.ticket_id,
author_id=token_payload.user_id,
user_id=token_payload.user_id,
field_name="assignee",
old_value=ticket.assignee.login,
old_value="None",
new_value=current_admin.login
)
ticket.assignee = current_admin

new_status = StatusStrToModel.convert("OPEN")
new_status = StatusConverter.convert(1)
create_ticket_action(
ticket_id=ticket_data.ticket_id,
author_id=token_payload.user_id,
user_id=token_payload.user_id,
field_name="status",
old_value=ticket.status.name,
new_value=new_status.name
Expand Down
4 changes: 2 additions & 2 deletions burrito/apps/anon/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
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),
"queue": q_is_valid_queue(filters.queue, filters.faculty),
"faculty": q_is_valid_faculty(filters.faculty) if filters.faculty else None,
"queue": q_is_valid_queue(filters.queue, filters.faculty) if filters.faculty and filters.faculty else None,
"status": q_is_valid_status_list(filters.status)
}
final_filters = select_filters(available_filters, filters) + [
Expand Down
10 changes: 2 additions & 8 deletions burrito/apps/meta/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from burrito.schemas.status_schema import StatusResponseSchema
from burrito.schemas.queue_schema import QueueResponseSchema

from burrito.utils.converter import FacultyStrToModel
from burrito.utils.converter import FacultyConverter


async def meta__get_statuses_list():
Expand Down Expand Up @@ -52,13 +52,7 @@ async def meta__faculties_list():


async def meta__get_queues_list(faculty_data: RequestQueueListSchema):
faculty_object = FacultyStrToModel.convert(faculty_data.faculty)

if not faculty_object:
return JSONResponse(
status_code=status.HTTP_403_FORBIDDEN,
content={"detail": "Faculty name is wrong"}
)
faculty_object = FacultyConverter.convert(faculty_data.faculty)

response_list: list[QueueResponseSchema] = []
for queue in Queues.select().where(
Expand Down
9 changes: 7 additions & 2 deletions burrito/apps/profile/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from playhouse.shortcuts import model_to_dict

from burrito.utils.auth import get_auth_core
from burrito.utils.users_util import get_user_by_id

Expand All @@ -8,6 +10,9 @@
from burrito.models.group_model import Groups

from burrito.schemas.profile_schema import ResponseProfileSchema
from burrito.schemas.faculty_schema import FacultyResponseSchema
from burrito.schemas.group_schema import GroupResponseSchema


__all__ = (
"get_auth_core",
Expand All @@ -27,8 +32,8 @@ async def view_profile_by_user_id(user_id: int) -> ResponseProfileSchema | None:
firstname=current_user.firstname,
lastname=current_user.lastname,
login=current_user.login,
faculty=faculty_object.name if faculty_object else None,
group=group_object.name if group_object else None,
faculty=FacultyResponseSchema(**model_to_dict(faculty_object)) if faculty_object else None,
group=GroupResponseSchema(**model_to_dict(group_object)) if group_object else None,
phone=current_user.phone,
email=current_user.email,
registration_date=str(current_user.registration_date)
Expand Down
10 changes: 5 additions & 5 deletions burrito/apps/profile/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
)

from burrito.utils.converter import (
FacultyStrToModel,
GroupStrToModel
FacultyConverter,
GroupConverter
)

from .utils import (
Expand Down Expand Up @@ -52,7 +52,7 @@ async def profile__check_by_id(

@check_permission(permission_list={"UPDATE_PROFILE"})
async def profile__update_my_profile(
profile_updated_data: RequestUpdateProfileSchema,
profile_updated_data: RequestUpdateProfileSchema | None = RequestUpdateProfileSchema(),
Authorize: AuthJWT = Depends(get_auth_core())
):
"""Update profile data"""
Expand All @@ -77,12 +77,12 @@ async def profile__update_my_profile(
current_user.email = profile_updated_data.email

# check faculty
faculty_id = FacultyStrToModel.convert(profile_updated_data.faculty)
faculty_id = FacultyConverter.convert(profile_updated_data.faculty)
if faculty_id and profile_updated_data.faculty:
current_user.faculty = faculty_id

# check group
group_id = GroupStrToModel.convert(profile_updated_data.group)
group_id = GroupConverter.convert(profile_updated_data.group)
if group_id and profile_updated_data.group:
current_user.group = group_id

Expand Down
8 changes: 5 additions & 3 deletions burrito/apps/registration/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from burrito.models.user_model import Users

from burrito.utils.converter import GroupConverter, FacultyConverter

from burrito.utils.auth import get_auth_core
from burrito.utils.auth_token_util import (
AuthTokenPayload,
Expand Down Expand Up @@ -47,8 +49,8 @@ async def registration__user_registration(
current_user: Users | None = create_user_tmp_foo(
user_data.login,
get_hash(user_data.password),
user_data.group,
user_data.faculty
GroupConverter.convert(user_data.group),
FacultyConverter.convert(user_data.faculty)
)

if current_user:
Expand All @@ -75,5 +77,5 @@ async def registration__user_registration(

return JSONResponse(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
content={"detail": "Group or faculty is not valid"}
content={"detail": "..."}
)
22 changes: 11 additions & 11 deletions burrito/apps/tickets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@
)
from burrito.utils.logger import get_logger
from burrito.utils.converter import (
FacultyStrToModel,
StatusStrToModel
FacultyConverter,
StatusConverter,
QueueConverter
)

from .utils import (
Expand All @@ -78,9 +79,8 @@ async def tickets__create_new_ticket(
Authorize.get_jwt_subject()
)

faculty_id = FacultyStrToModel.convert(ticket_creation_data.faculty)

queue: Queues | None = Queues.get_or_none(Queues.queue_id == ticket_creation_data.queue)
faculty_id = FacultyConverter.convert(ticket_creation_data.faculty)
queue: Queues = QueueConverter.convert(ticket_creation_data.queue)

ticket: Tickets = Tickets.create(
creator=token_payload.user_id,
Expand Down Expand Up @@ -326,8 +326,8 @@ async def tickets__show_tickets_list_by_filter(
"creator": q_is_creator(filters.creator),
"hidden": q_is_hidden(filters.hidden),
"anonymous": q_is_anonymous(filters.anonymous),
"faculty": q_is_valid_faculty(filters.faculty),
"queue": q_is_valid_queue(filters.queue, filters.faculty),
"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)
}
final_filters = select_filters(available_filters, filters) + (
Expand Down Expand Up @@ -545,11 +545,11 @@ async def tickets__close_own_ticket(
token_payload.user_id
)

status_name = "CLOSE"
status_object = StatusStrToModel.convert(status_name)
status_id = 6
status_object = StatusConverter.convert(status_id)

if not status_object:
get_logger().critical(f"Status {status_name} is not exist in database")
get_logger().critical(f"Status {status_id} is not exist in database")

return JSONResponse(
status_code=500,
Expand All @@ -558,7 +558,7 @@ async def tickets__close_own_ticket(

create_ticket_action(
ticket_id=data_to_close_ticket.ticket_id,
author_id=token_payload.user_id,
user_id=token_payload.user_id,
field_name="status",
old_value=ticket.status.name,
new_value=status_object.name
Expand Down
2 changes: 1 addition & 1 deletion burrito/models/actions_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Actions(BurritoBasicModel):
on_delete="NO ACTION"
)

author = ForeignKeyField(
user = ForeignKeyField(
Users,
field="user_id",
on_delete="NO ACTION"
Expand Down
2 changes: 1 addition & 1 deletion burrito/schemas/action_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class ActionSchema(BaseModel):
action_id: int
ticket_id: int
author_id: int
user_id: int
action_date: str
field_name: str
old_value: str
Expand Down
6 changes: 3 additions & 3 deletions burrito/schemas/admin_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

class AdminUpdateTicketSchema(BaseModel):
ticket_id: int
faculty: str | None
queue: str | None
status: str | None
faculty: int | None
queue: int | None
status: int | None


class AdminGetTicketListSchema(BurritoPagination):
Expand Down
2 changes: 1 addition & 1 deletion burrito/schemas/anon_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AnonTicketListRequestSchema(BurritoPagination):
anonymous: bool | None
faculty: str | None
queue: str | None
status: list[str] | None
status: list[int] | None


class AnonTicketUsersInfoSchema(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion burrito/schemas/meta_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ResponseFacultiesListSchema(BaseModel):


class RequestQueueListSchema(BaseModel):
faculty: str
faculty: int


class ResponseQueueListSchema(BaseModel):
Expand Down
10 changes: 8 additions & 2 deletions burrito/schemas/profile_schema.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from pydantic import BaseModel

from burrito.schemas.faculty_schema import FacultyResponseSchema
from burrito.schemas.group_schema import GroupResponseSchema


class CheckProfileSchema(BaseModel):
user_id: int | None
Expand Down Expand Up @@ -28,8 +31,8 @@ class BaseProfile(BaseModel):

login: str

faculty: str | None
group: str | None
faculty: int | None
group: int | None

phone: str | None
email: str | None
Expand All @@ -44,6 +47,9 @@ class ResponseProfileSchema(BaseProfile):
registration_date (str): date when user registered account
"""

faculty: FacultyResponseSchema | None
group: GroupResponseSchema | None

registration_date: str


Expand Down
4 changes: 2 additions & 2 deletions burrito/schemas/registration_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
class RegistrationSchema(BaseModel):
login: str
password: str
group: str
faculty: str
group: int
faculty: int
Loading

0 comments on commit a5da007

Please sign in to comment.