diff options
-rw-r--r-- | jimbrella/database.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/jimbrella/database.py b/jimbrella/database.py index b8522ab..a8d480b 100644 --- a/jimbrella/database.py +++ b/jimbrella/database.py @@ -1,6 +1,5 @@ from datetime import datetime, timedelta from .csv_table import CsvTable -from .admin_log import AdminLog from .utils import human_datetime, human_timedelta from .config import DUE_HOURS, ADMIN_LOG_PATH from .exceptions import * @@ -61,7 +60,6 @@ class Database(CsvTable): }, ], ) - self.admin_log = AdminLog(ADMIN_LOG_PATH) def _find_by_serial(self, serial: int) -> dict: """Given a serial number, returns an umbrella with such serial. @@ -201,7 +199,7 @@ class Database(CsvTable): umb = self._find_by_serial(serial) if umb is None: raise UmbrellaNotFoundError(serial) - elif umb["status"] != "available": + if umb["status"] != "available": raise UmbrellaStatusError umb["status"] = "lent" umb["tenant_name"] = tenant_name @@ -210,16 +208,20 @@ class Database(CsvTable): umb["tenant_email"] = tenant_email umb["lent_at"] = date self._update(umb) - self.admin_log.log("TAKEAWAY", umb) - def give_back(self, serial) -> None: - """When a user has returned an umbrella.""" + def give_back(self, serial, tenant_name, tenant_id) -> None: + """When a user has returned an umbrella. + + `tenant_name` and `tenant_id` are used to verify if the umbrella is returned by the same + person who borrowed it. + """ umb = self._find_by_serial(serial) if umb is None: raise UmbrellaNotFoundError(serial) - elif umb["status"] not in ("lent", "overdue"): + if umb["status"] not in ("lent", "overdue"): raise UmbrellaStatusError - self.admin_log.log("GIVEBACK", umb) + if umb["tenant_name"] != tenant_name or umb["tenant_id"] != tenant_id: + raise TenantIdentityError(umb["tenant_name"], tenant_name) umb["status"] = "available" for key in ["tenant_name", "tenant_id", "tenant_phone", "tenant_email"]: umb[key] = "" @@ -235,4 +237,3 @@ class Database(CsvTable): raise UmbrellaStatusError umb["status"] = "overdue" self._update(umb) - self.admin_log.log("OVERDUE", umb) |