Skip to content

Commit

Permalink
prevent users deleting the only admin user docker-homebridge#83
Browse files Browse the repository at this point in the history
  • Loading branch information
oznu committed Mar 17, 2018
1 parent 64b56a0 commit 45fc1cb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions src/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/users/users.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
);
}
Expand Down

0 comments on commit 45fc1cb

Please sign in to comment.