Много изменений в бд

This commit is contained in:
2025-05-30 12:19:25 +03:00
parent 21b202f090
commit f21acb23ab
6 changed files with 173 additions and 65 deletions

View File

@@ -23,7 +23,8 @@ class RedmineAPI(RedmineConfig):
"""
def __init__(self, token):
super().__init__()
self.token = self._check_token(token)
self.token = token
self._check_token()
def track_activities(self, activities: list[Activity]) -> list[Activity]:
"""Заносит трудочасы на сервер Redmine"""
@@ -75,12 +76,21 @@ class RedmineAPI(RedmineConfig):
if act.get("active")
]
def _check_token(self, token):
"""Проверяет токен"""
resp = requests.get(self.base_url + self.my_account_url, headers={"X-Redmine-Api-Key": token})
def get_user(self):
"""Проверяет токен и возвращает данные юзера"""
resp = requests.get(self.base_url + self.my_account_url, headers={"X-Redmine-Api-Key": self.token})
if not resp.ok:
logger.error("Invalid Token for RedmineAPI")
raise InvalidToken
resp = resp.json()['user']
logger.debug({"login": resp["login"], "email": resp["mail"], "full_name": f'{resp["firstname"]} {resp["lastname"]}'})
return token
json = resp.json()["user"]
return {
"id": json["id"],
"first_name": json["firstname"],
"last_name": json["lastname"],
"email": json["mail"],
"username": json["login"]
}
def _check_token(self):
user = self.get_user()
logging.debug(user)