Rank log: inactive ranks (Guardian) count as promotions to and from, demotion when lost; Guardian is staff

This commit is contained in:
Astra 2026-09-29 17:19:53 +01:00
parent 611b79cdba
commit 0af93d1eab
7 changed files with 76 additions and 24 deletions

View file

@ -214,6 +214,20 @@ type rankChangeView struct {
New *rankView `json:"new,omitempty"`
}
// inactiveKind overrides the stored kind (which compares immunity) for changes to or from an
// inactive rank: moving between an inactive rank and any other rank is a promotion either way,
// and losing an inactive rank altogether is a demotion.
func inactiveKind(kind string, old, new *rankView) string {
oldIn, newIn := old != nil && old.Inactive, new != nil && new.Inactive
switch {
case old != nil && new != nil && oldIn != newIn:
return "promoted"
case oldIn && new == nil:
return "demoted"
}
return kind
}
// publicRankChanges is the promotions and demotions list, with each rank's label and colour.
func (s *Server) publicRankChanges(w http.ResponseWriter, r *http.Request) {
lim, off, num := page(r)
@ -232,11 +246,13 @@ func (s *Server) publicRankChanges(w http.ResponseWriter, r *http.Request) {
return nil
}
rk := s.site.rank(g, x.groupIndex(g))
return &rankView{Name: g, Label: rk.Label, Color: rk.Color, Supporter: rk.Supporter}
return &rankView{Name: g, Label: rk.Label, Color: rk.Color, Supporter: rk.Supporter, Inactive: rk.Inactive}
}
out := make([]rankChangeView, 0, len(items))
for _, c := range items {
out = append(out, rankChangeView{RankChange: c, Old: view(c.OldRank), New: view(c.NewRank)})
v := rankChangeView{RankChange: c, Old: view(c.OldRank), New: view(c.NewRank)}
v.Kind = inactiveKind(v.Kind, v.Old, v.New)
out = append(out, v)
}
writeJSON(w, http.StatusOK, newList(out, total, num))
}