Skip to content

Commit

Permalink
cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmer committed Oct 15, 2024
1 parent 082f0bc commit de819ae
Show file tree
Hide file tree
Showing 30 changed files with 184 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,24 @@ import 'package:privacyidea_authenticator/l10n/app_localizations_en.dart';
import 'package:privacyidea_authenticator/model/extensions/token_folder_extension.dart';
import 'package:privacyidea_authenticator/processors/scheme_processors/token_import_scheme_processors/otp_auth_processor.dart';
import 'package:privacyidea_authenticator/utils/ecc_utils.dart';
import 'package:privacyidea_authenticator/utils/errors.dart';
import 'package:privacyidea_authenticator/model/exception_errors/localized_argument_error.dart';
import 'package:privacyidea_authenticator/utils/privacyidea_io_client.dart';

import '../model/api_results/pi_server_results/pi_server_result_value.dart';
import '../model/exception_errors/response_error.dart';
import '../model/pi_server_response.dart';
import '../model/riverpod_states/token_state.dart';
import '../model/token_template.dart';
import '../model/token_container.dart';
import '../model/token_template.dart';
import '../model/tokens/token.dart';
import '../utils/globals.dart';
import '../utils/identifiers.dart';
import '../utils/logger.dart';
import '../widgets/dialog_widgets/enter_passphrase_dialog.dart';

class PiSyncResponse {
final List<Token> updatedTokens;
final List<String> deletedSerials;

const PiSyncResponse({
required this.updatedTokens,
required this.deletedSerials,
});
}

