2021-01-06 17:35:57 +00:00
|
|
|
part of 'users.dart';
|
|
|
|
|
2023-03-22 11:38:18 +00:00
|
|
|
@RoutePage()
|
2023-02-23 14:49:14 +00:00
|
|
|
class UserDetailsPage extends StatelessWidget {
|
|
|
|
const UserDetailsPage({
|
2022-09-08 15:13:18 +00:00
|
|
|
required this.login,
|
2022-10-26 16:26:09 +00:00
|
|
|
super.key,
|
2022-06-09 21:13:06 +00:00
|
|
|
});
|
2021-01-06 17:35:57 +00:00
|
|
|
|
2022-09-08 15:13:18 +00:00
|
|
|
final String login;
|
2021-01-06 17:35:57 +00:00
|
|
|
@override
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
final ServerInstallationState config =
|
|
|
|
context.watch<ServerInstallationCubit>().state;
|
2021-03-18 00:55:38 +00:00
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
final String domainName = UiHelpers.getDomainName(config);
|
2021-03-18 00:55:38 +00:00
|
|
|
|
2022-09-08 15:13:18 +00:00
|
|
|
final User user = context.watch<UsersCubit>().state.users.firstWhere(
|
|
|
|
(final User user) => user.login == login,
|
|
|
|
orElse: () => const User(
|
|
|
|
type: UserType.normal,
|
|
|
|
login: 'error',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
if (user.type == UserType.root) {
|
|
|
|
return BrandHeroScreen(
|
|
|
|
hasBackButton: true,
|
2023-03-22 12:13:47 +00:00
|
|
|
hasFlashButton: true,
|
2022-10-03 23:32:35 +00:00
|
|
|
heroTitle: 'ssh.root_title'.tr(),
|
|
|
|
heroSubtitle: 'ssh.root_subtitle'.tr(),
|
2022-09-08 15:13:18 +00:00
|
|
|
children: [
|
|
|
|
_SshKeysCard(user: user),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-05 12:12:00 +00:00
|
|
|
return BrandHeroScreen(
|
|
|
|
hasBackButton: true,
|
2023-03-22 12:13:47 +00:00
|
|
|
hasFlashButton: true,
|
2022-09-05 12:12:00 +00:00
|
|
|
heroTitle: user.login,
|
|
|
|
children: [
|
2022-09-08 15:13:18 +00:00
|
|
|
_UserLogins(user: user, domainName: domainName),
|
2022-09-05 12:12:00 +00:00
|
|
|
const SizedBox(height: 8),
|
2022-09-08 15:13:18 +00:00
|
|
|
_SshKeysCard(user: user),
|
2022-09-05 12:12:00 +00:00
|
|
|
const SizedBox(height: 8),
|
|
|
|
ListTile(
|
|
|
|
iconColor: Theme.of(context).colorScheme.onBackground,
|
2022-09-18 20:25:26 +00:00
|
|
|
onTap: () => {
|
|
|
|
showModalBottomSheet(
|
|
|
|
context: context,
|
|
|
|
isScrollControlled: true,
|
2023-07-10 12:39:57 +00:00
|
|
|
useRootNavigator: true,
|
2022-09-18 20:25:26 +00:00
|
|
|
builder: (final BuildContext context) => Padding(
|
|
|
|
padding: MediaQuery.of(context).viewInsets,
|
|
|
|
child: ResetPassword(user: user),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
2022-09-05 12:12:00 +00:00
|
|
|
leading: const Icon(Icons.lock_reset_outlined),
|
|
|
|
title: Text(
|
|
|
|
'users.reset_password'.tr(),
|
|
|
|
),
|
|
|
|
),
|
2022-09-08 15:13:18 +00:00
|
|
|
if (user.type == UserType.normal) _DeleteUserTile(user: user),
|
2022-09-05 12:12:00 +00:00
|
|
|
const Divider(height: 8),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
2022-09-14 16:45:50 +00:00
|
|
|
child: InfoBox(
|
2022-10-03 23:32:35 +00:00
|
|
|
text: 'users.no_ssh_notice'.tr(),
|
2022-09-14 16:45:50 +00:00
|
|
|
isWarning: true,
|
2022-09-05 12:12:00 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2021-01-06 17:35:57 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-09-08 15:13:18 +00:00
|
|
|
|
|
|
|
class _DeleteUserTile extends StatelessWidget {
|
|
|
|
const _DeleteUserTile({
|
|
|
|
required this.user,
|
|
|
|
});
|
|
|
|
|
|
|
|
final User user;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(final BuildContext context) => ListTile(
|
|
|
|
iconColor: Theme.of(context).colorScheme.error,
|
|
|
|
textColor: Theme.of(context).colorScheme.error,
|
|
|
|
onTap: () => {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
2023-02-24 16:45:32 +00:00
|
|
|
// useRootNavigator: false,
|
2022-09-08 15:13:18 +00:00
|
|
|
builder: (final BuildContext context) => AlertDialog(
|
|
|
|
title: Text('basis.confirmation'.tr()),
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: ListBody(
|
|
|
|
children: <Widget>[
|
|
|
|
Text(
|
|
|
|
'users.delete_confirm_question'.tr(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
TextButton(
|
|
|
|
child: Text('basis.cancel'.tr()),
|
|
|
|
onPressed: () {
|
2023-02-24 16:45:32 +00:00
|
|
|
context.router.pop();
|
2022-09-08 15:13:18 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
TextButton(
|
|
|
|
child: Text(
|
|
|
|
'basis.delete'.tr(),
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).colorScheme.error,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
context.read<JobsCubit>().addJob(DeleteUserJob(user: user));
|
2023-02-24 16:45:32 +00:00
|
|
|
context.router.childControllers.first.pop();
|
|
|
|
context.router.pop();
|
2022-09-08 15:13:18 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
},
|
|
|
|
leading: const Icon(Icons.person_remove_outlined),
|
|
|
|
title: Text(
|
|
|
|
'users.delete_user'.tr(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
class _UserLogins extends StatelessWidget {
|
|
|
|
const _UserLogins({
|
|
|
|
required this.user,
|
|
|
|
required this.domainName,
|
|
|
|
});
|
|
|
|
|
|
|
|
final User user;
|
|
|
|
final String domainName;
|
|
|
|
|
|
|
|
@override
|
2022-09-15 16:57:26 +00:00
|
|
|
Widget build(final BuildContext context) => FilledCard(
|
2022-09-08 15:13:18 +00:00
|
|
|
child: Column(
|
|
|
|
children: [
|
2022-09-18 13:24:17 +00:00
|
|
|
ListTileOnSurfaceVariant(
|
|
|
|
title: '${user.login}@$domainName',
|
|
|
|
subtitle: 'users.email_login'.tr(),
|
|
|
|
leadingIcon: Icons.alternate_email_outlined,
|
2022-09-08 15:13:18 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SshKeysCard extends StatelessWidget {
|
|
|
|
const _SshKeysCard({
|
|
|
|
required this.user,
|
|
|
|
});
|
|
|
|
|
|
|
|
final User user;
|
|
|
|
|
|
|
|
@override
|
2022-09-15 16:57:26 +00:00
|
|
|
Widget build(final BuildContext context) => FilledCard(
|
2022-09-08 15:13:18 +00:00
|
|
|
child: Column(
|
|
|
|
children: [
|
2022-09-18 13:24:17 +00:00
|
|
|
ListTileOnSurfaceVariant(
|
|
|
|
title: 'ssh.title'.tr(),
|
2022-09-08 15:13:18 +00:00
|
|
|
),
|
|
|
|
const Divider(height: 0),
|
2022-09-18 13:24:17 +00:00
|
|
|
ListTileOnSurfaceVariant(
|
|
|
|
title: 'ssh.create'.tr(),
|
|
|
|
leadingIcon: Icons.add_circle_outline,
|
2022-09-08 15:13:18 +00:00
|
|
|
onTap: () {
|
|
|
|
showModalBottomSheet<void>(
|
|
|
|
context: context,
|
|
|
|
isScrollControlled: true,
|
2023-07-10 12:39:57 +00:00
|
|
|
useRootNavigator: true,
|
2022-09-08 15:13:18 +00:00
|
|
|
builder: (final BuildContext context) => Padding(
|
|
|
|
padding: MediaQuery.of(context).viewInsets,
|
|
|
|
child: NewSshKey(user),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Column(
|
|
|
|
children: user.sshKeys.map((final String key) {
|
|
|
|
final publicKey =
|
|
|
|
key.split(' ').length > 1 ? key.split(' ')[1] : key;
|
|
|
|
final keyType = key.split(' ')[0];
|
|
|
|
final keyName = key.split(' ').length > 2
|
|
|
|
? key.split(' ')[2]
|
|
|
|
: 'ssh.no_key_name'.tr();
|
2022-09-18 13:24:17 +00:00
|
|
|
return ListTileOnSurfaceVariant(
|
|
|
|
title: '$keyName ($keyType)',
|
|
|
|
disableSubtitleOverflow: true,
|
2022-09-08 15:13:18 +00:00
|
|
|
// do not overflow text
|
2022-09-18 13:24:17 +00:00
|
|
|
subtitle: publicKey,
|
2022-09-08 15:13:18 +00:00
|
|
|
onTap: () {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (final BuildContext context) => AlertDialog(
|
|
|
|
title: Text('ssh.delete'.tr()),
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: ListBody(
|
|
|
|
children: <Widget>[
|
|
|
|
Text('ssh.delete_confirm_question'.tr()),
|
|
|
|
Text('$keyName ($keyType)'),
|
|
|
|
Text(publicKey),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
TextButton(
|
|
|
|
child: Text('basis.cancel'.tr()),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
TextButton(
|
|
|
|
child: Text(
|
|
|
|
'basis.delete'.tr(),
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).colorScheme.error,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
context.read<JobsCubit>().addJob(
|
|
|
|
DeleteSSHKeyJob(
|
|
|
|
user: user,
|
|
|
|
publicKey: key,
|
|
|
|
),
|
|
|
|
);
|
2023-03-21 17:44:52 +00:00
|
|
|
context.popRoute();
|
2022-09-08 15:13:18 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
class NewSshKey extends StatelessWidget {
|
2022-10-26 16:26:09 +00:00
|
|
|
const NewSshKey(this.user, {super.key});
|
2022-09-08 15:13:18 +00:00
|
|
|
final User user;
|
|
|
|
|
|
|
|
@override
|
2023-03-31 14:17:22 +00:00
|
|
|
Widget build(final BuildContext context) => BlocProvider(
|
2023-04-04 14:31:35 +00:00
|
|
|
create: (final context) {
|
|
|
|
final jobCubit = context.read<JobsCubit>();
|
|
|
|
final jobState = jobCubit.state;
|
|
|
|
if (jobState is JobsStateWithJobs) {
|
|
|
|
final jobs = jobState.clientJobList;
|
|
|
|
for (final job in jobs) {
|
|
|
|
if (job is CreateSSHKeyJob && job.user.login == user.login) {
|
|
|
|
user.sshKeys.add(job.publicKey);
|
|
|
|
}
|
|
|
|
}
|
2023-03-31 14:17:22 +00:00
|
|
|
}
|
2023-04-04 14:31:35 +00:00
|
|
|
return SshFormCubit(
|
|
|
|
jobsCubit: jobCubit,
|
|
|
|
user: user,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: Builder(
|
|
|
|
builder: (final context) {
|
|
|
|
final formCubitState = context.watch<SshFormCubit>().state;
|
2023-03-31 14:17:22 +00:00
|
|
|
|
2023-04-04 14:31:35 +00:00
|
|
|
return BlocListener<SshFormCubit, FormCubitState>(
|
|
|
|
listener: (final context, final state) {
|
|
|
|
if (state.isSubmitted) {
|
|
|
|
Navigator.pop(context);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
BrandHeader(
|
|
|
|
title: user.login,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 14),
|
|
|
|
Padding(
|
|
|
|
padding: paddingH15V0,
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
IntrinsicHeight(
|
|
|
|
child: CubitFormTextField(
|
|
|
|
formFieldCubit: context.read<SshFormCubit>().key,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: 'ssh.input_label'.tr(),
|
|
|
|
),
|
|
|
|
),
|
2023-03-31 14:17:22 +00:00
|
|
|
),
|
2023-04-04 14:31:35 +00:00
|
|
|
const SizedBox(height: 30),
|
|
|
|
BrandButton.rised(
|
|
|
|
onPressed: formCubitState.isSubmitting
|
|
|
|
? null
|
|
|
|
: () => context.read<SshFormCubit>().trySubmit(),
|
|
|
|
text: 'ssh.create'.tr(),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 30),
|
|
|
|
],
|
2023-03-31 14:17:22 +00:00
|
|
|
),
|
2023-04-04 14:31:35 +00:00
|
|
|
),
|
|
|
|
],
|
2023-03-31 14:17:22 +00:00
|
|
|
),
|
2023-04-04 14:31:35 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
2022-09-08 15:13:18 +00:00
|
|
|
}
|