fix: Adapt to new provider strucutre

This commit is contained in:
Anton Stubenbord
2023-05-11 12:37:17 +02:00
parent d5c68e023c
commit f388f77d63
43 changed files with 540 additions and 1254 deletions

View File

@@ -53,5 +53,6 @@ enum ErrorCode {
requestTimedOut,
unsupportedFileFormat,
missingClientCertificate,
acknowledgeTasksError;
acknowledgeTasksError,
notAuthorized;
}

View File

@@ -3,25 +3,17 @@ import 'package:paperless_api/src/request_utils.dart';
class PaperlessServerInformationModel {
static const String versionHeader = 'x-version';
static const String apiVersionHeader = 'x-api-version';
static const String hostHeader = 'x-served-by';
final String? version;
final int? apiVersion;
final String? username;
final String? host;
String? get userInitials {
return username?.substring(0, 1).toUpperCase();
}
final String version;
final int apiVersion;
final bool isUpdateAvailable;
PaperlessServerInformationModel({
this.host,
this.username,
this.version = 'unknown',
this.apiVersion = 1,
required this.version,
required this.apiVersion,
required this.isUpdateAvailable,
});
int compareToOtherVersion(String? other) {
return getExtendedVersionNumber(version ?? '0.0.0')
.compareTo(getExtendedVersionNumber(other ?? '0.0.0'));
int compareToOtherVersion(String other) {
return getExtendedVersionNumber(version).compareTo(getExtendedVersionNumber(other));
}
}

View File

@@ -130,7 +130,9 @@ enum InheritedPermissions {
@HiveField(60)
documentsChangeSavedviewfilterrule("documents.change_savedviewfilterrule"),
@HiveField(61)
documentsChangeStoragepathdocuments("documents.change_storagepathdocuments.change_tag"),
documentsChangeStoragepath("documents.change_storagepath"),
@HiveField(111)
documentsChangeTag("documents.change_tag"),
@HiveField(62)
documentsChangeUisettings("documents.change_uisettings"),
@HiveField(63)

View File

@@ -64,7 +64,7 @@ class UserModel with _$UserModel {
return value.userPermissions.contains(permission);
},
v2: (value) {
// In previous versions, all users have access to all
// In previous versions, all users have all permissions.
return true;
},
);

View File

@@ -78,7 +78,6 @@ class PaperlessDocumentsApiImpl implements PaperlessDocumentsApi {
throw const PaperlessServerException(ErrorCode.documentUpdateFailed);
}
} on DioError catch (err) {
//TODO: Handle 403 permission errors for 1.14.0
throw err.error!;
}
}

View File

@@ -22,16 +22,13 @@ class PaperlessServerStatsApiImpl implements PaperlessServerStatsApi {
if (response.statusCode == 200) {
final version = response.data["version"] as String;
final updateAvailable = response.data["update_available"] as bool;
return PaperlessServerInformationModel(
apiVersion: int.parse(response.headers.value('x-api-version')!),
version: version,
isUpdateAvailable: updateAvailable,
);
}
throw PaperlessServerException.unknown();
final version =
response.headers[PaperlessServerInformationModel.versionHeader]?.first ?? 'unknown';
final apiVersion = int.tryParse(
response.headers[PaperlessServerInformationModel.apiVersionHeader]?.first ?? '1');
return PaperlessServerInformationModel(
version: version,
apiVersion: apiVersion,
);
throw const PaperlessServerException.unknown();
}
@override

View File

@@ -52,7 +52,7 @@ class PaperlessUserApiV3Impl implements PaperlessUserApi, PaperlessUserApiV3 {
if (response.statusCode == 200) {
return PagedSearchResult<UserModelV3>.fromJson(
response.data,
UserModelV3.fromJson as UserModelV3 Function(Object?),
(json) => UserModelV3.fromJson(json as dynamic),
).results;
}
throw const PaperlessServerException.unknown();