oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package equipo
2
3import (
4 "errors"
5 "net/http"
6
7 "amadan.net/oficina/equipo/internal/equipo/setup"
8)
9
10func (a *application) invitationHandler() *setup.Handler {
11 return &setup.Handler{Key: a.store.invitationKey, Now: a.store.runnerClock.Now, Store: a.store, Invalid: ErrInvalid, Forbidden: ErrForbidden, Expired: ErrInvitationExpired, Failure: a.failure,
12 Actor: func(r *http.Request) (Actor, error) {
13 id, ok := a.sessionFrom(r)
14 if !ok || id.At.IsZero() {
15 return Actor{}, ErrForbidden
16 }
17 member, err := a.store.Member(r.Context(), id.Address)
18 if err != nil && !errors.Is(err, ErrNotFound) {
19 return Actor{}, err
20 }
21 if err == nil && id.At.Unix() < member.SessionEpoch {
22 return Actor{}, ErrForbidden
23 }
24 return Actor{Address: id.Address}, nil
25 },
26 Owner: func(r *http.Request, actor Actor) error {
27 return a.store.InvitationOwner(r.Context(), actor)
28 },
29 Render: func(w http.ResponseWriter, r *http.Request, status int, v setup.InviteView) {
30 // Pending invitees receive no team page data or private navigation counts.
31 renderStatus(w, status, "invite", pageData{Title: "invite.welcome", TeamName: copyBrand, Invite: v})
32 },
33 }
34}
35