From 1ec5d2ca3f6c36411b866ad38353b1ff1afaea54 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Sun, 28 Feb 2021 17:52:24 +0000 Subject: [PATCH] add disabled badge, extend expiry button to accounts --- api.go | 40 ++++++++++++++++-- html/admin.html | 39 +++++++++++++++-- lang/admin/en-us.json | 12 ++++++ models.go | 9 +++- router.go | 1 + ts/admin.ts | 2 + ts/modules/accounts.ts | 96 ++++++++++++++++++++++++++++++++++++++++-- ts/modules/invites.ts | 8 ++++ ts/typings/d.ts | 5 ++- 9 files changed, 198 insertions(+), 14 deletions(-) diff --git a/api.go b/api.go index 5b0aeb8..8dd1835 100644 --- a/api.go +++ b/api.go @@ -457,6 +457,36 @@ func (app *appContext) newUser(req newUserDTO, confirmed bool) (f errorFunc, suc return } +// @Summary Extend time before the user(s) expiry. +// @Produce json +// @Param extendExpiryDTO body extendExpiryDTO true "Extend expiry object" +// @Success 200 {object} boolResponse +// @Failure 400 {object} boolResponse +// @Failure 500 {object} boolResponse +// @Router /users/extend [post] +// @tags Users +func (app *appContext) ExtendExpiry(gc *gin.Context) { + var req extendExpiryDTO + app.info.Printf("Expiry extension requested for %d user(s)", len(req.Users)) + gc.BindJSON(&req) + if req.Days == 0 && req.Hours == 0 && req.Minutes == 0 { + respondBool(400, false, gc) + return + } + for _, id := range req.Users { + if expiry, ok := app.storage.users[id]; ok { + app.storage.users[id] = expiry.Add(time.Duration(60*(req.Days*24+req.Hours)+req.Minutes) * time.Minute) + app.debug.Printf("Expiry extended for \"%s\"", id) + } + } + if err := app.storage.storeUsers(); err != nil { + app.err.Printf("Failed to store user duration: %s", err) + respondBool(500, false, gc) + return + } + respondBool(204, true, gc) +} + // @Summary Creates a new Jellyfin user via invite code // @Produce json // @Param newUserDTO body newUserDTO true "New user request object" @@ -998,9 +1028,10 @@ func (app *appContext) GetUsers(gc *gin.Context) { } for _, jfUser := range users { user := respUser{ - ID: jfUser.ID, - Name: jfUser.Name, - Admin: jfUser.Policy.IsAdministrator, + ID: jfUser.ID, + Name: jfUser.Name, + Admin: jfUser.Policy.IsAdministrator, + Disabled: jfUser.Policy.IsDisabled, } user.LastActive = "n/a" if !jfUser.LastActivityDate.IsZero() { @@ -1009,6 +1040,9 @@ func (app *appContext) GetUsers(gc *gin.Context) { if email, ok := app.storage.emails[jfUser.ID]; ok { user.Email = email.(string) } + if expiry, ok := app.storage.users[jfUser.ID]; ok { + user.Expiry = app.formatDatetime(expiry) + } resp.UserList = append(resp.UserList, user) } diff --git a/html/admin.html b/html/admin.html index 4b2a270..bfc71be 100644 --- a/html/admin.html +++ b/html/admin.html @@ -94,6 +94,35 @@ +