0.3 #146

Merged
edraft merged 359 commits from 0.3 into master 2023-01-12 07:04:40 +01:00
3 changed files with 29 additions and 10 deletions
Showing only changes of commit f634ad552e - Show all commits

View File

@ -4,8 +4,10 @@ from cpl_core.configuration import ConfigurationABC
from cpl_core.environment import ApplicationEnvironmentABC
from cpl_core.mailing import EMail, EMailClientABC, EMailClientSettings
from cpl_translation import TranslatePipe
from flask import jsonify
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.model.settings_dto import SettingsDTO
from bot_api.model.version_dto import VersionDTO
@ -23,7 +25,8 @@ class GuiController:
t: TranslatePipe,
api: Api,
mail_settings: EMailClientSettings,
mailer: EMailClientABC
mailer: EMailClientABC,
auth_settings: AuthenticationSettings
):
self._config = config
self._env = env
@ -32,6 +35,7 @@ class GuiController:
self._api = api
self._mail_settings = mail_settings
self._mailer = mailer
self._auth_settings = auth_settings
@Route.get(f'{BasePath}/api-version')
async def api_version(self):
@ -42,29 +46,27 @@ class GuiController:
@Route.get(f'{BasePath}/settings')
@Route.authorize
async def settings(self):
# TODO: Authentication
import bot_api
version = bot_api.version_info
return SettingsDTO(
return jsonify(SettingsDTO(
'',
VersionDTO(version.major, version.minor, version.micro),
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.port,
self._mail_settings.host,
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
async def send_test_mail(self, email: str):
# TODO: Authentication
mail = EMail()
mail.add_header('Mime-Version: 1.0')
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.body = self._t.transform('api.api.test_mail.message').format(self._env.host_name, self._env.environment_name)
self._mailer.send_mail(mail)
return '', 200

View File

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

View File

@ -14,6 +14,22 @@ class VersionDTO(DtoABC):
self._minor = minor
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):
self._major = values['major']
self._minor = values['minor']