~gitpocket/gitpocket

1

feat(profile): link the workplace to its account

commit
9afcd8eac1635659eb7fea3c41a20790561c260d browse tree
parent
c5a2e8a3f88d09ac380e1d245d568fb9ae34f511
author
obscurejames <354576047+obscurejames@users.noreply.github.com>
signature
Verified ~james signed with a key registered by ~james
date
2026-10-22 23:24 UTC

3 files changed, +20 −1

flow_test.go modified

@@ -211,3 +211,17 @@ func commitFile(t *testing.T, g Git, branch, parent, name, content string) strin
211211 g.run(nil, "update-ref", "refs/heads/"+branch, hash)
212212 return hash
213213 }
214+
215+func TestWorkplaceLink(t *testing.T) {
216+ s, h := testServer(t)
217+ alice, _ := s.store.CreateUser("alice", "correct horse")
218+ s.store.CreateOrg("team")
219+ s.store.UpdateProfile(alice.ID, Profile{Workplace: "@Team"})
220+ if body := get(h, "/~alice", "").Body.String(); !strings.Contains(body, `<a href="/~team">@Team</a>`) {
221+ t.Error("workplace naming an org is not linked")
222+ }
223+ s.store.UpdateProfile(alice.ID, Profile{Workplace: "Nowhere Ltd"})
224+ if body := get(h, "/~alice", "").Body.String(); !strings.Contains(body, "Nowhere Ltd") || strings.Contains(body, `">Nowhere Ltd</a>`) {
225+ t.Error("unknown workplace should be plain text")
226+ }
227+}

templates/user.html modified

@@ -12,7 +12,7 @@
1212 {{with .Data.Bio}}<div class="bio readme">{{.}}</div>{{end}}
1313 <ul class="facts">
1414 {{if $p.Location}}<li><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M8 15s5-4.6 5-8.5A5 5 0 0 0 3 6.5C3 10.4 8 15 8 15z"/><circle cx="8" cy="6.5" r="1.8"/></svg>{{$p.Location}}</li>{{end}}
15-{{if $p.Workplace}}<li><svg viewBox="0 0 16 16" aria-hidden="true"><rect x="2" y="5" width="12" height="9" rx="1.5"/><path d="M6 5V3.5A1 1 0 0 1 7 2.5h2a1 1 0 0 1 1 1V5"/></svg>{{$p.Workplace}}</li>{{end}}
15+{{if $p.Workplace}}<li><svg viewBox="0 0 16 16" aria-hidden="true"><rect x="2" y="5" width="12" height="9" rx="1.5"/><path d="M6 5V3.5A1 1 0 0 1 7 2.5h2a1 1 0 0 1 1 1V5"/></svg>{{with .Data.Workplace}}<a href="/~{{.}}">{{$p.Workplace}}</a>{{else}}{{$p.Workplace}}{{end}}</li>{{end}}
1616 {{if $p.Website}}<li><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M6.8 9.2a3 3 0 0 0 4.2 0l2.2-2.2a3 3 0 0 0-4.2-4.2l-.9.9"/><path d="M9.2 6.8a3 3 0 0 0-4.2 0L2.8 9a3 3 0 0 0 4.2 4.2l.9-.9"/></svg><a href="{{$p.Website}}" rel="nofollow me">{{bare $p.Website}}</a></li>{{end}}
1717 <li title="{{date .Data.Owner.Created}}"><svg viewBox="0 0 16 16" aria-hidden="true"><rect x="2" y="3" width="12" height="11" rx="1.5"/><path d="M2 6.5h12M5.5 1.5v3M10.5 1.5v3"/></svg>Joined {{.Data.Owner.Created.Format "January 2006"}}</li>
1818 </ul>

web.go modified

@@ -822,6 +822,11 @@ func (s *Server) route(w http.ResponseWriter, r *http.Request) {
822822 orgs = append(orgs, userHit{User: o, Profile: s.store.Profile(o.ID)})
823823 }
824824 data["Orgs"] = orgs
825+ if name := strings.ToLower(strings.TrimLeft(strings.TrimSpace(profile.Workplace), "@~")); validName(name) && name != owner.Name {
826+ if place, err := s.store.UserByName(name); err == nil {
827+ data["Workplace"] = place.Name
828+ }
829+ }
825830 s.render(w, r, "user", page{Title: "~" + owner.Name, User: user, Math: hasMath(bio), Data: data})
826831 return
827832 }