Browse Source

Merge pull request #325 from provokateurin/feature/expose-supported-versions

Expose supported versions
pull/330/head
Kate 2 years ago committed by GitHub
parent
commit
955f78c770
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      packages/neon/neon/lib/src/pages/home.dart
  2. 47
      packages/nextcloud/lib/src/version_supported.dart
  3. 12
      packages/nextcloud/test/core.dart
  4. 4
      packages/nextcloud/test/news.dart
  5. 4
      packages/nextcloud/test/notes.dart

22
packages/neon/neon/lib/src/pages/home.dart

@ -60,20 +60,13 @@ class _HomePageState extends State<HomePage> {
...appsResult.data!.map((final a) => a.id), ...appsResult.data!.map((final a) => a.id),
]) { ]) {
try { try {
bool? supported; final (supported, _) = switch (id) {
switch (id) { 'core' => await widget.account.client.core.isSupported(result.data),
case 'core': 'news' => await widget.account.client.news.isSupported(),
supported = await widget.account.client.core.isSupported(result.data); 'notes' => await widget.account.client.notes.isSupported(result.data),
break; _ => (true, null),
case 'news': };
supported = await widget.account.client.news.isSupported(); if (supported || !mounted) {
break;
case 'notes':
supported = await widget.account.client.notes.isSupported(result.data);
break;
}
if (!(supported ?? true)) {
if (!mounted) {
return; return;
} }
var name = AppLocalizations.of(context).appImplementationName(id); var name = AppLocalizations.of(context).appImplementationName(id);
@ -83,7 +76,6 @@ class _HomePageState extends State<HomePage> {
await _showProblem( await _showProblem(
AppLocalizations.of(context).errorUnsupportedVersion(name), AppLocalizations.of(context).errorUnsupportedVersion(name),
); );
}
} catch (e, s) { } catch (e, s) {
debugPrint(e.toString()); debugPrint(e.toString());
debugPrint(s.toString()); debugPrint(s.toString());

47
packages/nextcloud/lib/src/version_supported.dart

@ -1,33 +1,56 @@
part of '../nextcloud.dart'; part of '../nextcloud.dart';
/// Version of core/Server supported
const coreSupportedVersion = 26;
/// API version of the news app supported
const newsSupportedVersion = 'v1-3';
/// API version of the notes app supported
const notesSupportedVersion = 1;
// ignore: public_member_api_docs // ignore: public_member_api_docs
extension CoreVersionSupported on NextcloudCoreClient { extension CoreVersionSupported on NextcloudCoreClient {
/// Checks if the app on the server is supported by the client /// Check if the core/Server version is supported by this client
Future<bool> isSupported([final NextcloudCoreServerCapabilities_Ocs_Data? capabilities]) async => ///
(capabilities ?? (await getCapabilities()).ocs.data).version.major == 26; /// Also returns the supported version number
Future<(bool, int)> isSupported([
final NextcloudCoreServerCapabilities_Ocs_Data? capabilities,
]) async =>
(
(capabilities ?? (await getCapabilities()).ocs.data).version.major == coreSupportedVersion,
coreSupportedVersion,
);
} }
// ignore: public_member_api_docs // ignore: public_member_api_docs
extension NewsVersionSupported on NextcloudNewsClient { extension NewsVersionSupported on NextcloudNewsClient {
/// Checks if the app on the server is supported by the client /// Check if the news app version is supported by this client
Future<bool> isSupported() async { ///
/// Also returns the supported API version number
Future<(bool, String)> isSupported() async {
final versions = await getSupportedApiVersions(); final versions = await getSupportedApiVersions();
return versions.apiLevels!.contains('v1-3'); return (
versions.apiLevels!.contains(newsSupportedVersion),
newsSupportedVersion,
);
} }
} }
// ignore: public_member_api_docs // ignore: public_member_api_docs
extension NotesVersionSupported on NextcloudNotesClient { extension NotesVersionSupported on NextcloudNotesClient {
/// Checks if the app on the server is supported by the client /// Check if the notes app version is supported by this client
Future<bool> isSupported([final NextcloudCoreServerCapabilities_Ocs_Data? capabilities]) async => ///
/// Also returns the supported API version number
Future<(bool, int)> isSupported([final NextcloudCoreServerCapabilities_Ocs_Data? capabilities]) async => (
(capabilities ?? (await rootClient.core.getCapabilities()).ocs.data) (capabilities ?? (await rootClient.core.getCapabilities()).ocs.data)
.capabilities .capabilities
.notes .notes
?.apiVersion ?.apiVersion
?.map(Version.parse) ?.map(Version.parse)
.where((final version) => version.major == 1) .where((final version) => version.major == notesSupportedVersion)
.isNotEmpty ?? .isNotEmpty ??
false; false,
notesSupportedVersion,
);
} }
// Notifications, ProvisioningApi, UserStatus and Webdav are shipped with the Nextcloud server, so their supported versions depend on the major version of the Nextcloud instance.

12
packages/nextcloud/test/core.dart

@ -18,8 +18,8 @@ Future run(final DockerImage image) async {
tearDown(() => container.destroy()); tearDown(() => container.destroy());
test('Is supported', () async { test('Is supported', () async {
final response = await client.core.isSupported(); final (supported, _) = await client.core.isSupported();
expect(response, isTrue); expect(supported, isTrue);
}); });
test('Get status', () async { test('Get status', () async {
@ -27,8 +27,8 @@ Future run(final DockerImage image) async {
expect(status.installed, true); expect(status.installed, true);
expect(status.maintenance, false); expect(status.maintenance, false);
expect(status.needsDbUpgrade, false); expect(status.needsDbUpgrade, false);
expect(status.version, startsWith('26.0.1')); expect(status.version, startsWith('$coreSupportedVersion.'));
expect(status.versionstring, '26.0.1'); expect(status.versionstring, startsWith('$coreSupportedVersion.'));
expect(status.edition, ''); expect(status.edition, '');
expect(status.productname, 'Nextcloud'); expect(status.productname, 'Nextcloud');
expect(status.extendedSupport, false); expect(status.extendedSupport, false);
@ -36,8 +36,8 @@ Future run(final DockerImage image) async {
test('Get capabilities', () async { test('Get capabilities', () async {
final capabilities = await client.core.getCapabilities(); final capabilities = await client.core.getCapabilities();
expect(capabilities.ocs.data.version.major.toString(), '26'); expect(capabilities.ocs.data.version.major, coreSupportedVersion);
expect(capabilities.ocs.data.version.string, '26.0.1'); expect(capabilities.ocs.data.version.string, startsWith('$coreSupportedVersion.'));
expect(capabilities.ocs.data.capabilities.theming!.name, 'Nextcloud'); expect(capabilities.ocs.data.capabilities.theming!.name, 'Nextcloud');
expect(capabilities.ocs.data.capabilities.theming!.url, 'https://nextcloud.com'); expect(capabilities.ocs.data.capabilities.theming!.url, 'https://nextcloud.com');
expect(capabilities.ocs.data.capabilities.theming!.slogan, 'a safe home for all your data'); expect(capabilities.ocs.data.capabilities.theming!.slogan, 'a safe home for all your data');

4
packages/nextcloud/test/news.dart

@ -30,8 +30,8 @@ Future run(final DockerImage image) async {
); );
test('Is supported', () async { test('Is supported', () async {
final response = await client.news.isSupported(); final (supported, _) = await client.news.isSupported();
expect(response, isTrue); expect(supported, isTrue);
}); });
test('Add feed', () async { test('Add feed', () async {

4
packages/nextcloud/test/notes.dart

@ -18,8 +18,8 @@ Future run(final DockerImage image) async {
tearDown(() => container.destroy()); tearDown(() => container.destroy());
test('Is supported', () async { test('Is supported', () async {
final response = await client.notes.isSupported(); final (supported, _) = await client.notes.isSupported();
expect(response, isTrue); expect(supported, isTrue);
}); });
test('Create note favorite', () async { test('Create note favorite', () async {

Loading…
Cancel
Save