package web
import (
"net/http"
"net/url"
"craftdesign.group/quarry/internal/ops"
)
// fossilUsersPanel is Advanced's Fossil users block: the repository's
// synced fossil user table, kept as a reference an admin links to
// accounts. nil where the forge keeps no such list.
type fossilUsersPanel struct {
Upstream string
Refused string
Users []fossilUserView
}
type fossilUserView struct {
Login string
Caps string
Decoded []string
Info string
Linked string
Suggest bool
}
// linkedTo maps each linked quarry account to its fossil login, for
// the People chip.
func (p *fossilUsersPanel) linkedTo() map[string]string {
out := map[string]string{}
if p == nil {
return out
}
for _, u := range p.Users {
if u.Linked != "" {
out[u.Linked] = u.Login
}
}
return out
}
func fossilUsersPanelFor(r *ops.Registry, req *http.Request, repo string) *fossilUsersPanel {
out, err := invoke(req.Context(), r, "repo.fossil.users", url.Values{"repo": {repo}})
if err != nil {
return nil
}
var v struct {
Upstream string `json:"upstream"`
Users []struct {
Login string `json:"login"`
Caps string `json:"caps"`
Decoded []string `json:"decoded"`
Info string `json:"info"`
Linked string `json:"linked"`
Suggest bool `json:"suggest"`
} `json:"users"`
}
remarshal(out, &v)
p := &fossilUsersPanel{Upstream: v.Upstream, Refused: req.URL.Query().Get("fe")}
for _, u := range v.Users {
p.Users = append(p.Users, fossilUserView{Login: u.Login, Caps: u.Caps, Decoded: u.Decoded,
Info: u.Info, Linked: u.Linked, Suggest: u.Suggest})
}
return p
}