Fixed settings dto #70

This commit is contained in:
Sven Heidemann 2022-10-16 21:29:58 +02:00
parent 29fa35dffe
commit f634ad552e
3 changed files with 29 additions and 10 deletions

View File

@ -4,8 +4,10 @@ from cpl_core.configuration import ConfigurationABC
from cpl_core.environment import ApplicationEnvironmentABC from cpl_core.environment import ApplicationEnvironmentABC
from cpl_core.mailing import EMail, EMailClientABC, EMailClientSettings from cpl_core.mailing import EMail, EMailClientABC, EMailClientSettings
from cpl_translation import TranslatePipe from cpl_translation import TranslatePipe
from flask import jsonify
from bot_api.api import Api from bot_api.api import Api
from bot_api.configuration.authentication_settings import AuthenticationSettings
from bot_api.logging.api_logger import ApiLogger from bot_api.logging.api_logger import ApiLogger
from bot_api.model.settings_dto import SettingsDTO from bot_api.model.settings_dto import SettingsDTO
from bot_api.model.version_dto import VersionDTO from bot_api.model.version_dto import VersionDTO
@ -23,7 +25,8 @@ class GuiController:
t: TranslatePipe, t: TranslatePipe,
api: Api, api: Api,
mail_settings: EMailClientSettings, mail_settings: EMailClientSettings,
mailer: EMailClientABC mailer: EMailClientABC,
auth_settings: AuthenticationSettings
): ):
self._config = config self._config = config
self._env = env self._env = env
@ -32,6 +35,7 @@ class GuiController:
self._api = api self._api = api
self._mail_settings = mail_settings self._mail_settings = mail_settings
self._mailer = mailer self._mailer = mailer
self._auth_settings = auth_settings
@Route.get(f'{BasePath}/api-version') @Route.get(f'{BasePath}/api-version')
async def api_version(self): async def api_version(self):
@ -42,29 +46,27 @@ class GuiController:
@Route.get(f'{BasePath}/settings') @Route.get(f'{BasePath}/settings')
@Route.authorize @Route.authorize
async def settings(self): async def settings(self):
# TODO: Authentication
import bot_api import bot_api
version = bot_api.version_info version = bot_api.version_info
return SettingsDTO( return jsonify(SettingsDTO(
'', '',
VersionDTO(version.major, version.minor, version.micro), VersionDTO(version.major, version.minor, version.micro),
os.path.abspath(os.path.join(self._env.working_directory, 'config')), os.path.abspath(os.path.join(self._env.working_directory, 'config')),
'',
'/', '/',
0, '/',
0, self._auth_settings.token_expire_time,
self._auth_settings.refresh_token_expire_time,
self._mail_settings.user_name, self._mail_settings.user_name,
self._mail_settings.port, self._mail_settings.port,
self._mail_settings.host, self._mail_settings.host,
self._mail_settings.user_name, self._mail_settings.user_name,
self._mail_settings.user_name, self._mail_settings.user_name,
).to_dict() ).to_dict())
@Route.get(f'{BasePath}/send-test-mail/<email>') @Route.post(f'{BasePath}/send-test-mail/<email>')
@Route.authorize @Route.authorize
async def send_test_mail(self, email: str): async def send_test_mail(self, email: str):
# TODO: Authentication
mail = EMail() mail = EMail()
mail.add_header('Mime-Version: 1.0') mail.add_header('Mime-Version: 1.0')
mail.add_header('Content-Type: text/plain; charset=utf-8') mail.add_header('Content-Type: text/plain; charset=utf-8')
@ -73,3 +75,4 @@ class GuiController:
mail.subject = self._t.transform('api.api.test_mail.subject') mail.subject = self._t.transform('api.api.test_mail.subject')
mail.body = self._t.transform('api.api.test_mail.message').format(self._env.host_name, self._env.environment_name) mail.body = self._t.transform('api.api.test_mail.message').format(self._env.host_name, self._env.environment_name)
self._mailer.send_mail(mail) self._mailer.send_mail(mail)
return '', 200

View File

@ -53,7 +53,7 @@ class SettingsDTO(DtoABC):
def to_dict(self) -> dict: def to_dict(self) -> dict:
return { return {
'webVersion': self._web_version, 'webVersion': self._web_version,
'apiVersion': self._api_version.to_dict(), 'apiVersion': self._api_version.str,
'configPath': self._config_path, 'configPath': self._config_path,
'webBaseURL': self._web_base_url, 'webBaseURL': self._web_base_url,
'apiBaseURL': self._api_base_url, 'apiBaseURL': self._api_base_url,

View File

@ -14,6 +14,22 @@ class VersionDTO(DtoABC):
self._minor = minor self._minor = minor
self._micro = micro self._micro = micro
@property
def major(self) -> str:
return self._major
@property
def minor(self) -> str:
return self._minor
@property
def micro(self) -> str:
return self._micro
@property
def str(self) -> str:
return f'{self._major}.{self._minor}.{self._micro}'
def from_dict(self, values: dict): def from_dict(self, values: dict):
self._major = values['major'] self._major = values['major']
self._minor = values['minor'] self._minor = values['minor']