mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
feat(server,web): Delete and restore user from the admin portal (#935)
* delete and restore user from admin UI * addressed review comments and fix e2e test * added cron job to delete user, and some formatting changes * addressed review comments * adding missing queue registration
This commit is contained in:
@@ -120,6 +120,54 @@ class UserApi {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Performs an HTTP 'DELETE /user/{userId}' operation and returns the [Response].
|
||||
/// Parameters:
|
||||
///
|
||||
/// * [String] userId (required):
|
||||
Future<Response> deleteUserWithHttpInfo(String userId,) async {
|
||||
// ignore: prefer_const_declarations
|
||||
final path = r'/user/{userId}'
|
||||
.replaceAll('{userId}', userId);
|
||||
|
||||
// ignore: prefer_final_locals
|
||||
Object? postBody;
|
||||
|
||||
final queryParams = <QueryParam>[];
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
const contentTypes = <String>[];
|
||||
|
||||
|
||||
return apiClient.invokeAPI(
|
||||
path,
|
||||
'DELETE',
|
||||
queryParams,
|
||||
postBody,
|
||||
headerParams,
|
||||
formParams,
|
||||
contentTypes.isEmpty ? null : contentTypes.first,
|
||||
);
|
||||
}
|
||||
|
||||
/// Parameters:
|
||||
///
|
||||
/// * [String] userId (required):
|
||||
Future<UserResponseDto?> deleteUser(String userId,) async {
|
||||
final response = await deleteUserWithHttpInfo(userId,);
|
||||
if (response.statusCode >= HttpStatus.badRequest) {
|
||||
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
|
||||
}
|
||||
// When a remote server returns no body with a status of 204, we shall not decode it.
|
||||
// At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
|
||||
// FormatException when trying to decode an empty string.
|
||||
if (response.body.isNotEmpty && response.statusCode != HttpStatus.noContent) {
|
||||
return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'UserResponseDto',) as UserResponseDto;
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Performs an HTTP 'GET /user' operation and returns the [Response].
|
||||
/// Parameters:
|
||||
///
|
||||
@@ -350,6 +398,54 @@ class UserApi {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Performs an HTTP 'POST /user/{userId}/restore' operation and returns the [Response].
|
||||
/// Parameters:
|
||||
///
|
||||
/// * [String] userId (required):
|
||||
Future<Response> restoreUserWithHttpInfo(String userId,) async {
|
||||
// ignore: prefer_const_declarations
|
||||
final path = r'/user/{userId}/restore'
|
||||
.replaceAll('{userId}', userId);
|
||||
|
||||
// ignore: prefer_final_locals
|
||||
Object? postBody;
|
||||
|
||||
final queryParams = <QueryParam>[];
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
const contentTypes = <String>[];
|
||||
|
||||
|
||||
return apiClient.invokeAPI(
|
||||
path,
|
||||
'POST',
|
||||
queryParams,
|
||||
postBody,
|
||||
headerParams,
|
||||
formParams,
|
||||
contentTypes.isEmpty ? null : contentTypes.first,
|
||||
);
|
||||
}
|
||||
|
||||
/// Parameters:
|
||||
///
|
||||
/// * [String] userId (required):
|
||||
Future<UserResponseDto?> restoreUser(String userId,) async {
|
||||
final response = await restoreUserWithHttpInfo(userId,);
|
||||
if (response.statusCode >= HttpStatus.badRequest) {
|
||||
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
|
||||
}
|
||||
// When a remote server returns no body with a status of 204, we shall not decode it.
|
||||
// At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
|
||||
// FormatException when trying to decode an empty string.
|
||||
if (response.body.isNotEmpty && response.statusCode != HttpStatus.noContent) {
|
||||
return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'UserResponseDto',) as UserResponseDto;
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Performs an HTTP 'PUT /user' operation and returns the [Response].
|
||||
/// Parameters:
|
||||
///
|
||||
|
||||
@@ -21,6 +21,7 @@ class UserResponseDto {
|
||||
required this.profileImagePath,
|
||||
required this.shouldChangePassword,
|
||||
required this.isAdmin,
|
||||
required this.deletedAt,
|
||||
});
|
||||
|
||||
String id;
|
||||
@@ -39,6 +40,8 @@ class UserResponseDto {
|
||||
|
||||
bool isAdmin;
|
||||
|
||||
DateTime? deletedAt;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => identical(this, other) || other is UserResponseDto &&
|
||||
other.id == id &&
|
||||
@@ -48,7 +51,8 @@ class UserResponseDto {
|
||||
other.createdAt == createdAt &&
|
||||
other.profileImagePath == profileImagePath &&
|
||||
other.shouldChangePassword == shouldChangePassword &&
|
||||
other.isAdmin == isAdmin;
|
||||
other.isAdmin == isAdmin &&
|
||||
other.deletedAt == deletedAt;
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
@@ -60,10 +64,11 @@ class UserResponseDto {
|
||||
(createdAt.hashCode) +
|
||||
(profileImagePath.hashCode) +
|
||||
(shouldChangePassword.hashCode) +
|
||||
(isAdmin.hashCode);
|
||||
(isAdmin.hashCode) +
|
||||
(deletedAt == null ? 0 : deletedAt!.hashCode);
|
||||
|
||||
@override
|
||||
String toString() => 'UserResponseDto[id=$id, email=$email, firstName=$firstName, lastName=$lastName, createdAt=$createdAt, profileImagePath=$profileImagePath, shouldChangePassword=$shouldChangePassword, isAdmin=$isAdmin]';
|
||||
String toString() => 'UserResponseDto[id=$id, email=$email, firstName=$firstName, lastName=$lastName, createdAt=$createdAt, profileImagePath=$profileImagePath, shouldChangePassword=$shouldChangePassword, isAdmin=$isAdmin, deletedAt=$deletedAt]';
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final _json = <String, dynamic>{};
|
||||
@@ -75,6 +80,11 @@ class UserResponseDto {
|
||||
_json[r'profileImagePath'] = profileImagePath;
|
||||
_json[r'shouldChangePassword'] = shouldChangePassword;
|
||||
_json[r'isAdmin'] = isAdmin;
|
||||
if (deletedAt != null) {
|
||||
_json[r'deletedAt'] = deletedAt!.toUtc().toIso8601String();
|
||||
} else {
|
||||
_json[r'deletedAt'] = null;
|
||||
}
|
||||
return _json;
|
||||
}
|
||||
|
||||
@@ -105,6 +115,7 @@ class UserResponseDto {
|
||||
profileImagePath: mapValueOfType<String>(json, r'profileImagePath')!,
|
||||
shouldChangePassword: mapValueOfType<bool>(json, r'shouldChangePassword')!,
|
||||
isAdmin: mapValueOfType<bool>(json, r'isAdmin')!,
|
||||
deletedAt: mapDateTime(json, r'deletedAt', ''),
|
||||
);
|
||||
}
|
||||
return null;
|
||||
@@ -162,6 +173,7 @@ class UserResponseDto {
|
||||
'profileImagePath',
|
||||
'shouldChangePassword',
|
||||
'isAdmin',
|
||||
'deletedAt',
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user