diff --git a/misc/BreCalApi.cs b/misc/BreCalApi.cs index 7537be1..399c1ab 100644 --- a/misc/BreCalApi.cs +++ b/misc/BreCalApi.cs @@ -5008,7 +5008,7 @@ namespace BreCalClient.misc.Client { Proxy = null; UserAgent = WebUtility.UrlEncode("OpenAPI-Generator/1.0.0/csharp"); - BasePath = "https://brecaldevel.bsmd-emswe.eu"; + BasePath = "https://brecaltest.bsmd-emswe.eu"; DefaultHeaders = new ConcurrentDictionary(); ApiKey = new ConcurrentDictionary(); ApiKeyPrefix = new ConcurrentDictionary(); @@ -5016,7 +5016,7 @@ namespace BreCalClient.misc.Client { { new Dictionary { - {"url", "https://brecaldevel.bsmd-emswe.eu"}, + {"url", "https://brecaltest.bsmd-emswe.eu"}, {"description", "Development server hosted on vcup"}, } } @@ -5035,7 +5035,7 @@ namespace BreCalClient.misc.Client IDictionary defaultHeaders, IDictionary apiKey, IDictionary apiKeyPrefix, - string basePath = "https://brecaldevel.bsmd-emswe.eu") : this() + string basePath = "https://brecaltest.bsmd-emswe.eu") : this() { if (string.IsNullOrWhiteSpace(basePath)) throw new ArgumentException("The provided basePath is invalid.", "basePath"); diff --git a/misc/BreCalApi.yaml b/misc/BreCalApi.yaml index fc33cf2..4bac560 100644 --- a/misc/BreCalApi.yaml +++ b/misc/BreCalApi.yaml @@ -14,7 +14,7 @@ info: name: Use at your own risk url: 'https://www.bsmd.de/license' servers: - - url: 'https://brecaldevel.bsmd-emswe.eu' + - url: 'https://brecaltest.bsmd-emswe.eu' description: Development server hosted on vcup tags: - name: user diff --git a/misc/version.txt b/misc/version.txt index 571adb2..0faf9f7 100644 --- a/misc/version.txt +++ b/misc/version.txt @@ -1 +1 @@ -1.8.0.0 \ No newline at end of file +1.8.0.0 diff --git a/src/BreCalClient/App.config b/src/BreCalClient/App.config index 56618bf..94d76c9 100644 --- a/src/BreCalClient/App.config +++ b/src/BreCalClient/App.config @@ -29,7 +29,7 @@ - #1D751F + #751D1F !!Bremen calling Entwicklungsversion!! @@ -38,7 +38,7 @@ https://www.textbausteine.net/ - https://brecaldevel.bsmd-emswe.eu + https://brecaltest.bsmd-emswe.eu diff --git a/src/BreCalClient/AppNotificationPart.xaml.cs b/src/BreCalClient/AppNotificationPart.xaml.cs index b2f26ad..39a2f52 100644 --- a/src/BreCalClient/AppNotificationPart.xaml.cs +++ b/src/BreCalClient/AppNotificationPart.xaml.cs @@ -35,7 +35,7 @@ namespace BreCalClient this.ContentWrapper.Background = Brushes.Gray; break; case "MissingData": - this.ContentWrapper.Background= Brushes.Yellow; + this.ContentWrapper.Background = Brushes.DarkKhaki; break; case "Cancelled": this.ContentWrapper.Background = Brushes.DarkGray; diff --git a/src/BreCalClient/BreCalClient.csproj b/src/BreCalClient/BreCalClient.csproj index ceed7b6..ef97aaf 100644 --- a/src/BreCalClient/BreCalClient.csproj +++ b/src/BreCalClient/BreCalClient.csproj @@ -13,7 +13,7 @@ Bremen calling client A Windows WPF client for the Bremen calling API. containership.ico - BreCalDevelClient + BreCalTestClient diff --git a/src/BreCalClient/Properties/PublishProfiles/ClickOnceTestProfile.pubxml b/src/BreCalClient/Properties/PublishProfiles/ClickOnceTestProfile.pubxml index ba852d6..a725450 100644 --- a/src/BreCalClient/Properties/PublishProfiles/ClickOnceTestProfile.pubxml +++ b/src/BreCalClient/Properties/PublishProfiles/ClickOnceTestProfile.pubxml @@ -4,8 +4,8 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> - 0 - 1.6.0.3 + 5 + 1.7.0.7 True Debug True @@ -27,10 +27,10 @@ https://go.microsoft.com/fwlink/?LinkID=208121. True (none) False - net6.0-windows + net8.0-windows7.0 True Foreground - False + True Publish.html True https://www.bsmd-emswe.eu/ @@ -38,8 +38,10 @@ https://go.microsoft.com/fwlink/?LinkID=208121. Informatikbüro Daniel Schick Bremen Calling http://www.textbausteine.net/ - bin\Debug\net6.0-windows\win-x64\app.publish\ + bin\Debug\net8.0-windows7.0\win-x64\app.publish\ win-x64 + false + 1.7.0.7 diff --git a/src/BreCalClient/Properties/Settings.Designer.cs b/src/BreCalClient/Properties/Settings.Designer.cs index 0996820..dddc1c7 100644 --- a/src/BreCalClient/Properties/Settings.Designer.cs +++ b/src/BreCalClient/Properties/Settings.Designer.cs @@ -9,29 +9,29 @@ //------------------------------------------------------------------------------ namespace BreCalClient.Properties { - - + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.12.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { - + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - + public static Settings Default { get { return defaultInstance; } } - + [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("#1D751F")] + [global::System.Configuration.DefaultSettingValueAttribute("#751D1F")] public string BG_COLOR { get { return ((string)(this["BG_COLOR"])); } } - + [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("!!Bremen calling Entwicklungsversion!!")] @@ -40,7 +40,7 @@ namespace BreCalClient.Properties { return ((string)(this["APP_TITLE"])); } } - + [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("https://www.textbausteine.net/")] @@ -49,7 +49,7 @@ namespace BreCalClient.Properties { return ((string)(this["LOGO_IMAGE_URL"])); } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("")] @@ -61,16 +61,16 @@ namespace BreCalClient.Properties { this["FilterCriteria"] = value; } } - + [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("https://brecaldevel.bsmd-emswe.eu")] + [global::System.Configuration.DefaultSettingValueAttribute("https://brecaltest.bsmd-emswe.eu")] public string API_URL { get { return ((string)(this["API_URL"])); } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("800")] @@ -82,7 +82,7 @@ namespace BreCalClient.Properties { this["Width"] = value; } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("450")] @@ -94,7 +94,7 @@ namespace BreCalClient.Properties { this["Height"] = value; } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("0")] @@ -106,7 +106,7 @@ namespace BreCalClient.Properties { this["Left"] = value; } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("0")] @@ -118,7 +118,7 @@ namespace BreCalClient.Properties { this["Top"] = value; } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("0")] @@ -130,7 +130,7 @@ namespace BreCalClient.Properties { this["W1Left"] = value; } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("0")] @@ -142,7 +142,7 @@ namespace BreCalClient.Properties { this["W1Top"] = value; } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("0")] @@ -154,7 +154,7 @@ namespace BreCalClient.Properties { this["W2Left"] = value; } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("0")] @@ -166,7 +166,7 @@ namespace BreCalClient.Properties { this["W2Top"] = value; } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("0")] @@ -178,7 +178,7 @@ namespace BreCalClient.Properties { this["W3Left"] = value; } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("0")] @@ -190,7 +190,7 @@ namespace BreCalClient.Properties { this["W3Top"] = value; } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("0")] @@ -202,7 +202,7 @@ namespace BreCalClient.Properties { this["W4Left"] = value; } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("0")] @@ -214,7 +214,7 @@ namespace BreCalClient.Properties { this["W4Top"] = value; } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("")] @@ -226,7 +226,7 @@ namespace BreCalClient.Properties { this["FilterCriteriaMap"] = value; } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] public global::System.Collections.Specialized.StringCollection Notifications { @@ -237,7 +237,7 @@ namespace BreCalClient.Properties { this["Notifications"] = value; } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("0")] @@ -249,7 +249,7 @@ namespace BreCalClient.Properties { this["W5Top"] = value; } } - + [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("0")] diff --git a/src/BreCalClient/Properties/Settings.settings b/src/BreCalClient/Properties/Settings.settings index bc7dc35..0c77a41 100644 --- a/src/BreCalClient/Properties/Settings.settings +++ b/src/BreCalClient/Properties/Settings.settings @@ -3,7 +3,7 @@ - #1D751F + #751D1F !!Bremen calling Entwicklungsversion!! @@ -15,7 +15,7 @@ - https://brecaldevel.bsmd-emswe.eu + https://brecaltest.bsmd-emswe.eu 800 diff --git a/src/BreCalClient/ShipcallControl.xaml b/src/BreCalClient/ShipcallControl.xaml index 3dc9001..e70c56c 100644 --- a/src/BreCalClient/ShipcallControl.xaml +++ b/src/BreCalClient/ShipcallControl.xaml @@ -5,7 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:p = "clr-namespace:BreCalClient.Resources" xmlns:sets="clr-namespace:BreCalClient.Properties" - xmlns:db="clr-namespace:BreCalClient;assembly=BreCalDevelClient" + xmlns:db="clr-namespace:BreCalClient;assembly=BreCalTestClient" mc:Ignorable="d" d:DesignHeight="135" d:DesignWidth="800"> diff --git a/src/BreCalClient/ShipcallControl.xaml.cs b/src/BreCalClient/ShipcallControl.xaml.cs index 3e907cc..16416b5 100644 --- a/src/BreCalClient/ShipcallControl.xaml.cs +++ b/src/BreCalClient/ShipcallControl.xaml.cs @@ -215,13 +215,13 @@ namespace BreCalClient switch (this.ShipcallControlModel?.Shipcall?.Type) { case ShipcallType.Arrival: // incoming - this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalDevelClient;component/Resources/arrow_down_red.png")); + this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalTestClient;component/Resources/arrow_down_red.png")); break; case ShipcallType.Departure: // outgoing - this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalDevelClient;component/Resources/arrow_up_blue.png")); + this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalTestClient;component/Resources/arrow_up_blue.png")); break; case ShipcallType.Shifting: // shifting - this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalDevelClient;component/Resources/arrow_right_green.png")); + this.imageShipcallType.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalTestClient;component/Resources/arrow_right_green.png")); break; default: break; @@ -230,13 +230,13 @@ namespace BreCalClient switch(this.ShipcallControlModel?.LightMode) { case EvaluationType.Green: - this.imageEvaluation.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalDevelClient;component/Resources/check.png")); + this.imageEvaluation.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalTestClient;component/Resources/check.png")); break; case EvaluationType.Yellow: - this.imageEvaluation.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalDevelClient;component/Resources/sign_warning.png")); + this.imageEvaluation.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalTestClient;component/Resources/sign_warning.png")); break; case EvaluationType.Red: - this.imageEvaluation.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalDevelClient;component/Resources/delete2.png")); + this.imageEvaluation.Source = new BitmapImage(new Uri("pack://application:,,,/BreCalTestClient;component/Resources/delete2.png")); break; default: break; diff --git a/src/RoleEditor/App.config b/src/RoleEditor/App.config index 51c1ce1..bd2b4e4 100644 --- a/src/RoleEditor/App.config +++ b/src/RoleEditor/App.config @@ -8,7 +8,7 @@ - Server=localhost;User ID=ds;Password=HalloWach_2323XXL!!;Database=bremen_calling_devel;Port=33306 + Server=localhost;User ID=ds;Password=HalloWach_2323XXL!!;Database=bremen_calling_test;Port=33306 diff --git a/src/RoleEditor/Properties/Settings.Designer.cs b/src/RoleEditor/Properties/Settings.Designer.cs index c0ea20b..e97e569 100644 --- a/src/RoleEditor/Properties/Settings.Designer.cs +++ b/src/RoleEditor/Properties/Settings.Designer.cs @@ -9,24 +9,24 @@ //------------------------------------------------------------------------------ namespace RoleEditor.Properties { - - + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.10.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { - + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - + public static Settings Default { get { return defaultInstance; } } - + [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("Server=localhost;User ID=ds;Password=HalloWach_2323XXL!!;Database=bremen_calling_" + - "devel;Port=33306")] + "test;Port=33306")] public string ConnectionString { get { return ((string)(this["ConnectionString"])); diff --git a/src/RoleEditor/Properties/Settings.settings b/src/RoleEditor/Properties/Settings.settings index 33aa443..e7843c5 100644 --- a/src/RoleEditor/Properties/Settings.settings +++ b/src/RoleEditor/Properties/Settings.settings @@ -3,7 +3,7 @@ - Server=localhost;User ID=ds;Password=HalloWach_2323XXL!!;Database=bremen_calling_devel;Port=33306 + Server=localhost;User ID=ds;Password=HalloWach_2323XXL!!;Database=bremen_calling_test;Port=33306 \ No newline at end of file diff --git a/src/server/BreCal/__init__.py b/src/server/BreCal/__init__.py index c3674bc..8924b11 100644 --- a/src/server/BreCal/__init__.py +++ b/src/server/BreCal/__init__.py @@ -69,7 +69,7 @@ def create_app(test_config=None, instance_path=None): app.register_blueprint(history.bp) app.register_blueprint(ports.bp) - logging.basicConfig(filename='brecal.log', level=logging.WARNING, format='%(asctime)s | %(name)s | %(levelname)s | %(message)s') + logging.basicConfig(filename='brecaltest.log', level=logging.DEBUG, format='%(asctime)s | %(name)s | %(levelname)s | %(message)s') local_db.initPool(os.path.dirname(app.instance_path)) logging.info('App started') diff --git a/src/server/BreCal/database/sql_queries.py b/src/server/BreCal/database/sql_queries.py index 47e4bfa..62fe49d 100644 --- a/src/server/BreCal/database/sql_queries.py +++ b/src/server/BreCal/database/sql_queries.py @@ -281,10 +281,8 @@ class SQLQuery(): def get_next24hrs_shipcalls()->str: query = ("SELECT s.id as id, ship.name as name FROM shipcall s INNER JOIN ship ON s.ship_id = ship.id LEFT JOIN times t on t.shipcall_id = s.id AND t.participant_type = 8 " + \ - "WHERE (type = 1 AND ((t.id IS NOT NULL AND t.eta_berth >= NOW() AND t.eta_berth < (NOW() + INTERVAL 1 DAY))" + \ - "OR (eta >= NOW() AND eta < (NOW() + INTERVAL 1 DAY)))) OR " + \ - "((type = 2 OR type = 3) AND ((t.id IS NOT NULL AND t.etd_berth >= NOW() AND " + \ - "t.etd_berth < (NOW() + INTERVAL 1 DAY)) OR (etd >= NOW() AND etd < (NOW() + INTERVAL 1 DAY))))" + \ + "WHERE (type = 1 AND (COALESCE(t.eta_berth, eta) >= NOW() AND COALESCE(t.eta_berth, eta) < (NOW() + INTERVAL 1 DAY)))" + \ + "OR ((type = 2 OR type = 3) AND (COALESCE(t.etd_berth, etd) >= NOW() AND COALESCE(t.etd_berth, etd) < (NOW() + INTERVAL 1 DAY)))" "AND s.canceled = 0") return query diff --git a/src/server/BreCal/impl/login.py b/src/server/BreCal/impl/login.py index c2a2fa6..f1d7d00 100644 --- a/src/server/BreCal/impl/login.py +++ b/src/server/BreCal/impl/login.py @@ -8,6 +8,7 @@ from .. import local_db from ..services import jwt_handler + def GetUser(options): pooledConnection = None diff --git a/src/server/BreCal/local_db.py b/src/server/BreCal/local_db.py index 4bb15c5..95af1be 100644 --- a/src/server/BreCal/local_db.py +++ b/src/server/BreCal/local_db.py @@ -56,8 +56,8 @@ def initPool(instancePath, connection_filename="connection_data_prod.json", credentials_file = "email_credentials_test.json" credentials_path = os.path.join(instancePath, f'../../../secure/{credentials_file}') - - # credentials_path = 'C:\\temp\\email_credentials_test.json' + + # credentials_path = "E:/temp/email_credentials_devel.json" if not os.path.exists(credentials_path): print('cannot find ' + os.path.abspath(credentials_path)) diff --git a/src/server/BreCal/services/email_handling.py b/src/server/BreCal/services/email_handling.py index e06021d..58ac710 100644 --- a/src/server/BreCal/services/email_handling.py +++ b/src/server/BreCal/services/email_handling.py @@ -15,13 +15,13 @@ from email.mime.application import MIMEApplication class EmailHandler(): """ - Creates an EmailHandler, which is capable of connecting to a mail server at a respective port, - as well as logging into a specific user's mail address. - Upon creating messages, these can be sent via this handler. + Creates an EmailHandler, which is capable of connecting to a mail server at a respective port, + as well as logging into a specific user's mail address. + Upon creating messages, these can be sent via this handler. Options: mail_server: address of the server, such as 'smtp.gmail.com' or 'w01d5503.kasserver.com - mail_port: + mail_port: 25 - SMTP Port, to send emails 110 - POP3 Port, to receive emails 143 - IMAP Port, to receive from IMAP @@ -38,6 +38,9 @@ class EmailHandler(): self.server = smtplib.SMTP_SSL(self.mail_server, self.mail_port) # alternatively, SMTP + # set the following to 0 to avoid log spamming + self.server.set_debuglevel(1) # 0: no debug, 1: debug + def check_state(self): """check, whether the server login took place and is open.""" try: @@ -45,7 +48,7 @@ class EmailHandler(): return status_code==250 # 250: b'2.0.0 Ok' except smtplib.SMTPServerDisconnected: return False - + def check_connection(self): """check, whether the server object is connected to the server. If not, connect it. """ try: @@ -53,7 +56,7 @@ class EmailHandler(): except smtplib.SMTPServerDisconnected: self.server.connect(self.mail_server, self.mail_port) return - + def check_login(self)->bool: """check, whether the server object is logged in as a user""" user = self.server.__dict__.get("user",None) @@ -61,8 +64,8 @@ class EmailHandler(): def login(self, interactive:bool=True): """ - login on the determined mail server's mail address. By default, this function opens an interactive window to - type the password without echoing (printing '*******' instead of readable characters). + login on the determined mail server's mail address. By default, this function opens an interactive window to + type the password without echoing (printing '*******' instead of readable characters). returns (status_code, status_msg) """ @@ -77,7 +80,7 @@ class EmailHandler(): def create_email(self, subject:str, message_body:str)->EmailMessage: """ Create an EmailMessage object, which contains the Email's header ("Subject"), content ("Message Body") and the sender's address ("From"). - The EmailMessage object does not contain the recipients yet, as these will be defined upon sending the Email. + The EmailMessage object does not contain the recipients yet, as these will be defined upon sending the Email. """ msg = EmailMessage() msg["Subject"] = subject @@ -85,16 +88,16 @@ class EmailHandler(): #msg["To"] = email_tgts # will be defined in self.send_email msg.set_content(message_body) return msg - + def build_recipients(self, email_tgts:list[str]): """ - email formatting does not support lists. Instead, items are joined into a comma-space-separated string. - Example: - [mail1@mail.com, mail2@mail.com] becomes + email formatting does not support lists. Instead, items are joined into a comma-space-separated string. + Example: + [mail1@mail.com, mail2@mail.com] becomes 'mail1@mail.com, mail2@mail.com' """ return ', '.join(email_tgts) - + def open_mime_application(self, path:str)->MIMEApplication: """open a local file, read the bytes into a MIMEApplication object, which is built with the proper subtype (based on the file extension)""" with open(path, 'rb') as file: @@ -102,24 +105,24 @@ class EmailHandler(): attachment.add_header('Content-Disposition','attachment',filename=str(os.path.basename(path))) return attachment - + def attach_file(self, path:str, msg:email.mime.multipart.MIMEMultipart)->None: """ - attach a file to the message. This function opens the file, reads its bytes, defines the mime type by the - path extension. The filename is appended as the header. + attach a file to the message. This function opens the file, reads its bytes, defines the mime type by the + path extension. The filename is appended as the header. mimetypes: # https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types """ attachment = self.open_mime_application(path) msg.attach(attachment) return - + def send_email(self, msg:EmailMessage, email_tgts:list[str], cc_tgts:typing.Optional[list[str]]=None, bcc_tgts:typing.Optional[list[str]]=None, debug:bool=False)->typing.Union[dict,EmailMessage]: """ - send a prepared email message to recipients (email_tgts), copy (cc_tgts) and blind copy (bcc_tgts). - Returns a dictionary of feedback, which is commonly empty and the EmailMessage. - - When failing, this function returns an SMTP error instead of returning the default outputs. + send a prepared email message to recipients (email_tgts), copy (cc_tgts) and blind copy (bcc_tgts). + Returns a dictionary of feedback, which is commonly empty and the EmailMessage. + + When failing, this function returns an SMTP error instead of returning the default outputs. """ # Set the Recipients msg["To"] = self.build_recipients(email_tgts) @@ -130,15 +133,15 @@ class EmailHandler(): if bcc_tgts is not None: msg["Bcc"] = self.build_recipients(bcc_tgts) - # when debugging, do not send the Email, but return the EmailMessage. + # when debugging, do not send the Email, but return the EmailMessage. if debug: return {}, msg - + assert self.check_login(), f"currently not logged in. Cannot send an Email. Make sure to properly use self.login first. " # send the prepared EmailMessage via the server. feedback = self.server.send_message(msg) return feedback, msg - + def translate_mail_to_multipart(self, msg:EmailMessage): """EmailMessage does not support HTML and attachments. Hence, one can convert an EmailMessage object.""" if msg.is_multipart(): @@ -159,11 +162,11 @@ class EmailHandler(): # attach the remainder of the msg, such as the body, to the MIMEMultipart msg_new.attach(msg) return msg_new - + def print_email_attachments(self, msg:MIMEMultipart)->list[str]: """return a list of lines of an Email, which contain 'filename=' as a list. """ return [line_ for line_ in msg.as_string().split("\n") if "filename=" in line_] - + def close(self): self.server.__dict__.pop("user",None) self.server.__dict__.pop("password",None) diff --git a/src/server/BreCal/services/schedule_routines.py b/src/server/BreCal/services/schedule_routines.py index 2889e50..9608aca 100644 --- a/src/server/BreCal/services/schedule_routines.py +++ b/src/server/BreCal/services/schedule_routines.py @@ -124,11 +124,11 @@ def SendEmails(email_dict): defs.message_types = json.load(f) f.close() - for user, notifications in email_dict.items(): + for user_email, notifications in email_dict.items(): msg = EmailMessage() msg["Subject"] = '[Bremen calling] Notification' msg["From"] = defs.email_credentials["sender"] - msg["To"] = user.user_email + msg["To"] = user_email with open(os.path.join(current_path,'../msg/notification_template.html'), mode="r", encoding="utf-8") as file: body = file.read() @@ -180,7 +180,7 @@ def SendEmails(email_dict): body = body.replace("[[NOTIFICATION_ELEMENTS]]", replacement) msg.set_content(body, subtype='html', charset='utf-8', cte='8bit') - conn.sendmail(defs.email_credentials["sender"], user.user_email, msg.as_string()) + conn.sendmail(defs.email_credentials["sender"], user_email, msg.as_string()) except Exception as ex: logging.error(ex) @@ -210,10 +210,10 @@ def SendNotifications(): email_dict = dict() users_dict = dict() user_query = "SELECT * from user" - users = commands.query(user_query, model=model.User) + users = commands.query(user_query) for participant in participants: for user in users: - if user.participant_id == participant.id: + if user["participant_id"] == participant.id: if not participant.id in users_dict: users_dict[participant.id] = [] users_dict[participant.id].append(user) @@ -225,33 +225,39 @@ def SendNotifications(): p_query = "SELECT * from shipcall_participant_map where shipcall_id = ?id?" assigned_participants = commands.query(p_query, model=model.ShipcallParticipantMap, param={"id":notification.shipcall_id}) for assigned_participant in assigned_participants: + if not assigned_participant.participant_id in users_dict: + continue users = users_dict[assigned_participant.participant_id] for user in users: # send notification to user - if user.notify_email: - if user not in email_dict: - email_dict[user] = [] - email_dict[user].append(notification) - if user.notify_whatsapp: + if user["notify_email"]: + if user["user_email"] not in email_dict: + email_dict[user["user_email"]] = [] + if notification not in email_dict[user["user_email"]]: + email_dict[user["user_email"]].append(notification) + if user["notify_whatsapp"]: # TBD pass - if user.notify_signal: + if user["notify_signal"]: # TBD pass else: - users = users_dict[notification.participant_id] - for user in users: - # send notification to user - if user.notify_email and user.wants_notifications(notification.type): - if user not in email_dict: - email_dict[user] = [] - email_dict[user].append(notification) - if user.notify_whatsapp and user.wants_notifications(notification.type): - # TBD - pass - if user.notify_signal and user.wants_notifications(notification.type): - # TBD - pass + if notification.participant_id in users_dict: + users = users_dict[notification.participant_id] + for user in users: + user_notifications = model.bitflag_to_list(user["notify_event"]) + # send notification to user + if user["notify_email"] and notification.type in user_notifications: + if user["user_email"] not in email_dict: + email_dict[user["user_email"]] = [] + if notification not in email_dict[user["user_email"]]: + email_dict[user["user_email"]].append(notification) + if user["notify_whatsapp"] and notification.type in user_notifications: + # TBD + pass + if user["notify_signal"] and notification.type in user_notifications: + # TBD + pass # mark as sent commands.execute("UPDATE notification SET level = 2 WHERE id = ?id?", param={"id":notification.id}) diff --git a/src/server/BreCal/validators/validation_error.py b/src/server/BreCal/validators/validation_error.py index 30d093a..5040d28 100644 --- a/src/server/BreCal/validators/validation_error.py +++ b/src/server/BreCal/validators/validation_error.py @@ -59,7 +59,7 @@ def create_validation_error_response(ex:ValidationError, status_code:int=400, cr if create_log: logging.warning(ex) if ex is not None else logging.warning(message) - print(ex) if ex is not None else print(message) + # print(ex) if ex is not None else print(message) return (serialized_response, status_code) def create_werkzeug_error_response(ex:Forbidden, status_code:int=403, create_log:bool=True)->typing.Tuple[str,int]: @@ -71,7 +71,7 @@ def create_werkzeug_error_response(ex:Forbidden, status_code:int=403, create_log if create_log: logging.warning(ex) if ex is not None else logging.warning(message) - print(ex) if ex is not None else print(message) + # print(ex) if ex is not None else print(message) return serialized_response, status_code def create_dynamic_exception_response(ex, status_code:int=400, message:typing.Optional[str]=None, create_log:bool=True): @@ -83,5 +83,5 @@ def create_dynamic_exception_response(ex, status_code:int=400, message:typing.Op if create_log: logging.warning(ex) if ex is not None else logging.warning(message) - print(ex) if ex is not None else print(message) + # print(ex) if ex is not None else print(message) return (serialized_response, status_code) diff --git a/src/server/BreCal/validators/validation_rules.py b/src/server/BreCal/validators/validation_rules.py index 3ceea99..03ce506 100644 --- a/src/server/BreCal/validators/validation_rules.py +++ b/src/server/BreCal/validators/validation_rules.py @@ -52,7 +52,8 @@ class ValidationRules(ValidationRuleFunctions): # 'translate' all error codes into readable, human-understandable format. evaluation_results = [(state, self.describe_error_message(msg)) for (state, msg) in evaluation_results] - logging.info(f"Validation results for shipcall {shipcall.id}: {evaluation_results}") + if evaluation_results: + logging.info(f"Validation results for shipcall {shipcall.id}: {evaluation_results}") # check, what the maximum state flag is and return it evaluation_state = np.max(np.array([result[0].value for result in evaluation_results])) if len(evaluation_results)>0 else StatusFlags.GREEN.value diff --git a/src/server/flaskapp.wsgi b/src/server/flaskapp.wsgi index a043504..4bf64f7 100644 --- a/src/server/flaskapp.wsgi +++ b/src/server/flaskapp.wsgi @@ -2,7 +2,7 @@ import os import sys import logging -sys.path.insert(0, '/var/www/brecal/src/server') +sys.path.insert(0, '/var/www/brecal_test/src/server') sys.path.insert(0, '/var/www/venv/lib/python3.12/site-packages/') import schedule