add auth to all container chip widgets
This commit is contained in:
+11
-2
@@ -25,6 +25,7 @@ import 'package:go_router/go_router.dart';
|
|||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
|
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
|
||||||
import 'package:weblibre/features/geckoview/features/tabs/data/models/container_data.dart';
|
import 'package:weblibre/features/geckoview/features/tabs/data/models/container_data.dart';
|
||||||
|
import 'package:weblibre/features/geckoview/features/tabs/domain/providers/selected_container.dart';
|
||||||
import 'package:weblibre/features/geckoview/features/tabs/presentation/widgets/container_chips.dart';
|
import 'package:weblibre/features/geckoview/features/tabs/presentation/widgets/container_chips.dart';
|
||||||
import 'package:weblibre/utils/form_validators.dart';
|
import 'package:weblibre/utils/form_validators.dart';
|
||||||
|
|
||||||
@@ -69,8 +70,16 @@ class OpenSharedContent extends HookConsumerWidget {
|
|||||||
child: ContainerChips(
|
child: ContainerChips(
|
||||||
displayMenu: false,
|
displayMenu: false,
|
||||||
selectedContainer: selectedContainer.value,
|
selectedContainer: selectedContainer.value,
|
||||||
onSelected: (container) {
|
onSelected: (container) async {
|
||||||
selectedContainer.value = container;
|
if (container != null) {
|
||||||
|
if (await ref
|
||||||
|
.read(selectedContainerProvider.notifier)
|
||||||
|
.authenticateContainer(container)) {
|
||||||
|
selectedContainer.value = container;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
selectedContainer.value = container;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onDeleted: (container) {
|
onDeleted: (container) {
|
||||||
selectedContainer.value = null;
|
selectedContainer.value = null;
|
||||||
|
|||||||
+10
-2
@@ -100,8 +100,16 @@ class TabSearch extends HookConsumerWidget {
|
|||||||
ContainerChips(
|
ContainerChips(
|
||||||
displayMenu: false,
|
displayMenu: false,
|
||||||
selectedContainer: selectedContainer.value,
|
selectedContainer: selectedContainer.value,
|
||||||
onSelected: (container) {
|
onSelected: (container) async {
|
||||||
selectedContainer.value = container;
|
if (container != null) {
|
||||||
|
if (await ref
|
||||||
|
.read(selectedContainerProvider.notifier)
|
||||||
|
.authenticateContainer(container)) {
|
||||||
|
selectedContainer.value = container;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
selectedContainer.value = container;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onDeleted: (container) {
|
onDeleted: (container) {
|
||||||
selectedContainer.value = null;
|
selectedContainer.value = null;
|
||||||
|
|||||||
@@ -45,30 +45,35 @@ class SelectedContainer extends _$SelectedContainer {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> authenticateContainer(ContainerData container) async {
|
||||||
|
var passAuth = false;
|
||||||
|
if (container.metadata.authSettings.authenticationRequired) {
|
||||||
|
final authResult = await ref
|
||||||
|
.read(localAuthenticationServiceProvider.notifier)
|
||||||
|
.authenticate(
|
||||||
|
authKey: 'container_access::${container.id}',
|
||||||
|
localizedReason: 'Require authentication for container',
|
||||||
|
settings: container.metadata.authSettings,
|
||||||
|
useAuthCache: true,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (authResult) {
|
||||||
|
passAuth = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
passAuth = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return passAuth;
|
||||||
|
}
|
||||||
|
|
||||||
Future<SetContainerResult> setContainerId(String id) async {
|
Future<SetContainerResult> setContainerId(String id) async {
|
||||||
final container = await ref
|
final container = await ref
|
||||||
.read(containerRepositoryProvider.notifier)
|
.read(containerRepositoryProvider.notifier)
|
||||||
.getContainerData(id);
|
.getContainerData(id);
|
||||||
|
|
||||||
if (container != null) {
|
if (container != null) {
|
||||||
var passAuth = false;
|
final passAuth = await authenticateContainer(container);
|
||||||
if (container.metadata.authSettings.authenticationRequired) {
|
|
||||||
final authResult = await ref
|
|
||||||
.read(localAuthenticationServiceProvider.notifier)
|
|
||||||
.authenticate(
|
|
||||||
authKey: 'container_access::${container.id}',
|
|
||||||
localizedReason: 'Require authentication for container',
|
|
||||||
settings: container.metadata.authSettings,
|
|
||||||
useAuthCache: true,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (authResult) {
|
|
||||||
passAuth = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
passAuth = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (passAuth) {
|
if (passAuth) {
|
||||||
if (container.metadata.useProxy) {
|
if (container.metadata.useProxy) {
|
||||||
final proxyPluginHealthy = await GeckoContainerProxyService()
|
final proxyPluginHealthy = await GeckoContainerProxyService()
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ final class SelectedContainerProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String _$selectedContainerHash() => r'9e9a9b5e3c91ff1fbf8544e329524f8e064587fe';
|
String _$selectedContainerHash() => r'94d68a5b8f2746166ab2269afb6cd50c7c7599bf';
|
||||||
|
|
||||||
abstract class _$SelectedContainer extends $Notifier<String?> {
|
abstract class _$SelectedContainer extends $Notifier<String?> {
|
||||||
String? build();
|
String? build();
|
||||||
|
|||||||
Reference in New Issue
Block a user