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