From 5d289ce023e7ef6bc590f5febcbbc0339e546b8f Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Wed, 1 Feb 2023 15:25:47 +0000 Subject: [PATCH] Admin: auto enable contact when an email is added "Contact through email" is now automatically enabled when adding an email address to an account without one on the admin page. Solves #233. --- api-messages.go | 2 +- api-users.go | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/api-messages.go b/api-messages.go index f91b472..e571803 100644 --- a/api-messages.go +++ b/api-messages.go @@ -326,7 +326,7 @@ func (app *appContext) TelegramAddUser(gc *gin.Context) { // @Success 200 {object} boolResponse // @Success 400 {object} boolResponse // @Success 500 {object} boolResponse -// @Router /users/telegram/notify [post] +// @Router /users/contact [post] // @Security Bearer // @tags Other func (app *appContext) SetContactMethods(gc *gin.Context) { diff --git a/api-users.go b/api-users.go index 2a98073..1cc25e6 100644 --- a/api-users.go +++ b/api-users.go @@ -1023,9 +1023,16 @@ func (app *appContext) ModifyEmails(gc *gin.Context) { id := jfUser.ID if address, ok := req[id]; ok { var emailStore = EmailAddress{} - if oldEmail, ok := app.storage.emails[id]; ok { + oldEmail, ok := app.storage.emails[id] + if ok { emailStore = oldEmail } + // Auto enable contact by email for newly added addresses + if !ok || oldEmail.Addr == "" { + emailStore.Contact = true + app.storage.storeEmails() + } + emailStore.Addr = address app.storage.emails[id] = emailStore if ombiEnabled {