users: consolidate methods for disable/enable and deleting users

now both in users.go and shared between the admin UI and daemon. Will be
used for discord role auto-add/deletion.
This commit is contained in:
Harvey Tindall
2024-08-04 15:14:51 +01:00
parent f289680d98
commit 44311162a6
3 changed files with 102 additions and 46 deletions
+9 -3
View File
@@ -72,14 +72,20 @@ func (app *appContext) checkUsers() {
}
if mode == "delete" {
status, err = app.jf.DeleteUser(id)
deleted := false
err, deleted = app.DeleteUser(user)
// Silence unimportant errors
if deleted {
err = nil
}
activity.Type = ActivityDeletion
// Store the user name, since there's no longer a user ID to reference back to
activity.Value = user.Name
} else if mode == "disable" {
user.Policy.IsDisabled = true
// Admins can't be disabled
// so they're not an admin anymore, sorry
user.Policy.IsAdministrator = false
status, err = app.jf.SetPolicy(id, user.Policy)
err, _, _ = app.SetUserDisabled(user, true)
activity.Type = ActivityDisabled
}
if !(status == 200 || status == 204) || err != nil {