class PrivacyideaContainerApi {
class PrivacyIdeaContainerApi {
final PrivacyideaIOClient _ioClient;
const PrivacyideaContainerApi({required PrivacyideaIOClient ioClient}) : _ioClient = ioClient;
const PrivacyIdeaContainerApi({required PrivacyideaIOClient ioClient}) : _ioClient = ioClient;

// Returns a tuple of updated/new tokens and serials of deleted tokens
Future<(List<Token>, List<String>)?> sync(TokenContainerFinalized container, TokenState tokenState) async {
Expand Down Expand Up @@ -289,23 +280,3 @@ class PrivacyideaContainerApi {
return (mergedTemplatesWithSerial, deleteSerials);
}
}

class ResponseError {
final int _statusCode;
int get statusCode => _statusCode;
final String _message;
String get message => _message.substring(0, _message.length > 100 ? 100 : _message.length);
String get fullMessage => _message;

const ResponseError._(int statusCode, String message)
: _statusCode = statusCode,
_message = message;

factory ResponseError(Response response) {
assert(response.statusCode != 200, 'Status code of an response error should not be 200');
return ResponseError._(response.statusCode, response.body);
}

@override
String toString() => '($statusCode) $message';
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import 'pi_server_result_error.dart';
import '../../exception_errors/pi_server_result_error.dart';
import 'pi_server_result_value.dart';

abstract class PiServerResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import '../l10n/app_localizations.dart';
import '../../l10n/app_localizations.dart';
import 'localized_exception.dart';

class LocalizedArgumentError extends LocalizedException implements ArgumentError {
final String _invalidValue;
Expand Down Expand Up @@ -60,13 +61,3 @@ class LocalizedArgumentError extends LocalizedException implements ArgumentError
@override
String toString() => 'ArgumentError: $message';
}

class LocalizedException implements Exception {
final String Function(AppLocalizations localizations) localizedMessage;
final String unlocalizedMessage;

const LocalizedException({required this.localizedMessage, required this.unlocalizedMessage});

@override
String toString() => 'Exception: $unlocalizedMessage';
}
31 changes: 31 additions & 0 deletions lib/model/exception_errors/localized_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* privacyIDEA Authenticator
*
* Author: Frank Merkel <[email protected]>
*
* Copyright (c) 2024 NetKnights GmbH
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import '../../l10n/app_localizations.dart';

class LocalizedException implements Exception {
final String Function(AppLocalizations localizations) localizedMessage;
final String unlocalizedMessage;

const LocalizedException({required this.localizedMessage, required this.unlocalizedMessage});

@override
String toString() => 'Exception: $unlocalizedMessage';
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import '../../../utils/object_validator.dart';
import 'pi_server_result.dart';
import '../../utils/object_validator.dart';
import '../api_results/pi_server_results/pi_server_result.dart';

class PiServerResultError extends PiServerResult implements Error {
static const CODE = 'code';
Expand Down
37 changes: 37 additions & 0 deletions lib/model/exception_errors/response_error.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* privacyIDEA Authenticator
*
* Author: Frank Merkel <[email protected]>
*
* Copyright (c) 2024 NetKnights GmbH
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import 'package:http/http.dart';

class ResponseError {
final int _statusCode;
int get statusCode => _statusCode;
final String _message;
String get message => _message.substring(0, _message.length > 100 ? 100 : _message.length);
String get fullMessage => _message;

const ResponseError._(int statusCode, String message)
: _statusCode = statusCode,
_message = message;

factory ResponseError(Response response) {
assert(response.statusCode != 200, 'Status code of an response error should not be 200');
return ResponseError._(response.statusCode, response.body);
}
}
2 changes: 1 addition & 1 deletion lib/model/pi_server_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import 'package:http/http.dart';

import '../utils/logger.dart';
import '../utils/object_validator.dart';
import 'api_results/pi_server_results/pi_server_result_error.dart';
import 'exception_errors/pi_server_result_error.dart';
import 'api_results/pi_server_results/pi_server_result_value.dart';

part 'pi_server_response.freezed.dart';
Expand Down
10 changes: 10 additions & 0 deletions lib/model/riverpod_states/token_container_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import 'dart:convert';

import 'package:collection/collection.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:privacyidea_authenticator/model/tokens/token.dart';

import '../enums/sync_state.dart';
import '../token_container.dart';

part 'token_container_state.freezed.dart';
Expand Down Expand Up @@ -51,4 +53,12 @@ class TokenContainerState with _$TokenContainerState {
TokenContainer? ofSerial(String serial) => containerList.firstWhereOrNull((container) => container.serial == serial);

factory TokenContainerState.fromJson(Map<String, dynamic> json) => _$TokenContainerStateFromJson(json);

SyncState? getSyncState(Token token) {
if (token.containerSerial == null) return null;
final container = containerOf(token.containerSerial!);
if (container == null) return null;
if (container is TokenContainerFinalized) return container.syncState;
return null;
}
}
2 changes: 1 addition & 1 deletion lib/model/token_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import 'package:privacyidea_authenticator/utils/identifiers.dart';
import '../utils/ecc_utils.dart';
import '../utils/logger.dart';
import '../utils/object_validator.dart';
import 'enums/rollout_state.dart';
import 'enums/ec_key_algorithm.dart';
import 'enums/rollout_state.dart';
import 'enums/sync_state.dart';
import 'enums/token_origin_source_type.dart';
import 'token_import/token_origin_data.dart';
Expand Down
6 changes: 3 additions & 3 deletions lib/model/tokens/day_password_token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@

import 'package:flutter/material.dart';
import 'package:json_annotation/json_annotation.dart';
import '../../utils/identifiers.dart';
import '../../utils/object_validator.dart';
import '../token_template.dart';
import 'package:uuid/uuid.dart';

import '../../utils/identifiers.dart';
import '../../utils/object_validator.dart';
import '../enums/algorithms.dart';
import '../enums/day_password_token_view_mode.dart';
import '../enums/token_types.dart';
import '../extensions/enums/algorithms_extension.dart';
import '../token_import/token_origin_data.dart';
import '../token_template.dart';
import 'otp_token.dart';
import 'token.dart';

Expand Down
4 changes: 2 additions & 2 deletions lib/model/tokens/otp_token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import 'dart:convert';
import '../../utils/identifiers.dart';
import '../../utils/logger.dart';
import '../enums/algorithms.dart';
import '../token_template.dart';
import '../token_import/token_origin_data.dart';
import '../token_container.dart';
import '../token_import/token_origin_data.dart';
import '../token_template.dart';
import 'token.dart';

abstract class OTPToken extends Token {
Expand Down
4 changes: 2 additions & 2 deletions lib/model/tokens/push_token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import 'package:privacyidea_authenticator/model/token_template.dart';
import 'package:uuid/uuid.dart';

import '../../utils/custom_int_buffer.dart';
import '../../utils/errors.dart';
import '../exception_errors/localized_argument_error.dart';
import '../../utils/identifiers.dart';
import '../../utils/object_validator.dart';
import '../../utils/rsa_utils.dart';
import '../enums/push_token_rollout_state.dart';
import '../enums/token_types.dart';
import '../token_import/token_origin_data.dart';
import '../token_container.dart';
import '../token_import/token_origin_data.dart';
import 'token.dart';

part 'push_token.g.dart';
Expand Down
4 changes: 2 additions & 2 deletions lib/model/tokens/token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
*/
import 'package:flutter/material.dart';
import 'package:privacyidea_authenticator/model/token_container.dart';
import '../../utils/object_validator.dart';
import '../token_template.dart';

import '../../utils/identifiers.dart';
import '../../utils/object_validator.dart';
import '../enums/token_types.dart';
import '../extensions/enum_extension.dart';
import '../mixins/sortable_mixin.dart';
import '../token_import/token_origin_data.dart';
import '../token_template.dart';
import 'day_password_token.dart';
import 'hotp_token.dart';
import 'push_token.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* limitations under the License.
*/
import 'package:privacyidea_authenticator/l10n/app_localizations.dart';
import 'package:privacyidea_authenticator/utils/errors.dart';
import 'package:privacyidea_authenticator/model/exception_errors/localized_argument_error.dart';
import 'package:privacyidea_authenticator/utils/globals.dart';

import '../../model/processor_result.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ import 'package:pointycastle/export.dart';
import '../../l10n/app_localizations.dart';
import '../../model/enums/encodings.dart';
import '../../model/enums/token_origin_source_type.dart';
import '../../model/exception_errors/localized_exception.dart';
import '../../model/extensions/enums/encodings_extension.dart';
import '../../model/extensions/enums/token_origin_source_type.dart';
import '../../model/processor_result.dart';
import '../../model/tokens/token.dart';
import '../../utils/errors.dart';
import '../../model/exception_errors/localized_argument_error.dart';
import '../../utils/globals.dart';
import '../../utils/identifiers.dart';
import '../../utils/logger.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import '../../model/encryption/uint_8_buffer.dart';
import '../../model/enums/algorithms.dart';
import '../../model/enums/token_origin_source_type.dart';
import '../../model/enums/token_types.dart';
import '../../model/exception_errors/localized_exception.dart';
import '../../model/extensions/enums/token_origin_source_type.dart';
import '../../model/processor_result.dart';
import '../../model/tokens/token.dart';
import '../../processors/scheme_processors/token_import_scheme_processors/otp_auth_processor.dart';
import '../../processors/token_import_file_processor/two_fas_import_file_processor.dart';
import '../../utils/encryption/aes_encrypted.dart';
import '../../utils/errors.dart';
import '../../utils/globals.dart';
import '../../utils/identifiers.dart';
import '../../utils/logger.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import 'package:privacyidea_authenticator/model/extensions/enums/encodings_exten

import '../../l10n/app_localizations.dart';
import '../../model/enums/token_origin_source_type.dart';
import '../../model/exception_errors/localized_exception.dart';
import '../../model/extensions/enums/token_origin_source_type.dart';
import '../../model/processor_result.dart';
import '../../model/tokens/token.dart';
import '../../utils/errors.dart';
import '../../utils/globals.dart';
import '../../utils/identifiers.dart';
import '../../utils/logger.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import 'package:file_selector/file_selector.dart';

import '../../l10n/app_localizations.dart';
import '../../model/enums/token_origin_source_type.dart';
import '../../model/exception_errors/localized_exception.dart';
import '../../model/extensions/enums/token_origin_source_type.dart';
import '../../model/processor_result.dart';
import '../../model/tokens/token.dart';
import '../../utils/encryption/aes_encrypted.dart';
import '../../utils/errors.dart';
import '../../utils/globals.dart';
import '../../utils/identifiers.dart';
import '../../utils/logger.dart';
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/customization/theme_customization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import 'dart:math';

import 'package:flutter/material.dart';
import 'package:privacyidea_authenticator/model/extensions/color_extension.dart';
import 'theme_extentions/elevated_delete_button_theme.dart';

import 'theme_extentions/action_theme.dart';
import 'theme_extentions/elevated_delete_button_theme.dart';
import 'theme_extentions/extended_text_theme.dart';
import 'theme_extentions/push_request_theme.dart';

Expand Down
Loading

0 comments on commit de819ae

Please sign in to comment.