From 5e653c51f318c096d398e0ac67bb6a3d118aa494 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Wed, 26 Nov 2025 15:30:45 +0000 Subject: [PATCH] accounts: add "extend from previous expiry" If the expiry time of an expired user is still in the activity log, extending and re-enabling a user with this option checked will extend the expiry from this time, rather than the current time. For #379, i think this is basically what they wanted. --- api-users.go | 18 ++++++++ css/tooltip.css | 3 +- html/admin.html | 48 +++++++++++--------- lang/admin/en-us.json | 2 + logmessages/logmessages.go | 6 ++- models.go | 17 +++---- ts/modules/accounts.ts | 93 +++++++++++++++++++++++++------------- 7 files changed, 124 insertions(+), 63 deletions(-) diff --git a/api-users.go b/api-users.go index 51f59bd..13aa233 100644 --- a/api-users.go +++ b/api-users.go @@ -525,6 +525,24 @@ func (app *appContext) ExtendExpiry(gc *gin.Context) { base := time.Now() if expiry, ok := app.storage.GetUserExpiryKey(id); ok { base = expiry.Expiry + app.debug.Printf(lm.FoundExistingExpiry) + } else if req.TryExtendFromPreviousExpiry { + var acts []Activity + app.storage.db.Find(&acts, badgerhold.Where("Type").Eq(ActivityDisabled).And("UserID").Eq(id).SortBy("Time").Reverse().Limit(1)) + if len(acts) != 0 { + // Only do it if the most recent reason for disabling was expiry + if acts[0].SourceType == ActivityDaemon { + app.debug.Printf(lm.FoundPreviousExpiryLog, acts[0].Time) + newExpiry := acts[0].Time.AddDate(0, req.Months, req.Days).Add(time.Duration(((60 * req.Hours) + req.Minutes)) * time.Minute) + if newExpiry.After(base) { + base = acts[0].Time + } else { + app.debug.Printf(lm.ExpiryWouldBeInPast) + } + } else { + app.debug.Printf(lm.PreviousExpiryNotExpiry) + } + } } app.debug.Printf(lm.ExtendCreateExpiry, id) expiry := UserExpiry{} diff --git a/css/tooltip.css b/css/tooltip.css index c6a193c..ab4d187 100644 --- a/css/tooltip.css +++ b/css/tooltip.css @@ -6,7 +6,7 @@ .tooltip .content { visibility: hidden; opacity: 0; - max-width: 10rem; + max-width: 16rem; min-width: 6rem; background-color: rgba(0, 0, 0, 0.6); color: #fff; @@ -29,6 +29,7 @@ } .tooltip.above .content { + top: unset; bottom: calc(100% + 0.125rem); left: 50%; right: 0; diff --git a/html/admin.html b/html/admin.html index 8ad6dd6..580963b 100644 --- a/html/admin.html +++ b/html/admin.html @@ -186,56 +186,60 @@