Skip to content

Commit

Permalink
Enhance ApplicationCustomization to include dynamic subject prefixes …
Browse files Browse the repository at this point in the history
…for crash and feedback emails
  • Loading branch information
frankmer committed Nov 22, 2024
1 parent 3f85a91 commit 94b7d66
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
20 changes: 20 additions & 0 deletions lib/utils/customization/application_customization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class ApplicationCustomization {
static const _defaultAppName = 'privacyIDEA Authenticator';
static const _defaultWebsiteLink = 'https://netknights.it/';
static const _defaultCrashRecipient = '[email protected]';
static const _defaultCrashSubjectPrefix = '(\$version) privacyIDEA Authenticator >>>';
static const _defaultFeedbackRecipient = '[email protected]';
static const _defaultFeedbackSubjectPrefix = '(\$version) privacyIDEA Authenticator >>> [Feedback]';

static const String _defaultFontName = 'defaultFont';
final String fontFamilyName;
Expand Down Expand Up @@ -69,7 +71,9 @@ class ApplicationCustomization {
final String appName;
final String websiteLink;
final String crashRecipient;
final String crashSubjectPrefix;
final String feedbackRecipient;
final String feedbackSubjectPrefix;
final WidgetImage appbarIcon;
static const String appbarIconFileName = 'appbar_icon';
final WidgetImage splashScreenImage;
Expand All @@ -87,7 +91,9 @@ class ApplicationCustomization {
this.appName = _defaultAppName,
this.websiteLink = _defaultWebsiteLink,
this.crashRecipient = _defaultCrashRecipient,
this.crashSubjectPrefix = _defaultCrashSubjectPrefix,
this.feedbackRecipient = _defaultFeedbackRecipient,
this.feedbackSubjectPrefix = _defaultFeedbackSubjectPrefix,
this.fontFamilyName = _defaultFontName,
this.customFontBytes,
WidgetImage? appbarIcon,
Expand All @@ -108,7 +114,9 @@ class ApplicationCustomization {
String? appName,
String? websiteLink,
String? crashRecipient,
String? crashSubjectPrefix,
String? feedbackRecipient,
String? feedbackSubjectPrefix,
WidgetImage? appbarIcon,
WidgetImage? splashScreenImage,
WidgetImage? backgroundImage,
Expand All @@ -121,7 +129,9 @@ class ApplicationCustomization {
appName: appName ?? this.appName,
websiteLink: websiteLink ?? this.websiteLink,
crashRecipient: crashRecipient ?? this.crashRecipient,
crashSubjectPrefix: crashSubjectPrefix ?? this.crashSubjectPrefix,
feedbackRecipient: feedbackRecipient ?? this.feedbackRecipient,
feedbackSubjectPrefix: feedbackSubjectPrefix ?? this.feedbackSubjectPrefix,
fontFamilyName: fontFamilyName,
customFontBytes: customFontBytes,
appbarIcon: appbarIcon ?? this.appbarIcon,
Expand All @@ -140,7 +150,9 @@ class ApplicationCustomization {
appName == other.appName &&
websiteLink == other.websiteLink &&
crashRecipient == other.crashRecipient &&
crashSubjectPrefix == other.crashSubjectPrefix &&
feedbackRecipient == other.feedbackRecipient &&
feedbackSubjectPrefix == other.feedbackSubjectPrefix &&
fontFamilyName == other.fontFamilyName &&
customFontBytes == other.customFontBytes &&
appbarIcon == other.appbarIcon &&
Expand All @@ -156,7 +168,9 @@ class ApplicationCustomization {
appName,
websiteLink,
crashRecipient,
crashSubjectPrefix,
feedbackRecipient,
feedbackSubjectPrefix,
fontFamilyName,
customFontBytes,
appbarIcon,
Expand All @@ -173,7 +187,9 @@ class ApplicationCustomization {
appName: appName,
websiteLink: websiteLink,
crashRecipient: crashRecipient,
crashSubjectPrefix: crashSubjectPrefix,
feedbackRecipient: feedbackRecipient,
feedbackSubjectPrefix: feedbackSubjectPrefix,
fontFamilyName: fontName,
customFontBytes: fontBytes,
appbarIcon: appbarIcon,
Expand Down Expand Up @@ -203,7 +219,9 @@ class ApplicationCustomization {
appName: json['appName'] as String? ?? _defaultAppName,
websiteLink: json['websiteLink'] as String? ?? _defaultWebsiteLink,
crashRecipient: json['crashRecipient'] as String? ?? _defaultCrashRecipient,
crashSubjectPrefix: json['crashSubjectPrefix'] as String? ?? _defaultCrashSubjectPrefix,
feedbackRecipient: json['feedbackRecipient'] as String? ?? _defaultFeedbackRecipient,
feedbackSubjectPrefix: json['feedbackSubjectPrefix'] as String? ?? _defaultFeedbackSubjectPrefix,
customFontBytes: json['customFontBytes'] != null ? base64Decode(json['customFontBytes'] as String) : null,
fontFamilyName: json['fontFamilyName'] as String? ?? _defaultFontName,
appbarIcon: json['appbarIcon'] != null
Expand Down Expand Up @@ -236,7 +254,9 @@ class ApplicationCustomization {
'appName': appName,
'websiteLink': websiteLink,
'crashRecipient': crashRecipient,
'crashSubjectPrefix': crashSubjectPrefix,
'feedbackRecipient': feedbackRecipient,
'feedbackSubjectPrefix': feedbackSubjectPrefix,
'fontFamilyName': fontFamilyName,
'customFontBytes': customFontBytes != null ? base64Encode(customFontBytes!) : null,
'appbarIcon': appbarIcon.toJson(),
Expand Down
8 changes: 7 additions & 1 deletion lib/utils/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,13 @@ class Logger {
---------------------------------------------------------
Device Parameters $deviceInfo""";
return PiMailer(mailRecipients: _mailRecipients).sendMail(subject: _lastError, body: completeMailBody, attachments: [_fullPath!]);
return PiMailer.sendMail(
mailRecipients: _mailRecipients,
subjectPrefix: PrivacyIDEAAuthenticator.currentCustomization?.crashSubjectPrefix,
subject: _lastError,
body: completeMailBody,
attachments: [_fullPath!],
);
}

static void clearErrorLog() {
Expand Down
17 changes: 5 additions & 12 deletions lib/utils/pi_mailer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,17 @@ import 'package:flutter_mailer/flutter_mailer.dart';

import '../l10n/app_localizations.dart';
import '../widgets/dialog_widgets/default_dialog.dart';
import 'app_info_utils.dart';
import 'logger.dart';
import 'view_utils.dart';

class PiMailer {
final Set<String> mailRecipients;
const PiMailer({required this.mailRecipients});

static String _mailSubject(String? subject, String? subjectPrefix, bool subjectAppVersion) {
String mailSubject = subjectPrefix != null ? '[$subjectPrefix] ' : '';
if (subjectAppVersion) mailSubject += '(${InfoUtils.currentVersionString}+${InfoUtils.currentBuildNumber}) ';
mailSubject += '${InfoUtils.appName}';
if (subject != null) mailSubject += ' >>> $subject';
return mailSubject;
static String _mailSubject(String subject, String? subjectPrefix, bool subjectAppVersion) {
return subjectPrefix != null ? '$subjectPrefix $subject' : subject;
}

Future<bool> sendMail({
String? subject,
static Future<bool> sendMail({
required Set<String> mailRecipients,
required String subject,
String? subjectPrefix,
bool subjectAppVersion = true,
required String body,
Expand Down
11 changes: 7 additions & 4 deletions lib/views/feedback_view/widgets/feedback_send_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import 'package:flutter/material.dart';
import 'package:privacyidea_authenticator/mains/main_netknights.dart';
import 'package:privacyidea_authenticator/utils/globals.dart';

import '../../../l10n/app_localizations.dart';
import '../../../utils/app_info_utils.dart';
Expand Down Expand Up @@ -135,9 +134,13 @@ class _FeedbackSendRowState extends State<FeedbackSendRow> {
}

String _addDeviceInfoToMail(String feedback) => '$feedback\n\n[${InfoUtils.currentVersionAndBuildNumber}] ${InfoUtils.deviceInfoString}';
Future<bool> _sendMail(String mailText) => globalRef != null
? PiMailer(mailRecipients: _mailRecipients).sendMail(subjectPrefix: 'Feedback', body: mailText, subjectAppVersion: false)
: Future.value(false);
Future<bool> _sendMail(String mailText) => PiMailer.sendMail(
mailRecipients: _mailRecipients,
subjectPrefix: PrivacyIDEAAuthenticator.currentCustomization?.feedbackSubjectPrefix,
subject: '',
body: mailText,
subjectAppVersion: false,
);

Set<String> get _mailRecipients =>
PrivacyIDEAAuthenticator.currentCustomization != null ? {PrivacyIDEAAuthenticator.currentCustomization!.feedbackRecipient} : {};
Expand Down

0 comments on commit 94b7d66

Please sign in to comment.