feat(profile): link the workplace when it names an existing account
3 files changed, +20 −1
- flow_test.go modified +14 −0
- templates/user.html modified +1 −1
- web.go modified +5 −0
flow_test.go modified
| @@ -211,3 +211,17 @@ func commitFile(t *testing.T, g Git, branch, parent, name, content string) strin | ||
| 211 | 211 | g.run(nil, "update-ref", "refs/heads/"+branch, hash) |
| 212 | 212 | return hash |
| 213 | 213 | } |
| 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 @@ | ||
| 12 | 12 | {{with .Data.Bio}}<div class="bio readme">{{.}}</div>{{end}} |
| 13 | 13 | <ul class="facts"> |
| 14 | 14 | {{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}} | |
| 16 | 16 | {{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}} |
| 17 | 17 | <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> |
| 18 | 18 | </ul> |
web.go modified
| @@ -822,6 +822,11 @@ func (s *Server) route(w http.ResponseWriter, r *http.Request) { | ||
| 822 | 822 | orgs = append(orgs, userHit{User: o, Profile: s.store.Profile(o.ID)}) |
| 823 | 823 | } |
| 824 | 824 | 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 | + } | |
| 825 | 830 | s.render(w, r, "user", page{Title: "~" + owner.Name, User: user, Math: hasMath(bio), Data: data}) |
| 826 | 831 | return |
| 827 | 832 | } |