Merge pull request #155 from ssb-ngi-pointer/dashboard-content-fixes
more content and member links on the dashboard
This commit is contained in:
commit
b411692782
|
@ -7,7 +7,10 @@ import (
|
|||
"net/http"
|
||||
|
||||
"go.mindeco.de/http/render"
|
||||
refs "go.mindeco.de/ssb-refs"
|
||||
|
||||
"github.com/ssb-ngi-pointer/go-ssb-room/internal/network"
|
||||
"github.com/ssb-ngi-pointer/go-ssb-room/roomdb"
|
||||
"github.com/ssb-ngi-pointer/go-ssb-room/roomstate"
|
||||
weberrors "github.com/ssb-ngi-pointer/go-ssb-room/web/errors"
|
||||
)
|
||||
|
@ -17,31 +20,52 @@ type dashboardHandler struct {
|
|||
flashes *weberrors.FlashHelper
|
||||
|
||||
roomState *roomstate.Manager
|
||||
netInfo network.ServerEndpointDetails
|
||||
dbs Databases
|
||||
}
|
||||
|
||||
func (h dashboardHandler) overview(w http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||
roomRef := h.netInfo.RoomID.Ref()
|
||||
|
||||
onlineRefs := h.roomState.List()
|
||||
onlineCount := len(onlineRefs)
|
||||
|
||||
onlineMembers := make([]roomdb.Member, len(onlineRefs))
|
||||
for i := range onlineRefs {
|
||||
ref, err := refs.ParseFeedRef(onlineRefs[i])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse online ref: %w", err)
|
||||
}
|
||||
onlineMembers[i], err = h.dbs.Members.GetByFeed(req.Context(), *ref)
|
||||
if err != nil {
|
||||
// TODO: do we want to show "external users" (non-members) on the dashboard?
|
||||
return nil, fmt.Errorf("failed to lookup online member: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
onlineCount := len(onlineMembers)
|
||||
|
||||
memberCount, err := h.dbs.Members.Count(req.Context())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to count members: %w", err)
|
||||
}
|
||||
|
||||
inviteCount, err := h.dbs.Invites.Count(req.Context())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to count invites: %w", err)
|
||||
}
|
||||
|
||||
deniedCount, err := h.dbs.DeniedKeys.Count(req.Context())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to count denied keys: %w", err)
|
||||
}
|
||||
|
||||
pageData := map[string]interface{}{
|
||||
"OnlineRefs": onlineRefs,
|
||||
"OnlineCount": onlineCount,
|
||||
"MemberCount": memberCount,
|
||||
"InviteCount": inviteCount,
|
||||
"DeniedCount": deniedCount,
|
||||
"RoomRef": roomRef,
|
||||
"OnlineMembers": onlineMembers,
|
||||
"OnlineCount": onlineCount,
|
||||
"MemberCount": memberCount,
|
||||
"InviteCount": inviteCount,
|
||||
"DeniedCount": deniedCount,
|
||||
}
|
||||
|
||||
pageData["Flashes"], err = h.flashes.GetAll(w, req)
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/vcraescu/go-paginator/v2/view"
|
||||
"go.mindeco.de/http/render"
|
||||
|
||||
"github.com/ssb-ngi-pointer/go-ssb-room/internal/network"
|
||||
"github.com/ssb-ngi-pointer/go-ssb-room/roomdb"
|
||||
"github.com/ssb-ngi-pointer/go-ssb-room/roomstate"
|
||||
weberrors "github.com/ssb-ngi-pointer/go-ssb-room/web/errors"
|
||||
|
@ -58,7 +59,7 @@ type Databases struct {
|
|||
// Handler supplies the elevated access pages to known users.
|
||||
// It is not registering on the mux router like other pages to clean up the authorize flow.
|
||||
func Handler(
|
||||
domainName string,
|
||||
netInfo network.ServerEndpointDetails,
|
||||
r *render.Renderer,
|
||||
roomState *roomstate.Manager,
|
||||
fh *weberrors.FlashHelper,
|
||||
|
@ -69,6 +70,7 @@ func Handler(
|
|||
var dashboardHandler = dashboardHandler{
|
||||
r: r,
|
||||
flashes: fh,
|
||||
netInfo: netInfo,
|
||||
|
||||
dbs: dbs,
|
||||
roomState: roomState,
|
||||
|
@ -126,7 +128,7 @@ func Handler(
|
|||
db: dbs.Invites,
|
||||
config: dbs.Config,
|
||||
|
||||
domainName: domainName,
|
||||
domainName: netInfo.Domain,
|
||||
}
|
||||
|
||||
mux.HandleFunc("/invites", r.HTML("admin/invite-list.tmpl", ih.overview))
|
||||
|
|
|
@ -15,7 +15,7 @@ func TestDashoard(t *testing.T) {
|
|||
ts := newSession(t)
|
||||
a := assert.New(t)
|
||||
|
||||
testRef := refs.FeedRef{Algo: "test", ID: bytes.Repeat([]byte{0}, 16)}
|
||||
testRef := refs.FeedRef{Algo: "ed25519", ID: bytes.Repeat([]byte{0}, 32)}
|
||||
ts.RoomState.AddEndpoint(testRef, nil) // 1 online
|
||||
ts.MembersDB.CountReturns(4, nil) // 4 members
|
||||
ts.InvitesDB.CountReturns(3, nil) // 3 invites
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
package admin
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"net/http"
|
||||
|
@ -18,7 +19,9 @@ import (
|
|||
"go.mindeco.de/http/render"
|
||||
"go.mindeco.de/http/tester"
|
||||
"go.mindeco.de/logging/logtest"
|
||||
refs "go.mindeco.de/ssb-refs"
|
||||
|
||||
"github.com/ssb-ngi-pointer/go-ssb-room/internal/network"
|
||||
"github.com/ssb-ngi-pointer/go-ssb-room/internal/randutil"
|
||||
"github.com/ssb-ngi-pointer/go-ssb-room/internal/repo"
|
||||
"github.com/ssb-ngi-pointer/go-ssb-room/roomdb"
|
||||
|
@ -33,8 +36,8 @@ import (
|
|||
)
|
||||
|
||||
type testSession struct {
|
||||
Domain string
|
||||
Mux *http.ServeMux
|
||||
netInfo network.ServerEndpointDetails
|
||||
Mux *http.ServeMux
|
||||
|
||||
Client *tester.Tester
|
||||
|
||||
|
@ -71,7 +74,10 @@ func newSession(t *testing.T) *testSession {
|
|||
ctx := context.TODO()
|
||||
ts.RoomState = roomstate.NewManager(ctx, log)
|
||||
|
||||
ts.Domain = randutil.String(10)
|
||||
ts.netInfo = network.ServerEndpointDetails{
|
||||
Domain: randutil.String(10),
|
||||
RoomID: refs.FeedRef{Algo: "ed25519", ID: bytes.Repeat([]byte{0}, 32)},
|
||||
}
|
||||
|
||||
// instantiate the urlTo helper (constructs urls for us!)
|
||||
// the cookiejar in our custom http/tester needs a non-empty domain and scheme
|
||||
|
@ -82,7 +88,7 @@ func newSession(t *testing.T) *testSession {
|
|||
if testURL == nil {
|
||||
t.Fatalf("no URL for %s", name)
|
||||
}
|
||||
testURL.Host = ts.Domain
|
||||
testURL.Host = ts.netInfo.Domain
|
||||
testURL.Scheme = "https" // fake
|
||||
return testURL
|
||||
}
|
||||
|
@ -139,7 +145,7 @@ func newSession(t *testing.T) *testSession {
|
|||
}
|
||||
|
||||
handler := Handler(
|
||||
ts.Domain,
|
||||
ts.netInfo,
|
||||
r,
|
||||
ts.RoomState,
|
||||
flashHelper,
|
||||
|
|
|
@ -178,7 +178,7 @@ func TestFallbackAuthWorks(t *testing.T) {
|
|||
{"title", "AdminDashboardTitle"},
|
||||
})
|
||||
|
||||
testRef := refs.FeedRef{Algo: "test", ID: bytes.Repeat([]byte{0}, 16)}
|
||||
testRef := refs.FeedRef{Algo: "ed25519", ID: bytes.Repeat([]byte{0}, 32)}
|
||||
ts.RoomState.AddEndpoint(testRef, nil)
|
||||
|
||||
html, resp = ts.Client.GetHTML(dashboardURL)
|
||||
|
@ -189,7 +189,7 @@ func TestFallbackAuthWorks(t *testing.T) {
|
|||
{"title", "AdminDashboardTitle"},
|
||||
})
|
||||
|
||||
testRef2 := refs.FeedRef{Algo: "test", ID: bytes.Repeat([]byte{1}, 16)}
|
||||
testRef2 := refs.FeedRef{Algo: "ed25519", ID: bytes.Repeat([]byte{1}, 32)}
|
||||
ts.RoomState.AddEndpoint(testRef2, nil)
|
||||
|
||||
html, resp = ts.Client.GetHTML(dashboardURL)
|
||||
|
|
|
@ -233,7 +233,7 @@ func New(
|
|||
|
||||
// all the admin routes
|
||||
adminHandler := admin.Handler(
|
||||
netInfo.Domain,
|
||||
netInfo,
|
||||
r,
|
||||
roomState,
|
||||
flashHelper,
|
||||
|
|
|
@ -63,7 +63,7 @@ AuthFallbackInstruct = "This method is an acceptable fallback, if you have a use
|
|||
#########################
|
||||
|
||||
AdminDashboardTitle = "Dashboard"
|
||||
AdminDashboardWelcome = "Welcome to your dashboard"
|
||||
AdminDashboardRoomID = "This room's ID is"
|
||||
|
||||
# privacy modes
|
||||
###############
|
||||
|
|
|
@ -5,7 +5,13 @@
|
|||
>{{i18n "AdminDashboardTitle"}}</h1>
|
||||
|
||||
{{ template "flashes" . }}
|
||||
|
||||
|
||||
<div class="mt-6 flex flex-row justify-start items-center py-3 px-4 border-gray-200 border-2 rounded-3xl text-gray-500">
|
||||
<span class="break-all"
|
||||
>{{i18n "AdminDashboardRoomID"}} <span class="font-mono">{{.RoomRef}}</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col-reverse sm:flex-row justify-start items-stretch ">
|
||||
<div class="sm:mr-4 mt-6 py-6 px-4 border-gray-200 border-2 rounded-3xl flex flex-col justify-start items-start">
|
||||
<div class="grid grid-rows-2 grid-flow-col gap-x-4 gap-y-0">
|
||||
|
@ -79,11 +85,22 @@
|
|||
<div class="ml-11 h-8 w-0.5 bg-gray-200"></div>
|
||||
{{end}}
|
||||
|
||||
{{range .OnlineRefs}}
|
||||
{{range .OnlineMembers}}
|
||||
{{$member := .PubKey.Ref}}
|
||||
{{$memberIsAlias := false}}
|
||||
{{range $index, $alias := .Aliases}}
|
||||
{{if eq $index 0}}
|
||||
{{$member = $alias.Name}}
|
||||
{{$memberIsAlias = true}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
<div class="ml-11 h-8 w-0.5 bg-gray-200"></div>
|
||||
<div class="ml-11 relative h-3">
|
||||
<div class="absolute inline-flex w-3 h-3 bg-green-500 rounded-full -left-1 -ml-px"></div>
|
||||
<div class="absolute w-44 sm:w-auto -top-1.5 ml-5 pl-1 font-mono truncate flex-auto text-gray-700">{{.}}</div>
|
||||
<a
|
||||
href="{{urlTo "admin:member:details" "id" .ID}}"
|
||||
class="absolute w-44 sm:w-auto -top-1.5 ml-5 pl-1 font-mono truncate flex-auto text-gray-700 hover:underline"
|
||||
>{{$member}}</a>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue