| 1 | package equipo |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | |
| 6 | "amadan.net/oficina/equipo/internal/equipo/push" |
| 7 | "amadan.net/oficina/equipo/internal/equipo/setup" |
| 8 | "amadan.net/oficina/equipo/internal/runnerproto" |
| 9 | "gorm.io/gorm" |
| 10 | ) |
| 11 | |
| 12 | type Invitation = setup.Invitation |
| 13 | |
| 14 | var ErrInvitationExpired = &refusal{copyInviteExpired, ErrConflict} |
| 15 | |
| 16 | func (s *Store) invitationsAt(tx *gorm.DB) *setup.Store { |
| 17 | return setup.New(tx, setup.Dependencies{RunnerCurrent: func(tx *gorm.DB, p runnerproto.RunnerPrincipal) error { |
| 18 | _, err := runnerPrincipalAt(tx, p, s.runnerClock.Now()) |
| 19 | return err |
| 20 | }, ConnectAccount: setup.ConnectAccount, Key: s.invitationKey, Origin: s.personOrigin, Now: s.runnerClock.Now().UTC(), Owner: requireOwner, Member: memberAt, Audit: appendAudit, Invalid: ErrInvalid, Forbidden: ErrForbidden, NotFound: ErrNotFound, Conflict: ErrConflict, Unavailable: ErrUnavailable, Expired: ErrInvitationExpired, |
| 21 | Normalize: normalizeAddress, ValidAddress: validAddress, Seed: seedSpecialists, TeamName: copyBrand, BootstrapOwners: ErrBootstrapOwners, LastOwner: ErrLastOwner, DecisionOwnerAssigned: ErrDecisionOwnerAssigned, |
| 22 | LapseOwner: func(tx *gorm.DB, address string) error { |
| 23 | return lapseOwnerAcknowledgements(tx, address, s.runnerClock.Now().UTC()) |
| 24 | }, |
| 25 | RevokeRunners: func(tx *gorm.DB, address string) error { |
| 26 | return revokePersonRunners(tx, address, s.runnerClock.Now().UTC()) |
| 27 | }, |
| 28 | ForgetPush: push.ForgetPerson, |
| 29 | Fence: func(tx *gorm.DB) error { return s.fenceAuthority(tx.Statement.Context, tx, 0) }, |
| 30 | }) |
| 31 | } |
| 32 | |
| 33 | func (s *Store) invitationRead(ctx context.Context, fn func(*gorm.DB) error) error { |
| 34 | if s == nil || s.db == nil { |
| 35 | return ErrUnavailable |
| 36 | } |
| 37 | return s.db.G.WithContext(ctx).Transaction(func(tx *gorm.DB) error { |
| 38 | if err := s.currentPersonAPI(tx, ctx); err != nil { |
| 39 | return err |
| 40 | } |
| 41 | return fn(tx) |
| 42 | }) |
| 43 | } |
| 44 | |