feat(consent): add versioned append-only consent ledger C1-C5

This commit is contained in:
shira committed 2026-10-06 14:52:33 +03:00
1 parent 008254e44a
commit de49f93b0b
64 files changed
+9244 -132

No files matched your search

@@ -5223,6 +5223,237 @@ func (s *Server) handleGetSpecializationCatalogRequest(args [0]string, argsEscap
}
}
// handleListMyConsentsRequest handles ListMyConsents operation.
//
// Requires the session cookie of a candidate or an employer account. The subject comes from the
// session, never from a request parameter, so the response holds only the caller's own consents: no
// request can name another account, and records of other accounts are never listed. Returns a page of
// the consent ledger of the account, newest grant first with the identifier as the tie-breaker, with
// cursor pagination.
//
// The ledger is append-only. Every grant is a record with its purpose, the accepted text version, the
// source, and the grant time; the server also stores the hash of exactly the text the subject saw. A
// newer text version of the same purpose is a new record, and the earlier one becomes `superseded`
// without any change. A revocation stamps every unrevoked record of the purpose, and for c4 of one
// organization, once; a later grant is a new record. Purposes are independent.
//
// Without `state` the page lists the whole history; `state=active` lists the consents that hold now,
// one per purpose for c1, c2, c3, and c5 and one per accepted invitation for c4. A c4 record names the
// organization with the name its consent text showed (a snapshot that a later rename does not change),
// the selected contact fields, and the invitation with its terms version; it never carries a contact
// value. A c2 record proves the consent to the publication text; the published field set and its
// changes are evidence of the publication history (TASK-088).
//
// Granting c1, c2, c3, and c5 in the consent settings and revoking any purpose are planned operations
// of this tag (TASK-063 and TASK-064); c1 is given at registration and c4 only in AcceptMyInvitation.
//
// Access: a missing, unknown, expired, or revoked session answers 401 unauthenticated. A malformed
// `limit`, `cursor`, or `state` answers 400 validation_failed.
//
// GET /api/v1/me/consents
func (s *Server) handleListMyConsentsRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
statusWriter := &codeRecorder{ResponseWriter: w}
w = statusWriter
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("ListMyConsents"),
semconv.HTTPRequestMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/api/v1/me/consents"),
}
// Add attributes from config.
otelAttrs = append(otelAttrs, s.cfg.Attributes...)
// Start a span for this request.
ctx, span := s.cfg.Tracer.Start(r.Context(), ListMyConsentsOperation,
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Add Labeler to context.
labeler := &Labeler{attrs: otelAttrs}
ctx = contextWithLabeler(ctx, labeler)
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
attrSet := labeler.AttributeSet()
attrs := attrSet.ToSlice()
code := statusWriter.status
if code != 0 {
codeAttr := semconv.HTTPResponseStatusCode(code)
attrs = append(attrs, codeAttr)
span.SetAttributes(attrs...)
}
attrOpt := metric.WithAttributes(attrs...)
// Increment request counter.
s.requests.Add(ctx, 1, attrOpt)
// Use floating point division here for higher precision (instead of Millisecond method).
s.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), attrOpt)
}()
var (
recordError = func(stage string, err error) {
span.RecordError(err)
// https://opentelemetry.io/docs/specs/semconv/http/http-spans/#status
// Span Status MUST be left unset if HTTP status code was in the 1xx, 2xx or 3xx ranges,
// unless there was another error (e.g., network error receiving the response body; or 3xx codes with
// max redirects exceeded), in which case status MUST be set to Error.
code := statusWriter.status
if code < 100 || code >= 500 {
span.SetStatus(codes.Error, stage)
}
attrSet := labeler.AttributeSet()
attrs := attrSet.ToSlice()
if code != 0 {
attrs = append(attrs, semconv.HTTPResponseStatusCode(code))
}
s.errors.Add(ctx, 1, metric.WithAttributes(attrs...))
}
err error
opErrContext = ogenerrors.OperationContext{
Name: ListMyConsentsOperation,
ID: "ListMyConsents",
}
)
{
type bitset = [1]uint8
var satisfied bitset
{
sctx, ok, err := s.securitySessionCookie(ctx, ListMyConsentsOperation, r)
if err != nil {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Security: "SessionCookie",
Err: err,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security:SessionCookie", err)
}
return
}
if ok {
satisfied[0] |= 1 << 0
ctx = sctx
}
}
if ok := func() bool {
nextRequirement:
for _, requirement := range []bitset{
{0b00000001},
} {
for i, mask := range requirement {
if satisfied[i]&mask != mask {
continue nextRequirement
}
}
return true
}
return false
}(); !ok {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security", err)
}
return
}
}
params, err := decodeListMyConsentsParams(args, argsEscaped, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
defer recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var rawBody []byte
var response ListMyConsentsRes
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
OperationName: ListMyConsentsOperation,
OperationSummary: "List the consents of the current account with their history.",
OperationID: "ListMyConsents",
Body: nil,
RawBody: rawBody,
Params: middleware.Parameters{
{
Name: "state",
In: "query",
}: params.State,
{
Name: "limit",
In: "query",
}: params.Limit,
{
Name: "cursor",
In: "query",
}: params.Cursor,
},
Raw: r,
}
type (
Request = struct{}
Params = ListMyConsentsParams
Response = ListMyConsentsRes
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackListMyConsentsParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.ListMyConsents(ctx, params)
return response, err
},
)
} else {
response, err = s.h.ListMyConsents(ctx, params)
}
if err != nil {
if errRes, ok := errors.Into[*ProblemStatusCode](err); ok {
if err := encodeErrorResponse(errRes, w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if errors.Is(err, ht.ErrNotImplemented) {
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if err := encodeListMyConsentsResponse(response, w, span); err != nil {
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
}
return
}
}
// handleListMyInvitationsRequest handles ListMyInvitations operation.
//
// Requires the session cookie of a candidate account. The candidate comes from the session, never from
@@ -85,6 +85,10 @@ type GetOrganizationNeedRes interface {
getOrganizationNeedRes()
}
type ListMyConsentsRes interface {
listMyConsentsRes()
}
type ListMyInvitationsRes interface {
listMyInvitationsRes()
}
@@ -7165,6 +7165,119 @@ func (s *ConfirmEmailForbidden) UnmarshalJSON(data []byte) error {
return s.Decode(d)
}
// Encode implements json.Marshaler.
func (s *ConsentOrganization) Encode(e *jx.Encoder) {
e.ObjStart()
s.encodeFields(e)
e.ObjEnd()
}
// encodeFields encodes fields.
func (s *ConsentOrganization) encodeFields(e *jx.Encoder) {
{
e.FieldStart("id")
json.EncodeUUID(e, s.ID)
}
{
e.FieldStart("name")
e.Str(s.Name)
}
}
var jsonFieldsNameOfConsentOrganization = [2]string{
0: "id",
1: "name",
}
// Decode decodes ConsentOrganization from json.
func (s *ConsentOrganization) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode ConsentOrganization to nil")
}
var requiredBitSet [1]uint8
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
switch string(k) {
case "id":
requiredBitSet[0] |= 1 << 0
if err := func() error {
v, err := json.DecodeUUID(d)
s.ID = v
if err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"id\"")
}
case "name":
requiredBitSet[0] |= 1 << 1
if err := func() error {
v, err := d.Str()
s.Name = string(v)
if err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"name\"")
}
default:
return errors.Errorf("unexpected field %q", k)
}
return nil
}); err != nil {
return errors.Wrap(err, "decode ConsentOrganization")
}
// Validate required fields.
var failures []validate.FieldError
for i, mask := range [1]uint8{
0b00000011,
} {
if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
// Mask only required fields and check equality to mask using XOR.
//
// If XOR result is not zero, result is not equal to expected, so some fields are missed.
// Bits of fields which would be set are actually bits of missed fields.
missed := bits.OnesCount8(result)
for bitN := 0; bitN < missed; bitN++ {
bitIdx := bits.TrailingZeros8(result)
fieldIdx := i*8 + bitIdx
var name string
if fieldIdx < len(jsonFieldsNameOfConsentOrganization) {
name = jsonFieldsNameOfConsentOrganization[fieldIdx]
} else {
name = strconv.Itoa(fieldIdx)
}
failures = append(failures, validate.FieldError{
Name: name,
Error: validate.ErrFieldRequired,
})
// Reset bit.
result &^= 1 << bitIdx
}
}
}
if len(failures) > 0 {
return &validate.Error{Fields: failures}
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *ConsentOrganization) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *ConsentOrganization) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes ConsentPurpose as json.
func (s ConsentPurpose) Encode(e *jx.Encoder) {
e.Str(string(s))
@@ -7203,6 +7316,582 @@ func (s *ConsentPurpose) UnmarshalJSON(data []byte) error {
return s.Decode(d)
}
// Encode encodes ConsentPurposeCode as json.
func (s ConsentPurposeCode) Encode(e *jx.Encoder) {
e.Str(string(s))
}
// Decode decodes ConsentPurposeCode from json.
func (s *ConsentPurposeCode) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode ConsentPurposeCode to nil")
}
v, err := d.StrBytes()
if err != nil {
return err
}
// Try to use constant string.
switch ConsentPurposeCode(v) {
case ConsentPurposeCodeC1:
*s = ConsentPurposeCodeC1
case ConsentPurposeCodeC2:
*s = ConsentPurposeCodeC2
case ConsentPurposeCodeC3:
*s = ConsentPurposeCodeC3
case ConsentPurposeCodeC4:
*s = ConsentPurposeCodeC4
case ConsentPurposeCodeC5:
*s = ConsentPurposeCodeC5
default:
*s = ConsentPurposeCode(v)
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s ConsentPurposeCode) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *ConsentPurposeCode) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode implements json.Marshaler.
func (s *ConsentRecord) Encode(e *jx.Encoder) {
e.ObjStart()
s.encodeFields(e)
e.ObjEnd()
}
// encodeFields encodes fields.
func (s *ConsentRecord) encodeFields(e *jx.Encoder) {
{
e.FieldStart("id")
json.EncodeUUID(e, s.ID)
}
{
e.FieldStart("purpose")
s.Purpose.Encode(e)
}
{
e.FieldStart("state")
s.State.Encode(e)
}
{
e.FieldStart("text_version")
s.TextVersion.Encode(e)
}
{
e.FieldStart("source")
s.Source.Encode(e)
}
{
e.FieldStart("granted_at")
s.GrantedAt.Encode(e)
}
{
e.FieldStart("revoked_at")
s.RevokedAt.Encode(e)
}
{
e.FieldStart("revocation_source")
s.RevocationSource.Encode(e)
}
{
e.FieldStart("organization")
s.Organization.Encode(e)
}
{
e.FieldStart("fields")
if s.Fields == nil {
e.Null()
} else {
e.ArrStart()
for _, elem := range s.Fields {
elem.Encode(e)
}
e.ArrEnd()
}
}
{
e.FieldStart("invitation_id")
s.InvitationID.Encode(e)
}
{
e.FieldStart("invitation_terms_version")
s.InvitationTermsVersion.Encode(e)
}
}
var jsonFieldsNameOfConsentRecord = [12]string{
0: "id",
1: "purpose",
2: "state",
3: "text_version",
4: "source",
5: "granted_at",
6: "revoked_at",
7: "revocation_source",
8: "organization",
9: "fields",
10: "invitation_id",
11: "invitation_terms_version",
}
// Decode decodes ConsentRecord from json.
func (s *ConsentRecord) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode ConsentRecord to nil")
}
var requiredBitSet [2]uint8
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
switch string(k) {
case "id":
requiredBitSet[0] |= 1 << 0
if err := func() error {
v, err := json.DecodeUUID(d)
s.ID = v
if err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"id\"")
}
case "purpose":
requiredBitSet[0] |= 1 << 1
if err := func() error {
if err := s.Purpose.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"purpose\"")
}
case "state":
requiredBitSet[0] |= 1 << 2
if err := func() error {
if err := s.State.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"state\"")
}
case "text_version":
requiredBitSet[0] |= 1 << 3
if err := func() error {
if err := s.TextVersion.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"text_version\"")
}
case "source":
requiredBitSet[0] |= 1 << 4
if err := func() error {
if err := s.Source.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"source\"")
}
case "granted_at":
requiredBitSet[0] |= 1 << 5
if err := func() error {
if err := s.GrantedAt.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"granted_at\"")
}
case "revoked_at":
requiredBitSet[0] |= 1 << 6
if err := func() error {
if err := s.RevokedAt.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"revoked_at\"")
}
case "revocation_source":
requiredBitSet[0] |= 1 << 7
if err := func() error {
if err := s.RevocationSource.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"revocation_source\"")
}
case "organization":
requiredBitSet[1] |= 1 << 0
if err := func() error {
if err := s.Organization.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"organization\"")
}
case "fields":
requiredBitSet[1] |= 1 << 1
if err := func() error {
switch tt := d.Next(); tt {
case jx.Null:
if err := d.Skip(); err != nil {
return err
}
default:
s.Fields = make([]ContactFieldKind, 0)
if err := d.Arr(func(d *jx.Decoder) error {
var elem ContactFieldKind
if err := elem.Decode(d); err != nil {
return err
}
s.Fields = append(s.Fields, elem)
return nil
}); err != nil {
return err
}
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"fields\"")
}
case "invitation_id":
requiredBitSet[1] |= 1 << 2
if err := func() error {
if err := s.InvitationID.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"invitation_id\"")
}
case "invitation_terms_version":
requiredBitSet[1] |= 1 << 3
if err := func() error {
if err := s.InvitationTermsVersion.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"invitation_terms_version\"")
}
default:
return errors.Errorf("unexpected field %q", k)
}
return nil
}); err != nil {
return errors.Wrap(err, "decode ConsentRecord")
}
// Validate required fields.
var failures []validate.FieldError
for i, mask := range [2]uint8{
0b11111111,
0b00001111,
} {
if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
// Mask only required fields and check equality to mask using XOR.
//
// If XOR result is not zero, result is not equal to expected, so some fields are missed.
// Bits of fields which would be set are actually bits of missed fields.
missed := bits.OnesCount8(result)
for bitN := 0; bitN < missed; bitN++ {
bitIdx := bits.TrailingZeros8(result)
fieldIdx := i*8 + bitIdx
var name string
if fieldIdx < len(jsonFieldsNameOfConsentRecord) {
name = jsonFieldsNameOfConsentRecord[fieldIdx]
} else {
name = strconv.Itoa(fieldIdx)
}
failures = append(failures, validate.FieldError{
Name: name,
Error: validate.ErrFieldRequired,
})
// Reset bit.
result &^= 1 << bitIdx
}
}
}
if len(failures) > 0 {
return &validate.Error{Fields: failures}
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *ConsentRecord) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *ConsentRecord) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode implements json.Marshaler.
func (s *ConsentRecordList) Encode(e *jx.Encoder) {
e.ObjStart()
s.encodeFields(e)
e.ObjEnd()
}
// encodeFields encodes fields.
func (s *ConsentRecordList) encodeFields(e *jx.Encoder) {
{
e.FieldStart("items")
e.ArrStart()
for _, elem := range s.Items {
elem.Encode(e)
}
e.ArrEnd()
}
{
e.FieldStart("page")
s.Page.Encode(e)
}
}
var jsonFieldsNameOfConsentRecordList = [2]string{
0: "items",
1: "page",
}
// Decode decodes ConsentRecordList from json.
func (s *ConsentRecordList) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode ConsentRecordList to nil")
}
var requiredBitSet [1]uint8
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
switch string(k) {
case "items":
requiredBitSet[0] |= 1 << 0
if err := func() error {
s.Items = make([]ConsentRecord, 0)
if err := d.Arr(func(d *jx.Decoder) error {
var elem ConsentRecord
if err := elem.Decode(d); err != nil {
return err
}
s.Items = append(s.Items, elem)
return nil
}); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"items\"")
}
case "page":
requiredBitSet[0] |= 1 << 1
if err := func() error {
if err := s.Page.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"page\"")
}
default:
return errors.Errorf("unexpected field %q", k)
}
return nil
}); err != nil {
return errors.Wrap(err, "decode ConsentRecordList")
}
// Validate required fields.
var failures []validate.FieldError
for i, mask := range [1]uint8{
0b00000011,
} {
if result := (requiredBitSet[i] & mask) ^ mask; result != 0 {
// Mask only required fields and check equality to mask using XOR.
//
// If XOR result is not zero, result is not equal to expected, so some fields are missed.
// Bits of fields which would be set are actually bits of missed fields.
missed := bits.OnesCount8(result)
for bitN := 0; bitN < missed; bitN++ {
bitIdx := bits.TrailingZeros8(result)
fieldIdx := i*8 + bitIdx
var name string
if fieldIdx < len(jsonFieldsNameOfConsentRecordList) {
name = jsonFieldsNameOfConsentRecordList[fieldIdx]
} else {
name = strconv.Itoa(fieldIdx)
}
failures = append(failures, validate.FieldError{
Name: name,
Error: validate.ErrFieldRequired,
})
// Reset bit.
result &^= 1 << bitIdx
}
}
}
if len(failures) > 0 {
return &validate.Error{Fields: failures}
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *ConsentRecordList) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *ConsentRecordList) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes ConsentRevocationSource as json.
func (s ConsentRevocationSource) Encode(e *jx.Encoder) {
e.Str(string(s))
}
// Decode decodes ConsentRevocationSource from json.
func (s *ConsentRevocationSource) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode ConsentRevocationSource to nil")
}
v, err := d.StrBytes()
if err != nil {
return err
}
// Try to use constant string.
switch ConsentRevocationSource(v) {
case ConsentRevocationSourceConsentSettings:
*s = ConsentRevocationSourceConsentSettings
case ConsentRevocationSourceSupportRequest:
*s = ConsentRevocationSourceSupportRequest
default:
*s = ConsentRevocationSource(v)
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s ConsentRevocationSource) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *ConsentRevocationSource) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes ConsentSource as json.
func (s ConsentSource) Encode(e *jx.Encoder) {
e.Str(string(s))
}
// Decode decodes ConsentSource from json.
func (s *ConsentSource) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode ConsentSource to nil")
}
v, err := d.StrBytes()
if err != nil {
return err
}
// Try to use constant string.
switch ConsentSource(v) {
case ConsentSourceRegistration:
*s = ConsentSourceRegistration
case ConsentSourceConsentSettings:
*s = ConsentSourceConsentSettings
case ConsentSourceInvitationAcceptance:
*s = ConsentSourceInvitationAcceptance
default:
*s = ConsentSource(v)
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s ConsentSource) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *ConsentSource) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes ConsentState as json.
func (s ConsentState) Encode(e *jx.Encoder) {
e.Str(string(s))
}
// Decode decodes ConsentState from json.
func (s *ConsentState) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode ConsentState to nil")
}
v, err := d.StrBytes()
if err != nil {
return err
}
// Try to use constant string.
switch ConsentState(v) {
case ConsentStateActive:
*s = ConsentStateActive
case ConsentStateSuperseded:
*s = ConsentStateSuperseded
case ConsentStateRevoked:
*s = ConsentStateRevoked
default:
*s = ConsentState(v)
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s ConsentState) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *ConsentState) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode implements json.Marshaler.
func (s *ConsentText) Encode(e *jx.Encoder) {
e.ObjStart()
@@ -15058,6 +15747,82 @@ func (s *ItemContent) UnmarshalJSON(data []byte) error {
return s.Decode(d)
}
// Encode encodes ListMyConsentsBadRequest as json.
func (s *ListMyConsentsBadRequest) Encode(e *jx.Encoder) {
unwrapped := (*Problem)(s)
unwrapped.Encode(e)
}
// Decode decodes ListMyConsentsBadRequest from json.
func (s *ListMyConsentsBadRequest) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode ListMyConsentsBadRequest to nil")
}
var unwrapped Problem
if err := func() error {
if err := unwrapped.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "alias")
}
*s = ListMyConsentsBadRequest(unwrapped)
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *ListMyConsentsBadRequest) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *ListMyConsentsBadRequest) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes ListMyConsentsUnauthorized as json.
func (s *ListMyConsentsUnauthorized) Encode(e *jx.Encoder) {
unwrapped := (*Problem)(s)
unwrapped.Encode(e)
}
// Decode decodes ListMyConsentsUnauthorized from json.
func (s *ListMyConsentsUnauthorized) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode ListMyConsentsUnauthorized to nil")
}
var unwrapped Problem
if err := func() error {
if err := unwrapped.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "alias")
}
*s = ListMyConsentsUnauthorized(unwrapped)
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *ListMyConsentsUnauthorized) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *ListMyConsentsUnauthorized) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes ListMyInvitationsBadRequest as json.
func (s *ListMyInvitationsBadRequest) Encode(e *jx.Encoder) {
unwrapped := (*Problem)(s)
@@ -21368,6 +22133,94 @@ func (s *NilCandidateExperience) UnmarshalJSON(data []byte) error {
return s.Decode(d)
}
// Encode encodes ConsentOrganization as json.
func (o NilConsentOrganization) Encode(e *jx.Encoder) {
if o.Null {
e.Null()
return
}
o.Value.Encode(e)
}
// Decode decodes ConsentOrganization from json.
func (o *NilConsentOrganization) Decode(d *jx.Decoder) error {
if o == nil {
return errors.New("invalid: unable to decode NilConsentOrganization to nil")
}
if d.Next() == jx.Null {
if err := d.Null(); err != nil {
return err
}
var v ConsentOrganization
o.Value = v
o.Null = true
return nil
}
o.Null = false
if err := o.Value.Decode(d); err != nil {
return err
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s NilConsentOrganization) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *NilConsentOrganization) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes ConsentRevocationSource as json.
func (o NilConsentRevocationSource) Encode(e *jx.Encoder) {
if o.Null {
e.Null()
return
}
e.Str(string(o.Value))
}
// Decode decodes ConsentRevocationSource from json.
func (o *NilConsentRevocationSource) Decode(d *jx.Decoder) error {
if o == nil {
return errors.New("invalid: unable to decode NilConsentRevocationSource to nil")
}
if d.Next() == jx.Null {
if err := d.Null(); err != nil {
return err
}
var v ConsentRevocationSource
o.Value = v
o.Null = true
return nil
}
o.Null = false
if err := o.Value.Decode(d); err != nil {
return err
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s NilConsentRevocationSource) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *NilConsentRevocationSource) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes ContactAccessBlock as json.
func (o NilContactAccessBlock) Encode(e *jx.Encoder) {
if o.Null {
@@ -22076,6 +22929,50 @@ func (s *NilInvitationNeedReference) UnmarshalJSON(data []byte) error {
return s.Decode(d)
}
// Encode encodes InvitationTermsVersion as json.
func (o NilInvitationTermsVersion) Encode(e *jx.Encoder) {
if o.Null {
e.Null()
return
}
o.Value.Encode(e)
}
// Decode decodes InvitationTermsVersion from json.
func (o *NilInvitationTermsVersion) Decode(d *jx.Decoder) error {
if o == nil {
return errors.New("invalid: unable to decode NilInvitationTermsVersion to nil")
}
if d.Next() == jx.Null {
if err := d.Null(); err != nil {
return err
}
var v InvitationTermsVersion
o.Value = v
o.Null = true
return nil
}
o.Null = false
if err := o.Value.Decode(d); err != nil {
return err
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s NilInvitationTermsVersion) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *NilInvitationTermsVersion) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes NeedDomainName as json.
func (o NilNeedDomainName) Encode(e *jx.Encoder) {
if o.Null {
@@ -29,6 +29,7 @@ const (
GetOrganizationInvitationContactsOperation OperationName = "GetOrganizationInvitationContacts"
GetOrganizationNeedOperation OperationName = "GetOrganizationNeed"
GetSpecializationCatalogOperation OperationName = "GetSpecializationCatalog"
ListMyConsentsOperation OperationName = "ListMyConsents"
ListMyInvitationsOperation OperationName = "ListMyInvitations"
ListMySupportCasesOperation OperationName = "ListMySupportCases"
ListOrganizationInvitationsOperation OperationName = "ListOrganizationInvitations"
@@ -1819,6 +1819,249 @@ func decodeGetOrganizationNeedParams(args [2]string, argsEscaped bool, r *http.R
return params, nil
}
// ListMyConsentsParams is parameters of ListMyConsents operation.
type ListMyConsentsParams struct {
// Lists only the records in this state; omit it for the whole history.
State OptConsentState `json:",omitempty,omitzero"`
// Maximum number of items in the page. The server may return fewer items even when more remain; use
// `page.has_more` to detect the end.
Limit OptInt32 `json:",omitempty,omitzero"`
// Opaque `page.next_cursor` value from the previous page of the same listing. Omit it to read the
// first page. A malformed or foreign cursor returns 400 with code validation_failed.
Cursor OptString `json:",omitempty,omitzero"`
}
func unpackListMyConsentsParams(packed middleware.Parameters) (params ListMyConsentsParams) {
{
key := middleware.ParameterKey{
Name: "state",
In: "query",
}
if v, ok := packed[key]; ok {
params.State = v.(OptConsentState)
}
}
{
key := middleware.ParameterKey{
Name: "limit",
In: "query",
}
if v, ok := packed[key]; ok {
params.Limit = v.(OptInt32)
}
}
{
key := middleware.ParameterKey{
Name: "cursor",
In: "query",
}
if v, ok := packed[key]; ok {
params.Cursor = v.(OptString)
}
}
return params
}
func decodeListMyConsentsParams(args [0]string, argsEscaped bool, r *http.Request) (params ListMyConsentsParams, _ error) {
q := uri.NewQueryDecoder(r.URL.Query())
// Decode query: state.
if err := func() error {
cfg := uri.QueryParameterDecodingConfig{
Name: "state",
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.HasParam(cfg); err == nil {
if err := q.DecodeParam(cfg, func(d uri.Decoder) error {
var paramsDotStateVal ConsentState
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToString(val)
if err != nil {
return err
}
paramsDotStateVal = ConsentState(c)
return nil
}(); err != nil {
return err
}
params.State.SetTo(paramsDotStateVal)
return nil
}); err != nil {
return err
}
if err := func() error {
if value, ok := params.State.Get(); ok {
if err := func() error {
if err := value.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
return err
}
}
return nil
}(); err != nil {
return err
}
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "state",
In: "query",
Err: err,
}
}
// Set default value for query: limit.
{
val := int32(20)
params.Limit.SetTo(val)
}
// Decode query: limit.
if err := func() error {
cfg := uri.QueryParameterDecodingConfig{
Name: "limit",
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.HasParam(cfg); err == nil {
if err := q.DecodeParam(cfg, func(d uri.Decoder) error {
var paramsDotLimitVal int32
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToInt32(val)
if err != nil {
return err
}
paramsDotLimitVal = c
return nil
}(); err != nil {
return err
}
params.Limit.SetTo(paramsDotLimitVal)
return nil
}); err != nil {
return err
}
if err := func() error {
if value, ok := params.Limit.Get(); ok {
if err := func() error {
if err := (validate.Int{
MinSet: true,
Min: 1,
MaxSet: true,
Max: 100,
MinExclusive: false,
MaxExclusive: false,
MultipleOfSet: false,
MultipleOf: 0,
Pattern: nil,
}).Validate(int64(value)); err != nil {
return errors.Wrap(err, "int")
}
return nil
}(); err != nil {
return err
}
}
return nil
}(); err != nil {
return err
}
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "limit",
In: "query",
Err: err,
}
}
// Decode query: cursor.
if err := func() error {
cfg := uri.QueryParameterDecodingConfig{
Name: "cursor",
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.HasParam(cfg); err == nil {
if err := q.DecodeParam(cfg, func(d uri.Decoder) error {
var paramsDotCursorVal string
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToString(val)
if err != nil {
return err
}
paramsDotCursorVal = c
return nil
}(); err != nil {
return err
}
params.Cursor.SetTo(paramsDotCursorVal)
return nil
}); err != nil {
return err
}
if err := func() error {
if value, ok := params.Cursor.Get(); ok {
if err := func() error {
if err := (validate.String{
MinLength: 1,
MinLengthSet: true,
MaxLength: 512,
MaxLengthSet: true,
Email: false,
Hostname: false,
Regex: regexMap["^[A-Za-z0-9_-]+$"],
MinNumeric: 0,
MinNumericSet: false,
MaxNumeric: 0,
MaxNumericSet: false,
}).Validate(string(value)); err != nil {
return errors.Wrap(err, "string")
}
return nil
}(); err != nil {
return err
}
}
return nil
}(); err != nil {
return err
}
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "cursor",
In: "query",
Err: err,
}
}
return params, nil
}
// ListMyInvitationsParams is parameters of ListMyInvitations operation.
type ListMyInvitationsParams struct {
// Maximum number of items in the page. The server may return fewer items even when more remain; use
@@ -2031,6 +2031,65 @@ func encodeGetSpecializationCatalogResponse(response *SpecializationCatalog, w h
return nil
}
func encodeListMyConsentsResponse(response ListMyConsentsRes, w http.ResponseWriter, span trace.Span) error {
switch response := response.(type) {
case *ConsentRecordListHeaders:
w.Header().Set("Content-Type", "application/json; charset=utf-8")
// Encoding response headers.
{
h := uri.NewHeaderEncoder(w.Header())
// Encode "Cache-Control" header.
{
cfg := uri.HeaderParameterEncodingConfig{
Name: "Cache-Control",
Explode: false,
}
if err := h.EncodeParam(cfg, func(e uri.Encoder) error {
return e.EncodeValue(conv.StringToString(string(response.CacheControl)))
}); err != nil {
return errors.Wrap(err, "encode Cache-Control header")
}
}
}
w.WriteHeader(200)
e := new(jx.Encoder)
response.Response.Encode(e)
if _, err := e.WriteTo(w); err != nil {
return errors.Wrap(err, "write")
}
return nil
case *ListMyConsentsBadRequest:
w.Header().Set("Content-Type", "application/problem+json")
w.WriteHeader(400)
e := new(jx.Encoder)
response.Encode(e)
if _, err := e.WriteTo(w); err != nil {
return errors.Wrap(err, "write")
}
return nil
case *ListMyConsentsUnauthorized:
w.Header().Set("Content-Type", "application/problem+json")
w.WriteHeader(401)
e := new(jx.Encoder)
response.Encode(e)
if _, err := e.WriteTo(w); err != nil {
return errors.Wrap(err, "write")
}
return nil
default:
return errors.Errorf("unexpected response type: %T", response)
}
}
func encodeListMyInvitationsResponse(response ListMyInvitationsRes, w http.ResponseWriter, span trace.Span) error {
switch response := response.(type) {
case *CandidateInvitationListHeaders:
@@ -11,16 +11,16 @@ import (
)
var (
rn45AllowedHeaders = map[string]string{
rn46AllowedHeaders = map[string]string{
"POST": "Content-Type",
}
rn7AllowedHeaders = map[string]string{
"POST": "Content-Type",
}
rn43AllowedHeaders = map[string]string{
rn44AllowedHeaders = map[string]string{
"POST": "Content-Type,Idempotency-Key",
}
rn40AllowedHeaders = map[string]string{
rn41AllowedHeaders = map[string]string{
"POST": "Content-Type",
}
rn24AllowedHeaders = map[string]string{
@@ -29,7 +29,7 @@ var (
rn9AllowedHeaders = map[string]string{
"POST": "Content-Type,Idempotency-Key,X-Csrf-Token",
}
rn48AllowedHeaders = map[string]string{
rn49AllowedHeaders = map[string]string{
"POST": "Content-Type,Idempotency-Key,X-Csrf-Token",
}
rn19AllowedHeaders = map[string]string{
@@ -44,7 +44,7 @@ var (
rn16AllowedHeaders = map[string]string{
"POST": "Content-Type,Idempotency-Key,X-Csrf-Token",
}
rn49AllowedHeaders = map[string]string{
rn50AllowedHeaders = map[string]string{
"POST": "X-Csrf-Token",
}
rn30AllowedHeaders = map[string]string{
@@ -59,13 +59,13 @@ var (
rn34AllowedHeaders = map[string]string{
"PATCH": "Content-Type,X-Csrf-Token",
}
rn42AllowedHeaders = map[string]string{
rn43AllowedHeaders = map[string]string{
"POST": "Content-Type,Idempotency-Key,X-Csrf-Token",
}
rn47AllowedHeaders = map[string]string{
rn48AllowedHeaders = map[string]string{
"POST": "Content-Type,Idempotency-Key,X-Csrf-Token",
}
rn50AllowedHeaders = map[string]string{
rn51AllowedHeaders = map[string]string{
"POST": "Content-Type,Idempotency-Key,X-Csrf-Token",
}
rn15AllowedHeaders = map[string]string{
@@ -228,7 +228,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
default:
s.notAllowed(w, r, notAllowedParams{
allowedMethods: "POST",
allowedHeaders: rn45AllowedHeaders,
allowedHeaders: rn46AllowedHeaders,
acceptPost: "application/json",
acceptPatch: "",
})
@@ -305,7 +305,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
default:
s.notAllowed(w, r, notAllowedParams{
allowedMethods: "POST",
allowedHeaders: rn43AllowedHeaders,
allowedHeaders: rn44AllowedHeaders,
acceptPost: "application/json",
acceptPatch: "",
})
@@ -329,7 +329,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
default:
s.notAllowed(w, r, notAllowedParams{
allowedMethods: "POST",
allowedHeaders: rn40AllowedHeaders,
allowedHeaders: rn41AllowedHeaders,
acceptPost: "application/json",
acceptPatch: "",
})
@@ -482,7 +482,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
default:
s.notAllowed(w, r, notAllowedParams{
allowedMethods: "POST",
allowedHeaders: rn48AllowedHeaders,
allowedHeaders: rn49AllowedHeaders,
acceptPost: "application/json",
acceptPatch: "",
})
@@ -578,6 +578,31 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
case 'c': // Prefix: "consents"
if l := len("consents"); len(elem) >= l && elem[0:l] == "consents" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
// Leaf node.
switch r.Method {
case "GET":
s.handleListMyConsentsRequest([0]string{}, elemIsEscaped, w, r)
default:
s.notAllowed(w, r, notAllowedParams{
allowedMethods: "GET",
allowedHeaders: nil,
acceptPost: "",
acceptPatch: "",
})
}
return
}
case 'i': // Prefix: "invitations"
if l := len("invitations"); len(elem) >= l && elem[0:l] == "invitations" {
@@ -748,7 +773,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
default:
s.notAllowed(w, r, notAllowedParams{
allowedMethods: "POST",
allowedHeaders: rn49AllowedHeaders,
allowedHeaders: rn50AllowedHeaders,
acceptPost: "",
acceptPatch: "",
})
@@ -1031,7 +1056,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
default:
s.notAllowed(w, r, notAllowedParams{
allowedMethods: "POST",
allowedHeaders: rn42AllowedHeaders,
allowedHeaders: rn43AllowedHeaders,
acceptPost: "application/json",
acceptPatch: "",
})
@@ -1059,7 +1084,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
default:
s.notAllowed(w, r, notAllowedParams{
allowedMethods: "POST",
allowedHeaders: rn47AllowedHeaders,
allowedHeaders: rn48AllowedHeaders,
acceptPost: "application/json",
acceptPatch: "",
})
@@ -1089,7 +1114,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
default:
s.notAllowed(w, r, notAllowedParams{
allowedMethods: "POST",
allowedHeaders: rn50AllowedHeaders,
allowedHeaders: rn51AllowedHeaders,
acceptPost: "application/json",
acceptPatch: "",
})
@@ -1755,6 +1780,31 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
}
case 'c': // Prefix: "consents"
if l := len("consents"); len(elem) >= l && elem[0:l] == "consents" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
// Leaf node.
switch method {
case "GET":
r.name = ListMyConsentsOperation
r.summary = "List the consents of the current account with their history."
r.operationID = "ListMyConsents"
r.operationGroup = ""
r.pathPattern = "/api/v1/me/consents"
r.args = args
r.count = 0
return r, true
default:
return
}
}
case 'i': // Prefix: "invitations"
if l := len("invitations"); len(elem) >= l && elem[0:l] == "invitations" {
@@ -3353,6 +3353,39 @@ type ConfirmEmailForbidden Problem
func (*ConfirmEmailForbidden) confirmEmailRes() {}
// Organization of a c4 consent as the consent recorded it. `name` is a snapshot of the name that the
// shown consent text carried at the time of the consent, and the stored text hash proves that text
// with this name; a later rename of the organization does not change it, so it can differ from the
// current name.
// Ref: #/components/schemas/ConsentOrganization
type ConsentOrganization struct {
// Identifier of the organization.
ID uuid.UUID `json:"id"`
// Name of the organization in the consent text at the time of the consent. Plain text; clients show it
// as text, never as HTML.
Name string `json:"name"`
}
// GetID returns the value of ID.
func (s *ConsentOrganization) GetID() uuid.UUID {
return s.ID
}
// GetName returns the value of Name.
func (s *ConsentOrganization) GetName() string {
return s.Name
}
// SetID sets the value of ID.
func (s *ConsentOrganization) SetID(val uuid.UUID) {
s.ID = val
}
// SetName sets the value of Name.
func (s *ConsentOrganization) SetName(val string) {
s.Name = val
}
// Consent whose text the client may read before an account exists. Only the consents given at
// registration are listed: `c1` is the consent to the processing of personal data.
// Ref: #/components/schemas/ConsentPurpose
@@ -3390,6 +3423,452 @@ func (s *ConsentPurpose) UnmarshalText(data []byte) error {
}
}
// One of the independent consents of PRD FR01. A grant or a revocation of one purpose never changes
// another.
//
// - c1: processing of personal data, given at registration.
// - c2: publication of the candidate card. The record proves the consent to the published text; which
// fields were published and when is evidence of the publication history (TASK-088), not of this
// record. Adding a field scope to c2 records later is an additive change.
// - c3: automatic categorization. Without it the candidate can request a manual assessment by the
// same rubric.
// - c4: transfer of the selected contact data to one organization, currently given only in an
// invitation acceptance.
// - c5: import of FSP results.
//
// ConsentPurpose lists the subset whose text the client may read before an account exists.
// Ref: #/components/schemas/ConsentPurposeCode
type ConsentPurposeCode string
const (
ConsentPurposeCodeC1 ConsentPurposeCode = "c1"
ConsentPurposeCodeC2 ConsentPurposeCode = "c2"
ConsentPurposeCodeC3 ConsentPurposeCode = "c3"
ConsentPurposeCodeC4 ConsentPurposeCode = "c4"
ConsentPurposeCodeC5 ConsentPurposeCode = "c5"
)
// AllValues returns all ConsentPurposeCode values.
func (ConsentPurposeCode) AllValues() []ConsentPurposeCode {
return []ConsentPurposeCode{
ConsentPurposeCodeC1,
ConsentPurposeCodeC2,
ConsentPurposeCodeC3,
ConsentPurposeCodeC4,
ConsentPurposeCodeC5,
}
}
// MarshalText implements encoding.TextMarshaler.
func (s ConsentPurposeCode) MarshalText() ([]byte, error) {
switch s {
case ConsentPurposeCodeC1:
return []byte(s), nil
case ConsentPurposeCodeC2:
return []byte(s), nil
case ConsentPurposeCodeC3:
return []byte(s), nil
case ConsentPurposeCodeC4:
return []byte(s), nil
case ConsentPurposeCodeC5:
return []byte(s), nil
default:
return nil, errors.Errorf("invalid value: %q", s)
}
}
// UnmarshalText implements encoding.TextUnmarshaler.
func (s *ConsentPurposeCode) UnmarshalText(data []byte) error {
switch ConsentPurposeCode(data) {
case ConsentPurposeCodeC1:
*s = ConsentPurposeCodeC1
return nil
case ConsentPurposeCodeC2:
*s = ConsentPurposeCodeC2
return nil
case ConsentPurposeCodeC3:
*s = ConsentPurposeCodeC3
return nil
case ConsentPurposeCodeC4:
*s = ConsentPurposeCodeC4
return nil
case ConsentPurposeCodeC5:
*s = ConsentPurposeCodeC5
return nil
default:
return errors.Errorf("invalid value: %q", data)
}
}
// One record of the consent ledger as its subject reads it: the purpose, the text version the subject
// accepted, where and when the consent was given, its state, and the revocation. A c4 record also
// names the organization, the contact fields, and the invitation with its terms version; these fields
// are null for every other purpose. The server also stores the SHA-256 hash of exactly the text the
// subject saw, which a client never sends or receives.
// Ref: #/components/schemas/ConsentRecord
type ConsentRecord struct {
// Identifier of the record.
ID uuid.UUID `json:"id"`
Purpose ConsentPurposeCode `json:"purpose"`
State ConsentState `json:"state"`
// Version of the consent text that the subject accepted.
TextVersion ConsentTextVersion `json:"text_version"`
Source ConsentSource `json:"source"`
GrantedAt Timestamp `json:"granted_at"`
// Moment of the revocation, or null unless `state` is `revoked`.
RevokedAt NilTimestamp `json:"revoked_at"`
// Who recorded the revocation, or null unless `state` is `revoked`.
RevocationSource NilConsentRevocationSource `json:"revocation_source"`
// Organization that a c4 consent allows to read the fields, with the name the consent text showed, or
// null for every other purpose.
Organization NilConsentOrganization `json:"organization"`
// Contact fields that a c4 consent covers, or null for every other purpose. One kind never implies
// another.
Fields []ContactFieldKind `json:"fields"`
// Invitation whose acceptance gave a c4 consent, or null for every other purpose.
InvitationID NilUUID `json:"invitation_id"`
// Terms version that the acceptance accepted, or null for every other purpose.
InvitationTermsVersion NilInvitationTermsVersion `json:"invitation_terms_version"`
}
// GetID returns the value of ID.
func (s *ConsentRecord) GetID() uuid.UUID {
return s.ID
}
// GetPurpose returns the value of Purpose.
func (s *ConsentRecord) GetPurpose() ConsentPurposeCode {
return s.Purpose
}
// GetState returns the value of State.
func (s *ConsentRecord) GetState() ConsentState {
return s.State
}
// GetTextVersion returns the value of TextVersion.
func (s *ConsentRecord) GetTextVersion() ConsentTextVersion {
return s.TextVersion
}
// GetSource returns the value of Source.
func (s *ConsentRecord) GetSource() ConsentSource {
return s.Source
}
// GetGrantedAt returns the value of GrantedAt.
func (s *ConsentRecord) GetGrantedAt() Timestamp {
return s.GrantedAt
}
// GetRevokedAt returns the value of RevokedAt.
func (s *ConsentRecord) GetRevokedAt() NilTimestamp {
return s.RevokedAt
}
// GetRevocationSource returns the value of RevocationSource.
func (s *ConsentRecord) GetRevocationSource() NilConsentRevocationSource {
return s.RevocationSource
}
// GetOrganization returns the value of Organization.
func (s *ConsentRecord) GetOrganization() NilConsentOrganization {
return s.Organization
}
// GetFields returns the value of Fields.
func (s *ConsentRecord) GetFields() []ContactFieldKind {
return s.Fields
}
// GetInvitationID returns the value of InvitationID.
func (s *ConsentRecord) GetInvitationID() NilUUID {
return s.InvitationID
}
// GetInvitationTermsVersion returns the value of InvitationTermsVersion.
func (s *ConsentRecord) GetInvitationTermsVersion() NilInvitationTermsVersion {
return s.InvitationTermsVersion
}
// SetID sets the value of ID.
func (s *ConsentRecord) SetID(val uuid.UUID) {
s.ID = val
}
// SetPurpose sets the value of Purpose.
func (s *ConsentRecord) SetPurpose(val ConsentPurposeCode) {
s.Purpose = val
}
// SetState sets the value of State.
func (s *ConsentRecord) SetState(val ConsentState) {
s.State = val
}
// SetTextVersion sets the value of TextVersion.
func (s *ConsentRecord) SetTextVersion(val ConsentTextVersion) {
s.TextVersion = val
}
// SetSource sets the value of Source.
func (s *ConsentRecord) SetSource(val ConsentSource) {
s.Source = val
}
// SetGrantedAt sets the value of GrantedAt.
func (s *ConsentRecord) SetGrantedAt(val Timestamp) {
s.GrantedAt = val
}
// SetRevokedAt sets the value of RevokedAt.
func (s *ConsentRecord) SetRevokedAt(val NilTimestamp) {
s.RevokedAt = val
}
// SetRevocationSource sets the value of RevocationSource.
func (s *ConsentRecord) SetRevocationSource(val NilConsentRevocationSource) {
s.RevocationSource = val
}
// SetOrganization sets the value of Organization.
func (s *ConsentRecord) SetOrganization(val NilConsentOrganization) {
s.Organization = val
}
// SetFields sets the value of Fields.
func (s *ConsentRecord) SetFields(val []ContactFieldKind) {
s.Fields = val
}
// SetInvitationID sets the value of InvitationID.
func (s *ConsentRecord) SetInvitationID(val NilUUID) {
s.InvitationID = val
}
// SetInvitationTermsVersion sets the value of InvitationTermsVersion.
func (s *ConsentRecord) SetInvitationTermsVersion(val NilInvitationTermsVersion) {
s.InvitationTermsVersion = val
}
// One page of the consent ledger of the current account, newest grant first.
// Ref: #/components/schemas/ConsentRecordList
type ConsentRecordList struct {
// Records of the page.
Items []ConsentRecord `json:"items"`
Page PageInfo `json:"page"`
}
// GetItems returns the value of Items.
func (s *ConsentRecordList) GetItems() []ConsentRecord {
return s.Items
}
// GetPage returns the value of Page.
func (s *ConsentRecordList) GetPage() PageInfo {
return s.Page
}
// SetItems sets the value of Items.
func (s *ConsentRecordList) SetItems(val []ConsentRecord) {
s.Items = val
}
// SetPage sets the value of Page.
func (s *ConsentRecordList) SetPage(val PageInfo) {
s.Page = val
}
// ConsentRecordListHeaders wraps ConsentRecordList with response headers.
type ConsentRecordListHeaders struct {
CacheControl CacheControlNoStore
Response ConsentRecordList
}
// GetCacheControl returns the value of CacheControl.
func (s *ConsentRecordListHeaders) GetCacheControl() CacheControlNoStore {
return s.CacheControl
}
// GetResponse returns the value of Response.
func (s *ConsentRecordListHeaders) GetResponse() ConsentRecordList {
return s.Response
}
// SetCacheControl sets the value of CacheControl.
func (s *ConsentRecordListHeaders) SetCacheControl(val CacheControlNoStore) {
s.CacheControl = val
}
// SetResponse sets the value of Response.
func (s *ConsentRecordListHeaders) SetResponse(val ConsentRecordList) {
s.Response = val
}
func (*ConsentRecordListHeaders) listMyConsentsRes() {}
// Who recorded a revocation.
//
// - consent_settings: the subject revoked the consent in the product.
// - support_request: an operator recorded a revocation that the subject requested through support.
//
// Ref: #/components/schemas/ConsentRevocationSource
type ConsentRevocationSource string
const (
ConsentRevocationSourceConsentSettings ConsentRevocationSource = "consent_settings"
ConsentRevocationSourceSupportRequest ConsentRevocationSource = "support_request"
)
// AllValues returns all ConsentRevocationSource values.
func (ConsentRevocationSource) AllValues() []ConsentRevocationSource {
return []ConsentRevocationSource{
ConsentRevocationSourceConsentSettings,
ConsentRevocationSourceSupportRequest,
}
}
// MarshalText implements encoding.TextMarshaler.
func (s ConsentRevocationSource) MarshalText() ([]byte, error) {
switch s {
case ConsentRevocationSourceConsentSettings:
return []byte(s), nil
case ConsentRevocationSourceSupportRequest:
return []byte(s), nil
default:
return nil, errors.Errorf("invalid value: %q", s)
}
}
// UnmarshalText implements encoding.TextUnmarshaler.
func (s *ConsentRevocationSource) UnmarshalText(data []byte) error {
switch ConsentRevocationSource(data) {
case ConsentRevocationSourceConsentSettings:
*s = ConsentRevocationSourceConsentSettings
return nil
case ConsentRevocationSourceSupportRequest:
*s = ConsentRevocationSourceSupportRequest
return nil
default:
return errors.Errorf("invalid value: %q", data)
}
}
// Where the subject gave the consent.
//
// - registration: the c1 acceptance of RegisterAccount.
// - consent_settings: the consent settings of the account, for c1, c2, c3, and c5 (planned, TASK-063
// and TASK-064).
// - invitation_acceptance: the c4 acceptance of AcceptMyInvitation.
//
// A c4 given when sending an application (PRD Q9) is planned as an additional value.
// Ref: #/components/schemas/ConsentSource
type ConsentSource string
const (
ConsentSourceRegistration ConsentSource = "registration"
ConsentSourceConsentSettings ConsentSource = "consent_settings"
ConsentSourceInvitationAcceptance ConsentSource = "invitation_acceptance"
)
// AllValues returns all ConsentSource values.
func (ConsentSource) AllValues() []ConsentSource {
return []ConsentSource{
ConsentSourceRegistration,
ConsentSourceConsentSettings,
ConsentSourceInvitationAcceptance,
}
}
// MarshalText implements encoding.TextMarshaler.
func (s ConsentSource) MarshalText() ([]byte, error) {
switch s {
case ConsentSourceRegistration:
return []byte(s), nil
case ConsentSourceConsentSettings:
return []byte(s), nil
case ConsentSourceInvitationAcceptance:
return []byte(s), nil
default:
return nil, errors.Errorf("invalid value: %q", s)
}
}
// UnmarshalText implements encoding.TextUnmarshaler.
func (s *ConsentSource) UnmarshalText(data []byte) error {
switch ConsentSource(data) {
case ConsentSourceRegistration:
*s = ConsentSourceRegistration
return nil
case ConsentSourceConsentSettings:
*s = ConsentSourceConsentSettings
return nil
case ConsentSourceInvitationAcceptance:
*s = ConsentSourceInvitationAcceptance
return nil
default:
return errors.Errorf("invalid value: %q", data)
}
}
// State of a consent record, computed from the ledger.
//
// - active: the consent holds. For c1, c2, c3, and c5 it is the newest unrevoked record of its
// purpose; every unrevoked c4 record is active, one per accepted invitation.
// - superseded: the subject later accepted another text version of the same purpose and has not
// revoked either. The record stays as evidence for its own time; it never applies to c4.
// - revoked: the consent was revoked. The record keeps its grant and its one revocation time; a later
// grant is a new record and never reopens it.
//
// Ref: #/components/schemas/ConsentState
type ConsentState string
const (
ConsentStateActive ConsentState = "active"
ConsentStateSuperseded ConsentState = "superseded"
ConsentStateRevoked ConsentState = "revoked"
)
// AllValues returns all ConsentState values.
func (ConsentState) AllValues() []ConsentState {
return []ConsentState{
ConsentStateActive,
ConsentStateSuperseded,
ConsentStateRevoked,
}
}
// MarshalText implements encoding.TextMarshaler.
func (s ConsentState) MarshalText() ([]byte, error) {
switch s {
case ConsentStateActive:
return []byte(s), nil
case ConsentStateSuperseded:
return []byte(s), nil
case ConsentStateRevoked:
return []byte(s), nil
default:
return nil, errors.Errorf("invalid value: %q", s)
}
}
// UnmarshalText implements encoding.TextUnmarshaler.
func (s *ConsentState) UnmarshalText(data []byte) error {
switch ConsentState(data) {
case ConsentStateActive:
*s = ConsentStateActive
return nil
case ConsentStateSuperseded:
*s = ConsentStateSuperseded
return nil
case ConsentStateRevoked:
*s = ConsentStateRevoked
return nil
default:
return errors.Errorf("invalid value: %q", data)
}
}
// Currently published consent text. The server stores an acceptance with `text_version` and the hash
// of exactly this text.
// Ref: #/components/schemas/ConsentText
@@ -6367,6 +6846,14 @@ func NewPracticeItemContentItemContent(v PracticeItemContent) ItemContent {
return s
}
type ListMyConsentsBadRequest Problem
func (*ListMyConsentsBadRequest) listMyConsentsRes() {}
type ListMyConsentsUnauthorized Problem
func (*ListMyConsentsUnauthorized) listMyConsentsRes() {}
type ListMyInvitationsBadRequest Problem
func (*ListMyInvitationsBadRequest) listMyInvitationsRes() {}
@@ -9105,6 +9592,96 @@ func (o NilCandidateExperience) Or(d CandidateExperience) CandidateExperience {
return d
}
// NewNilConsentOrganization returns new NilConsentOrganization with value set to v.
func NewNilConsentOrganization(v ConsentOrganization) NilConsentOrganization {
return NilConsentOrganization{
Value: v,
}
}
// NilConsentOrganization is nullable ConsentOrganization.
type NilConsentOrganization struct {
Value ConsentOrganization
Null bool
}
// SetTo sets value to v.
func (o *NilConsentOrganization) SetTo(v ConsentOrganization) {
o.Null = false
o.Value = v
}
// IsNull returns true if value is Null.
func (o NilConsentOrganization) IsNull() bool { return o.Null }
// SetToNull sets value to null.
func (o *NilConsentOrganization) SetToNull() {
o.Null = true
var v ConsentOrganization
o.Value = v
}
// Get returns value and boolean that denotes whether value was set.
func (o NilConsentOrganization) Get() (v ConsentOrganization, ok bool) {
if o.Null {
return v, false
}
return o.Value, true
}
// Or returns value if set, or given parameter if does not.
func (o NilConsentOrganization) Or(d ConsentOrganization) ConsentOrganization {
if v, ok := o.Get(); ok {
return v
}
return d
}
// NewNilConsentRevocationSource returns new NilConsentRevocationSource with value set to v.
func NewNilConsentRevocationSource(v ConsentRevocationSource) NilConsentRevocationSource {
return NilConsentRevocationSource{
Value: v,
}
}
// NilConsentRevocationSource is nullable ConsentRevocationSource.
type NilConsentRevocationSource struct {
Value ConsentRevocationSource
Null bool
}
// SetTo sets value to v.
func (o *NilConsentRevocationSource) SetTo(v ConsentRevocationSource) {
o.Null = false
o.Value = v
}
// IsNull returns true if value is Null.
func (o NilConsentRevocationSource) IsNull() bool { return o.Null }
// SetToNull sets value to null.
func (o *NilConsentRevocationSource) SetToNull() {
o.Null = true
var v ConsentRevocationSource
o.Value = v
}
// Get returns value and boolean that denotes whether value was set.
func (o NilConsentRevocationSource) Get() (v ConsentRevocationSource, ok bool) {
if o.Null {
return v, false
}
return o.Value, true
}
// Or returns value if set, or given parameter if does not.
func (o NilConsentRevocationSource) Or(d ConsentRevocationSource) ConsentRevocationSource {
if v, ok := o.Get(); ok {
return v
}
return d
}
// NewNilContactAccessBlock returns new NilContactAccessBlock with value set to v.
func NewNilContactAccessBlock(v ContactAccessBlock) NilContactAccessBlock {
return NilContactAccessBlock{
@@ -9825,6 +10402,51 @@ func (o NilInvitationNeedReference) Or(d InvitationNeedReference) InvitationNeed
return d
}
// NewNilInvitationTermsVersion returns new NilInvitationTermsVersion with value set to v.
func NewNilInvitationTermsVersion(v InvitationTermsVersion) NilInvitationTermsVersion {
return NilInvitationTermsVersion{
Value: v,
}
}
// NilInvitationTermsVersion is nullable InvitationTermsVersion.
type NilInvitationTermsVersion struct {
Value InvitationTermsVersion
Null bool
}
// SetTo sets value to v.
func (o *NilInvitationTermsVersion) SetTo(v InvitationTermsVersion) {
o.Null = false
o.Value = v
}
// IsNull returns true if value is Null.
func (o NilInvitationTermsVersion) IsNull() bool { return o.Null }
// SetToNull sets value to null.
func (o *NilInvitationTermsVersion) SetToNull() {
o.Null = true
var v InvitationTermsVersion
o.Value = v
}
// Get returns value and boolean that denotes whether value was set.
func (o NilInvitationTermsVersion) Get() (v InvitationTermsVersion, ok bool) {
if o.Null {
return v, false
}
return o.Value, true
}
// Or returns value if set, or given parameter if does not.
func (o NilInvitationTermsVersion) Or(d InvitationTermsVersion) InvitationTermsVersion {
if v, ok := o.Get(); ok {
return v
}
return d
}
// NewNilNeedDomainName returns new NilNeedDomainName with value set to v.
func NewNilNeedDomainName(v NeedDomainName) NilNeedDomainName {
return NilNeedDomainName{
@@ -11114,6 +11736,52 @@ func (s *OnboardingStep) UnmarshalText(data []byte) error {
}
}
// NewOptConsentState returns new OptConsentState with value set to v.
func NewOptConsentState(v ConsentState) OptConsentState {
return OptConsentState{
Value: v,
Set: true,
}
}
// OptConsentState is optional ConsentState.
type OptConsentState struct {
Value ConsentState
Set bool
}
// IsSet returns true if OptConsentState was set.
func (o OptConsentState) IsSet() bool { return o.Set }
// Reset unsets value.
func (o *OptConsentState) Reset() {
var v ConsentState
o.Value = v
o.Set = false
}
// SetTo sets value to v.
func (o *OptConsentState) SetTo(v ConsentState) {
o.Set = true
o.Value = v
}
// Get returns value and boolean that denotes whether value was set.
func (o OptConsentState) Get() (v ConsentState, ok bool) {
if !o.Set {
return v, false
}
return o.Value, true
}
// Or returns value if set, or given parameter if does not.
func (o OptConsentState) Or(d ConsentState) ConsentState {
if v, ok := o.Get(); ok {
return v
}
return d
}
// NewOptInt32 returns new OptInt32 with value set to v.
func NewOptInt32(v int32) OptInt32 {
return OptInt32{
@@ -75,6 +75,7 @@ var operationRolesSessionCookie = map[string][]string{
GetOrganizationInvitationOperation: []string{},
GetOrganizationInvitationContactsOperation: []string{},
GetOrganizationNeedOperation: []string{},
ListMyConsentsOperation: []string{},
ListMyInvitationsOperation: []string{},
ListMySupportCasesOperation: []string{},
ListOrganizationInvitationsOperation: []string{},
@@ -718,6 +718,35 @@ type Handler interface {
//
// GET /api/v1/specializations
GetSpecializationCatalog(ctx context.Context) (*SpecializationCatalog, error)
// ListMyConsents implements ListMyConsents operation.
//
// Requires the session cookie of a candidate or an employer account. The subject comes from the
// session, never from a request parameter, so the response holds only the caller's own consents: no
// request can name another account, and records of other accounts are never listed. Returns a page of
// the consent ledger of the account, newest grant first with the identifier as the tie-breaker, with
// cursor pagination.
//
// The ledger is append-only. Every grant is a record with its purpose, the accepted text version, the
// source, and the grant time; the server also stores the hash of exactly the text the subject saw. A
// newer text version of the same purpose is a new record, and the earlier one becomes `superseded`
// without any change. A revocation stamps every unrevoked record of the purpose, and for c4 of one
// organization, once; a later grant is a new record. Purposes are independent.
//
// Without `state` the page lists the whole history; `state=active` lists the consents that hold now,
// one per purpose for c1, c2, c3, and c5 and one per accepted invitation for c4. A c4 record names the
// organization with the name its consent text showed (a snapshot that a later rename does not change),
// the selected contact fields, and the invitation with its terms version; it never carries a contact
// value. A c2 record proves the consent to the publication text; the published field set and its
// changes are evidence of the publication history (TASK-088).
//
// Granting c1, c2, c3, and c5 in the consent settings and revoking any purpose are planned operations
// of this tag (TASK-063 and TASK-064); c1 is given at registration and c4 only in AcceptMyInvitation.
//
// Access: a missing, unknown, expired, or revoked session answers 401 unauthenticated. A malformed
// `limit`, `cursor`, or `state` answers 400 validation_failed.
//
// GET /api/v1/me/consents
ListMyConsents(ctx context.Context, params ListMyConsentsParams) (ListMyConsentsRes, error)
// ListMyInvitations implements ListMyInvitations operation.
//
// Requires the session cookie of a candidate account. The candidate comes from the session, never from
@@ -792,6 +792,38 @@ func (UnimplementedHandler) GetSpecializationCatalog(ctx context.Context) (r *Sp
return r, ht.ErrNotImplemented
}
// ListMyConsents implements ListMyConsents operation.
//
// Requires the session cookie of a candidate or an employer account. The subject comes from the
// session, never from a request parameter, so the response holds only the caller's own consents: no
// request can name another account, and records of other accounts are never listed. Returns a page of
// the consent ledger of the account, newest grant first with the identifier as the tie-breaker, with
// cursor pagination.
//
// The ledger is append-only. Every grant is a record with its purpose, the accepted text version, the
// source, and the grant time; the server also stores the hash of exactly the text the subject saw. A
// newer text version of the same purpose is a new record, and the earlier one becomes `superseded`
// without any change. A revocation stamps every unrevoked record of the purpose, and for c4 of one
// organization, once; a later grant is a new record. Purposes are independent.
//
// Without `state` the page lists the whole history; `state=active` lists the consents that hold now,
// one per purpose for c1, c2, c3, and c5 and one per accepted invitation for c4. A c4 record names the
// organization with the name its consent text showed (a snapshot that a later rename does not change),
// the selected contact fields, and the invitation with its terms version; it never carries a contact
// value. A c2 record proves the consent to the publication text; the published field set and its
// changes are evidence of the publication history (TASK-088).
//
// Granting c1, c2, c3, and c5 in the consent settings and revoking any purpose are planned operations
// of this tag (TASK-063 and TASK-064); c1 is given at registration and c4 only in AcceptMyInvitation.
//
// Access: a missing, unknown, expired, or revoked session answers 401 unauthenticated. A malformed
// `limit`, `cursor`, or `state` answers 400 validation_failed.
//
// GET /api/v1/me/consents
func (UnimplementedHandler) ListMyConsents(ctx context.Context, params ListMyConsentsParams) (r ListMyConsentsRes, _ error) {
return r, ht.ErrNotImplemented
}
// ListMyInvitations implements ListMyInvitations operation.
//
// Requires the session cookie of a candidate account. The candidate comes from the session, never from
@@ -3405,6 +3405,41 @@ func (s *ConfirmEmailForbidden) Validate() error {
return nil
}
func (s *ConsentOrganization) Validate() error {
if s == nil {
return validate.ErrNilPointer
}
var failures []validate.FieldError
if err := func() error {
if err := (validate.String{
MinLength: 1,
MinLengthSet: true,
MaxLength: 200,
MaxLengthSet: true,
Email: false,
Hostname: false,
Regex: nil,
MinNumeric: 0,
MinNumericSet: false,
MaxNumeric: 0,
MaxNumericSet: false,
}).Validate(string(s.Name)); err != nil {
return errors.Wrap(err, "string")
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: "name",
Error: err,
})
}
if len(failures) > 0 {
return &validate.Error{Fields: failures}
}
return nil
}
func (s ConsentPurpose) Validate() error {
switch s {
case "c1":
@@ -3414,6 +3449,302 @@ func (s ConsentPurpose) Validate() error {
}
}
func (s ConsentPurposeCode) Validate() error {
switch s {
case "c1":
return nil
case "c2":
return nil
case "c3":
return nil
case "c4":
return nil
case "c5":
return nil
default:
return errors.Errorf("invalid value: %v", s)
}
}
func (s *ConsentRecord) Validate() error {
if s == nil {
return validate.ErrNilPointer
}
var failures []validate.FieldError
if err := func() error {
if err := s.Purpose.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: "purpose",
Error: err,
})
}
if err := func() error {
if err := s.State.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: "state",
Error: err,
})
}
if err := func() error {
if err := s.TextVersion.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: "text_version",
Error: err,
})
}
if err := func() error {
if err := s.Source.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: "source",
Error: err,
})
}
if err := func() error {
if value, ok := s.RevocationSource.Get(); ok {
if err := func() error {
if err := value.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
return err
}
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: "revocation_source",
Error: err,
})
}
if err := func() error {
if value, ok := s.Organization.Get(); ok {
if err := func() error {
if err := value.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
return err
}
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: "organization",
Error: err,
})
}
if err := func() error {
if s.Fields == nil {
return nil // null
}
if err := (validate.Array{
MinLength: 1,
MinLengthSet: true,
MaxLength: 4,
MaxLengthSet: true,
}).ValidateLength(len(s.Fields)); err != nil {
return errors.Wrap(err, "array")
}
if err := validate.UniqueItems(s.Fields); err != nil {
return errors.Wrap(err, "array")
}
var failures []validate.FieldError
for i, elem := range s.Fields {
if err := func() error {
if err := elem.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: fmt.Sprintf("[%d]", i),
Error: err,
})
}
}
if len(failures) > 0 {
return &validate.Error{Fields: failures}
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: "fields",
Error: err,
})
}
if err := func() error {
if value, ok := s.InvitationTermsVersion.Get(); ok {
if err := func() error {
if err := value.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
return err
}
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: "invitation_terms_version",
Error: err,
})
}
if len(failures) > 0 {
return &validate.Error{Fields: failures}
}
return nil
}
func (s *ConsentRecordList) Validate() error {
if s == nil {
return validate.ErrNilPointer
}
var failures []validate.FieldError
if err := func() error {
if s.Items == nil {
return errors.New("nil is invalid value")
}
if err := (validate.Array{
MinLength: 0,
MinLengthSet: false,
MaxLength: 100,
MaxLengthSet: true,
}).ValidateLength(len(s.Items)); err != nil {
return errors.Wrap(err, "array")
}
var failures []validate.FieldError
for i, elem := range s.Items {
if err := func() error {
if err := elem.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: fmt.Sprintf("[%d]", i),
Error: err,
})
}
}
if len(failures) > 0 {
return &validate.Error{Fields: failures}
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: "items",
Error: err,
})
}
if err := func() error {
if err := s.Page.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: "page",
Error: err,
})
}
if len(failures) > 0 {
return &validate.Error{Fields: failures}
}
return nil
}
func (s *ConsentRecordListHeaders) Validate() error {
if s == nil {
return validate.ErrNilPointer
}
var failures []validate.FieldError
if err := func() error {
if err := s.CacheControl.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: "CacheControl",
Error: err,
})
}
if err := func() error {
if err := s.Response.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: "Response",
Error: err,
})
}
if len(failures) > 0 {
return &validate.Error{Fields: failures}
}
return nil
}
func (s ConsentRevocationSource) Validate() error {
switch s {
case "consent_settings":
return nil
case "support_request":
return nil
default:
return errors.Errorf("invalid value: %v", s)
}
}
func (s ConsentSource) Validate() error {
switch s {
case "registration":
return nil
case "consent_settings":
return nil
case "invitation_acceptance":
return nil
default:
return errors.Errorf("invalid value: %v", s)
}
}
func (s ConsentState) Validate() error {
switch s {
case "active":
return nil
case "superseded":
return nil
case "revoked":
return nil
default:
return errors.Errorf("invalid value: %v", s)
}
}
func (s *ConsentText) Validate() error {
if s == nil {
return validate.ErrNilPointer
@@ -6139,6 +6470,22 @@ func (s ItemContent) Validate() error {
}
}
func (s *ListMyConsentsBadRequest) Validate() error {
alias := (*Problem)(s)
if err := alias.Validate(); err != nil {
return err
}
return nil
}
func (s *ListMyConsentsUnauthorized) Validate() error {
alias := (*Problem)(s)
if err := alias.Validate(); err != nil {
return err
}
return nil
}
func (s *ListMyInvitationsBadRequest) Validate() error {
alias := (*Problem)(s)
if err := alias.Validate(); err != nil {
@@ -9,6 +9,7 @@ import (
"log/slog"
"net/http"
"net/http/httptest"
"reflect"
"strings"
"testing"
"time"
@@ -1884,6 +1885,94 @@ func TestInvitationDTOsCarryNoContactOrMinimum(t *testing.T) {
}
}
// myConsentsPath is the consent ledger of the session account.
const myConsentsPath = "/api/v1/me/consents"
// The schema alone must accept the read of the own ledger with an optional
// state filter and reject an unknown state and malformed page parameters.
// Security accepts the session here, so the request reaches validation; a
// valid request then answers 501 until the ledger read is implemented.
func TestConsentSchemaValidationPrecedesImplementation(t *testing.T) {
session := map[string]string{"Cookie": testSessionCookie}
for _, test := range []struct {
name string
query string
pointer string
}{
{name: "the whole history", query: ""},
{name: "the active consents", query: "?state=active"},
{name: "the revoked consents of the next page", query: "?state=revoked&limit=50&cursor=b3BhcXVlLWN1cnNvcg"},
{name: "an unknown state", query: "?state=granted", pointer: "/state"},
{name: "a purpose instead of a state", query: "?state=c4", pointer: "/state"},
{name: "a limit over 100", query: "?limit=101", pointer: "/limit"},
{name: "a malformed cursor", query: "?cursor=not%20a%20cursor", pointer: "/cursor"},
} {
t.Run(test.name, func(t *testing.T) {
logger := slog.New(slog.DiscardHandler)
healthHandler := newTestHealthHandler(func(context.Context) error { return nil })
router, err := NewRouter(healthHandler, v1.NewHandler(healthHandler, problem.NewResponder(logger)), &recordingSecurity{}, problem.NewResponder(logger), metrics.New(), logger)
if err != nil {
t.Fatalf("NewRouter() error = %v", err)
}
response := serveIdentityRequest(t, router, identityRequest{method: http.MethodGet, path: myConsentsPath + test.query, headers: session})
if test.pointer == "" {
requireProblem(t, response, http.StatusNotImplemented, api.ProblemCodeNotImplemented)
return
}
body := requireProblem(t, response, http.StatusBadRequest, api.ProblemCodeValidationFailed)
want := api.ProblemFieldError{In: api.ProblemFieldLocationQuery, Pointer: test.pointer, Code: "invalid"}
for _, field := range body.Errors {
if field.In == want.In && field.Pointer == want.Pointer && field.Code == want.Code {
return
}
}
t.Fatalf("errors = %+v, want an entry %+v", body.Errors, want)
})
}
}
// The ledger read requires a session; DenyAllSecurity grants none, with or
// without a cookie, and a request cannot name another subject instead.
func TestConsentAccessBeforeImplementation(t *testing.T) {
for _, test := range []identityRequest{
{method: http.MethodGet, path: myConsentsPath},
{method: http.MethodGet, path: myConsentsPath + "?state=active", headers: map[string]string{"Cookie": testSessionCookie}},
{method: http.MethodGet, path: myConsentsPath + "?subject_id=01928f7a-0000-7000-8000-00000000c0de", headers: map[string]string{"Cookie": testSessionCookie}},
} {
t.Run(test.method+" "+test.path, func(t *testing.T) {
router := newTestRouter(t, func(context.Context) error { return nil })
requireProblem(t, serveIdentityRequest(t, router, test), http.StatusUnauthorized, api.ProblemCodeUnauthenticated)
})
}
}
// The read model never carries the stored text hash, a subject, or a contact
// value, and its parameters cannot select a subject.
func TestConsentDTOsCarryNoHashSubjectOrContact(t *testing.T) {
private := []string{"text_hash", "hash", "body_sha256", "subject_id", "user_id", "account_id", "email", "phone", "telegram", "full_name"}
for _, dto := range []any{api.ConsentRecord{}, api.ConsentRecordList{}, api.ConsentOrganization{}} {
assertNoJSONFields(t, dto, private)
}
params := reflect.TypeFor[api.ListMyConsentsParams]()
names := make([]string, 0, params.NumField())
for i := range params.NumField() {
names = append(names, params.Field(i).Name)
}
if got := strings.Join(names, ","); got != "State,Limit,Cursor" {
t.Fatalf("ListMyConsentsParams fields = %s, want only the state filter and the page", got)
}
// The documented example is a valid response of the generated server.
var page api.ConsentRecordList
if err := page.UnmarshalJSON(supportCaseExample(t, "ConsentRecordListPage")); err != nil {
t.Fatalf("decode the ConsentRecordListPage example: %v", err)
}
if err := page.Validate(); err != nil {
t.Fatalf("validate the ConsentRecordListPage example: %v", err)
}
}
func TestPublicOperationInternalErrorIsLoggedButNotExposed(t *testing.T) {
var logs bytes.Buffer
logger := slog.New(slog.NewJSONHandler(&logs, nil))