mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-30 04:36:53 +00:00
Add user deletion (for real)
This commit is contained in:
parent
9b2fe905e6
commit
4ca873e794
|
@ -248,7 +248,8 @@
|
|||
"title": "Jobs list",
|
||||
"start": "Start",
|
||||
"empty": "No jobs",
|
||||
"createUser": "Create",
|
||||
"createUser": "Create user",
|
||||
"deleteUser": "Delete user",
|
||||
"serviceTurnOff": "Turn off",
|
||||
"serviceTurnOn": "Turn on",
|
||||
"jobAdded": "Job added",
|
||||
|
|
|
@ -249,7 +249,8 @@
|
|||
"title": "Задачи",
|
||||
"start": "Начать выполенение",
|
||||
"empty": "Пусто.",
|
||||
"createUser": "Создать запись",
|
||||
"createUser": "Создать пользователя",
|
||||
"deleteUser": "Удалить пользователя",
|
||||
"serviceTurnOff": "Остановить",
|
||||
"serviceTurnOn": "Запустить",
|
||||
"jobAdded": "Задача добавленна",
|
||||
|
|
|
@ -74,6 +74,28 @@ class ServerApi extends ApiMap {
|
|||
return res;
|
||||
}
|
||||
|
||||
Future<bool> deleteUser(User user) async {
|
||||
bool res;
|
||||
Response response;
|
||||
|
||||
var client = await getClient();
|
||||
try {
|
||||
response = await client.delete(
|
||||
'/users/${user.login}',
|
||||
options: Options(
|
||||
contentType: 'application/json',
|
||||
),
|
||||
);
|
||||
res = response.statusCode == HttpStatus.ok;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
res = false;
|
||||
}
|
||||
|
||||
close(client);
|
||||
return res;
|
||||
}
|
||||
|
||||
String get rootAddress =>
|
||||
throw UnimplementedError('not used in with implementation');
|
||||
|
||||
|
|
|
@ -105,7 +105,12 @@ class JobsCubit extends Cubit<JobsState> {
|
|||
if (job is CreateUserJob) {
|
||||
newUsers.add(job.user);
|
||||
await api.createUser(job.user);
|
||||
} else if (job is ServiceToggleJob) {
|
||||
}
|
||||
if (job is DeleteUserJob) {
|
||||
final deleted = await api.deleteUser(job.user);
|
||||
if (deleted) usersCubit.remove(job.user);
|
||||
}
|
||||
if (job is ServiceToggleJob) {
|
||||
hasServiceJobs = true;
|
||||
await api.switchService(job.type, job.needToTurnOn);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,17 @@ class CreateUserJob extends Job {
|
|||
List<Object> get props => [id, title, user];
|
||||
}
|
||||
|
||||
class DeleteUserJob extends Job {
|
||||
DeleteUserJob({
|
||||
required this.user,
|
||||
}) : super(title: '${"jobs.deleteUser".tr()} ${user.login}');
|
||||
|
||||
final User user;
|
||||
|
||||
@override
|
||||
List<Object> get props => [id, title, user];
|
||||
}
|
||||
|
||||
class ServiceToggleJob extends Job {
|
||||
ServiceToggleJob({
|
||||
required this.type,
|
||||
|
|
|
@ -76,8 +76,8 @@ class _UserDetails extends StatelessWidget {
|
|||
),
|
||||
onPressed: () {
|
||||
context
|
||||
.read<UsersCubit>()
|
||||
.remove(user);
|
||||
.read<JobsCubit>()
|
||||
.addJob(DeleteUserJob(user: user));
|
||||
Navigator.of(context)
|
||||
..pop()
|
||||
..pop();
|
||||
|
|
Loading…
Reference in a new issue