1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-05 02:29:54 +00:00

Offer to pass -create-admin option if no admins were found

Implements: #218
This commit is contained in:
Timur Ismagilov 2024-06-01 23:43:26 +03:00
parent 2702b4da63
commit d1bf1f76eb
2 changed files with 14 additions and 1 deletions

View File

@ -61,5 +61,9 @@ func main() {
// Static files: // Static files:
static.InitFS(files.StaticFiles()) static.InitFS(files.StaticFiles())
if !user.HasAnyAdmins() {
log.Println("Your wiki has no admin yet. Run Mycorrhiza with -create-admin <username> option to create an admin.")
}
serveHTTP(web.Handler()) serveHTTP(web.Handler())
} }

View File

@ -9,7 +9,7 @@ var tokens sync.Map
func YieldUsers() chan *User { func YieldUsers() chan *User {
ch := make(chan *User) ch := make(chan *User)
go func(ch chan *User) { go func(ch chan *User) {
users.Range(func(_, v interface{}) bool { users.Range(func(_, v any) bool {
ch <- v.(*User) ch <- v.(*User)
return true return true
}) })
@ -38,6 +38,15 @@ func Count() (i uint64) {
return i return i
} }
func HasAnyAdmins() bool {
for u := range YieldUsers() {
if u.Group == "admin" {
return true
}
}
return false
}
// HasUsername checks whether the desired user exists // HasUsername checks whether the desired user exists
func HasUsername(username string) bool { func HasUsername(username string) bool {
_, has := users.Load(username) _, has := users.Load(username)