Refactor Users cubit to use GraphQL and unified data model
parent
c1bb617ca7
commit
0879ea8e97
|
@ -281,7 +281,11 @@
|
|||
"delete_confirm_question": "Are you sure?",
|
||||
"reset_password": "Reset password",
|
||||
"account": "Account",
|
||||
"send_registration_data": "Share login credentials"
|
||||
"send_registration_data": "Share login credentials",
|
||||
"could_not_fetch_users": "Couldn't fetch users list",
|
||||
"could_not_create_user": "Couldn't create user",
|
||||
"could_not_delete_user": "Couldn't delete user",
|
||||
"could_not_add_ssh_key": "Couldn't add SSH key"
|
||||
},
|
||||
"initializing": {
|
||||
"_comment": "initializing page",
|
||||
|
|
|
@ -15,6 +15,9 @@ query AllUsers {
|
|||
allUsers {
|
||||
...userFields
|
||||
}
|
||||
rootUser: getUser(username: "root") {
|
||||
...userFields
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -6,37 +6,28 @@ part of 'users.graphql.dart';
|
|||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Fragment$basicMutationReturnFields _$Fragment$basicMutationReturnFieldsFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Fragment$basicMutationReturnFields(
|
||||
Fragment$basicMutationReturnFields _$Fragment$basicMutationReturnFieldsFromJson(Map<String, dynamic> json) => Fragment$basicMutationReturnFields(
|
||||
code: json['code'] as int,
|
||||
message: json['message'] as String,
|
||||
success: json['success'] as bool,
|
||||
$__typename: json['__typename'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Fragment$basicMutationReturnFieldsToJson(
|
||||
Fragment$basicMutationReturnFields instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Fragment$basicMutationReturnFieldsToJson(Fragment$basicMutationReturnFields instance) => <String, dynamic>{
|
||||
'code': instance.code,
|
||||
'message': instance.message,
|
||||
'success': instance.success,
|
||||
'__typename': instance.$__typename,
|
||||
};
|
||||
|
||||
Fragment$userFields _$Fragment$userFieldsFromJson(Map<String, dynamic> json) =>
|
||||
Fragment$userFields(
|
||||
Fragment$userFields _$Fragment$userFieldsFromJson(Map<String, dynamic> json) => Fragment$userFields(
|
||||
username: json['username'] as String,
|
||||
userType: $enumDecode(_$Enum$UserTypeEnumMap, json['userType'],
|
||||
unknownValue: Enum$UserType.$unknown),
|
||||
sshKeys:
|
||||
(json['sshKeys'] as List<dynamic>).map((e) => e as String).toList(),
|
||||
userType: $enumDecode(_$Enum$UserTypeEnumMap, json['userType'], unknownValue: Enum$UserType.$unknown),
|
||||
sshKeys: (json['sshKeys'] as List<dynamic>).map((e) => e as String).toList(),
|
||||
$__typename: json['__typename'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Fragment$userFieldsToJson(
|
||||
Fragment$userFields instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Fragment$userFieldsToJson(Fragment$userFields instance) => <String, dynamic>{
|
||||
'username': instance.username,
|
||||
'userType': _$Enum$UserTypeEnumMap[instance.userType]!,
|
||||
'sshKeys': instance.sshKeys,
|
||||
|
@ -50,118 +41,83 @@ const _$Enum$UserTypeEnumMap = {
|
|||
Enum$UserType.$unknown: r'$unknown',
|
||||
};
|
||||
|
||||
Query$AllUsers _$Query$AllUsersFromJson(Map<String, dynamic> json) =>
|
||||
Query$AllUsers(
|
||||
users:
|
||||
Query$AllUsers$users.fromJson(json['users'] as Map<String, dynamic>),
|
||||
Query$AllUsers _$Query$AllUsersFromJson(Map<String, dynamic> json) => Query$AllUsers(
|
||||
users: Query$AllUsers$users.fromJson(json['users'] as Map<String, dynamic>),
|
||||
$__typename: json['__typename'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Query$AllUsersToJson(Query$AllUsers instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Query$AllUsersToJson(Query$AllUsers instance) => <String, dynamic>{
|
||||
'users': instance.users.toJson(),
|
||||
'__typename': instance.$__typename,
|
||||
};
|
||||
|
||||
Query$AllUsers$users _$Query$AllUsers$usersFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Query$AllUsers$users(
|
||||
allUsers: (json['allUsers'] as List<dynamic>)
|
||||
.map((e) => Fragment$userFields.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
Query$AllUsers$users _$Query$AllUsers$usersFromJson(Map<String, dynamic> json) => Query$AllUsers$users(
|
||||
allUsers: (json['allUsers'] as List<dynamic>).map((e) => Fragment$userFields.fromJson(e as Map<String, dynamic>)).toList(),
|
||||
rootUser: json['rootUser'] == null ? null : Fragment$userFields.fromJson(json['rootUser'] as Map<String, dynamic>),
|
||||
$__typename: json['__typename'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Query$AllUsers$usersToJson(
|
||||
Query$AllUsers$users instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Query$AllUsers$usersToJson(Query$AllUsers$users instance) => <String, dynamic>{
|
||||
'allUsers': instance.allUsers.map((e) => e.toJson()).toList(),
|
||||
'rootUser': instance.rootUser?.toJson(),
|
||||
'__typename': instance.$__typename,
|
||||
};
|
||||
|
||||
Variables$Query$GetUser _$Variables$Query$GetUserFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Variables$Query$GetUser(
|
||||
Variables$Query$GetUser _$Variables$Query$GetUserFromJson(Map<String, dynamic> json) => Variables$Query$GetUser(
|
||||
username: json['username'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Variables$Query$GetUserToJson(
|
||||
Variables$Query$GetUser instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Variables$Query$GetUserToJson(Variables$Query$GetUser instance) => <String, dynamic>{
|
||||
'username': instance.username,
|
||||
};
|
||||
|
||||
Query$GetUser _$Query$GetUserFromJson(Map<String, dynamic> json) =>
|
||||
Query$GetUser(
|
||||
users:
|
||||
Query$GetUser$users.fromJson(json['users'] as Map<String, dynamic>),
|
||||
Query$GetUser _$Query$GetUserFromJson(Map<String, dynamic> json) => Query$GetUser(
|
||||
users: Query$GetUser$users.fromJson(json['users'] as Map<String, dynamic>),
|
||||
$__typename: json['__typename'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Query$GetUserToJson(Query$GetUser instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Query$GetUserToJson(Query$GetUser instance) => <String, dynamic>{
|
||||
'users': instance.users.toJson(),
|
||||
'__typename': instance.$__typename,
|
||||
};
|
||||
|
||||
Query$GetUser$users _$Query$GetUser$usersFromJson(Map<String, dynamic> json) =>
|
||||
Query$GetUser$users(
|
||||
getUser: json['getUser'] == null
|
||||
? null
|
||||
: Fragment$userFields.fromJson(
|
||||
json['getUser'] as Map<String, dynamic>),
|
||||
Query$GetUser$users _$Query$GetUser$usersFromJson(Map<String, dynamic> json) => Query$GetUser$users(
|
||||
getUser: json['getUser'] == null ? null : Fragment$userFields.fromJson(json['getUser'] as Map<String, dynamic>),
|
||||
$__typename: json['__typename'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Query$GetUser$usersToJson(
|
||||
Query$GetUser$users instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Query$GetUser$usersToJson(Query$GetUser$users instance) => <String, dynamic>{
|
||||
'getUser': instance.getUser?.toJson(),
|
||||
'__typename': instance.$__typename,
|
||||
};
|
||||
|
||||
Variables$Mutation$CreateUser _$Variables$Mutation$CreateUserFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Variables$Mutation$CreateUser(
|
||||
user: Input$UserMutationInput.fromJson(
|
||||
json['user'] as Map<String, dynamic>),
|
||||
Variables$Mutation$CreateUser _$Variables$Mutation$CreateUserFromJson(Map<String, dynamic> json) => Variables$Mutation$CreateUser(
|
||||
user: Input$UserMutationInput.fromJson(json['user'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Variables$Mutation$CreateUserToJson(
|
||||
Variables$Mutation$CreateUser instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Variables$Mutation$CreateUserToJson(Variables$Mutation$CreateUser instance) => <String, dynamic>{
|
||||
'user': instance.user.toJson(),
|
||||
};
|
||||
|
||||
Mutation$CreateUser _$Mutation$CreateUserFromJson(Map<String, dynamic> json) =>
|
||||
Mutation$CreateUser(
|
||||
createUser: Mutation$CreateUser$createUser.fromJson(
|
||||
json['createUser'] as Map<String, dynamic>),
|
||||
Mutation$CreateUser _$Mutation$CreateUserFromJson(Map<String, dynamic> json) => Mutation$CreateUser(
|
||||
createUser: Mutation$CreateUser$createUser.fromJson(json['createUser'] as Map<String, dynamic>),
|
||||
$__typename: json['__typename'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Mutation$CreateUserToJson(
|
||||
Mutation$CreateUser instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Mutation$CreateUserToJson(Mutation$CreateUser instance) => <String, dynamic>{
|
||||
'createUser': instance.createUser.toJson(),
|
||||
'__typename': instance.$__typename,
|
||||
};
|
||||
|
||||
Mutation$CreateUser$createUser _$Mutation$CreateUser$createUserFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Mutation$CreateUser$createUser(
|
||||
Mutation$CreateUser$createUser _$Mutation$CreateUser$createUserFromJson(Map<String, dynamic> json) => Mutation$CreateUser$createUser(
|
||||
code: json['code'] as int,
|
||||
message: json['message'] as String,
|
||||
success: json['success'] as bool,
|
||||
$__typename: json['__typename'] as String,
|
||||
user: json['user'] == null
|
||||
? null
|
||||
: Fragment$userFields.fromJson(json['user'] as Map<String, dynamic>),
|
||||
user: json['user'] == null ? null : Fragment$userFields.fromJson(json['user'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Mutation$CreateUser$createUserToJson(
|
||||
Mutation$CreateUser$createUser instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Mutation$CreateUser$createUserToJson(Mutation$CreateUser$createUser instance) => <String, dynamic>{
|
||||
'code': instance.code,
|
||||
'message': instance.message,
|
||||
'success': instance.success,
|
||||
|
@ -169,92 +125,65 @@ Map<String, dynamic> _$Mutation$CreateUser$createUserToJson(
|
|||
'user': instance.user?.toJson(),
|
||||
};
|
||||
|
||||
Variables$Mutation$DeleteUser _$Variables$Mutation$DeleteUserFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Variables$Mutation$DeleteUser(
|
||||
Variables$Mutation$DeleteUser _$Variables$Mutation$DeleteUserFromJson(Map<String, dynamic> json) => Variables$Mutation$DeleteUser(
|
||||
username: json['username'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Variables$Mutation$DeleteUserToJson(
|
||||
Variables$Mutation$DeleteUser instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Variables$Mutation$DeleteUserToJson(Variables$Mutation$DeleteUser instance) => <String, dynamic>{
|
||||
'username': instance.username,
|
||||
};
|
||||
|
||||
Mutation$DeleteUser _$Mutation$DeleteUserFromJson(Map<String, dynamic> json) =>
|
||||
Mutation$DeleteUser(
|
||||
deleteUser: Mutation$DeleteUser$deleteUser.fromJson(
|
||||
json['deleteUser'] as Map<String, dynamic>),
|
||||
Mutation$DeleteUser _$Mutation$DeleteUserFromJson(Map<String, dynamic> json) => Mutation$DeleteUser(
|
||||
deleteUser: Mutation$DeleteUser$deleteUser.fromJson(json['deleteUser'] as Map<String, dynamic>),
|
||||
$__typename: json['__typename'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Mutation$DeleteUserToJson(
|
||||
Mutation$DeleteUser instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Mutation$DeleteUserToJson(Mutation$DeleteUser instance) => <String, dynamic>{
|
||||
'deleteUser': instance.deleteUser.toJson(),
|
||||
'__typename': instance.$__typename,
|
||||
};
|
||||
|
||||
Mutation$DeleteUser$deleteUser _$Mutation$DeleteUser$deleteUserFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Mutation$DeleteUser$deleteUser(
|
||||
Mutation$DeleteUser$deleteUser _$Mutation$DeleteUser$deleteUserFromJson(Map<String, dynamic> json) => Mutation$DeleteUser$deleteUser(
|
||||
code: json['code'] as int,
|
||||
message: json['message'] as String,
|
||||
success: json['success'] as bool,
|
||||
$__typename: json['__typename'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Mutation$DeleteUser$deleteUserToJson(
|
||||
Mutation$DeleteUser$deleteUser instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Mutation$DeleteUser$deleteUserToJson(Mutation$DeleteUser$deleteUser instance) => <String, dynamic>{
|
||||
'code': instance.code,
|
||||
'message': instance.message,
|
||||
'success': instance.success,
|
||||
'__typename': instance.$__typename,
|
||||
};
|
||||
|
||||
Variables$Mutation$UpdateUser _$Variables$Mutation$UpdateUserFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Variables$Mutation$UpdateUser(
|
||||
user: Input$UserMutationInput.fromJson(
|
||||
json['user'] as Map<String, dynamic>),
|
||||
Variables$Mutation$UpdateUser _$Variables$Mutation$UpdateUserFromJson(Map<String, dynamic> json) => Variables$Mutation$UpdateUser(
|
||||
user: Input$UserMutationInput.fromJson(json['user'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Variables$Mutation$UpdateUserToJson(
|
||||
Variables$Mutation$UpdateUser instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Variables$Mutation$UpdateUserToJson(Variables$Mutation$UpdateUser instance) => <String, dynamic>{
|
||||
'user': instance.user.toJson(),
|
||||
};
|
||||
|
||||
Mutation$UpdateUser _$Mutation$UpdateUserFromJson(Map<String, dynamic> json) =>
|
||||
Mutation$UpdateUser(
|
||||
updateUser: Mutation$UpdateUser$updateUser.fromJson(
|
||||
json['updateUser'] as Map<String, dynamic>),
|
||||
Mutation$UpdateUser _$Mutation$UpdateUserFromJson(Map<String, dynamic> json) => Mutation$UpdateUser(
|
||||
updateUser: Mutation$UpdateUser$updateUser.fromJson(json['updateUser'] as Map<String, dynamic>),
|
||||
$__typename: json['__typename'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Mutation$UpdateUserToJson(
|
||||
Mutation$UpdateUser instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Mutation$UpdateUserToJson(Mutation$UpdateUser instance) => <String, dynamic>{
|
||||
'updateUser': instance.updateUser.toJson(),
|
||||
'__typename': instance.$__typename,
|
||||
};
|
||||
|
||||
Mutation$UpdateUser$updateUser _$Mutation$UpdateUser$updateUserFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Mutation$UpdateUser$updateUser(
|
||||
Mutation$UpdateUser$updateUser _$Mutation$UpdateUser$updateUserFromJson(Map<String, dynamic> json) => Mutation$UpdateUser$updateUser(
|
||||
code: json['code'] as int,
|
||||
message: json['message'] as String,
|
||||
success: json['success'] as bool,
|
||||
$__typename: json['__typename'] as String,
|
||||
user: json['user'] == null
|
||||
? null
|
||||
: Fragment$userFields.fromJson(json['user'] as Map<String, dynamic>),
|
||||
user: json['user'] == null ? null : Fragment$userFields.fromJson(json['user'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Mutation$UpdateUser$updateUserToJson(
|
||||
Mutation$UpdateUser$updateUser instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Mutation$UpdateUser$updateUserToJson(Mutation$UpdateUser$updateUser instance) => <String, dynamic>{
|
||||
'code': instance.code,
|
||||
'message': instance.message,
|
||||
'success': instance.success,
|
||||
|
@ -262,47 +191,33 @@ Map<String, dynamic> _$Mutation$UpdateUser$updateUserToJson(
|
|||
'user': instance.user?.toJson(),
|
||||
};
|
||||
|
||||
Variables$Mutation$AddSshKey _$Variables$Mutation$AddSshKeyFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Variables$Mutation$AddSshKey(
|
||||
sshInput: Input$SshMutationInput.fromJson(
|
||||
json['sshInput'] as Map<String, dynamic>),
|
||||
Variables$Mutation$AddSshKey _$Variables$Mutation$AddSshKeyFromJson(Map<String, dynamic> json) => Variables$Mutation$AddSshKey(
|
||||
sshInput: Input$SshMutationInput.fromJson(json['sshInput'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Variables$Mutation$AddSshKeyToJson(
|
||||
Variables$Mutation$AddSshKey instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Variables$Mutation$AddSshKeyToJson(Variables$Mutation$AddSshKey instance) => <String, dynamic>{
|
||||
'sshInput': instance.sshInput.toJson(),
|
||||
};
|
||||
|
||||
Mutation$AddSshKey _$Mutation$AddSshKeyFromJson(Map<String, dynamic> json) =>
|
||||
Mutation$AddSshKey(
|
||||
addSshKey: Mutation$AddSshKey$addSshKey.fromJson(
|
||||
json['addSshKey'] as Map<String, dynamic>),
|
||||
Mutation$AddSshKey _$Mutation$AddSshKeyFromJson(Map<String, dynamic> json) => Mutation$AddSshKey(
|
||||
addSshKey: Mutation$AddSshKey$addSshKey.fromJson(json['addSshKey'] as Map<String, dynamic>),
|
||||
$__typename: json['__typename'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Mutation$AddSshKeyToJson(Mutation$AddSshKey instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Mutation$AddSshKeyToJson(Mutation$AddSshKey instance) => <String, dynamic>{
|
||||
'addSshKey': instance.addSshKey.toJson(),
|
||||
'__typename': instance.$__typename,
|
||||
};
|
||||
|
||||
Mutation$AddSshKey$addSshKey _$Mutation$AddSshKey$addSshKeyFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Mutation$AddSshKey$addSshKey(
|
||||
Mutation$AddSshKey$addSshKey _$Mutation$AddSshKey$addSshKeyFromJson(Map<String, dynamic> json) => Mutation$AddSshKey$addSshKey(
|
||||
code: json['code'] as int,
|
||||
message: json['message'] as String,
|
||||
success: json['success'] as bool,
|
||||
$__typename: json['__typename'] as String,
|
||||
user: json['user'] == null
|
||||
? null
|
||||
: Fragment$userFields.fromJson(json['user'] as Map<String, dynamic>),
|
||||
user: json['user'] == null ? null : Fragment$userFields.fromJson(json['user'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Mutation$AddSshKey$addSshKeyToJson(
|
||||
Mutation$AddSshKey$addSshKey instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Mutation$AddSshKey$addSshKeyToJson(Mutation$AddSshKey$addSshKey instance) => <String, dynamic>{
|
||||
'code': instance.code,
|
||||
'message': instance.message,
|
||||
'success': instance.success,
|
||||
|
@ -310,49 +225,33 @@ Map<String, dynamic> _$Mutation$AddSshKey$addSshKeyToJson(
|
|||
'user': instance.user?.toJson(),
|
||||
};
|
||||
|
||||
Variables$Mutation$RemoveSshKey _$Variables$Mutation$RemoveSshKeyFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Variables$Mutation$RemoveSshKey(
|
||||
sshInput: Input$SshMutationInput.fromJson(
|
||||
json['sshInput'] as Map<String, dynamic>),
|
||||
Variables$Mutation$RemoveSshKey _$Variables$Mutation$RemoveSshKeyFromJson(Map<String, dynamic> json) => Variables$Mutation$RemoveSshKey(
|
||||
sshInput: Input$SshMutationInput.fromJson(json['sshInput'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Variables$Mutation$RemoveSshKeyToJson(
|
||||
Variables$Mutation$RemoveSshKey instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Variables$Mutation$RemoveSshKeyToJson(Variables$Mutation$RemoveSshKey instance) => <String, dynamic>{
|
||||
'sshInput': instance.sshInput.toJson(),
|
||||
};
|
||||
|
||||
Mutation$RemoveSshKey _$Mutation$RemoveSshKeyFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Mutation$RemoveSshKey(
|
||||
removeSshKey: Mutation$RemoveSshKey$removeSshKey.fromJson(
|
||||
json['removeSshKey'] as Map<String, dynamic>),
|
||||
Mutation$RemoveSshKey _$Mutation$RemoveSshKeyFromJson(Map<String, dynamic> json) => Mutation$RemoveSshKey(
|
||||
removeSshKey: Mutation$RemoveSshKey$removeSshKey.fromJson(json['removeSshKey'] as Map<String, dynamic>),
|
||||
$__typename: json['__typename'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Mutation$RemoveSshKeyToJson(
|
||||
Mutation$RemoveSshKey instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Mutation$RemoveSshKeyToJson(Mutation$RemoveSshKey instance) => <String, dynamic>{
|
||||
'removeSshKey': instance.removeSshKey.toJson(),
|
||||
'__typename': instance.$__typename,
|
||||
};
|
||||
|
||||
Mutation$RemoveSshKey$removeSshKey _$Mutation$RemoveSshKey$removeSshKeyFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
Mutation$RemoveSshKey$removeSshKey(
|
||||
Mutation$RemoveSshKey$removeSshKey _$Mutation$RemoveSshKey$removeSshKeyFromJson(Map<String, dynamic> json) => Mutation$RemoveSshKey$removeSshKey(
|
||||
code: json['code'] as int,
|
||||
message: json['message'] as String,
|
||||
success: json['success'] as bool,
|
||||
$__typename: json['__typename'] as String,
|
||||
user: json['user'] == null
|
||||
? null
|
||||
: Fragment$userFields.fromJson(json['user'] as Map<String, dynamic>),
|
||||
user: json['user'] == null ? null : Fragment$userFields.fromJson(json['user'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$Mutation$RemoveSshKey$removeSshKeyToJson(
|
||||
Mutation$RemoveSshKey$removeSshKey instance) =>
|
||||
<String, dynamic>{
|
||||
Map<String, dynamic> _$Mutation$RemoveSshKey$removeSshKeyToJson(Mutation$RemoveSshKey$removeSshKey instance) => <String, dynamic>{
|
||||
'code': instance.code,
|
||||
'message': instance.message,
|
||||
'success': instance.success,
|
||||
|
|
|
@ -21,6 +21,10 @@ mixin UsersApi on ApiMap {
|
|||
print(response.exception.toString());
|
||||
}
|
||||
users = response.parsedData?.users.allUsers.map<User>((final user) => User.fromGraphQL(user)).toList() ?? [];
|
||||
final rootUser = response.parsedData?.users.rootUser;
|
||||
if (rootUser != null) {
|
||||
users.add(User.fromGraphQL(rootUser));
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/config/hive_config.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server.dart';
|
||||
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||
|
||||
|
@ -14,8 +16,6 @@ class UsersCubit extends ServerInstallationDependendCubit<UsersState> {
|
|||
serverInstallationCubit,
|
||||
const UsersState(
|
||||
<User>[],
|
||||
User(login: 'root', type: UserType.root),
|
||||
User(login: 'loading...', type: UserType.primary),
|
||||
),
|
||||
);
|
||||
Box<User> box = Hive.box<User>(BNames.usersBox);
|
||||
|
@ -25,167 +25,38 @@ class UsersCubit extends ServerInstallationDependendCubit<UsersState> {
|
|||
|
||||
@override
|
||||
Future<void> load() async {
|
||||
if (serverInstallationCubit.state is ServerInstallationFinished) {
|
||||
if (serverInstallationCubit.state is! ServerInstallationFinished) {
|
||||
return;
|
||||
}
|
||||
final List<User> loadedUsers = box.values.toList();
|
||||
final primaryUser = serverInstallationBox.get(
|
||||
BNames.rootUser,
|
||||
defaultValue: const User(login: 'loading...', type: UserType.primary),
|
||||
);
|
||||
final List<String> rootKeys = [...serverInstallationBox.get(BNames.rootKeys, defaultValue: [])];
|
||||
if (loadedUsers.isNotEmpty) {
|
||||
emit(
|
||||
UsersState(
|
||||
loadedUsers,
|
||||
User(login: 'root', sshKeys: rootKeys, type: UserType.root),
|
||||
primaryUser,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final ApiResponse<List<String>> usersFromServer = await api.getUsersList();
|
||||
if (usersFromServer.isSuccess) {
|
||||
final List<User> updatedList = mergeLocalAndServerUsers(loadedUsers, usersFromServer.data);
|
||||
emit(
|
||||
UsersState(
|
||||
updatedList,
|
||||
User(login: 'root', sshKeys: rootKeys, type: UserType.root),
|
||||
primaryUser,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final List<User> usersWithSshKeys = await loadSshKeys(state.users);
|
||||
// Update the users it the box
|
||||
box.clear();
|
||||
box.addAll(usersWithSshKeys);
|
||||
|
||||
final User rootUserWithSshKeys = (await loadSshKeys([state.rootUser])).first;
|
||||
serverInstallationBox.put(BNames.rootKeys, rootUserWithSshKeys.sshKeys);
|
||||
final User primaryUserWithSshKeys = (await loadSshKeys([state.primaryUser])).first;
|
||||
serverInstallationBox.put(BNames.rootUser, primaryUserWithSshKeys);
|
||||
emit(
|
||||
UsersState(
|
||||
usersWithSshKeys,
|
||||
rootUserWithSshKeys,
|
||||
primaryUserWithSshKeys,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
List<User> mergeLocalAndServerUsers(
|
||||
final List<User> localUsers,
|
||||
final List<String> serverUsers,
|
||||
) {
|
||||
// If local user not exists on server, add it with isFoundOnServer = false
|
||||
// If server user not exists on local, add it
|
||||
|
||||
final List<User> mergedUsers = [];
|
||||
final List<String> serverUsersCopy = List.from(serverUsers);
|
||||
|
||||
for (final User localUser in localUsers) {
|
||||
if (serverUsersCopy.contains(localUser.login)) {
|
||||
mergedUsers.add(
|
||||
User(
|
||||
login: localUser.login,
|
||||
type: UserType.normal,
|
||||
isFoundOnServer: true,
|
||||
password: localUser.password,
|
||||
sshKeys: localUser.sshKeys,
|
||||
),
|
||||
);
|
||||
serverUsersCopy.remove(localUser.login);
|
||||
} else {
|
||||
mergedUsers.add(
|
||||
User(
|
||||
login: localUser.login,
|
||||
type: UserType.normal,
|
||||
isFoundOnServer: false,
|
||||
password: localUser.password,
|
||||
note: localUser.note,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (final String serverUser in serverUsersCopy) {
|
||||
mergedUsers.add(
|
||||
User(
|
||||
login: serverUser,
|
||||
type: UserType.normal,
|
||||
isFoundOnServer: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return mergedUsers;
|
||||
}
|
||||
|
||||
Future<List<User>> loadSshKeys(final List<User> users) async {
|
||||
final List<User> updatedUsers = [];
|
||||
|
||||
for (final User user in users) {
|
||||
if (user.isFoundOnServer || user.login == 'root' || user.login == state.primaryUser.login) {
|
||||
final ApiResponse<List<String>> sshKeys = await api.getUserSshKeys(user);
|
||||
print('sshKeys for $user: ${sshKeys.data}');
|
||||
if (sshKeys.isSuccess) {
|
||||
updatedUsers.add(
|
||||
User(
|
||||
login: user.login,
|
||||
type: user.type,
|
||||
isFoundOnServer: true,
|
||||
password: user.password,
|
||||
sshKeys: sshKeys.data,
|
||||
note: user.note,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
updatedUsers.add(
|
||||
User(
|
||||
login: user.login,
|
||||
type: user.type,
|
||||
isFoundOnServer: true,
|
||||
password: user.password,
|
||||
note: user.note,
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
updatedUsers.add(
|
||||
User(
|
||||
login: user.login,
|
||||
type: user.type,
|
||||
isFoundOnServer: false,
|
||||
password: user.password,
|
||||
note: user.note,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
return updatedUsers;
|
||||
refresh();
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
List<User> updatedUsers = List<User>.from(state.users);
|
||||
final ApiResponse<List<String>> usersFromServer = await api.getUsersList();
|
||||
if (usersFromServer.isSuccess) {
|
||||
updatedUsers = mergeLocalAndServerUsers(updatedUsers, usersFromServer.data);
|
||||
if (serverInstallationCubit.state is! ServerInstallationFinished) {
|
||||
return;
|
||||
}
|
||||
final List<User> usersWithSshKeys = await loadSshKeys(updatedUsers);
|
||||
box.clear();
|
||||
box.addAll(usersWithSshKeys);
|
||||
final User rootUserWithSshKeys = (await loadSshKeys([state.rootUser])).first;
|
||||
serverInstallationBox.put(BNames.rootKeys, rootUserWithSshKeys.sshKeys);
|
||||
final User primaryUserWithSshKeys = (await loadSshKeys([state.primaryUser])).first;
|
||||
serverInstallationBox.put(BNames.rootUser, primaryUserWithSshKeys);
|
||||
final List<User> usersFromServer = await api.getAllUsers();
|
||||
if (usersFromServer.isNotEmpty) {
|
||||
emit(
|
||||
UsersState(
|
||||
usersWithSshKeys,
|
||||
rootUserWithSshKeys,
|
||||
primaryUserWithSshKeys,
|
||||
usersFromServer,
|
||||
),
|
||||
);
|
||||
return;
|
||||
// Update the users it the box
|
||||
box.clear();
|
||||
box.addAll(usersFromServer);
|
||||
} else {
|
||||
getIt<NavigationService>().showSnackBar('users.could_not_fetch_users'.tr());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> createUser(final User user) async {
|
||||
|
@ -193,18 +64,21 @@ class UsersCubit extends ServerInstallationDependendCubit<UsersState> {
|
|||
if (state.users.any((final User u) => u.login == user.login && u.isFoundOnServer)) {
|
||||
return;
|
||||
}
|
||||
// If user is root or primary user, do nothing
|
||||
if (user.login == 'root' || user.login == state.primaryUser.login) {
|
||||
final String? password = user.password;
|
||||
if (password == null) {
|
||||
getIt<NavigationService>().showSnackBar('users.could_not_create_user'.tr());
|
||||
return;
|
||||
}
|
||||
// If API returned error, do nothing
|
||||
final ApiResponse<User> result = await api.createUser(user);
|
||||
if (!result.isSuccess) {
|
||||
final UserMutationResult result = await api.createUser(user.login, password);
|
||||
final User? createdUser = result.user;
|
||||
if (!result.success || createdUser == null) {
|
||||
getIt<NavigationService>().showSnackBar(result.message ?? 'users.could_not_create_user'.tr());
|
||||
return;
|
||||
}
|
||||
|
||||
final List<User> loadedUsers = List<User>.from(state.users);
|
||||
loadedUsers.add(result.data);
|
||||
loadedUsers.add(createdUser);
|
||||
await box.clear();
|
||||
await box.addAll(loadedUsers);
|
||||
emit(state.copyWith(users: loadedUsers));
|
||||
|
@ -212,142 +86,52 @@ class UsersCubit extends ServerInstallationDependendCubit<UsersState> {
|
|||
|
||||
Future<void> deleteUser(final User user) async {
|
||||
// If user is primary or root, don't delete
|
||||
if (user.login == state.primaryUser.login || user.login == 'root') {
|
||||
if (user.type != UserType.normal) {
|
||||
getIt<NavigationService>().showSnackBar('users.could_not_delete_user'.tr());
|
||||
return;
|
||||
}
|
||||
final List<User> loadedUsers = List<User>.from(state.users);
|
||||
final bool result = await api.deleteUser(user);
|
||||
if (result) {
|
||||
final GenericMutationResult result = await api.deleteUser(user.login);
|
||||
if (result.success) {
|
||||
loadedUsers.removeWhere((final User u) => u.login == user.login);
|
||||
await box.clear();
|
||||
await box.addAll(loadedUsers);
|
||||
emit(state.copyWith(users: loadedUsers));
|
||||
} else {
|
||||
getIt<NavigationService>().showSnackBar(result.message ?? 'users.could_not_delete_user'.tr());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> changeUserPassword(final User user, final String newPassword) async {
|
||||
if (user.type == UserType.root) {
|
||||
getIt<NavigationService>().showSnackBar('users.could_not_change_password'.tr());
|
||||
return;
|
||||
}
|
||||
final UserMutationResult result = await api.updateUser(user.login, newPassword);
|
||||
if (!result.success) {
|
||||
getIt<NavigationService>().showSnackBar(result.message ?? 'users.could_not_change_password'.tr());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addSshKey(final User user, final String publicKey) async {
|
||||
// If adding root key, use api.addRootSshKey
|
||||
// Otherwise, use api.addUserSshKey
|
||||
if (user.login == 'root') {
|
||||
final ApiResponse<void> result = await api.addRootSshKey(publicKey);
|
||||
if (result.isSuccess) {
|
||||
// Add ssh key to the array of root keys
|
||||
final List<String> rootKeys = serverInstallationBox.get(BNames.rootKeys, defaultValue: []) as List<String>;
|
||||
rootKeys.add(publicKey);
|
||||
serverInstallationBox.put(BNames.rootKeys, rootKeys);
|
||||
emit(
|
||||
state.copyWith(
|
||||
rootUser: User(
|
||||
login: state.rootUser.login,
|
||||
type: UserType.root,
|
||||
isFoundOnServer: true,
|
||||
password: state.rootUser.password,
|
||||
sshKeys: rootKeys,
|
||||
note: state.rootUser.note,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
final ApiResponse<void> result = await api.addUserSshKey(user, publicKey);
|
||||
if (result.isSuccess) {
|
||||
// If it is primary user, update primary user
|
||||
if (user.login == state.primaryUser.login) {
|
||||
final List<String> primaryUserKeys = List<String>.from(state.primaryUser.sshKeys);
|
||||
primaryUserKeys.add(publicKey);
|
||||
final User updatedUser = User(
|
||||
login: state.primaryUser.login,
|
||||
type: UserType.primary,
|
||||
isFoundOnServer: true,
|
||||
password: state.primaryUser.password,
|
||||
sshKeys: primaryUserKeys,
|
||||
note: state.primaryUser.note,
|
||||
);
|
||||
serverInstallationBox.put(BNames.rootUser, updatedUser);
|
||||
emit(
|
||||
state.copyWith(
|
||||
primaryUser: updatedUser,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
// If it is not primary user, update user
|
||||
final List<String> userKeys = List<String>.from(user.sshKeys);
|
||||
userKeys.add(publicKey);
|
||||
final User updatedUser = User(
|
||||
login: user.login,
|
||||
type: UserType.normal,
|
||||
isFoundOnServer: true,
|
||||
password: user.password,
|
||||
sshKeys: userKeys,
|
||||
note: user.note,
|
||||
);
|
||||
final UserMutationResult result = await api.addSshKey(user.login, publicKey);
|
||||
if (result.success) {
|
||||
final User updatedUser = result.user!;
|
||||
await box.putAt(box.values.toList().indexOf(user), updatedUser);
|
||||
emit(
|
||||
state.copyWith(
|
||||
users: box.values.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
getIt<NavigationService>().showSnackBar(result.message ?? 'users.could_not_add_ssh_key'.tr());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteSshKey(final User user, final String publicKey) async {
|
||||
// All keys are deleted via api.deleteUserSshKey
|
||||
|
||||
final ApiResponse<void> result = await api.deleteUserSshKey(user, publicKey);
|
||||
if (result.isSuccess) {
|
||||
// If it is root user, delete key from root keys
|
||||
// If it is primary user, update primary user
|
||||
// If it is not primary user, update user
|
||||
|
||||
if (user.login == 'root') {
|
||||
final List<String> rootKeys = serverInstallationBox.get(BNames.rootKeys, defaultValue: []) as List<String>;
|
||||
rootKeys.remove(publicKey);
|
||||
serverInstallationBox.put(BNames.rootKeys, rootKeys);
|
||||
emit(
|
||||
state.copyWith(
|
||||
rootUser: User(
|
||||
login: state.rootUser.login,
|
||||
type: UserType.root,
|
||||
isFoundOnServer: true,
|
||||
password: state.rootUser.password,
|
||||
sshKeys: rootKeys,
|
||||
note: state.rootUser.note,
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (user.login == state.primaryUser.login) {
|
||||
final List<String> primaryUserKeys = List<String>.from(state.primaryUser.sshKeys);
|
||||
primaryUserKeys.remove(publicKey);
|
||||
final User updatedUser = User(
|
||||
login: state.primaryUser.login,
|
||||
type: UserType.primary,
|
||||
isFoundOnServer: true,
|
||||
password: state.primaryUser.password,
|
||||
sshKeys: primaryUserKeys,
|
||||
note: state.primaryUser.note,
|
||||
);
|
||||
serverInstallationBox.put(BNames.rootUser, updatedUser);
|
||||
emit(
|
||||
state.copyWith(
|
||||
primaryUser: updatedUser,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final List<String> userKeys = List<String>.from(user.sshKeys);
|
||||
userKeys.remove(publicKey);
|
||||
final User updatedUser = User(
|
||||
login: user.login,
|
||||
type: UserType.normal,
|
||||
isFoundOnServer: true,
|
||||
password: user.password,
|
||||
sshKeys: userKeys,
|
||||
note: user.note,
|
||||
);
|
||||
final UserMutationResult result = await api.removeSshKey(user.login, publicKey);
|
||||
if (result.success) {
|
||||
final User updatedUser = result.user!;
|
||||
await box.putAt(box.values.toList().indexOf(user), updatedUser);
|
||||
emit(
|
||||
state.copyWith(
|
||||
|
@ -362,8 +146,6 @@ class UsersCubit extends ServerInstallationDependendCubit<UsersState> {
|
|||
emit(
|
||||
const UsersState(
|
||||
<User>[],
|
||||
User(login: 'root', type: UserType.root),
|
||||
User(login: 'loading...', type: UserType.primary),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,30 +1,27 @@
|
|||
part of 'users_cubit.dart';
|
||||
|
||||
class UsersState extends ServerInstallationDependendState {
|
||||
const UsersState(this.users, this.rootUser, this.primaryUser);
|
||||
const UsersState(this.users);
|
||||
|
||||
final List<User> users;
|
||||
final User rootUser;
|
||||
final User primaryUser;
|
||||
|
||||
User get rootUser => users.firstWhere((final user) => user.type == UserType.root);
|
||||
|
||||
User get primaryUser => users.firstWhere((final user) => user.type == UserType.primary);
|
||||
|
||||
List<User> get normalUsers => users.where((final user) => user.type == UserType.normal).toList();
|
||||
|
||||
@override
|
||||
List<Object> get props => [users, rootUser, primaryUser];
|
||||
List<Object> get props => [users];
|
||||
|
||||
UsersState copyWith({
|
||||
final List<User>? users,
|
||||
final User? rootUser,
|
||||
final User? primaryUser,
|
||||
}) =>
|
||||
UsersState(
|
||||
users ?? this.users,
|
||||
rootUser ?? this.rootUser,
|
||||
primaryUser ?? this.primaryUser,
|
||||
);
|
||||
|
||||
bool isLoginRegistered(final String login) =>
|
||||
users.any((final User user) => user.login == login) ||
|
||||
login == rootUser.login ||
|
||||
login == primaryUser.login;
|
||||
bool isLoginRegistered(final String login) => users.any((final User user) => user.login == login);
|
||||
|
||||
bool get isEmpty => users.isEmpty;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ class UserAdapter extends TypeAdapter<User> {
|
|||
};
|
||||
return User(
|
||||
login: fields[0] as String,
|
||||
type: fields[5] == null ? UserType.normal : fields[5] as UserType,
|
||||
password: fields[1] as String?,
|
||||
sshKeys: fields[2] == null ? [] : (fields[2] as List).cast<String>(),
|
||||
isFoundOnServer: fields[3] == null ? true : fields[3] as bool,
|
||||
|
@ -28,7 +29,7 @@ class UserAdapter extends TypeAdapter<User> {
|
|||
@override
|
||||
void write(BinaryWriter writer, User obj) {
|
||||
writer
|
||||
..writeByte(5)
|
||||
..writeByte(6)
|
||||
..writeByte(0)
|
||||
..write(obj.login)
|
||||
..writeByte(1)
|
||||
|
@ -38,16 +39,54 @@ class UserAdapter extends TypeAdapter<User> {
|
|||
..writeByte(3)
|
||||
..write(obj.isFoundOnServer)
|
||||
..writeByte(4)
|
||||
..write(obj.note);
|
||||
..write(obj.note)
|
||||
..writeByte(5)
|
||||
..write(obj.type);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is UserAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
bool operator ==(Object other) => identical(this, other) || other is UserAdapter && runtimeType == other.runtimeType && typeId == other.typeId;
|
||||
}
|
||||
|
||||
class UserTypeAdapter extends TypeAdapter<UserType> {
|
||||
@override
|
||||
final int typeId = 102;
|
||||
|
||||
@override
|
||||
UserType read(BinaryReader reader) {
|
||||
switch (reader.readByte()) {
|
||||
case 0:
|
||||
return UserType.root;
|
||||
case 1:
|
||||
return UserType.primary;
|
||||
case 2:
|
||||
return UserType.normal;
|
||||
default:
|
||||
return UserType.root;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, UserType obj) {
|
||||
switch (obj) {
|
||||
case UserType.root:
|
||||
writer.writeByte(0);
|
||||
break;
|
||||
case UserType.primary:
|
||||
writer.writeByte(1);
|
||||
break;
|
||||
case UserType.normal:
|
||||
writer.writeByte(2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => identical(this, other) || other is UserTypeAdapter && runtimeType == other.runtimeType && typeId == other.typeId;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue