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 "context"
5 "net/http"
6
7 "amadan.net/oficina/equipo/internal/equipo/personapi"
8 "amadan.net/oficina/equipo/internal/equipo/push"
9)
10
11type PersonDeviceChallenge = personapi.PersonDeviceChallenge
12type PersonDeviceProof = personapi.PersonDeviceProof
13type PersonCredential = personapi.PersonCredential
14
15func (s *Store) personDevices() *personapi.DeviceStore {
16 return &personapi.DeviceStore{NativeSession: s.personNativeSession, Write: s.write, Read: s.invitationRead, Member: memberAt, Instance: runnerInstance, Audit: appendAudit, Key: s.personKey, Origin: s.personOrigin, Now: s.runnerClock.Now, Revoked: push.ForgetCredential, Invalid: ErrInvalid, Forbidden: ErrForbidden, NotFound: ErrNotFound, Conflict: ErrConflict}
17}
18func (s *Store) BeginPersonDevice(ctx context.Context, key, label, request string) (PersonDeviceChallenge, error) {
19 return s.personDevices().Begin(ctx, key, label, request)
20}
21func (s *Store) ApprovePersonDevice(ctx context.Context, a Actor, id, code string, m Mutation) error {
22 return s.personDevices().Approve(ctx, a, id, code, m)
23}
24func (s *Store) ExchangePersonDevice(ctx context.Context, p PersonDeviceProof) (PersonCredential, error) {
25 return s.personDevices().Exchange(ctx, p)
26}
27func (s *Store) RevokePersonDevice(ctx context.Context, a Actor, id string, m Mutation) error {
28 return s.personDevices().Revoke(ctx, a, id, m)
29}
30
31func (a *application) deviceBrowser() *personapi.DeviceBrowser {
32 return &personapi.DeviceBrowser{Cookie: a.store.personCookie, List: a.store.personDevices().List, Revoke: a.store.RevokePersonDevice, RenderList: func(w http.ResponseWriter, r *http.Request, devices []personapi.Device, request string) {
33 data, err := a.page(r, "settings")
34 if err != nil {
35 a.failure(w, r, err)
36 return
37 }
38 data.PersonDevices = devices
39 data.PersonDeviceRequest = request
40 data.Title = "device.list"
41 render(w, "person_devices", data)
42 }, Member: a.store.Member, Read: a.store.personDevices().Approval, Approve: a.store.ApprovePersonDevice, Invalid: ErrInvalid, Forbidden: ErrForbidden, Failure: a.failure, Render: func(w http.ResponseWriter, r *http.Request, d personapi.Device, request string) {
43 data, err := a.page(r, "connections")
44 if err != nil {
45 a.failure(w, r, err)
46 return
47 }
48 data.PersonDevice = d
49 data.PersonDeviceRequest = request
50 data.Title = "device.title"
51 render(w, "person_device", data)
52 }}
53}
54