From d1bf1f76eb149bf1d9a544a6bd929bfb516a5824 Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Sat, 1 Jun 2024 23:43:26 +0300 Subject: [PATCH] Offer to pass -create-admin option if no admins were found Implements: #218 --- main.go | 4 ++++ user/users.go | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index f5d492b..5988df3 100644 --- a/main.go +++ b/main.go @@ -61,5 +61,9 @@ func main() { // Static files: static.InitFS(files.StaticFiles()) + if !user.HasAnyAdmins() { + log.Println("Your wiki has no admin yet. Run Mycorrhiza with -create-admin option to create an admin.") + } + serveHTTP(web.Handler()) } diff --git a/user/users.go b/user/users.go index fadc18a..41f4135 100644 --- a/user/users.go +++ b/user/users.go @@ -9,7 +9,7 @@ var tokens sync.Map func YieldUsers() chan *User { ch := make(chan *User) go func(ch chan *User) { - users.Range(func(_, v interface{}) bool { + users.Range(func(_, v any) bool { ch <- v.(*User) return true }) @@ -38,6 +38,15 @@ func Count() (i uint64) { return i } +func HasAnyAdmins() bool { + for u := range YieldUsers() { + if u.Group == "admin" { + return true + } + } + return false +} + // HasUsername checks whether the desired user exists func HasUsername(username string) bool { _, has := users.Load(username)