Add feature per OTP configuration type.

This commit is contained in:
Elias Bonnici 2023-12-15 08:39:11 +01:00
parent 2b8c5259ba
commit 868c96b72b
No known key found for this signature in database
GPG Key ID: 5EAC28EA3F980CCF
3 changed files with 80 additions and 61 deletions

View File

@ -22,5 +22,9 @@ final actionsSwap = actions.feature('swap');
final slots = otp.feature('slots'); final slots = otp.feature('slots');
final slotsConfigure = slots.feature('configure'); final slotsConfigureChalResp = slots.feature('configureChalResp');
final slotsConfigureHotp = slots.feature('configureHotp');
final slotsConfigureStatic = slots.feature('configureSlots');
final slotsConfigureYubiOtp = slots.feature('configureYubiOtp');
final slotsDelete = slots.feature('delete'); final slotsDelete = slots.feature('delete');

View File

@ -39,8 +39,6 @@ enum SlotId {
SlotId.values.firstWhere((e) => e.id == value); SlotId.values.firstWhere((e) => e.id == value);
} }
enum SlotConfigurationType { yubiotp, static, hotp, chalresp }
@freezed @freezed
class OtpState with _$OtpState { class OtpState with _$OtpState {
const OtpState._(); const OtpState._();

View File

@ -33,10 +33,20 @@ import 'configure_static_dialog.dart';
import 'configure_yubiotp_dialog.dart'; import 'configure_yubiotp_dialog.dart';
import 'delete_slot_dialog.dart'; import 'delete_slot_dialog.dart';
class ConfigureIntent extends Intent { class ConfigureChalRespIntent extends Intent {
const ConfigureIntent({required this.configurationType}); const ConfigureChalRespIntent();
}
final SlotConfigurationType configurationType; class ConfigureHotpIntent extends Intent {
const ConfigureHotpIntent();
}
class ConfigureStaticIntent extends Intent {
const ConfigureStaticIntent();
}
class ConfigureYubiOtpIntent extends Intent {
const ConfigureYubiOtpIntent();
} }
Widget registerOtpActions( Widget registerOtpActions(
@ -49,48 +59,58 @@ Widget registerOtpActions(
final hasFeature = ref.watch(featureProvider); final hasFeature = ref.watch(featureProvider);
return Actions( return Actions(
actions: { actions: {
if (hasFeature(features.slotsConfigure)) if (hasFeature(features.slotsConfigureChalResp))
ConfigureIntent: ConfigureChalRespIntent:
CallbackAction<ConfigureIntent>(onInvoke: (intent) async { CallbackAction<ConfigureChalRespIntent>(onInvoke: (intent) async {
final withContext = ref.read(withContextProvider); final withContext = ref.read(withContextProvider);
final configurationType = intent.configurationType;
switch (configurationType) { await withContext((context) async {
case SlotConfigurationType.chalresp: await showBlurDialog(
await withContext((context) async { context: context,
await showBlurDialog( builder: (context) =>
context: context, ConfigureChalrespDialog(devicePath, otpSlot));
builder: (context) => });
ConfigureChalrespDialog(devicePath, otpSlot)); return null;
}); }),
case SlotConfigurationType.hotp: if (hasFeature(features.slotsConfigureHotp))
await withContext((context) async { ConfigureHotpIntent:
await showBlurDialog( CallbackAction<ConfigureHotpIntent>(onInvoke: (intent) async {
context: context, final withContext = ref.read(withContextProvider);
builder: (context) =>
ConfigureHotpDialog(devicePath, otpSlot));
});
case SlotConfigurationType.static:
final keyboardLayouts = await ref
.read(otpStateProvider(devicePath).notifier)
.getKeyboardLayouts();
await withContext((context) async {
await showBlurDialog(
context: context,
builder: (context) => ConfigureStaticDialog(
devicePath, otpSlot, keyboardLayouts));
});
case SlotConfigurationType.yubiotp:
await withContext((context) async {
await showBlurDialog(
context: context,
builder: (context) =>
ConfigureYubiOtpDialog(devicePath, otpSlot));
});
default:
break;
}
await withContext((context) async {
await showBlurDialog(
context: context,
builder: (context) => ConfigureHotpDialog(devicePath, otpSlot));
});
return null;
}),
if (hasFeature(features.slotsConfigureStatic))
ConfigureStaticIntent:
CallbackAction<ConfigureStaticIntent>(onInvoke: (intent) async {
final withContext = ref.read(withContextProvider);
final keyboardLayouts = await ref
.read(otpStateProvider(devicePath).notifier)
.getKeyboardLayouts();
await withContext((context) async {
await showBlurDialog(
context: context,
builder: (context) => ConfigureStaticDialog(
devicePath, otpSlot, keyboardLayouts));
});
return null;
}),
if (hasFeature(features.slotsConfigureYubiOtp))
ConfigureYubiOtpIntent:
CallbackAction<ConfigureYubiOtpIntent>(onInvoke: (intent) async {
final withContext = ref.read(withContextProvider);
await withContext((context) async {
await showBlurDialog(
context: context,
builder: (context) =>
ConfigureYubiOtpDialog(devicePath, otpSlot));
});
return null; return null;
}), }),
if (hasFeature(features.slotsDelete)) if (hasFeature(features.slotsDelete))
@ -114,37 +134,34 @@ Widget registerOtpActions(
List<ActionItem> buildSlotActions(bool isConfigured, AppLocalizations l10n) { List<ActionItem> buildSlotActions(bool isConfigured, AppLocalizations l10n) {
return [ return [
ActionItem( ActionItem(
key: keys.configureYubiOtp, key: keys.configureYubiOtp,
feature: features.slotsConfigure, feature: features.slotsConfigureYubiOtp,
icon: const Icon(Icons.shuffle_outlined), icon: const Icon(Icons.shuffle_outlined),
title: l10n.s_yubiotp, title: l10n.s_yubiotp,
subtitle: l10n.l_yubiotp_desc, subtitle: l10n.l_yubiotp_desc,
intent: const ConfigureIntent( intent: const ConfigureYubiOtpIntent(),
configurationType: SlotConfigurationType.yubiotp)), ),
ActionItem( ActionItem(
key: keys.configureChalResp, key: keys.configureChalResp,
feature: features.slotsConfigure, feature: features.slotsConfigureChalResp,
icon: const Icon(Icons.key_outlined), icon: const Icon(Icons.key_outlined),
title: l10n.s_challenge_response, title: l10n.s_challenge_response,
subtitle: l10n.l_challenge_response_desc, subtitle: l10n.l_challenge_response_desc,
intent: const ConfigureIntent( intent: const ConfigureChalRespIntent()),
configurationType: SlotConfigurationType.chalresp)),
ActionItem( ActionItem(
key: keys.configureStatic, key: keys.configureStatic,
feature: features.slotsConfigure, feature: features.slotsConfigureStatic,
icon: const Icon(Icons.password_outlined), icon: const Icon(Icons.password_outlined),
title: l10n.s_static_password, title: l10n.s_static_password,
subtitle: l10n.l_static_password_desc, subtitle: l10n.l_static_password_desc,
intent: const ConfigureIntent( intent: const ConfigureStaticIntent()),
configurationType: SlotConfigurationType.static)),
ActionItem( ActionItem(
key: keys.configureHotp, key: keys.configureHotp,
feature: features.slotsConfigure, feature: features.slotsConfigureHotp,
icon: const Icon(Icons.tag_outlined), icon: const Icon(Icons.tag_outlined),
title: l10n.s_hotp, title: l10n.s_hotp,
subtitle: l10n.l_hotp_desc, subtitle: l10n.l_hotp_desc,
intent: const ConfigureIntent( intent: const ConfigureHotpIntent()),
configurationType: SlotConfigurationType.hotp)),
ActionItem( ActionItem(
key: keys.deleteAction, key: keys.deleteAction,
feature: features.slotsDelete, feature: features.slotsDelete,