mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-30 12:46:52 +00:00
Add user deletion (for real)
This commit is contained in:
parent
9b2fe905e6
commit
4ca873e794
|
@ -248,7 +248,8 @@
|
||||||
"title": "Jobs list",
|
"title": "Jobs list",
|
||||||
"start": "Start",
|
"start": "Start",
|
||||||
"empty": "No jobs",
|
"empty": "No jobs",
|
||||||
"createUser": "Create",
|
"createUser": "Create user",
|
||||||
|
"deleteUser": "Delete user",
|
||||||
"serviceTurnOff": "Turn off",
|
"serviceTurnOff": "Turn off",
|
||||||
"serviceTurnOn": "Turn on",
|
"serviceTurnOn": "Turn on",
|
||||||
"jobAdded": "Job added",
|
"jobAdded": "Job added",
|
||||||
|
|
|
@ -249,7 +249,8 @@
|
||||||
"title": "Задачи",
|
"title": "Задачи",
|
||||||
"start": "Начать выполенение",
|
"start": "Начать выполенение",
|
||||||
"empty": "Пусто.",
|
"empty": "Пусто.",
|
||||||
"createUser": "Создать запись",
|
"createUser": "Создать пользователя",
|
||||||
|
"deleteUser": "Удалить пользователя",
|
||||||
"serviceTurnOff": "Остановить",
|
"serviceTurnOff": "Остановить",
|
||||||
"serviceTurnOn": "Запустить",
|
"serviceTurnOn": "Запустить",
|
||||||
"jobAdded": "Задача добавленна",
|
"jobAdded": "Задача добавленна",
|
||||||
|
|
|
@ -74,6 +74,28 @@ class ServerApi extends ApiMap {
|
||||||
return res;
|
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 =>
|
String get rootAddress =>
|
||||||
throw UnimplementedError('not used in with implementation');
|
throw UnimplementedError('not used in with implementation');
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,12 @@ class JobsCubit extends Cubit<JobsState> {
|
||||||
if (job is CreateUserJob) {
|
if (job is CreateUserJob) {
|
||||||
newUsers.add(job.user);
|
newUsers.add(job.user);
|
||||||
await api.createUser(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;
|
hasServiceJobs = true;
|
||||||
await api.switchService(job.type, job.needToTurnOn);
|
await api.switchService(job.type, job.needToTurnOn);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,17 @@ class CreateUserJob extends Job {
|
||||||
List<Object> get props => [id, title, user];
|
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 {
|
class ServiceToggleJob extends Job {
|
||||||
ServiceToggleJob({
|
ServiceToggleJob({
|
||||||
required this.type,
|
required this.type,
|
||||||
|
|
|
@ -76,8 +76,8 @@ class _UserDetails extends StatelessWidget {
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
context
|
context
|
||||||
.read<UsersCubit>()
|
.read<JobsCubit>()
|
||||||
.remove(user);
|
.addJob(DeleteUserJob(user: user));
|
||||||
Navigator.of(context)
|
Navigator.of(context)
|
||||||
..pop()
|
..pop()
|
||||||
..pop();
|
..pop();
|
||||||
|
|
Loading…
Reference in a new issue