From 45fc1cbf35ffa00608d8b2454978a25d74bd2d5e Mon Sep 17 00:00:00 2001 From: oznu Date: Sat, 17 Mar 2018 12:06:19 +1100 Subject: [PATCH] prevent users deleting the only admin user docker-homebridge#83 --- CHANGELOG.md | 1 + src/users.ts | 5 +++++ ui/src/app/users/users.component.ts | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index adcb149f9..797913a09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. This projec ### Bug Fixes * Prevent zoom when using the config editor on iOS (@Yanni via Homebridge Slack) +* Prevent the deletion of an admin user if there are no other admin users ([docker-homebridge#83](https://github.com/oznu/docker-homebridge/issues/83)) ## 3.3.0 (2018-03-16) diff --git a/src/users.ts b/src/users.ts index d490679f5..c437e1057 100755 --- a/src/users.ts +++ b/src/users.ts @@ -121,6 +121,11 @@ class Users { throw new Error('User not found'); } + // prevent deleting the only admin user + if (authfile[index].admin && authfile.filter(x => x.admin === true).length < 2) { + throw new Error('Cannot delete only admin user'); + } + authfile.splice(index, 1); // update the auth.json diff --git a/ui/src/app/users/users.component.ts b/ui/src/app/users/users.component.ts index e43936bcd..0756a089e 100644 --- a/ui/src/app/users/users.component.ts +++ b/ui/src/app/users/users.component.ts @@ -45,7 +45,7 @@ export class UsersComponent implements OnInit { this.$state.reload(); }, err => { - this.toastr.error(`Failed To Delete User`, 'Error'); + this.toastr.error(err.error.message || 'Failed to delete user', 'Error'); } ); }