mirror of
https://github.com/linagora/tmail-flutter.git
synced 2026-12-06 16:04:20 +00:00
fixup! TF-4449 Connect real drive backend to client
This commit is contained in:
1 parent
f61cac8b58
commit
bd51cb57dd
3 files changed
+45
-23
No files matched your search
+18
-18
@@ -29,8 +29,8 @@ ProviderContainer _makeContainer({
|
||||
Uri? _currentUri(ProviderContainer c) =>
|
||||
c.read(driveAttachmentUriValueProvider).value;
|
||||
|
||||
bool _isFakeUri(Uri? uri) => uri?.scheme == 'data';
|
||||
bool _isRealUri(Uri? uri) => uri != null && !_isFakeUri(uri);
|
||||
bool _isNullUri(Uri? uri) => uri == null;
|
||||
bool _isRealUri(Uri? uri) => uri != null;
|
||||
|
||||
ProviderContainer _makeAllMetContainer() => _makeContainer(
|
||||
enabledDefault: true,
|
||||
@@ -83,33 +83,33 @@ void main() {
|
||||
|
||||
tearDown(() => container.dispose());
|
||||
|
||||
test('fake data URI when all conditions unset (defaults)', () {
|
||||
test('null URI when all conditions unset (defaults)', () {
|
||||
container = _makeContainer();
|
||||
expect(_isFakeUri(_currentUri(container)), isTrue);
|
||||
expect(_isNullUri(_currentUri(container)), isTrue);
|
||||
});
|
||||
|
||||
test('fake data URI when enabled=true and fqdn set but user preference off', () {
|
||||
test('null URI when enabled=true and fqdn set but user preference off', () {
|
||||
container = _makeContainer(
|
||||
enabledDefault: true,
|
||||
fqdnDefault: _kWorkplaceFqdn,
|
||||
);
|
||||
expect(_isFakeUri(_currentUri(container)), isTrue);
|
||||
expect(_isNullUri(_currentUri(container)), isTrue);
|
||||
});
|
||||
|
||||
test('fake data URI when enabled=true and user preference on but fqdn=null', () {
|
||||
test('null URI when enabled=true and user preference on but fqdn=null', () {
|
||||
container = _makeContainer(
|
||||
enabledDefault: true,
|
||||
userPreferenceDefault: true,
|
||||
);
|
||||
expect(_isFakeUri(_currentUri(container)), isTrue);
|
||||
expect(_isNullUri(_currentUri(container)), isTrue);
|
||||
});
|
||||
|
||||
test('fake data URI when fqdn set and user preference on but enabled=false', () {
|
||||
test('null URI when fqdn set and user preference on but enabled=false', () {
|
||||
container = _makeContainer(
|
||||
fqdnDefault: _kWorkplaceFqdn,
|
||||
userPreferenceDefault: true,
|
||||
);
|
||||
expect(_isFakeUri(_currentUri(container)), isTrue);
|
||||
expect(_isNullUri(_currentUri(container)), isTrue);
|
||||
});
|
||||
|
||||
test('real URI when all three conditions met', () {
|
||||
@@ -117,16 +117,16 @@ void main() {
|
||||
expect(_isRealUri(_currentUri(container)), isTrue);
|
||||
});
|
||||
|
||||
test('fake data URI when fqdn reset to null after all conditions met', () {
|
||||
test('null URI when fqdn reset to null after all conditions met', () {
|
||||
container = _makeAllMetContainer();
|
||||
_setFqdn(container, null);
|
||||
expect(_isFakeUri(_currentUri(container)), isTrue);
|
||||
expect(_isNullUri(_currentUri(container)), isTrue);
|
||||
});
|
||||
|
||||
test('fake data URI when enabled reset to false after all conditions met', () {
|
||||
test('null URI when enabled reset to false after all conditions met', () {
|
||||
container = _makeAllMetContainer();
|
||||
_setEnabled(container, false);
|
||||
expect(_isFakeUri(_currentUri(container)), isTrue);
|
||||
expect(_isNullUri(_currentUri(container)), isTrue);
|
||||
});
|
||||
|
||||
test('real URI when enabled=null (treated as true)', () {
|
||||
@@ -138,17 +138,17 @@ void main() {
|
||||
expect(_currentUri(container), Uri.parse(_kWorkplaceFqdn));
|
||||
});
|
||||
|
||||
test('transitions from fake to real URI when user preference toggled from false to true', () {
|
||||
test('transitions from null to real URI when user preference toggled from false to true', () {
|
||||
container = _makeContainer(
|
||||
enabledDefault: true,
|
||||
fqdnDefault: _kWorkplaceFqdn,
|
||||
);
|
||||
expect(_isFakeUri(_currentUri(container)), isTrue);
|
||||
expect(_isNullUri(_currentUri(container)), isTrue);
|
||||
_setUserPref(container, true);
|
||||
expect(_isRealUri(_currentUri(container)), isTrue);
|
||||
});
|
||||
|
||||
test('transitions from real to fake URI when user preference toggled from true to false', () {
|
||||
test('transitions from real to null URI when user preference toggled from true to false', () {
|
||||
container = _makeContainer(
|
||||
enabledDefault: true,
|
||||
fqdnDefault: _kWorkplaceFqdn,
|
||||
@@ -156,7 +156,7 @@ void main() {
|
||||
);
|
||||
expect(_isRealUri(_currentUri(container)), isTrue);
|
||||
_setUserPref(container, false);
|
||||
expect(_isFakeUri(_currentUri(container)), isTrue);
|
||||
expect(_isNullUri(_currentUri(container)), isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -67,7 +67,10 @@ class WorkplaceDataSourceImpl implements WorkplaceDataSource {
|
||||
'$platformUrl/auth/token_exchange',
|
||||
data: WorkplaceExchangeTokenRequest(idToken: oidcIdToken).toJson(),
|
||||
);
|
||||
final accessToken = response.data['access_token'];
|
||||
final data = response.data is Map<String, dynamic>
|
||||
? response.data as Map<String, dynamic>
|
||||
: jsonDecode(response.data) as Map<String, dynamic>;
|
||||
final accessToken = data['access_token'];
|
||||
if (accessToken is! String) {
|
||||
throw StateError('Invalid token response: access_token is ${accessToken.runtimeType}');
|
||||
}
|
||||
|
||||
@@ -37,25 +37,44 @@ class WorkplaceComposerAttachmentExtension implements ComposerAttachmentPlugin {
|
||||
}) async {
|
||||
final oidcToken = oidcTokenGetter();
|
||||
if (oidcToken == null) return null;
|
||||
final accessToken = await _exchangeAccessToken(platformUrl, oidcToken);
|
||||
if (accessToken == null) return null;
|
||||
return _createIntent(
|
||||
platformUrl,
|
||||
accessToken,
|
||||
addAsLink: addAsLink,
|
||||
addAsAttachment: addAsAttachment,
|
||||
);
|
||||
}
|
||||
|
||||
Future<String?> _exchangeAccessToken(Uri platformUrl, String oidcToken) async {
|
||||
String? accessToken;
|
||||
await for (final either in _exchangeTokenInteractor.execute(platformUrl, oidcToken)) {
|
||||
either.fold(
|
||||
(failure) => logWarning('WorkplaceComposerAttachmentExtension::_fetchIntent exchange failed: $failure'),
|
||||
(failure) => logWarning('WorkplaceComposerAttachmentExtension::_exchangeAccessToken failed: $failure'),
|
||||
(success) {
|
||||
if (success is ExchangeWorkplaceTokenSuccess) accessToken = success.accessToken;
|
||||
},
|
||||
);
|
||||
}
|
||||
if (accessToken == null) return null;
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
Future<WorkplaceIntent?> _createIntent(
|
||||
Uri platformUrl,
|
||||
String accessToken, {
|
||||
required String addAsLink,
|
||||
required String addAsAttachment,
|
||||
}) async {
|
||||
WorkplaceIntent? intent;
|
||||
await for (final either in _createIntentInteractor.execute(
|
||||
platformUrl,
|
||||
accessToken!,
|
||||
accessToken,
|
||||
addAsLink: addAsLink,
|
||||
addAsAttachment: addAsAttachment,
|
||||
)) {
|
||||
either.fold(
|
||||
(failure) => logWarning('WorkplaceComposerAttachmentExtension::_fetchIntent create failed: $failure'),
|
||||
(failure) => logWarning('WorkplaceComposerAttachmentExtension::_createIntent failed: $failure'),
|
||||
(success) {
|
||||
if (success is CreateWorkplaceIntentSuccess) intent = success.intent;
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user