Skip to content

Commit a1e55e7

Browse files
author
Guido Quezada
committed
fix: remove static method from TimeEntriesDao #227
1 parent 5203ff9 commit a1e55e7

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

time_tracker_api/time_entries/time_entries_model.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@
4242

4343

4444
class TimeEntriesDao(CRUDDao):
45-
@staticmethod
46-
def current_user_id():
47-
return current_user_id()
48-
4945
@abc.abstractmethod
5046
def find_running(self):
5147
pass
@@ -374,11 +370,9 @@ class TimeEntriesCosmosDBDao(APICosmosDBDao, TimeEntriesDao):
374370
def __init__(self, repository):
375371
CosmosDBDao.__init__(self, repository)
376372

377-
def check_whether_current_user_owns_item(self, data):
378-
if (
379-
data.owner_id is not None
380-
and data.owner_id != self.current_user_id()
381-
):
373+
@staticmethod
374+
def check_whether_current_user_owns_item(data):
375+
if data.owner_id is not None and data.owner_id != current_user_id():
382376
raise CustomError(
383377
HTTPStatus.FORBIDDEN,
384378
"The current user is not the owner of this time entry",
@@ -424,7 +418,8 @@ def get_all(self, conditions: dict = None, **kwargs) -> list:
424418
conditions.update({"owner_id": event_ctx.user_id})
425419

426420
custom_query = self.build_custom_query(
427-
is_admin=event_ctx.is_admin, conditions=conditions,
421+
is_admin=event_ctx.is_admin,
422+
conditions=conditions,
428423
)
429424
date_range = self.handle_date_filter_args(args=conditions)
430425
limit = conditions.get("limit", None)
@@ -444,7 +439,8 @@ def get_all_paginated(self, conditions: dict = None, **kwargs) -> list:
444439
event_ctx = self.create_event_context("read-many")
445440
get_all_conditions.update({"owner_id": event_ctx.user_id})
446441
custom_query = self.build_custom_query(
447-
is_admin=event_ctx.is_admin, conditions=get_all_conditions,
442+
is_admin=event_ctx.is_admin,
443+
conditions=get_all_conditions,
448444
)
449445
date_range = self.handle_date_filter_args(args=get_all_conditions)
450446
records_total = self.repository.count(
@@ -455,7 +451,8 @@ def get_all_paginated(self, conditions: dict = None, **kwargs) -> list:
455451
)
456452
conditions.update({"owner_id": event_ctx.user_id})
457453
custom_query = self.build_custom_query(
458-
is_admin=event_ctx.is_admin, conditions=conditions,
454+
is_admin=event_ctx.is_admin,
455+
conditions=conditions,
459456
)
460457
date_range = self.handle_date_filter_args(args=conditions)
461458
length = conditions.get("length", None)
@@ -499,7 +496,11 @@ def update(self, id, data: dict, description=None):
499496
time_entry = self.repository.find(id, event_ctx)
500497
self.check_whether_current_user_owns_item(time_entry)
501498

502-
return self.repository.partial_update(id, data, event_ctx,)
499+
return self.repository.partial_update(
500+
id,
501+
data,
502+
event_ctx,
503+
)
503504

504505
def stop(self, id):
505506
event_ctx = self.create_event_context("update", "Stop time entry")
@@ -509,7 +510,9 @@ def stop(self, id):
509510
self.check_time_entry_is_not_stopped(time_entry)
510511

511512
return self.repository.partial_update(
512-
id, {'end_date': current_datetime_str()}, event_ctx,
513+
id,
514+
{'end_date': current_datetime_str()},
515+
event_ctx,
513516
)
514517

515518
def restart(self, id):
@@ -520,15 +523,18 @@ def restart(self, id):
520523
self.check_time_entry_is_not_started(time_entry)
521524

522525
return self.repository.partial_update(
523-
id, {'end_date': None}, event_ctx,
526+
id,
527+
{'end_date': None},
528+
event_ctx,
524529
)
525530

526531
def delete(self, id):
527532
event_ctx = self.create_event_context("delete")
528533
time_entry = self.repository.find(id, event_ctx)
529534
self.check_whether_current_user_owns_item(time_entry)
530535
self.repository.delete(
531-
id, event_ctx,
536+
id,
537+
event_ctx,
532538
)
533539

534540
def find_running(self):

0 commit comments

Comments
 (0)