Move /user-list to the new system
This commit is contained in:
parent
bf03105d09
commit
65989c1db1
@ -1,8 +1,6 @@
|
|||||||
{% import "net/http" %}
|
{% import "net/http" %}
|
||||||
{% import "sort" %}
|
|
||||||
{% import "github.com/bouncepaw/mycorrhiza/cfg" %}
|
{% import "github.com/bouncepaw/mycorrhiza/cfg" %}
|
||||||
{% import "github.com/bouncepaw/mycorrhiza/l18n" %}
|
{% import "github.com/bouncepaw/mycorrhiza/l18n" %}
|
||||||
{% import "github.com/bouncepaw/mycorrhiza/user" %}
|
|
||||||
|
|
||||||
{% func Register(rq *http.Request) %}
|
{% func Register(rq *http.Request) %}
|
||||||
{% code
|
{% code
|
||||||
@ -143,71 +141,3 @@ Telegram auth widget was requested by Yogurt. As you can see, we don't offer use
|
|||||||
</html>
|
</html>
|
||||||
{% endfunc %}
|
{% endfunc %}
|
||||||
|
|
||||||
{% code
|
|
||||||
var userListL10n = map[string]L10nEntry{
|
|
||||||
"heading": En("List of users").Ru("Список пользователей"),
|
|
||||||
"administrators": En("Administrators").Ru("Администраторы"),
|
|
||||||
"moderators": En("Moderators").Ru("Модераторы"),
|
|
||||||
"editors": En("Editors").Ru("Редакторы"),
|
|
||||||
"readers": En("Readers").Ru("Читатели"),
|
|
||||||
}
|
|
||||||
%}
|
|
||||||
|
|
||||||
{% func UserList(lc *l18n.Localizer) %}
|
|
||||||
<main class="main-width user-list">
|
|
||||||
{% code
|
|
||||||
var get = func(key string) string {
|
|
||||||
return userListL10n[key].Get(lc.Locale)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
admins = make([]string, 0)
|
|
||||||
moderators = make([]string, 0)
|
|
||||||
editors = make([]string, 0)
|
|
||||||
readers = make([]string, 0)
|
|
||||||
)
|
|
||||||
for u := range user.YieldUsers() {
|
|
||||||
switch u.Group {
|
|
||||||
// What if we place the users into sorted slices?
|
|
||||||
case "admin":
|
|
||||||
admins = append(admins, u.Name)
|
|
||||||
case "moderator":
|
|
||||||
moderators = append(moderators, u.Name)
|
|
||||||
case "editor", "trusted":
|
|
||||||
editors = append(editors, u.Name)
|
|
||||||
case "reader":
|
|
||||||
readers = append(readers, u.Name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sort.Strings(admins)
|
|
||||||
sort.Strings(moderators)
|
|
||||||
sort.Strings(editors)
|
|
||||||
sort.Strings(readers)
|
|
||||||
%}
|
|
||||||
<h1>{%s get("heading") %}</h1>
|
|
||||||
<section>
|
|
||||||
<h2>{%s get("administrators") %}</h2>
|
|
||||||
<ol>{% for _, name := range admins %}
|
|
||||||
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
|
|
||||||
{% endfor %}</ol>
|
|
||||||
</section>
|
|
||||||
<section>
|
|
||||||
<h2>{%s get("moderators") %}</h2>
|
|
||||||
<ol>{% for _, name := range moderators %}
|
|
||||||
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
|
|
||||||
{% endfor %}</ol>
|
|
||||||
</section>
|
|
||||||
<section>
|
|
||||||
<h2>{%s get("editors") %}</h2>
|
|
||||||
<ol>{% for _, name := range editors %}
|
|
||||||
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
|
|
||||||
{% endfor %}</ol>
|
|
||||||
</section>
|
|
||||||
<section>
|
|
||||||
<h2>{%s get("readers") %}</h2>
|
|
||||||
<ol>{% for _, name := range readers %}
|
|
||||||
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
|
|
||||||
{% endfor %}</ol>
|
|
||||||
</section>
|
|
||||||
</main>
|
|
||||||
{% endfunc %}
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,9 @@
|
|||||||
package user
|
package user
|
||||||
|
|
||||||
import "sync"
|
import (
|
||||||
|
"sort"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
var users sync.Map
|
var users sync.Map
|
||||||
var tokens sync.Map
|
var tokens sync.Map
|
||||||
@ -99,3 +102,24 @@ func terminateSession(token string) {
|
|||||||
tokens.Delete(token)
|
tokens.Delete(token)
|
||||||
dumpTokens()
|
dumpTokens()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UsersInGroups() (admins []string, moderators []string, editors []string, readers []string) {
|
||||||
|
for u := range YieldUsers() {
|
||||||
|
switch u.Group {
|
||||||
|
// What if we place the users into sorted slices?
|
||||||
|
case "admin":
|
||||||
|
admins = append(admins, u.Name)
|
||||||
|
case "moderator":
|
||||||
|
moderators = append(moderators, u.Name)
|
||||||
|
case "editor", "trusted":
|
||||||
|
editors = append(editors, u.Name)
|
||||||
|
case "reader":
|
||||||
|
readers = append(readers, u.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Strings(admins)
|
||||||
|
sort.Strings(moderators)
|
||||||
|
sort.Strings(editors)
|
||||||
|
sort.Strings(readers)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import (
|
|||||||
//go:embed views/*.html
|
//go:embed views/*.html
|
||||||
var fs embed.FS
|
var fs embed.FS
|
||||||
|
|
||||||
var pageOrphans, pageBacklinks *newtmpl.Page
|
var pageOrphans, pageBacklinks, pageUserList *newtmpl.Page
|
||||||
|
|
||||||
func initPages() {
|
func initPages() {
|
||||||
pageOrphans = newtmpl.NewPage(fs, "views/orphans.html", map[string]string{
|
pageOrphans = newtmpl.NewPage(fs, "views/orphans.html", map[string]string{
|
||||||
@ -20,4 +20,11 @@ func initPages() {
|
|||||||
"backlinks to link": `Обратные ссылки на <a href="/hypha/{{.}}">{{beautifulName .}}</a>`,
|
"backlinks to link": `Обратные ссылки на <a href="/hypha/{{.}}">{{beautifulName .}}</a>`,
|
||||||
"description": `Ниже перечислены гифы, на которых есть ссылка на эту гифу, трансклюзия этой гифы или эта гифа вставлена как изображение.`,
|
"description": `Ниже перечислены гифы, на которых есть ссылка на эту гифу, трансклюзия этой гифы или эта гифа вставлена как изображение.`,
|
||||||
})
|
})
|
||||||
|
pageUserList = newtmpl.NewPage(fs, "views/user-list.html", map[string]string{
|
||||||
|
"title": "Список пользователей",
|
||||||
|
"administrators": "Администраторы",
|
||||||
|
"moderators": "Модераторы",
|
||||||
|
"editors": "Редакторы",
|
||||||
|
"readers": "Читатели",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
30
web/views/user-list.html
Normal file
30
web/views/user-list.html
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
{{define "title"}}List of users{{end}}
|
||||||
|
{{define "body"}}
|
||||||
|
<main class="main-width user-list">
|
||||||
|
<h1>{{template "title"}}</h1>
|
||||||
|
<section>{{$u := .UserHypha}}
|
||||||
|
<h2>{{block "administrators" .}}Administrators{{end}}</h2>
|
||||||
|
<ol>
|
||||||
|
{{range .Admins}}<li><a href="/hypha/{{$u}}/{{.}}">{{.}}</a></li>{{end}}
|
||||||
|
</ol>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<h2>{{block "moderators" .}}Moderators{{end}}</h2>
|
||||||
|
<ol>
|
||||||
|
{{range .Moderators}}<li><a href="/hypha/{{$u}}/{{.}}">{{.}}</a></li>{{end}}
|
||||||
|
</ol>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<h2>{{block "editors" .}}Editors{{end}}</h2>
|
||||||
|
<ol>
|
||||||
|
{{range .Editors}}<li><a href="/hypha/{{$u}}/{{.}}">{{.}}</a></li>{{end}}
|
||||||
|
</ol>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<h2>{{block "readers" .}}Readers{{end}}</h2>
|
||||||
|
<ol>
|
||||||
|
{{range .Readers}}<li><a href="/hypha/{{$u}}/{{.}}">{{.}}</a></li>{{end}}
|
||||||
|
</ol>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
{{end}}
|
||||||
12
web/web.go
12
web/web.go
@ -126,10 +126,14 @@ func groupMiddleware(group string) func(http.Handler) http.Handler {
|
|||||||
|
|
||||||
// Auth
|
// Auth
|
||||||
func handlerUserList(w http.ResponseWriter, rq *http.Request) {
|
func handlerUserList(w http.ResponseWriter, rq *http.Request) {
|
||||||
lc := l18n.FromRequest(rq)
|
admins, moderators, editors, readers := user.UsersInGroups()
|
||||||
w.Header().Set("Content-Type", mime.TypeByExtension(".html"))
|
_ = pageUserList.RenderTo(viewutil.MetaFrom(w, rq),
|
||||||
w.WriteHeader(http.StatusOK)
|
map[string]any{
|
||||||
w.Write([]byte(viewutil.Base(viewutil.MetaFrom(w, rq), lc.Get("ui.users_title"), auth.UserList(lc), map[string]string{})))
|
"Admins": admins,
|
||||||
|
"Moderators": moderators,
|
||||||
|
"Editors": editors,
|
||||||
|
"Readers": readers,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlerLock(w http.ResponseWriter, rq *http.Request) {
|
func handlerLock(w http.ResponseWriter, rq *http.Request) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user