feat(invitations): check contact grants on every read, cap pending invitations, and expire them at the deadline
This commit is contained in:
1 parent
676b3c6e24
commit
12a7213d4a
67 files changed
+4255
-149
No files matched your search
@@ -14035,8 +14035,8 @@ func (s *Server) handleSearchOrganizationMatchesRequest(args [1]string, argsEsca
|
||||
// answer per need (`delivered`, `viewed`, `counter`) and the 30-day pause for the pair of the
|
||||
// organization and the candidate after a decline or a no deal, regardless of the member or the need,
|
||||
// both with 409 state_conflict; and the rolling weekly quota of the organization, with 429 and
|
||||
// Retry-After. The organization quota is enforced; the pending limit and the pause are planned and are
|
||||
// not checked yet.
|
||||
// Retry-After. The organization quota, the pending limit, and the pause after a decline are enforced;
|
||||
// the pause after a no deal is planned, because no operation produces the state `no_deal` yet.
|
||||
//
|
||||
// Repeats return the same result: a retry with the same Idempotency-Key replays the stored response,
|
||||
// and a send of an invitation that was already sent answers 200 with the invitation in its current
|
||||
|
||||
@@ -1725,8 +1725,8 @@ type Handler interface {
|
||||
// answer per need (`delivered`, `viewed`, `counter`) and the 30-day pause for the pair of the
|
||||
// organization and the candidate after a decline or a no deal, regardless of the member or the need,
|
||||
// both with 409 state_conflict; and the rolling weekly quota of the organization, with 429 and
|
||||
// Retry-After. The organization quota is enforced; the pending limit and the pause are planned and are
|
||||
// not checked yet.
|
||||
// Retry-After. The organization quota, the pending limit, and the pause after a decline are enforced;
|
||||
// the pause after a no deal is planned, because no operation produces the state `no_deal` yet.
|
||||
//
|
||||
// Repeats return the same result: a retry with the same Idempotency-Key replays the stored response,
|
||||
// and a send of an invitation that was already sent answers 200 with the invitation in its current
|
||||
|
||||
@@ -1916,8 +1916,8 @@ func (UnimplementedHandler) SearchOrganizationMatches(ctx context.Context, req M
|
||||
// answer per need (`delivered`, `viewed`, `counter`) and the 30-day pause for the pair of the
|
||||
// organization and the candidate after a decline or a no deal, regardless of the member or the need,
|
||||
// both with 409 state_conflict; and the rolling weekly quota of the organization, with 429 and
|
||||
// Retry-After. The organization quota is enforced; the pending limit and the pause are planned and are
|
||||
// not checked yet.
|
||||
// Retry-After. The organization quota, the pending limit, and the pause after a decline are enforced;
|
||||
// the pause after a no deal is planned, because no operation produces the state `no_deal` yet.
|
||||
//
|
||||
// Repeats return the same result: a retry with the same Idempotency-Key replays the stored response,
|
||||
// and a send of an invitation that was already sent answers 200 with the invitation in its current
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"lincodex/backend/internal/adapter/primary/http/api"
|
||||
"lincodex/backend/internal/adapter/primary/http/problem"
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/port/outbound"
|
||||
)
|
||||
|
||||
func (handler *Handler) GetOrganizationInvitationContacts(ctx context.Context, params api.GetOrganizationInvitationContactsParams) (api.GetOrganizationInvitationContactsRes, error) {
|
||||
if handler.invitation == nil {
|
||||
return handler.UnimplementedHandler.GetOrganizationInvitationContacts(ctx, params)
|
||||
}
|
||||
return handler.invitation.GetOrganizationInvitationContacts(ctx, params)
|
||||
}
|
||||
|
||||
// GetOrganizationInvitationContacts serves the only operation that returns
|
||||
// contact values. The company middleware has already checked the session, the
|
||||
// owner membership, and the path, and the usecase repeats the owner check in
|
||||
// its transaction. Every failure of the grant read answers the same not found,
|
||||
// so the response never tells which condition applies.
|
||||
func (handler *InvitationHandler) GetOrganizationInvitationContacts(
|
||||
ctx context.Context,
|
||||
params api.GetOrganizationInvitationContactsParams,
|
||||
) (api.GetOrganizationInvitationContactsRes, error) {
|
||||
principal, ok := PrincipalFromContext(ctx)
|
||||
if !ok {
|
||||
return (*api.GetOrganizationInvitationContactsUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
|
||||
}
|
||||
disclosure, err := handler.operations.ReadContacts(ctx, principal.UserID, params.OrgID, params.InvitationID)
|
||||
if err != nil {
|
||||
return contactsReadFailure(ctx, err)
|
||||
}
|
||||
return &api.ContactDisclosureHeaders{CacheControl: api.CacheControlNoStoreNoStore, Response: contactDisclosureResponse(disclosure)}, nil
|
||||
}
|
||||
|
||||
func contactsReadFailure(ctx context.Context, err error) (api.GetOrganizationInvitationContactsRes, error) {
|
||||
// A missing grant is the not found of the contract. It is handled before the
|
||||
// shared classification, which treats an unexpected missing grant as a
|
||||
// storage defect on the other invitation paths.
|
||||
if errors.Is(err, outbound.ErrContactGrantNotFound) {
|
||||
return (*api.GetOrganizationInvitationContactsNotFound)(&problem.New(ctx, api.ProblemCodeNotFound).Response), nil
|
||||
}
|
||||
switch classifyInvitationError(err) {
|
||||
case invitationFailureForbidden:
|
||||
return (*api.GetOrganizationInvitationContactsForbidden)(&problem.New(ctx, api.ProblemCodeForbidden).Response), nil
|
||||
case invitationFailureNotFound:
|
||||
return (*api.GetOrganizationInvitationContactsNotFound)(&problem.New(ctx, api.ProblemCodeNotFound).Response), nil
|
||||
case invitationFailureKeyReused, invitationFailureBadKey, invitationFailureInvalid,
|
||||
invitationFailureVersionConflict, invitationFailureStateConflict, invitationFailureOther:
|
||||
return nil, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// contactDisclosureResponse maps the disclosure field by field. A kind that the
|
||||
// grant does not cover, or that the profile no longer holds, is null.
|
||||
func contactDisclosureResponse(disclosure domain.ContactDisclosure) api.ContactDisclosure {
|
||||
fields := make([]api.ContactFieldKind, 0, len(disclosure.Fields()))
|
||||
for _, field := range disclosure.Fields() {
|
||||
fields = append(fields, api.ContactFieldKind(field))
|
||||
}
|
||||
response := api.ContactDisclosure{
|
||||
InvitationID: disclosure.InvitationID(), GrantID: disclosure.GrantID(),
|
||||
Fields: fields, GrantedAt: api.Timestamp(disclosure.GrantedAt()),
|
||||
}
|
||||
if value, present := disclosure.FullName(); present {
|
||||
response.FullName = api.NewNilContactFullName(api.ContactFullName(value))
|
||||
} else {
|
||||
response.FullName.SetToNull()
|
||||
}
|
||||
if value, present := disclosure.Email(); present {
|
||||
response.Email = api.NewNilEmailAddress(api.EmailAddress(value))
|
||||
} else {
|
||||
response.Email.SetToNull()
|
||||
}
|
||||
if value, present := disclosure.Phone(); present {
|
||||
response.Phone = api.NewNilContactPhoneNumber(api.ContactPhoneNumber(value))
|
||||
} else {
|
||||
response.Phone.SetToNull()
|
||||
}
|
||||
if value, present := disclosure.Telegram(); present {
|
||||
response.Telegram = api.NewNilContactTelegramUsername(api.ContactTelegramUsername(value))
|
||||
} else {
|
||||
response.Telegram.SetToNull()
|
||||
}
|
||||
return response
|
||||
}
|
||||
@@ -31,6 +31,7 @@ type InvitationOperations interface {
|
||||
ViewMine(ctx context.Context, actorID, invitationID uuid.UUID) (domain.CandidateInvitationView, error)
|
||||
DeclineMine(ctx context.Context, command invitationusecase.DeclineCommand) (domain.CandidateInvitationView, error)
|
||||
AcceptMine(ctx context.Context, command invitationusecase.AcceptCommand) (domain.CandidateInvitationView, error)
|
||||
ReadContacts(ctx context.Context, actorID, organizationID, invitationID uuid.UUID) (domain.ContactDisclosure, error)
|
||||
}
|
||||
|
||||
// InvitationHandler serves the organization side of invitation drafts and
|
||||
@@ -590,10 +591,14 @@ func nullableTimestamp(value *time.Time) api.NilTimestamp {
|
||||
return response
|
||||
}
|
||||
|
||||
func invitationContactAccessResponse(access domain.InvitationContactAccess) api.InvitationContactAccess {
|
||||
// No contact grant exists before an acceptance, so no kind of contact is
|
||||
// listed and no contact value is ever part of this response.
|
||||
return api.InvitationContactAccess{Status: api.InvitationContactAccessState(access), Fields: []api.ContactFieldKind{}}
|
||||
func invitationContactAccessResponse(access domain.InvitationContactAccessView) api.InvitationContactAccess {
|
||||
// The usecase lists kinds only while the access is available. The kinds
|
||||
// name the contact read; no contact value is ever part of this response.
|
||||
fields := make([]api.ContactFieldKind, 0, len(access.Fields))
|
||||
for _, field := range access.Fields {
|
||||
fields = append(fields, api.ContactFieldKind(field))
|
||||
}
|
||||
return api.InvitationContactAccess{Status: api.InvitationContactAccessState(access.Status), Fields: fields}
|
||||
}
|
||||
|
||||
func organizationInvitationResponse(view domain.OrganizationInvitationView) api.OrganizationInvitation {
|
||||
|
||||
@@ -83,7 +83,8 @@ func TestInvitationResponseNeverCarriesACandidateIdentifierOrAContact(t *testing
|
||||
}
|
||||
view := domain.OrganizationInvitationView{
|
||||
InvitationSnapshot: draft.Snapshot(), CandidateHandle: "cv1_" + strings.Repeat("A", 43),
|
||||
SalaryFit: domain.InvitationSalaryNotAvailable, ContactAccess: domain.InvitationContactAccessNone,
|
||||
SalaryFit: domain.InvitationSalaryNotAvailable,
|
||||
ContactAccess: domain.NewInvitationContactAccessView(domain.InvitationContactAccessNone, nil),
|
||||
}
|
||||
for name, response := range map[string]any{
|
||||
"invitation": organizationInvitationResponse(view),
|
||||
|
||||
Reference in new issue
Block a user