-
Notifications
You must be signed in to change notification settings - Fork 32
/
org_invites.go
52 lines (42 loc) · 1.16 KB
/
org_invites.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package routes
// The file contains routes related to org invitations
import (
"encoding/json"
"log"
"net/http"
"github.com/go-zoo/bone"
"github.com/manifoldco/torus-cli/identity"
"github.com/manifoldco/torus-cli/daemon/logic"
"github.com/manifoldco/torus-cli/daemon/observer"
)
func orgInvitesApproveRoute(engine *logic.Engine, o *observer.Observer) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
n, err := o.Notifier(ctx, 1)
if err != nil {
log.Printf("Error creating Notififer: %s", err)
encodeResponseErr(w, err)
return
}
inviteID, err := identity.DecodeFromString(bone.GetValue(r, "id"))
if err != nil {
log.Printf("Could not approve org invite; invalid id: %s", err)
encodeResponseErr(w, err)
return
}
invite, err := engine.ApproveInvite(ctx, n, &inviteID)
if err != nil {
// Allow engine to log debugs
encodeResponseErr(w, err)
return
}
n.Notify(observer.Finished, "Completed", true)
enc := json.NewEncoder(w)
err = enc.Encode(invite)
if err != nil {
log.Printf("error encoding invite approve resp: %s", err)
encodeResponseErr(w, err)
return
}
}
}