feat(accounts): add consent settings and organization management

This commit is contained in:
TakuyaYagam1 committed 2026-10-07 13:00:39 +03:00
1 parent 24638d46d2
commit 391af7a1ef
83 files changed
+10198 -613

No files matched your search

File diff suppressed because it is too large. Load diff
@@ -69,6 +69,10 @@ type GetMyCardPreviewRes interface {
getMyCardPreviewRes()
}
type GetMyConsentTextRes interface {
getMyConsentTextRes()
}
type GetMyInvitationRes interface {
getMyInvitationRes()
}
@@ -105,6 +109,10 @@ type GetOrganizationRes interface {
getOrganizationRes()
}
type GrantMyConsentRes interface {
grantMyConsentRes()
}
type HideOrganizationRes interface {
hideOrganizationRes()
}
@@ -161,10 +169,22 @@ type RegisterAccountRes interface {
registerAccountRes()
}
type RequestMyAccountDeletionRes interface {
requestMyAccountDeletionRes()
}
type ResendEmailVerificationRes interface {
resendEmailVerificationRes()
}
type RevokeMyConsentRes interface {
revokeMyConsentRes()
}
type RevokeMyOrganizationContactConsentRes interface {
revokeMyOrganizationContactConsentRes()
}
type SaveMyProfileRes interface {
saveMyProfileRes()
}
@@ -12492,6 +12492,172 @@ func (s *ConfirmEmailForbidden) UnmarshalJSON(data []byte) error {
return s.Decode(d)
}
// Encode implements json.Marshaler.
func (s *ConsentDeletionRequest) Encode(e *jx.Encoder) {
e.ObjStart()
s.encodeFields(e)
e.ObjEnd()
}
// encodeFields encodes fields.
func (s *ConsentDeletionRequest) encodeFields(e *jx.Encoder) {
{
e.FieldStart("id")
json.EncodeUUID(e, s.ID)
}
{
e.FieldStart("status")
s.Status.Encode(e)
}
{
e.FieldStart("requested_at")
s.RequestedAt.Encode(e)
}
}
var jsonFieldsNameOfConsentDeletionRequest = [3]string{
0: "id",
1: "status",
2: "requested_at",
}
// Decode decodes ConsentDeletionRequest from json.
func (s *ConsentDeletionRequest) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode ConsentDeletionRequest 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 "status":
requiredBitSet[0] |= 1 << 1
if err := func() error {
if err := s.Status.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"status\"")
}
case "requested_at":
requiredBitSet[0] |= 1 << 2
if err := func() error {
if err := s.RequestedAt.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"requested_at\"")
}
default:
return errors.Errorf("unexpected field %q", k)
}
return nil
}); err != nil {
return errors.Wrap(err, "decode ConsentDeletionRequest")
}
// Validate required fields.
var failures []validate.FieldError
for i, mask := range [1]uint8{
0b00000111,
} {
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(jsonFieldsNameOfConsentDeletionRequest) {
name = jsonFieldsNameOfConsentDeletionRequest[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 *ConsentDeletionRequest) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *ConsentDeletionRequest) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes ConsentDeletionRequestStatus as json.
func (s ConsentDeletionRequestStatus) Encode(e *jx.Encoder) {
e.Str(string(s))
}
// Decode decodes ConsentDeletionRequestStatus from json.
func (s *ConsentDeletionRequestStatus) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode ConsentDeletionRequestStatus to nil")
}
v, err := d.StrBytes()
if err != nil {
return err
}
// Try to use constant string.
switch ConsentDeletionRequestStatus(v) {
case ConsentDeletionRequestStatusRequested:
*s = ConsentDeletionRequestStatusRequested
case ConsentDeletionRequestStatusProcessing:
*s = ConsentDeletionRequestStatusProcessing
default:
*s = ConsentDeletionRequestStatus(v)
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s ConsentDeletionRequestStatus) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *ConsentDeletionRequestStatus) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode implements json.Marshaler.
func (s *ConsentOrganization) Encode(e *jx.Encoder) {
e.ObjStart()
@@ -12605,44 +12771,6 @@ func (s *ConsentOrganization) UnmarshalJSON(data []byte) error {
return s.Decode(d)
}
// Encode encodes ConsentPurpose as json.
func (s ConsentPurpose) Encode(e *jx.Encoder) {
e.Str(string(s))
}
// Decode decodes ConsentPurpose from json.
func (s *ConsentPurpose) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode ConsentPurpose to nil")
}
v, err := d.StrBytes()
if err != nil {
return err
}
// Try to use constant string.
switch ConsentPurpose(v) {
case ConsentPurposeC1:
*s = ConsentPurposeC1
default:
*s = ConsentPurpose(v)
}
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s ConsentPurpose) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *ConsentPurpose) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes ConsentPurposeCode as json.
func (s ConsentPurposeCode) Encode(e *jx.Encoder) {
e.Str(string(s))
@@ -13135,6 +13263,147 @@ func (s *ConsentRevocationSource) UnmarshalJSON(data []byte) error {
return s.Decode(d)
}
// Encode implements json.Marshaler.
func (s *ConsentSettingsGrantRequest) Encode(e *jx.Encoder) {
e.ObjStart()
s.encodeFields(e)
e.ObjEnd()
}
// encodeFields encodes fields.
func (s *ConsentSettingsGrantRequest) encodeFields(e *jx.Encoder) {
{
e.FieldStart("text_version")
s.TextVersion.Encode(e)
}
{
e.FieldStart("accepted")
s.Accepted.Encode(e)
}
}
var jsonFieldsNameOfConsentSettingsGrantRequest = [2]string{
0: "text_version",
1: "accepted",
}
// Decode decodes ConsentSettingsGrantRequest from json.
func (s *ConsentSettingsGrantRequest) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode ConsentSettingsGrantRequest to nil")
}
var requiredBitSet [1]uint8
if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error {
switch string(k) {
case "text_version":
requiredBitSet[0] |= 1 << 0
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 "accepted":
requiredBitSet[0] |= 1 << 1
if err := func() error {
if err := s.Accepted.Decode(d); err != nil {
return err
}
return nil
}(); err != nil {
return errors.Wrap(err, "decode field \"accepted\"")
}
default:
return errors.Errorf("unexpected field %q", k)
}
return nil
}); err != nil {
return errors.Wrap(err, "decode ConsentSettingsGrantRequest")
}
// 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(jsonFieldsNameOfConsentSettingsGrantRequest) {
name = jsonFieldsNameOfConsentSettingsGrantRequest[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 *ConsentSettingsGrantRequest) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *ConsentSettingsGrantRequest) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes ConsentSettingsGrantRequestAccepted as json.
func (s ConsentSettingsGrantRequestAccepted) Encode(e *jx.Encoder) {
e.Bool(bool(s))
}
// Decode decodes ConsentSettingsGrantRequestAccepted from json.
func (s *ConsentSettingsGrantRequestAccepted) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode ConsentSettingsGrantRequestAccepted to nil")
}
v, err := d.Bool()
if err != nil {
return err
}
*s = ConsentSettingsGrantRequestAccepted(v)
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s ConsentSettingsGrantRequestAccepted) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *ConsentSettingsGrantRequestAccepted) 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))
@@ -17436,6 +17705,82 @@ func (s *GetMyCardPreviewUnauthorized) UnmarshalJSON(data []byte) error {
return s.Decode(d)
}
// Encode encodes GetMyConsentTextBadRequest as json.
func (s *GetMyConsentTextBadRequest) Encode(e *jx.Encoder) {
unwrapped := (*Problem)(s)
unwrapped.Encode(e)
}
// Decode decodes GetMyConsentTextBadRequest from json.
func (s *GetMyConsentTextBadRequest) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode GetMyConsentTextBadRequest 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 = GetMyConsentTextBadRequest(unwrapped)
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *GetMyConsentTextBadRequest) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *GetMyConsentTextBadRequest) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes GetMyConsentTextUnauthorized as json.
func (s *GetMyConsentTextUnauthorized) Encode(e *jx.Encoder) {
unwrapped := (*Problem)(s)
unwrapped.Encode(e)
}
// Decode decodes GetMyConsentTextUnauthorized from json.
func (s *GetMyConsentTextUnauthorized) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode GetMyConsentTextUnauthorized 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 = GetMyConsentTextUnauthorized(unwrapped)
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *GetMyConsentTextUnauthorized) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *GetMyConsentTextUnauthorized) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes GetMyInvitationBadRequest as json.
func (s *GetMyInvitationBadRequest) Encode(e *jx.Encoder) {
unwrapped := (*Problem)(s)
@@ -18582,6 +18927,120 @@ func (s *GradeCode) UnmarshalJSON(data []byte) error {
return s.Decode(d)
}
// Encode encodes GrantMyConsentBadRequest as json.
func (s *GrantMyConsentBadRequest) Encode(e *jx.Encoder) {
unwrapped := (*Problem)(s)
unwrapped.Encode(e)
}
// Decode decodes GrantMyConsentBadRequest from json.
func (s *GrantMyConsentBadRequest) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode GrantMyConsentBadRequest 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 = GrantMyConsentBadRequest(unwrapped)
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *GrantMyConsentBadRequest) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *GrantMyConsentBadRequest) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes GrantMyConsentForbidden as json.
func (s *GrantMyConsentForbidden) Encode(e *jx.Encoder) {
unwrapped := (*Problem)(s)
unwrapped.Encode(e)
}
// Decode decodes GrantMyConsentForbidden from json.
func (s *GrantMyConsentForbidden) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode GrantMyConsentForbidden 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 = GrantMyConsentForbidden(unwrapped)
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *GrantMyConsentForbidden) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *GrantMyConsentForbidden) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes GrantMyConsentUnauthorized as json.
func (s *GrantMyConsentUnauthorized) Encode(e *jx.Encoder) {
unwrapped := (*Problem)(s)
unwrapped.Encode(e)
}
// Decode decodes GrantMyConsentUnauthorized from json.
func (s *GrantMyConsentUnauthorized) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode GrantMyConsentUnauthorized 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 = GrantMyConsentUnauthorized(unwrapped)
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *GrantMyConsentUnauthorized) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *GrantMyConsentUnauthorized) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode implements json.Marshaler.
func (s *HealthResponse) Encode(e *jx.Encoder) {
e.ObjStart()
@@ -43764,6 +44223,82 @@ func (s *RegistrationRequest) UnmarshalJSON(data []byte) error {
return s.Decode(d)
}
// Encode encodes RequestMyAccountDeletionForbidden as json.
func (s *RequestMyAccountDeletionForbidden) Encode(e *jx.Encoder) {
unwrapped := (*Problem)(s)
unwrapped.Encode(e)
}
// Decode decodes RequestMyAccountDeletionForbidden from json.
func (s *RequestMyAccountDeletionForbidden) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode RequestMyAccountDeletionForbidden 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 = RequestMyAccountDeletionForbidden(unwrapped)
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *RequestMyAccountDeletionForbidden) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *RequestMyAccountDeletionForbidden) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes RequestMyAccountDeletionUnauthorized as json.
func (s *RequestMyAccountDeletionUnauthorized) Encode(e *jx.Encoder) {
unwrapped := (*Problem)(s)
unwrapped.Encode(e)
}
// Decode decodes RequestMyAccountDeletionUnauthorized from json.
func (s *RequestMyAccountDeletionUnauthorized) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode RequestMyAccountDeletionUnauthorized 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 = RequestMyAccountDeletionUnauthorized(unwrapped)
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *RequestMyAccountDeletionUnauthorized) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *RequestMyAccountDeletionUnauthorized) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes ResendEmailVerificationBadRequest as json.
func (s *ResendEmailVerificationBadRequest) Encode(e *jx.Encoder) {
unwrapped := (*Problem)(s)
@@ -43840,6 +44375,158 @@ func (s *ResendEmailVerificationForbidden) UnmarshalJSON(data []byte) error {
return s.Decode(d)
}
// Encode encodes RevokeMyConsentForbidden as json.
func (s *RevokeMyConsentForbidden) Encode(e *jx.Encoder) {
unwrapped := (*Problem)(s)
unwrapped.Encode(e)
}
// Decode decodes RevokeMyConsentForbidden from json.
func (s *RevokeMyConsentForbidden) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode RevokeMyConsentForbidden 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 = RevokeMyConsentForbidden(unwrapped)
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *RevokeMyConsentForbidden) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *RevokeMyConsentForbidden) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes RevokeMyConsentUnauthorized as json.
func (s *RevokeMyConsentUnauthorized) Encode(e *jx.Encoder) {
unwrapped := (*Problem)(s)
unwrapped.Encode(e)
}
// Decode decodes RevokeMyConsentUnauthorized from json.
func (s *RevokeMyConsentUnauthorized) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode RevokeMyConsentUnauthorized 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 = RevokeMyConsentUnauthorized(unwrapped)
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *RevokeMyConsentUnauthorized) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *RevokeMyConsentUnauthorized) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes RevokeMyOrganizationContactConsentForbidden as json.
func (s *RevokeMyOrganizationContactConsentForbidden) Encode(e *jx.Encoder) {
unwrapped := (*Problem)(s)
unwrapped.Encode(e)
}
// Decode decodes RevokeMyOrganizationContactConsentForbidden from json.
func (s *RevokeMyOrganizationContactConsentForbidden) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode RevokeMyOrganizationContactConsentForbidden 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 = RevokeMyOrganizationContactConsentForbidden(unwrapped)
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *RevokeMyOrganizationContactConsentForbidden) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *RevokeMyOrganizationContactConsentForbidden) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes RevokeMyOrganizationContactConsentUnauthorized as json.
func (s *RevokeMyOrganizationContactConsentUnauthorized) Encode(e *jx.Encoder) {
unwrapped := (*Problem)(s)
unwrapped.Encode(e)
}
// Decode decodes RevokeMyOrganizationContactConsentUnauthorized from json.
func (s *RevokeMyOrganizationContactConsentUnauthorized) Decode(d *jx.Decoder) error {
if s == nil {
return errors.New("invalid: unable to decode RevokeMyOrganizationContactConsentUnauthorized 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 = RevokeMyOrganizationContactConsentUnauthorized(unwrapped)
return nil
}
// MarshalJSON implements stdjson.Marshaler.
func (s *RevokeMyOrganizationContactConsentUnauthorized) MarshalJSON() ([]byte, error) {
e := jx.Encoder{}
s.Encode(&e)
return e.Bytes(), nil
}
// UnmarshalJSON implements stdjson.Unmarshaler.
func (s *RevokeMyOrganizationContactConsentUnauthorized) UnmarshalJSON(data []byte) error {
d := jx.DecodeBytes(data)
return s.Decode(d)
}
// Encode encodes RubAmount as json.
func (s RubAmount) Encode(e *jx.Encoder) {
unwrapped := int64(s)
@@ -6,60 +6,65 @@ package api
type OperationName = string
const (
AcceptMyInvitationOperation OperationName = "AcceptMyInvitation"
CancelMyInvitationOperation OperationName = "CancelMyInvitation"
ConfirmEmailOperation OperationName = "ConfirmEmail"
CreateMyAssessmentAttemptOperation OperationName = "CreateMyAssessmentAttempt"
CreateMySupportCaseOperation OperationName = "CreateMySupportCase"
CreateOrganizationOperation OperationName = "CreateOrganization"
CreateOrganizationInvitationOperation OperationName = "CreateOrganizationInvitation"
CreateOrganizationNeedOperation OperationName = "CreateOrganizationNeed"
DeclineMyInvitationOperation OperationName = "DeclineMyInvitation"
FinalizeMyAssessmentAttemptOperation OperationName = "FinalizeMyAssessmentAttempt"
GetConsentTextOperation OperationName = "GetConsentText"
GetCurrentAccountOperation OperationName = "GetCurrentAccount"
GetCurrentSessionOperation OperationName = "GetCurrentSession"
GetHealthzOperation OperationName = "GetHealthz"
GetMyAssessmentAttemptOperation OperationName = "GetMyAssessmentAttempt"
GetMyAssessmentAvailabilityOperation OperationName = "GetMyAssessmentAvailability"
GetMyAssessmentResultOperation OperationName = "GetMyAssessmentResult"
GetMyCardPreviewOperation OperationName = "GetMyCardPreview"
GetMyInvitationOperation OperationName = "GetMyInvitation"
GetMyPrivacySettingsOperation OperationName = "GetMyPrivacySettings"
GetMyProfileOperation OperationName = "GetMyProfile"
GetMyQuestionnaireOperation OperationName = "GetMyQuestionnaire"
GetMySupportCaseOperation OperationName = "GetMySupportCase"
GetOrganizationOperation OperationName = "GetOrganization"
GetOrganizationInvitationOperation OperationName = "GetOrganizationInvitation"
GetOrganizationInvitationContactsOperation OperationName = "GetOrganizationInvitationContacts"
GetOrganizationNeedOperation OperationName = "GetOrganizationNeed"
GetSpecializationCatalogOperation OperationName = "GetSpecializationCatalog"
HideOrganizationOperation OperationName = "HideOrganization"
ListMyCardAccessHistoryOperation OperationName = "ListMyCardAccessHistory"
ListMyConsentsOperation OperationName = "ListMyConsents"
ListMyHiddenOrganizationsOperation OperationName = "ListMyHiddenOrganizations"
ListMyInvitationsOperation OperationName = "ListMyInvitations"
ListMyOrganizationsOperation OperationName = "ListMyOrganizations"
ListMyPrivacyHistoryOperation OperationName = "ListMyPrivacyHistory"
ListMySupportCasesOperation OperationName = "ListMySupportCases"
ListOrganizationInvitationsOperation OperationName = "ListOrganizationInvitations"
ListOrganizationNeedsOperation OperationName = "ListOrganizationNeeds"
LoginOperation OperationName = "Login"
LogoutOperation OperationName = "Logout"
RaiseOrganizationInvitationSalaryOperation OperationName = "RaiseOrganizationInvitationSalary"
RegisterAccountOperation OperationName = "RegisterAccount"
ResendEmailVerificationOperation OperationName = "ResendEmailVerification"
SaveMyProfileOperation OperationName = "SaveMyProfile"
SaveMyQuestionnaireOperation OperationName = "SaveMyQuestionnaire"
SendOrganizationInvitationOperation OperationName = "SendOrganizationInvitation"
SetMyPublicationOperation OperationName = "SetMyPublication"
SetMySearchStatusOperation OperationName = "SetMySearchStatus"
StartMyAssessmentAttemptSessionOperation OperationName = "StartMyAssessmentAttemptSession"
SubmitMyAssessmentAnswerOperation OperationName = "SubmitMyAssessmentAnswer"
UnhideOrganizationOperation OperationName = "UnhideOrganization"
UpdateOrganizationOperation OperationName = "UpdateOrganization"
UpdateOrganizationInvitationOperation OperationName = "UpdateOrganizationInvitation"
UpdateOrganizationNeedOperation OperationName = "UpdateOrganizationNeed"
ViewMyInvitationOperation OperationName = "ViewMyInvitation"
WithdrawOrganizationInvitationOperation OperationName = "WithdrawOrganizationInvitation"
AcceptMyInvitationOperation OperationName = "AcceptMyInvitation"
CancelMyInvitationOperation OperationName = "CancelMyInvitation"
ConfirmEmailOperation OperationName = "ConfirmEmail"
CreateMyAssessmentAttemptOperation OperationName = "CreateMyAssessmentAttempt"
CreateMySupportCaseOperation OperationName = "CreateMySupportCase"
CreateOrganizationOperation OperationName = "CreateOrganization"
CreateOrganizationInvitationOperation OperationName = "CreateOrganizationInvitation"
CreateOrganizationNeedOperation OperationName = "CreateOrganizationNeed"
DeclineMyInvitationOperation OperationName = "DeclineMyInvitation"
FinalizeMyAssessmentAttemptOperation OperationName = "FinalizeMyAssessmentAttempt"
GetConsentTextOperation OperationName = "GetConsentText"
GetCurrentAccountOperation OperationName = "GetCurrentAccount"
GetCurrentSessionOperation OperationName = "GetCurrentSession"
GetHealthzOperation OperationName = "GetHealthz"
GetMyAssessmentAttemptOperation OperationName = "GetMyAssessmentAttempt"
GetMyAssessmentAvailabilityOperation OperationName = "GetMyAssessmentAvailability"
GetMyAssessmentResultOperation OperationName = "GetMyAssessmentResult"
GetMyCardPreviewOperation OperationName = "GetMyCardPreview"
GetMyConsentTextOperation OperationName = "GetMyConsentText"
GetMyInvitationOperation OperationName = "GetMyInvitation"
GetMyPrivacySettingsOperation OperationName = "GetMyPrivacySettings"
GetMyProfileOperation OperationName = "GetMyProfile"
GetMyQuestionnaireOperation OperationName = "GetMyQuestionnaire"
GetMySupportCaseOperation OperationName = "GetMySupportCase"
GetOrganizationOperation OperationName = "GetOrganization"
GetOrganizationInvitationOperation OperationName = "GetOrganizationInvitation"
GetOrganizationInvitationContactsOperation OperationName = "GetOrganizationInvitationContacts"
GetOrganizationNeedOperation OperationName = "GetOrganizationNeed"
GetSpecializationCatalogOperation OperationName = "GetSpecializationCatalog"
GrantMyConsentOperation OperationName = "GrantMyConsent"
HideOrganizationOperation OperationName = "HideOrganization"
ListMyCardAccessHistoryOperation OperationName = "ListMyCardAccessHistory"
ListMyConsentsOperation OperationName = "ListMyConsents"
ListMyHiddenOrganizationsOperation OperationName = "ListMyHiddenOrganizations"
ListMyInvitationsOperation OperationName = "ListMyInvitations"
ListMyOrganizationsOperation OperationName = "ListMyOrganizations"
ListMyPrivacyHistoryOperation OperationName = "ListMyPrivacyHistory"
ListMySupportCasesOperation OperationName = "ListMySupportCases"
ListOrganizationInvitationsOperation OperationName = "ListOrganizationInvitations"
ListOrganizationNeedsOperation OperationName = "ListOrganizationNeeds"
LoginOperation OperationName = "Login"
LogoutOperation OperationName = "Logout"
RaiseOrganizationInvitationSalaryOperation OperationName = "RaiseOrganizationInvitationSalary"
RegisterAccountOperation OperationName = "RegisterAccount"
RequestMyAccountDeletionOperation OperationName = "RequestMyAccountDeletion"
ResendEmailVerificationOperation OperationName = "ResendEmailVerification"
RevokeMyConsentOperation OperationName = "RevokeMyConsent"
RevokeMyOrganizationContactConsentOperation OperationName = "RevokeMyOrganizationContactConsent"
SaveMyProfileOperation OperationName = "SaveMyProfile"
SaveMyQuestionnaireOperation OperationName = "SaveMyQuestionnaire"
SendOrganizationInvitationOperation OperationName = "SendOrganizationInvitation"
SetMyPublicationOperation OperationName = "SetMyPublication"
SetMySearchStatusOperation OperationName = "SetMySearchStatus"
StartMyAssessmentAttemptSessionOperation OperationName = "StartMyAssessmentAttemptSession"
SubmitMyAssessmentAnswerOperation OperationName = "SubmitMyAssessmentAnswer"
UnhideOrganizationOperation OperationName = "UnhideOrganization"
UpdateOrganizationOperation OperationName = "UpdateOrganization"
UpdateOrganizationInvitationOperation OperationName = "UpdateOrganizationInvitation"
UpdateOrganizationNeedOperation OperationName = "UpdateOrganizationNeed"
ViewMyInvitationOperation OperationName = "ViewMyInvitation"
WithdrawOrganizationInvitationOperation OperationName = "WithdrawOrganizationInvitation"
)
@@ -1498,6 +1498,80 @@ func decodeGetMyAssessmentResultParams(args [1]string, argsEscaped bool, r *http
return params, nil
}
// GetMyConsentTextParams is parameters of GetMyConsentText operation.
type GetMyConsentTextParams struct {
// Consent whose current text is requested.
Purpose ConsentSettingsPurpose
}
func unpackGetMyConsentTextParams(packed middleware.Parameters) (params GetMyConsentTextParams) {
{
key := middleware.ParameterKey{
Name: "purpose",
In: "path",
}
params.Purpose = packed[key].(ConsentSettingsPurpose)
}
return params
}
func decodeGetMyConsentTextParams(args [1]string, argsEscaped bool, r *http.Request) (params GetMyConsentTextParams, _ error) {
// Decode path: purpose.
if err := func() error {
param := args[0]
if argsEscaped {
unescaped, err := url.PathUnescape(args[0])
if err != nil {
return errors.Wrap(err, "unescape path")
}
param = unescaped
}
if len(param) > 0 {
d := uri.NewPathDecoder(uri.PathDecoderConfig{
Param: "purpose",
Value: param,
Style: uri.PathStyleSimple,
Explode: false,
})
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToString(val)
if err != nil {
return err
}
params.Purpose = ConsentSettingsPurpose(c)
return nil
}(); err != nil {
return err
}
if err := func() error {
if err := params.Purpose.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
return err
}
} else {
return validate.ErrFieldRequired
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "purpose",
In: "path",
Err: err,
}
}
return params, nil
}
// GetMyInvitationParams is parameters of GetMyInvitation operation.
type GetMyInvitationParams struct {
// Identifier of an invitation addressed to the current candidate. A draft, an invitation addressed to
@@ -2074,6 +2148,80 @@ func decodeGetOrganizationNeedParams(args [2]string, argsEscaped bool, r *http.R
return params, nil
}
// GrantMyConsentParams is parameters of GrantMyConsent operation.
type GrantMyConsentParams struct {
// Independent consent being granted. C4 is not available here.
Purpose ConsentSettingsPurpose
}
func unpackGrantMyConsentParams(packed middleware.Parameters) (params GrantMyConsentParams) {
{
key := middleware.ParameterKey{
Name: "purpose",
In: "path",
}
params.Purpose = packed[key].(ConsentSettingsPurpose)
}
return params
}
func decodeGrantMyConsentParams(args [1]string, argsEscaped bool, r *http.Request) (params GrantMyConsentParams, _ error) {
// Decode path: purpose.
if err := func() error {
param := args[0]
if argsEscaped {
unescaped, err := url.PathUnescape(args[0])
if err != nil {
return errors.Wrap(err, "unescape path")
}
param = unescaped
}
if len(param) > 0 {
d := uri.NewPathDecoder(uri.PathDecoderConfig{
Param: "purpose",
Value: param,
Style: uri.PathStyleSimple,
Explode: false,
})
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToString(val)
if err != nil {
return err
}
params.Purpose = ConsentSettingsPurpose(c)
return nil
}(); err != nil {
return err
}
if err := func() error {
if err := params.Purpose.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
return err
}
} else {
return validate.ErrFieldRequired
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "purpose",
In: "path",
Err: err,
}
}
return params, nil
}
// HideOrganizationParams is parameters of HideOrganization operation.
type HideOrganizationParams struct {
// Identifier of the organization that the current candidate hides or stops hiding the profile from. It
@@ -4209,6 +4357,147 @@ func decodeRegisterAccountParams(args [0]string, argsEscaped bool, r *http.Reque
return params, nil
}
// RevokeMyConsentParams is parameters of RevokeMyConsent operation.
type RevokeMyConsentParams struct {
// Consent being revoked. C1 has a deletion-request operation and C4 requires an organization scope.
Purpose ConsentSettingsRevokePurpose
}
func unpackRevokeMyConsentParams(packed middleware.Parameters) (params RevokeMyConsentParams) {
{
key := middleware.ParameterKey{
Name: "purpose",
In: "path",
}
params.Purpose = packed[key].(ConsentSettingsRevokePurpose)
}
return params
}
func decodeRevokeMyConsentParams(args [1]string, argsEscaped bool, r *http.Request) (params RevokeMyConsentParams, _ error) {
// Decode path: purpose.
if err := func() error {
param := args[0]
if argsEscaped {
unescaped, err := url.PathUnescape(args[0])
if err != nil {
return errors.Wrap(err, "unescape path")
}
param = unescaped
}
if len(param) > 0 {
d := uri.NewPathDecoder(uri.PathDecoderConfig{
Param: "purpose",
Value: param,
Style: uri.PathStyleSimple,
Explode: false,
})
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToString(val)
if err != nil {
return err
}
params.Purpose = ConsentSettingsRevokePurpose(c)
return nil
}(); err != nil {
return err
}
if err := func() error {
if err := params.Purpose.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
return err
}
} else {
return validate.ErrFieldRequired
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "purpose",
In: "path",
Err: err,
}
}
return params, nil
}
// RevokeMyOrganizationContactConsentParams is parameters of RevokeMyOrganizationContactConsent operation.
type RevokeMyOrganizationContactConsentParams struct {
// Organization whose stored C4 grants this account revokes. A well-formed identifier outside the
// account's stored records changes nothing and does not reveal whether that organization exists.
OrgID uuid.UUID
}
func unpackRevokeMyOrganizationContactConsentParams(packed middleware.Parameters) (params RevokeMyOrganizationContactConsentParams) {
{
key := middleware.ParameterKey{
Name: "org_id",
In: "path",
}
params.OrgID = packed[key].(uuid.UUID)
}
return params
}
func decodeRevokeMyOrganizationContactConsentParams(args [1]string, argsEscaped bool, r *http.Request) (params RevokeMyOrganizationContactConsentParams, _ error) {
// Decode path: org_id.
if err := func() error {
param := args[0]
if argsEscaped {
unescaped, err := url.PathUnescape(args[0])
if err != nil {
return errors.Wrap(err, "unescape path")
}
param = unescaped
}
if len(param) > 0 {
d := uri.NewPathDecoder(uri.PathDecoderConfig{
Param: "org_id",
Value: param,
Style: uri.PathStyleSimple,
Explode: false,
})
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToUUID(val)
if err != nil {
return err
}
params.OrgID = c
return nil
}(); err != nil {
return err
}
} else {
return validate.ErrFieldRequired
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "org_id",
In: "path",
Err: err,
}
}
return params, nil
}
// SendOrganizationInvitationParams is parameters of SendOrganizationInvitation operation.
type SendOrganizationInvitationParams struct {
// Identifier of an organization. Access comes only from an active membership of the session account in
@@ -804,6 +804,85 @@ func (s *Server) decodeFinalizeMyAssessmentAttemptRequest(r *http.Request) (
}
}
func (s *Server) decodeGrantMyConsentRequest(r *http.Request) (
req *ConsentSettingsGrantRequest,
rawBody []byte,
close func() error,
rerr error,
) {
var closers []func() error
close = func() error {
var merr error
// Close in reverse order, to match defer behavior.
for i := len(closers) - 1; i >= 0; i-- {
c := closers[i]
merr = errors.Join(merr, c())
}
return merr
}
defer func() {
if rerr != nil {
rerr = errors.Join(rerr, close())
}
}()
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil {
return req, rawBody, close, errors.Wrap(err, "parse media type")
}
switch {
case ct == "application/json":
if r.ContentLength == 0 {
return req, rawBody, close, validate.ErrBodyRequired
}
buf, err := io.ReadAll(r.Body)
defer func() {
_ = r.Body.Close()
}()
if err != nil {
return req, rawBody, close, err
}
// Reset the body to allow for downstream reading.
r.Body = io.NopCloser(bytes.NewBuffer(buf))
if len(buf) == 0 {
return req, rawBody, close, validate.ErrBodyRequired
}
rawBody = append(rawBody, buf...)
d := jx.DecodeBytes(buf)
var request ConsentSettingsGrantRequest
if err := func() error {
if err := request.Decode(d); err != nil {
return err
}
if err := d.Skip(); err != io.EOF {
return errors.New("unexpected trailing data")
}
return nil
}(); err != nil {
err = &ogenerrors.DecodeBodyError{
ContentType: ct,
Body: buf,
Err: err,
}
return req, rawBody, close, err
}
if err := func() error {
if err := request.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
return req, rawBody, close, errors.Wrap(err, "validate")
}
return &request, rawBody, close, nil
default:
return req, rawBody, close, validate.InvalidContentType(ct)
}
}
func (s *Server) decodeLoginRequest(r *http.Request) (
req *LoginRequest,
rawBody []byte,
@@ -1742,6 +1742,65 @@ func encodeGetMyCardPreviewResponse(response GetMyCardPreviewRes, w http.Respons
}
}
func encodeGetMyConsentTextResponse(response GetMyConsentTextRes, w http.ResponseWriter, span trace.Span) error {
switch response := response.(type) {
case *ConsentTextHeaders:
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 *GetMyConsentTextBadRequest:
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 *GetMyConsentTextUnauthorized:
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 encodeGetMyInvitationResponse(response GetMyInvitationRes, w http.ResponseWriter, span trace.Span) error {
switch response := response.(type) {
case *CandidateInvitationHeaders:
@@ -2418,6 +2477,77 @@ func encodeGetSpecializationCatalogResponse(response *SpecializationCatalog, w h
return nil
}
func encodeGrantMyConsentResponse(response GrantMyConsentRes, w http.ResponseWriter, span trace.Span) error {
switch response := response.(type) {
case *ConsentRecordHeaders:
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 *GrantMyConsentBadRequest:
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 *GrantMyConsentUnauthorized:
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
case *GrantMyConsentForbidden:
w.Header().Set("Content-Type", "application/problem+json")
w.WriteHeader(403)
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 encodeHideOrganizationResponse(response HideOrganizationRes, w http.ResponseWriter, span trace.Span) error {
switch response := response.(type) {
case *HiddenOrganizationHeaders:
@@ -3620,6 +3750,65 @@ func encodeRegisterAccountResponse(response RegisterAccountRes, w http.ResponseW
}
}
func encodeRequestMyAccountDeletionResponse(response RequestMyAccountDeletionRes, w http.ResponseWriter, span trace.Span) error {
switch response := response.(type) {
case *ConsentDeletionRequestHeaders:
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(202)
e := new(jx.Encoder)
response.Response.Encode(e)
if _, err := e.WriteTo(w); err != nil {
return errors.Wrap(err, "write")
}
return nil
case *RequestMyAccountDeletionUnauthorized:
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
case *RequestMyAccountDeletionForbidden:
w.Header().Set("Content-Type", "application/problem+json")
w.WriteHeader(403)
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 encodeResendEmailVerificationResponse(response ResendEmailVerificationRes, w http.ResponseWriter, span trace.Span) error {
switch response := response.(type) {
case *IdentityRequestAccepted:
@@ -3695,6 +3884,78 @@ func encodeResendEmailVerificationResponse(response ResendEmailVerificationRes,
}
}
func encodeRevokeMyConsentResponse(response RevokeMyConsentRes, w http.ResponseWriter, span trace.Span) error {
switch response := response.(type) {
case *RevokeMyConsentNoContent:
w.WriteHeader(204)
return nil
case *RevokeMyConsentUnauthorized:
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
case *RevokeMyConsentForbidden:
w.Header().Set("Content-Type", "application/problem+json")
w.WriteHeader(403)
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 encodeRevokeMyOrganizationContactConsentResponse(response RevokeMyOrganizationContactConsentRes, w http.ResponseWriter, span trace.Span) error {
switch response := response.(type) {
case *RevokeMyOrganizationContactConsentNoContent:
w.WriteHeader(204)
return nil
case *RevokeMyOrganizationContactConsentUnauthorized:
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
case *RevokeMyOrganizationContactConsentForbidden:
w.Header().Set("Content-Type", "application/problem+json")
w.WriteHeader(403)
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 encodeSaveMyProfileResponse(response SaveMyProfileRes, w http.ResponseWriter, span trace.Span) error {
switch response := response.(type) {
case *CandidateProfileHeaders:
File diff suppressed because it is too large. Load diff
@@ -6261,6 +6261,117 @@ type ConfirmEmailForbidden Problem
func (*ConfirmEmailForbidden) confirmEmailRes() {}
// Durable request to delete the account and its personal data. The request is recorded before
// asynchronous processing starts; it does not mean deletion has completed.
// Ref: #/components/schemas/ConsentDeletionRequest
type ConsentDeletionRequest struct {
// Identifier of the durable deletion request.
ID uuid.UUID `json:"id"`
// Current state of the deletion request.
Status ConsentDeletionRequestStatus `json:"status"`
RequestedAt Timestamp `json:"requested_at"`
}
// GetID returns the value of ID.
func (s *ConsentDeletionRequest) GetID() uuid.UUID {
return s.ID
}
// GetStatus returns the value of Status.
func (s *ConsentDeletionRequest) GetStatus() ConsentDeletionRequestStatus {
return s.Status
}
// GetRequestedAt returns the value of RequestedAt.
func (s *ConsentDeletionRequest) GetRequestedAt() Timestamp {
return s.RequestedAt
}
// SetID sets the value of ID.
func (s *ConsentDeletionRequest) SetID(val uuid.UUID) {
s.ID = val
}
// SetStatus sets the value of Status.
func (s *ConsentDeletionRequest) SetStatus(val ConsentDeletionRequestStatus) {
s.Status = val
}
// SetRequestedAt sets the value of RequestedAt.
func (s *ConsentDeletionRequest) SetRequestedAt(val Timestamp) {
s.RequestedAt = val
}
// ConsentDeletionRequestHeaders wraps ConsentDeletionRequest with response headers.
type ConsentDeletionRequestHeaders struct {
CacheControl CacheControlNoStore
Response ConsentDeletionRequest
}
// GetCacheControl returns the value of CacheControl.
func (s *ConsentDeletionRequestHeaders) GetCacheControl() CacheControlNoStore {
return s.CacheControl
}
// GetResponse returns the value of Response.
func (s *ConsentDeletionRequestHeaders) GetResponse() ConsentDeletionRequest {
return s.Response
}
// SetCacheControl sets the value of CacheControl.
func (s *ConsentDeletionRequestHeaders) SetCacheControl(val CacheControlNoStore) {
s.CacheControl = val
}
// SetResponse sets the value of Response.
func (s *ConsentDeletionRequestHeaders) SetResponse(val ConsentDeletionRequest) {
s.Response = val
}
func (*ConsentDeletionRequestHeaders) requestMyAccountDeletionRes() {}
// Current state of the deletion request.
type ConsentDeletionRequestStatus string
const (
ConsentDeletionRequestStatusRequested ConsentDeletionRequestStatus = "requested"
ConsentDeletionRequestStatusProcessing ConsentDeletionRequestStatus = "processing"
)
// AllValues returns all ConsentDeletionRequestStatus values.
func (ConsentDeletionRequestStatus) AllValues() []ConsentDeletionRequestStatus {
return []ConsentDeletionRequestStatus{
ConsentDeletionRequestStatusRequested,
ConsentDeletionRequestStatusProcessing,
}
}
// MarshalText implements encoding.TextMarshaler.
func (s ConsentDeletionRequestStatus) MarshalText() ([]byte, error) {
switch s {
case ConsentDeletionRequestStatusRequested:
return []byte(s), nil
case ConsentDeletionRequestStatusProcessing:
return []byte(s), nil
default:
return nil, errors.Errorf("invalid value: %q", s)
}
}
// UnmarshalText implements encoding.TextUnmarshaler.
func (s *ConsentDeletionRequestStatus) UnmarshalText(data []byte) error {
switch ConsentDeletionRequestStatus(data) {
case ConsentDeletionRequestStatusRequested:
*s = ConsentDeletionRequestStatusRequested
return nil
case ConsentDeletionRequestStatusProcessing:
*s = ConsentDeletionRequestStatusProcessing
return nil
default:
return errors.Errorf("invalid value: %q", data)
}
}
// 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
@@ -6559,6 +6670,34 @@ func (s *ConsentRecord) SetInvitationTermsVersion(val NilInvitationTermsVersion)
s.InvitationTermsVersion = val
}
// ConsentRecordHeaders wraps ConsentRecord with response headers.
type ConsentRecordHeaders struct {
CacheControl CacheControlNoStore
Response ConsentRecord
}
// GetCacheControl returns the value of CacheControl.
func (s *ConsentRecordHeaders) GetCacheControl() CacheControlNoStore {
return s.CacheControl
}
// GetResponse returns the value of Response.
func (s *ConsentRecordHeaders) GetResponse() ConsentRecord {
return s.Response
}
// SetCacheControl sets the value of CacheControl.
func (s *ConsentRecordHeaders) SetCacheControl(val CacheControlNoStore) {
s.CacheControl = val
}
// SetResponse sets the value of Response.
func (s *ConsentRecordHeaders) SetResponse(val ConsentRecord) {
s.Response = val
}
func (*ConsentRecordHeaders) grantMyConsentRes() {}
// One page of the consent ledger of the current account, newest grant first.
// Ref: #/components/schemas/ConsentRecordList
type ConsentRecordList struct {
@@ -6662,6 +6801,158 @@ func (s *ConsentRevocationSource) UnmarshalText(data []byte) error {
}
}
// Accept the current published text shown by GetMyConsentText. The server checks its version again
// before recording the grant.
// Ref: #/components/schemas/ConsentSettingsGrantRequest
type ConsentSettingsGrantRequest struct {
TextVersion ConsentTextVersion `json:"text_version"`
// Must be true to record an explicit acceptance.
Accepted ConsentSettingsGrantRequestAccepted `json:"accepted"`
}
// GetTextVersion returns the value of TextVersion.
func (s *ConsentSettingsGrantRequest) GetTextVersion() ConsentTextVersion {
return s.TextVersion
}
// GetAccepted returns the value of Accepted.
func (s *ConsentSettingsGrantRequest) GetAccepted() ConsentSettingsGrantRequestAccepted {
return s.Accepted
}
// SetTextVersion sets the value of TextVersion.
func (s *ConsentSettingsGrantRequest) SetTextVersion(val ConsentTextVersion) {
s.TextVersion = val
}
// SetAccepted sets the value of Accepted.
func (s *ConsentSettingsGrantRequest) SetAccepted(val ConsentSettingsGrantRequestAccepted) {
s.Accepted = val
}
// Must be true to record an explicit acceptance.
type ConsentSettingsGrantRequestAccepted bool
const (
ConsentSettingsGrantRequestAcceptedTrue ConsentSettingsGrantRequestAccepted = true
)
// AllValues returns all ConsentSettingsGrantRequestAccepted values.
func (ConsentSettingsGrantRequestAccepted) AllValues() []ConsentSettingsGrantRequestAccepted {
return []ConsentSettingsGrantRequestAccepted{
ConsentSettingsGrantRequestAcceptedTrue,
}
}
// Consent text that an authenticated account can read and accept in settings. C4 is scoped to an
// invitation and organization, so it is not available through the general settings flow.
// Ref: #/components/schemas/ConsentSettingsPurpose
type ConsentSettingsPurpose string
const (
ConsentSettingsPurposeC1 ConsentSettingsPurpose = "c1"
ConsentSettingsPurposeC2 ConsentSettingsPurpose = "c2"
ConsentSettingsPurposeC3 ConsentSettingsPurpose = "c3"
ConsentSettingsPurposeC5 ConsentSettingsPurpose = "c5"
)
// AllValues returns all ConsentSettingsPurpose values.
func (ConsentSettingsPurpose) AllValues() []ConsentSettingsPurpose {
return []ConsentSettingsPurpose{
ConsentSettingsPurposeC1,
ConsentSettingsPurposeC2,
ConsentSettingsPurposeC3,
ConsentSettingsPurposeC5,
}
}
// MarshalText implements encoding.TextMarshaler.
func (s ConsentSettingsPurpose) MarshalText() ([]byte, error) {
switch s {
case ConsentSettingsPurposeC1:
return []byte(s), nil
case ConsentSettingsPurposeC2:
return []byte(s), nil
case ConsentSettingsPurposeC3:
return []byte(s), nil
case ConsentSettingsPurposeC5:
return []byte(s), nil
default:
return nil, errors.Errorf("invalid value: %q", s)
}
}
// UnmarshalText implements encoding.TextUnmarshaler.
func (s *ConsentSettingsPurpose) UnmarshalText(data []byte) error {
switch ConsentSettingsPurpose(data) {
case ConsentSettingsPurposeC1:
*s = ConsentSettingsPurposeC1
return nil
case ConsentSettingsPurposeC2:
*s = ConsentSettingsPurposeC2
return nil
case ConsentSettingsPurposeC3:
*s = ConsentSettingsPurposeC3
return nil
case ConsentSettingsPurposeC5:
*s = ConsentSettingsPurposeC5
return nil
default:
return errors.Errorf("invalid value: %q", data)
}
}
// Consent that can be revoked through the general settings flow. C1 uses the account deletion request,
// and C4 must be revoked for one organization.
// Ref: #/components/schemas/ConsentSettingsRevokePurpose
type ConsentSettingsRevokePurpose string
const (
ConsentSettingsRevokePurposeC2 ConsentSettingsRevokePurpose = "c2"
ConsentSettingsRevokePurposeC3 ConsentSettingsRevokePurpose = "c3"
ConsentSettingsRevokePurposeC5 ConsentSettingsRevokePurpose = "c5"
)
// AllValues returns all ConsentSettingsRevokePurpose values.
func (ConsentSettingsRevokePurpose) AllValues() []ConsentSettingsRevokePurpose {
return []ConsentSettingsRevokePurpose{
ConsentSettingsRevokePurposeC2,
ConsentSettingsRevokePurposeC3,
ConsentSettingsRevokePurposeC5,
}
}
// MarshalText implements encoding.TextMarshaler.
func (s ConsentSettingsRevokePurpose) MarshalText() ([]byte, error) {
switch s {
case ConsentSettingsRevokePurposeC2:
return []byte(s), nil
case ConsentSettingsRevokePurposeC3:
return []byte(s), nil
case ConsentSettingsRevokePurposeC5:
return []byte(s), nil
default:
return nil, errors.Errorf("invalid value: %q", s)
}
}
// UnmarshalText implements encoding.TextUnmarshaler.
func (s *ConsentSettingsRevokePurpose) UnmarshalText(data []byte) error {
switch ConsentSettingsRevokePurpose(data) {
case ConsentSettingsRevokePurposeC2:
*s = ConsentSettingsRevokePurposeC2
return nil
case ConsentSettingsRevokePurposeC3:
*s = ConsentSettingsRevokePurposeC3
return nil
case ConsentSettingsRevokePurposeC5:
*s = ConsentSettingsRevokePurposeC5
return nil
default:
return errors.Errorf("invalid value: %q", data)
}
}
// Where the subject gave the consent.
//
// - registration: the c1 acceptance of RegisterAccount.
@@ -6780,7 +7071,7 @@ func (s *ConsentState) UnmarshalText(data []byte) error {
// of exactly this text.
// Ref: #/components/schemas/ConsentText
type ConsentText struct {
Purpose ConsentPurpose `json:"purpose"`
Purpose ConsentPurposeCode `json:"purpose"`
TextVersion ConsentTextVersion `json:"text_version"`
// Full consent text in plain UTF-8; paragraphs are separated by an empty line. The client shows it as
// text, never as HTML.
@@ -6789,7 +7080,7 @@ type ConsentText struct {
}
// GetPurpose returns the value of Purpose.
func (s *ConsentText) GetPurpose() ConsentPurpose {
func (s *ConsentText) GetPurpose() ConsentPurposeCode {
return s.Purpose
}
@@ -6809,7 +7100,7 @@ func (s *ConsentText) GetPublishedAt() Timestamp {
}
// SetPurpose sets the value of Purpose.
func (s *ConsentText) SetPurpose(val ConsentPurpose) {
func (s *ConsentText) SetPurpose(val ConsentPurposeCode) {
s.Purpose = val
}
@@ -6830,6 +7121,34 @@ func (s *ConsentText) SetPublishedAt(val Timestamp) {
func (*ConsentText) getConsentTextRes() {}
// ConsentTextHeaders wraps ConsentText with response headers.
type ConsentTextHeaders struct {
CacheControl CacheControlNoStore
Response ConsentText
}
// GetCacheControl returns the value of CacheControl.
func (s *ConsentTextHeaders) GetCacheControl() CacheControlNoStore {
return s.CacheControl
}
// GetResponse returns the value of Response.
func (s *ConsentTextHeaders) GetResponse() ConsentText {
return s.Response
}
// SetCacheControl sets the value of CacheControl.
func (s *ConsentTextHeaders) SetCacheControl(val CacheControlNoStore) {
s.CacheControl = val
}
// SetResponse sets the value of Response.
func (s *ConsentTextHeaders) SetResponse(val ConsentText) {
s.Response = val
}
func (*ConsentTextHeaders) getMyConsentTextRes() {}
type ConsentTextVersion string
// Why an active grant does not allow a read now, shown only to the candidate.
@@ -8046,6 +8365,14 @@ type GetMyCardPreviewUnauthorized Problem
func (*GetMyCardPreviewUnauthorized) getMyCardPreviewRes() {}
type GetMyConsentTextBadRequest Problem
func (*GetMyConsentTextBadRequest) getMyConsentTextRes() {}
type GetMyConsentTextUnauthorized Problem
func (*GetMyConsentTextUnauthorized) getMyConsentTextRes() {}
type GetMyInvitationBadRequest Problem
func (*GetMyInvitationBadRequest) getMyInvitationRes() {}
@@ -8222,6 +8549,18 @@ func (s *GradeCode) UnmarshalText(data []byte) error {
}
}
type GrantMyConsentBadRequest Problem
func (*GrantMyConsentBadRequest) grantMyConsentRes() {}
type GrantMyConsentForbidden Problem
func (*GrantMyConsentForbidden) grantMyConsentRes() {}
type GrantMyConsentUnauthorized Problem
func (*GrantMyConsentUnauthorized) grantMyConsentRes() {}
// Ref: #/components/schemas/HealthResponse
type HealthResponse struct {
Status HealthResponseStatus `json:"status"`
@@ -21991,6 +22330,14 @@ func (s *RegistrationRequest) SetConsentC1(val PersonalDataConsentAcceptance) {
s.ConsentC1 = val
}
type RequestMyAccountDeletionForbidden Problem
func (*RequestMyAccountDeletionForbidden) requestMyAccountDeletionRes() {}
type RequestMyAccountDeletionUnauthorized Problem
func (*RequestMyAccountDeletionUnauthorized) requestMyAccountDeletionRes() {}
type ResendEmailVerificationBadRequest Problem
func (*ResendEmailVerificationBadRequest) resendEmailVerificationRes() {}
@@ -21999,6 +22346,32 @@ type ResendEmailVerificationForbidden Problem
func (*ResendEmailVerificationForbidden) resendEmailVerificationRes() {}
type RevokeMyConsentForbidden Problem
func (*RevokeMyConsentForbidden) revokeMyConsentRes() {}
// RevokeMyConsentNoContent is response for RevokeMyConsent operation.
type RevokeMyConsentNoContent struct{}
func (*RevokeMyConsentNoContent) revokeMyConsentRes() {}
type RevokeMyConsentUnauthorized Problem
func (*RevokeMyConsentUnauthorized) revokeMyConsentRes() {}
type RevokeMyOrganizationContactConsentForbidden Problem
func (*RevokeMyOrganizationContactConsentForbidden) revokeMyOrganizationContactConsentRes() {}
// RevokeMyOrganizationContactConsentNoContent is response for RevokeMyOrganizationContactConsent operation.
type RevokeMyOrganizationContactConsentNoContent struct{}
func (*RevokeMyOrganizationContactConsentNoContent) revokeMyOrganizationContactConsentRes() {}
type RevokeMyOrganizationContactConsentUnauthorized Problem
func (*RevokeMyOrganizationContactConsentUnauthorized) revokeMyOrganizationContactConsentRes() {}
type RubAmount int64
// Pay period of a salary amount. The MVP uses only `month`; adding a value is a contract change.
@@ -56,55 +56,60 @@ func findAuthorization(h http.Header, prefix string) (string, bool) {
// operationRolesSessionCookie is a private map storing roles per operation.
var operationRolesSessionCookie = map[string][]string{
AcceptMyInvitationOperation: []string{},
CancelMyInvitationOperation: []string{},
CreateMyAssessmentAttemptOperation: []string{},
CreateMySupportCaseOperation: []string{},
CreateOrganizationOperation: []string{},
CreateOrganizationInvitationOperation: []string{},
CreateOrganizationNeedOperation: []string{},
DeclineMyInvitationOperation: []string{},
FinalizeMyAssessmentAttemptOperation: []string{},
GetCurrentAccountOperation: []string{},
GetCurrentSessionOperation: []string{},
GetMyAssessmentAttemptOperation: []string{},
GetMyAssessmentAvailabilityOperation: []string{},
GetMyAssessmentResultOperation: []string{},
GetMyCardPreviewOperation: []string{},
GetMyInvitationOperation: []string{},
GetMyPrivacySettingsOperation: []string{},
GetMyProfileOperation: []string{},
GetMyQuestionnaireOperation: []string{},
GetMySupportCaseOperation: []string{},
GetOrganizationOperation: []string{},
GetOrganizationInvitationOperation: []string{},
GetOrganizationInvitationContactsOperation: []string{},
GetOrganizationNeedOperation: []string{},
HideOrganizationOperation: []string{},
ListMyCardAccessHistoryOperation: []string{},
ListMyConsentsOperation: []string{},
ListMyHiddenOrganizationsOperation: []string{},
ListMyInvitationsOperation: []string{},
ListMyOrganizationsOperation: []string{},
ListMyPrivacyHistoryOperation: []string{},
ListMySupportCasesOperation: []string{},
ListOrganizationInvitationsOperation: []string{},
ListOrganizationNeedsOperation: []string{},
LogoutOperation: []string{},
RaiseOrganizationInvitationSalaryOperation: []string{},
SaveMyProfileOperation: []string{},
SaveMyQuestionnaireOperation: []string{},
SendOrganizationInvitationOperation: []string{},
SetMyPublicationOperation: []string{},
SetMySearchStatusOperation: []string{},
StartMyAssessmentAttemptSessionOperation: []string{},
SubmitMyAssessmentAnswerOperation: []string{},
UnhideOrganizationOperation: []string{},
UpdateOrganizationOperation: []string{},
UpdateOrganizationInvitationOperation: []string{},
UpdateOrganizationNeedOperation: []string{},
ViewMyInvitationOperation: []string{},
WithdrawOrganizationInvitationOperation: []string{},
AcceptMyInvitationOperation: []string{},
CancelMyInvitationOperation: []string{},
CreateMyAssessmentAttemptOperation: []string{},
CreateMySupportCaseOperation: []string{},
CreateOrganizationOperation: []string{},
CreateOrganizationInvitationOperation: []string{},
CreateOrganizationNeedOperation: []string{},
DeclineMyInvitationOperation: []string{},
FinalizeMyAssessmentAttemptOperation: []string{},
GetCurrentAccountOperation: []string{},
GetCurrentSessionOperation: []string{},
GetMyAssessmentAttemptOperation: []string{},
GetMyAssessmentAvailabilityOperation: []string{},
GetMyAssessmentResultOperation: []string{},
GetMyCardPreviewOperation: []string{},
GetMyConsentTextOperation: []string{},
GetMyInvitationOperation: []string{},
GetMyPrivacySettingsOperation: []string{},
GetMyProfileOperation: []string{},
GetMyQuestionnaireOperation: []string{},
GetMySupportCaseOperation: []string{},
GetOrganizationOperation: []string{},
GetOrganizationInvitationOperation: []string{},
GetOrganizationInvitationContactsOperation: []string{},
GetOrganizationNeedOperation: []string{},
GrantMyConsentOperation: []string{},
HideOrganizationOperation: []string{},
ListMyCardAccessHistoryOperation: []string{},
ListMyConsentsOperation: []string{},
ListMyHiddenOrganizationsOperation: []string{},
ListMyInvitationsOperation: []string{},
ListMyOrganizationsOperation: []string{},
ListMyPrivacyHistoryOperation: []string{},
ListMySupportCasesOperation: []string{},
ListOrganizationInvitationsOperation: []string{},
ListOrganizationNeedsOperation: []string{},
LogoutOperation: []string{},
RaiseOrganizationInvitationSalaryOperation: []string{},
RequestMyAccountDeletionOperation: []string{},
RevokeMyConsentOperation: []string{},
RevokeMyOrganizationContactConsentOperation: []string{},
SaveMyProfileOperation: []string{},
SaveMyQuestionnaireOperation: []string{},
SendOrganizationInvitationOperation: []string{},
SetMyPublicationOperation: []string{},
SetMySearchStatusOperation: []string{},
StartMyAssessmentAttemptSessionOperation: []string{},
SubmitMyAssessmentAnswerOperation: []string{},
UnhideOrganizationOperation: []string{},
UpdateOrganizationOperation: []string{},
UpdateOrganizationInvitationOperation: []string{},
UpdateOrganizationNeedOperation: []string{},
ViewMyInvitationOperation: []string{},
WithdrawOrganizationInvitationOperation: []string{},
}
// GetRolesForSessionCookie returns the required roles for the given operation.
@@ -130,31 +135,35 @@ func GetRolesForSessionCookie(operation string) []string {
// operationRolesSessionCsrf is a private map storing roles per operation.
var operationRolesSessionCsrf = map[string][]string{
AcceptMyInvitationOperation: []string{},
CancelMyInvitationOperation: []string{},
CreateMyAssessmentAttemptOperation: []string{},
CreateMySupportCaseOperation: []string{},
CreateOrganizationOperation: []string{},
CreateOrganizationInvitationOperation: []string{},
CreateOrganizationNeedOperation: []string{},
DeclineMyInvitationOperation: []string{},
FinalizeMyAssessmentAttemptOperation: []string{},
HideOrganizationOperation: []string{},
LogoutOperation: []string{},
RaiseOrganizationInvitationSalaryOperation: []string{},
SaveMyProfileOperation: []string{},
SaveMyQuestionnaireOperation: []string{},
SendOrganizationInvitationOperation: []string{},
SetMyPublicationOperation: []string{},
SetMySearchStatusOperation: []string{},
StartMyAssessmentAttemptSessionOperation: []string{},
SubmitMyAssessmentAnswerOperation: []string{},
UnhideOrganizationOperation: []string{},
UpdateOrganizationOperation: []string{},
UpdateOrganizationInvitationOperation: []string{},
UpdateOrganizationNeedOperation: []string{},
ViewMyInvitationOperation: []string{},
WithdrawOrganizationInvitationOperation: []string{},
AcceptMyInvitationOperation: []string{},
CancelMyInvitationOperation: []string{},
CreateMyAssessmentAttemptOperation: []string{},
CreateMySupportCaseOperation: []string{},
CreateOrganizationOperation: []string{},
CreateOrganizationInvitationOperation: []string{},
CreateOrganizationNeedOperation: []string{},
DeclineMyInvitationOperation: []string{},
FinalizeMyAssessmentAttemptOperation: []string{},
GrantMyConsentOperation: []string{},
HideOrganizationOperation: []string{},
LogoutOperation: []string{},
RaiseOrganizationInvitationSalaryOperation: []string{},
RequestMyAccountDeletionOperation: []string{},
RevokeMyConsentOperation: []string{},
RevokeMyOrganizationContactConsentOperation: []string{},
SaveMyProfileOperation: []string{},
SaveMyQuestionnaireOperation: []string{},
SendOrganizationInvitationOperation: []string{},
SetMyPublicationOperation: []string{},
SetMySearchStatusOperation: []string{},
StartMyAssessmentAttemptSessionOperation: []string{},
SubmitMyAssessmentAnswerOperation: []string{},
UnhideOrganizationOperation: []string{},
UpdateOrganizationOperation: []string{},
UpdateOrganizationInvitationOperation: []string{},
UpdateOrganizationNeedOperation: []string{},
ViewMyInvitationOperation: []string{},
WithdrawOrganizationInvitationOperation: []string{},
}
// GetRolesForSessionCsrf returns the required roles for the given operation.
@@ -621,6 +621,15 @@ type Handler interface {
//
// GET /api/v1/me/privacy/preview
GetMyCardPreview(ctx context.Context) (GetMyCardPreviewRes, error)
// GetMyConsentText implements GetMyConsentText operation.
//
// Requires a verified session. Returns the current published text and version of c1, c2, c3, or c5 so
// the user can read the exact text before an explicit settings grant. C4 is excluded: its text
// includes an organization snapshot and it is granted only during invitation acceptance. The response
// is private and is not cached.
//
// GET /api/v1/me/consent-texts/{purpose}
GetMyConsentText(ctx context.Context, params GetMyConsentTextParams) (GetMyConsentTextRes, error)
// GetMyInvitation implements GetMyInvitation operation.
//
// Requires the session cookie of a candidate account. The candidate comes from the session; the
@@ -864,6 +873,20 @@ type Handler interface {
//
// GET /api/v1/specializations
GetSpecializationCatalog(ctx context.Context) (*SpecializationCatalog, error)
// GrantMyConsent implements GrantMyConsent operation.
//
// Requires a verified session, its CSRF token in X-CSRF-Token, and the exact configured Origin. The
// subject comes from the session. The body names the current text version the user read and requires
// `accepted: true`; the server verifies that version is still current and stores the hash of the exact
// text. A stale version answers 400 validation_failed at `/text_version`, without writing a grant.
//
// C1 is available to candidate and employer accounts. C2, C3, and C5 are available only to candidate
// accounts. C4 is excluded and can be granted only by accepting an invitation. A repeated grant of the
// same current version returns the existing record; after revocation a grant creates a new record and
// never reopens a publication or restores an older grant.
//
// PUT /api/v1/me/consents/{purpose}
GrantMyConsent(ctx context.Context, req *ConsentSettingsGrantRequest, params GrantMyConsentParams) (GrantMyConsentRes, error)
// HideOrganization implements HideOrganization operation.
//
// Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token,
@@ -945,8 +968,9 @@ type Handler interface {
// value. A c2 record proves the consent to the publication text; the published field set and its
// changes are evidence of the publication history.
//
// Granting c1, c2, c3, and c5 in the consent settings and revoking any purpose are planned operations
// of this tag; c1 is given at registration and c4 only in AcceptMyInvitation.
// Settings grants of c1, c2, c3, and c5 require the currently published text and an explicit
// acceptance. Revoking c2, c3, or c5 is available in settings; c1 creates a durable account-deletion
// request, and c4 is revoked only for one organization. C4 is granted only in AcceptMyInvitation.
//
// Access: a missing, unknown, expired, or revoked session answers 401 unauthenticated. A malformed
// `limit`, `cursor`, or `state` answers 400 validation_failed.
@@ -1210,6 +1234,16 @@ type Handler interface {
//
// POST /api/v1/identity/registrations
RegisterAccount(ctx context.Context, req *RegistrationRequest, params RegisterAccountParams) (RegisterAccountRes, error)
// RequestMyAccountDeletion implements RequestMyAccountDeletion operation.
//
// Requires a verified session, its CSRF token in X-CSRF-Token, and the exact configured Origin. The
// subject comes from the session. In one transaction, revokes any active C1 record, creates or returns
// the subject's active durable deletion request, and writes the outbox intent. The API does not delete
// the account synchronously. Repeating the request returns the same active request; a later C1 grant
// never cancels it.
//
// POST /api/v1/me/account-deletion-requests
RequestMyAccountDeletion(ctx context.Context) (RequestMyAccountDeletionRes, error)
// ResendEmailVerification implements ResendEmailVerification operation.
//
// Public operation without a session. The answer is the same 202 for an unknown email, a verified
@@ -1226,6 +1260,31 @@ type Handler interface {
//
// POST /api/v1/identity/email-verification-requests
ResendEmailVerification(ctx context.Context, req *EmailVerificationResendRequest) (ResendEmailVerificationRes, error)
// RevokeMyConsent implements RevokeMyConsent operation.
//
// Requires a verified candidate session, its CSRF token in X-CSRF-Token, and the exact configured
// Origin. The subject comes from the session. Revokes every unrevoked record of c2, c3, or c5,
// including superseded records, and never changes another purpose. Repeating a revocation is harmless
// and creates no duplicate event.
//
// Revoking c2 immediately closes the stored publication and records privacy history in the same
// transaction; a downstream revocation intent is written to the outbox. A later c2 grant does not
// reopen publication or restore old grants. Revoking c3 does not block the manual assessment path.
// Revoking c5 makes the consent gate deny further FSP import and writes a durable stop/delete intent;
// an external FSP deletion adapter is not available yet.
//
// DELETE /api/v1/me/consents/{purpose}
RevokeMyConsent(ctx context.Context, params RevokeMyConsentParams) (RevokeMyConsentRes, error)
// RevokeMyOrganizationContactConsent implements RevokeMyOrganizationContactConsent operation.
//
// Requires a verified candidate session, its CSRF token in X-CSRF-Token, and the exact configured
// Origin. The subject comes from the session; `org_id` is the only scope the caller may choose. The
// server revokes every unrevoked C4 record for this subject and organization, using the fields stored
// on those records to request downstream grant revocation. It does not affect another organization.
// Repeating the request is harmless and creates no duplicate event.
//
// DELETE /api/v1/me/consents/c4/organizations/{org_id}
RevokeMyOrganizationContactConsent(ctx context.Context, params RevokeMyOrganizationContactConsentParams) (RevokeMyOrganizationContactConsentRes, error)
// SaveMyProfile implements SaveMyProfile operation.
//
// Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token,
@@ -680,6 +680,18 @@ func (UnimplementedHandler) GetMyCardPreview(ctx context.Context) (r GetMyCardPr
return r, ht.ErrNotImplemented
}
// GetMyConsentText implements GetMyConsentText operation.
//
// Requires a verified session. Returns the current published text and version of c1, c2, c3, or c5 so
// the user can read the exact text before an explicit settings grant. C4 is excluded: its text
// includes an organization snapshot and it is granted only during invitation acceptance. The response
// is private and is not cached.
//
// GET /api/v1/me/consent-texts/{purpose}
func (UnimplementedHandler) GetMyConsentText(ctx context.Context, params GetMyConsentTextParams) (r GetMyConsentTextRes, _ error) {
return r, ht.ErrNotImplemented
}
// GetMyInvitation implements GetMyInvitation operation.
//
// Requires the session cookie of a candidate account. The candidate comes from the session; the
@@ -953,6 +965,23 @@ func (UnimplementedHandler) GetSpecializationCatalog(ctx context.Context) (r *Sp
return r, ht.ErrNotImplemented
}
// GrantMyConsent implements GrantMyConsent operation.
//
// Requires a verified session, its CSRF token in X-CSRF-Token, and the exact configured Origin. The
// subject comes from the session. The body names the current text version the user read and requires
// `accepted: true`; the server verifies that version is still current and stores the hash of the exact
// text. A stale version answers 400 validation_failed at `/text_version`, without writing a grant.
//
// C1 is available to candidate and employer accounts. C2, C3, and C5 are available only to candidate
// accounts. C4 is excluded and can be granted only by accepting an invitation. A repeated grant of the
// same current version returns the existing record; after revocation a grant creates a new record and
// never reopens a publication or restores an older grant.
//
// PUT /api/v1/me/consents/{purpose}
func (UnimplementedHandler) GrantMyConsent(ctx context.Context, req *ConsentSettingsGrantRequest, params GrantMyConsentParams) (r GrantMyConsentRes, _ error) {
return r, ht.ErrNotImplemented
}
// HideOrganization implements HideOrganization operation.
//
// Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token,
@@ -1040,8 +1069,9 @@ func (UnimplementedHandler) ListMyCardAccessHistory(ctx context.Context, params
// value. A c2 record proves the consent to the publication text; the published field set and its
// changes are evidence of the publication history.
//
// Granting c1, c2, c3, and c5 in the consent settings and revoking any purpose are planned operations
// of this tag; c1 is given at registration and c4 only in AcceptMyInvitation.
// Settings grants of c1, c2, c3, and c5 require the currently published text and an explicit
// acceptance. Revoking c2, c3, or c5 is available in settings; c1 creates a durable account-deletion
// request, and c4 is revoked only for one organization. C4 is granted only in AcceptMyInvitation.
//
// Access: a missing, unknown, expired, or revoked session answers 401 unauthenticated. A malformed
// `limit`, `cursor`, or `state` answers 400 validation_failed.
@@ -1341,6 +1371,19 @@ func (UnimplementedHandler) RegisterAccount(ctx context.Context, req *Registrati
return r, ht.ErrNotImplemented
}
// RequestMyAccountDeletion implements RequestMyAccountDeletion operation.
//
// Requires a verified session, its CSRF token in X-CSRF-Token, and the exact configured Origin. The
// subject comes from the session. In one transaction, revokes any active C1 record, creates or returns
// the subject's active durable deletion request, and writes the outbox intent. The API does not delete
// the account synchronously. Repeating the request returns the same active request; a later C1 grant
// never cancels it.
//
// POST /api/v1/me/account-deletion-requests
func (UnimplementedHandler) RequestMyAccountDeletion(ctx context.Context) (r RequestMyAccountDeletionRes, _ error) {
return r, ht.ErrNotImplemented
}
// ResendEmailVerification implements ResendEmailVerification operation.
//
// Public operation without a session. The answer is the same 202 for an unknown email, a verified
@@ -1360,6 +1403,37 @@ func (UnimplementedHandler) ResendEmailVerification(ctx context.Context, req *Em
return r, ht.ErrNotImplemented
}
// RevokeMyConsent implements RevokeMyConsent operation.
//
// Requires a verified candidate session, its CSRF token in X-CSRF-Token, and the exact configured
// Origin. The subject comes from the session. Revokes every unrevoked record of c2, c3, or c5,
// including superseded records, and never changes another purpose. Repeating a revocation is harmless
// and creates no duplicate event.
//
// Revoking c2 immediately closes the stored publication and records privacy history in the same
// transaction; a downstream revocation intent is written to the outbox. A later c2 grant does not
// reopen publication or restore old grants. Revoking c3 does not block the manual assessment path.
// Revoking c5 makes the consent gate deny further FSP import and writes a durable stop/delete intent;
// an external FSP deletion adapter is not available yet.
//
// DELETE /api/v1/me/consents/{purpose}
func (UnimplementedHandler) RevokeMyConsent(ctx context.Context, params RevokeMyConsentParams) (r RevokeMyConsentRes, _ error) {
return r, ht.ErrNotImplemented
}
// RevokeMyOrganizationContactConsent implements RevokeMyOrganizationContactConsent operation.
//
// Requires a verified candidate session, its CSRF token in X-CSRF-Token, and the exact configured
// Origin. The subject comes from the session; `org_id` is the only scope the caller may choose. The
// server revokes every unrevoked C4 record for this subject and organization, using the fields stored
// on those records to request downstream grant revocation. It does not affect another organization.
// Repeating the request is harmless and creates no duplicate event.
//
// DELETE /api/v1/me/consents/c4/organizations/{org_id}
func (UnimplementedHandler) RevokeMyOrganizationContactConsent(ctx context.Context, params RevokeMyOrganizationContactConsentParams) (r RevokeMyOrganizationContactConsentRes, _ error) {
return r, ht.ErrNotImplemented
}
// SaveMyProfile implements SaveMyProfile operation.
//
// Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token,
@@ -5934,6 +5934,74 @@ func (s *ConfirmEmailForbidden) Validate() error {
return nil
}
func (s *ConsentDeletionRequest) Validate() error {
if s == nil {
return validate.ErrNilPointer
}
var failures []validate.FieldError
if err := func() error {
if err := s.Status.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: "status",
Error: err,
})
}
if len(failures) > 0 {
return &validate.Error{Fields: failures}
}
return nil
}
func (s *ConsentDeletionRequestHeaders) 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 ConsentDeletionRequestStatus) Validate() error {
switch s {
case "requested":
return nil
case "processing":
return nil
default:
return errors.Errorf("invalid value: %v", s)
}
}
func (s *ConsentOrganization) Validate() error {
if s == nil {
return validate.ErrNilPointer
@@ -6144,6 +6212,40 @@ func (s *ConsentRecord) Validate() error {
return nil
}
func (s *ConsentRecordHeaders) 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 *ConsentRecordList) Validate() error {
if s == nil {
return validate.ErrNilPointer
@@ -6248,6 +6350,77 @@ func (s ConsentRevocationSource) Validate() error {
}
}
func (s *ConsentSettingsGrantRequest) Validate() error {
if s == nil {
return validate.ErrNilPointer
}
var failures []validate.FieldError
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.Accepted.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: "accepted",
Error: err,
})
}
if len(failures) > 0 {
return &validate.Error{Fields: failures}
}
return nil
}
func (s ConsentSettingsGrantRequestAccepted) Validate() error {
switch s {
case true:
return nil
default:
return errors.Errorf("invalid value: %v", s)
}
}
func (s ConsentSettingsPurpose) Validate() error {
switch s {
case "c1":
return nil
case "c2":
return nil
case "c3":
return nil
case "c5":
return nil
default:
return errors.Errorf("invalid value: %v", s)
}
}
func (s ConsentSettingsRevokePurpose) Validate() error {
switch s {
case "c2":
return nil
case "c3":
return nil
case "c5":
return nil
default:
return errors.Errorf("invalid value: %v", s)
}
}
func (s ConsentSource) Validate() error {
switch s {
case "registration":
@@ -6331,6 +6504,40 @@ func (s *ConsentText) Validate() error {
return nil
}
func (s *ConsentTextHeaders) 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 ConsentTextVersion) Validate() error {
alias := (string)(s)
if err := (validate.String{
@@ -7773,6 +7980,22 @@ func (s *GetMyCardPreviewUnauthorized) Validate() error {
return nil
}
func (s *GetMyConsentTextBadRequest) Validate() error {
alias := (*Problem)(s)
if err := alias.Validate(); err != nil {
return err
}
return nil
}
func (s *GetMyConsentTextUnauthorized) Validate() error {
alias := (*Problem)(s)
if err := alias.Validate(); err != nil {
return err
}
return nil
}
func (s *GetMyInvitationBadRequest) Validate() error {
alias := (*Problem)(s)
if err := alias.Validate(); err != nil {
@@ -8020,6 +8243,30 @@ func (s GradeCode) Validate() error {
}
}
func (s *GrantMyConsentBadRequest) Validate() error {
alias := (*Problem)(s)
if err := alias.Validate(); err != nil {
return err
}
return nil
}
func (s *GrantMyConsentForbidden) Validate() error {
alias := (*Problem)(s)
if err := alias.Validate(); err != nil {
return err
}
return nil
}
func (s *GrantMyConsentUnauthorized) Validate() error {
alias := (*Problem)(s)
if err := alias.Validate(); err != nil {
return err
}
return nil
}
func (s *HealthResponse) Validate() error {
if s == nil {
return validate.ErrNilPointer
@@ -17451,6 +17698,22 @@ func (s *RegistrationRequest) Validate() error {
return nil
}
func (s *RequestMyAccountDeletionForbidden) Validate() error {
alias := (*Problem)(s)
if err := alias.Validate(); err != nil {
return err
}
return nil
}
func (s *RequestMyAccountDeletionUnauthorized) Validate() error {
alias := (*Problem)(s)
if err := alias.Validate(); err != nil {
return err
}
return nil
}
func (s *ResendEmailVerificationBadRequest) Validate() error {
alias := (*Problem)(s)
if err := alias.Validate(); err != nil {
@@ -17467,6 +17730,38 @@ func (s *ResendEmailVerificationForbidden) Validate() error {
return nil
}
func (s *RevokeMyConsentForbidden) Validate() error {
alias := (*Problem)(s)
if err := alias.Validate(); err != nil {
return err
}
return nil
}
func (s *RevokeMyConsentUnauthorized) Validate() error {
alias := (*Problem)(s)
if err := alias.Validate(); err != nil {
return err
}
return nil
}
func (s *RevokeMyOrganizationContactConsentForbidden) Validate() error {
alias := (*Problem)(s)
if err := alias.Validate(); err != nil {
return err
}
return nil
}
func (s *RevokeMyOrganizationContactConsentUnauthorized) Validate() error {
alias := (*Problem)(s)
if err := alias.Validate(); err != nil {
return err
}
return nil
}
func (s RubAmount) Validate() error {
alias := (int64)(s)
if err := (validate.Int{
@@ -17,9 +17,11 @@ import (
type Handler struct {
api.UnimplementedHandler
health *HealthHandler
identity *IdentityHandler
problems *problem.Responder
health *HealthHandler
identity *IdentityHandler
consent *ConsentHandler
organization *OrganizationHandler
problems *problem.Responder
}
var _ api.Handler = (*Handler)(nil)
@@ -32,6 +34,16 @@ func WithIdentity(identity *IdentityHandler) HandlerOption {
return func(handler *Handler) { handler.identity = identity }
}
// WithConsent serves the published texts and ledger operations.
func WithConsent(consent *ConsentHandler) HandlerOption {
return func(handler *Handler) { handler.consent = consent }
}
// WithOrganization serves company profiles and owner operations.
func WithOrganization(organization *OrganizationHandler) HandlerOption {
return func(handler *Handler) { handler.organization = organization }
}
func NewHandler(health *HealthHandler, problems *problem.Responder, options ...HandlerOption) *Handler {
handler := &Handler{health: health, problems: problems}
for _, option := range options {
@@ -0,0 +1,432 @@
package v1
import (
"context"
"encoding/base64"
"encoding/binary"
"errors"
"fmt"
"time"
"github.com/google/uuid"
"lincodex/backend/internal/adapter/primary/http/api"
"lincodex/backend/internal/adapter/primary/http/problem"
"lincodex/backend/internal/domain"
"lincodex/backend/internal/port/outbound"
"lincodex/backend/internal/usecase/consent"
)
const (
defaultConsentPageLimit = 20
consentCursorVersion = 1
consentCursorBytes = 42
maxConsentCursorNanos = int64(1<<63 - 1)
minConsentCursorNanos = -maxConsentCursorNanos - 1
)
// ConsentQueries reads current texts and a subject's own consent history.
type ConsentQueries interface {
CurrentText(ctx context.Context, purpose domain.ConsentPurpose) (domain.ConsentText, error)
List(ctx context.Context, query outbound.ConsentListQuery) (outbound.ConsentPage, error)
}
// ConsentCommands records grants, revocations, and deletion requests.
type ConsentCommands interface {
GrantInSettingsInNewTransaction(ctx context.Context, input consent.SettingsGrantInput) (consent.GrantResult, error)
RevokeInSettingsInNewTransaction(ctx context.Context, input consent.SettingsRevocationInput) (consent.RevocationResult, error)
RequestAccountDeletionInNewTransaction(ctx context.Context, subjectID uuid.UUID) (domain.AccountDeletionRequest, error)
}
// ConsentHandler serves consent text and ledger operations.
type ConsentHandler struct {
queries ConsentQueries
commands ConsentCommands
}
func NewConsentHandler(queries ConsentQueries, commands ConsentCommands) *ConsentHandler {
if queries == nil || commands == nil {
panic("v1.NewConsentHandler - query and command services must not be nil")
}
return &ConsentHandler{queries: queries, commands: commands}
}
func (handler *Handler) GetConsentText(ctx context.Context, params api.GetConsentTextParams) (api.GetConsentTextRes, error) {
if handler.consent == nil {
return handler.UnimplementedHandler.GetConsentText(ctx, params)
}
return handler.consent.GetConsentText(ctx, params)
}
func (handler *Handler) GetMyConsentText(ctx context.Context, params api.GetMyConsentTextParams) (api.GetMyConsentTextRes, error) {
if handler.consent == nil {
return handler.UnimplementedHandler.GetMyConsentText(ctx, params)
}
return handler.consent.GetMyConsentText(ctx, params)
}
func (handler *Handler) ListMyConsents(ctx context.Context, params api.ListMyConsentsParams) (api.ListMyConsentsRes, error) {
if handler.consent == nil {
return handler.UnimplementedHandler.ListMyConsents(ctx, params)
}
return handler.consent.ListMyConsents(ctx, params)
}
func (handler *Handler) GrantMyConsent(ctx context.Context, request *api.ConsentSettingsGrantRequest, params api.GrantMyConsentParams) (api.GrantMyConsentRes, error) {
if handler.consent == nil {
return handler.UnimplementedHandler.GrantMyConsent(ctx, request, params)
}
return handler.consent.GrantMyConsent(ctx, request, params)
}
func (handler *Handler) RevokeMyConsent(ctx context.Context, params api.RevokeMyConsentParams) (api.RevokeMyConsentRes, error) {
if handler.consent == nil {
return handler.UnimplementedHandler.RevokeMyConsent(ctx, params)
}
return handler.consent.RevokeMyConsent(ctx, params)
}
func (handler *Handler) RevokeMyOrganizationContactConsent(ctx context.Context, params api.RevokeMyOrganizationContactConsentParams) (api.RevokeMyOrganizationContactConsentRes, error) {
if handler.consent == nil {
return handler.UnimplementedHandler.RevokeMyOrganizationContactConsent(ctx, params)
}
return handler.consent.RevokeMyOrganizationContactConsent(ctx, params)
}
func (handler *Handler) RequestMyAccountDeletion(ctx context.Context) (api.RequestMyAccountDeletionRes, error) {
if handler.consent == nil {
return handler.UnimplementedHandler.RequestMyAccountDeletion(ctx)
}
return handler.consent.RequestMyAccountDeletion(ctx)
}
func (handler *ConsentHandler) GetConsentText(ctx context.Context, params api.GetConsentTextParams) (api.GetConsentTextRes, error) {
purpose := domain.ConsentPurpose(params.Purpose)
if purpose != domain.ConsentPurposePersonalData {
response := problem.New(ctx, api.ProblemCodeValidationFailed).Response
return &response, nil
}
text, err := handler.queries.CurrentText(ctx, purpose)
if err != nil {
return nil, err
}
response := consentTextResponse(text)
return &response, nil
}
func (handler *ConsentHandler) GetMyConsentText(ctx context.Context, params api.GetMyConsentTextParams) (api.GetMyConsentTextRes, error) {
if _, ok := currentConsentPrincipal(ctx); !ok {
return (*api.GetMyConsentTextUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
}
text, err := handler.queries.CurrentText(ctx, domain.ConsentPurpose(params.Purpose))
if err != nil {
return nil, err
}
return &api.ConsentTextHeaders{
CacheControl: api.CacheControlNoStoreNoStore,
Response: consentTextResponse(text),
}, nil
}
func (handler *ConsentHandler) ListMyConsents(ctx context.Context, params api.ListMyConsentsParams) (api.ListMyConsentsRes, error) {
principal, ok := currentConsentPrincipal(ctx)
if !ok {
return (*api.ListMyConsentsUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
}
query, err := consentListQuery(principal.UserID, params)
if err != nil {
return consentListInvalid(ctx, err), nil
}
page, err := handler.queries.List(ctx, query)
if err != nil {
if errors.Is(err, domain.ErrInvalidConsent) {
return consentListInvalid(ctx, err), nil
}
return nil, err
}
items := make([]api.ConsentRecord, 0, len(page.Records))
for _, record := range page.Records {
items = append(items, consentRecordResponse(record))
}
var nextCursor api.NilString
nextCursor.SetToNull()
if page.HasMore && len(page.Records) > 0 {
last := page.Records[len(page.Records)-1]
cursor, err := encodeConsentCursor(principal.UserID, query.State, outbound.ConsentPositionOf(last))
if err != nil {
return nil, fmt.Errorf("ConsentHandler.ListMyConsents - encode cursor: %w", err)
}
nextCursor.SetTo(cursor)
}
return &api.ConsentRecordListHeaders{
CacheControl: api.CacheControlNoStoreNoStore,
Response: api.ConsentRecordList{
Items: items,
Page: api.PageInfo{HasMore: page.HasMore, NextCursor: nextCursor},
},
}, nil
}
func (handler *ConsentHandler) GrantMyConsent(ctx context.Context, request *api.ConsentSettingsGrantRequest, params api.GrantMyConsentParams) (api.GrantMyConsentRes, error) {
principal, session, ok := currentConsentSession(ctx)
if !ok {
return (*api.GrantMyConsentUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
}
purpose := domain.ConsentPurpose(params.Purpose)
if candidateOnlyConsent(purpose) && session.User.Scenario != domain.ScenarioCandidate {
return (*api.GrantMyConsentForbidden)(&problem.New(ctx, api.ProblemCodeForbidden).Response), nil
}
if request == nil || !bool(request.Accepted) {
return consentGrantInvalid(ctx, "/accepted"), nil
}
result, err := handler.commands.GrantInSettingsInNewTransaction(ctx, consent.SettingsGrantInput{
SubjectID: principal.UserID, Purpose: purpose, TextVersion: domain.ConsentTextVersion(request.TextVersion),
})
if err != nil {
if errors.Is(err, consent.ErrStaleConsentText) {
return consentGrantInvalid(ctx, "/text_version"), nil
}
return nil, err
}
return &api.ConsentRecordHeaders{
CacheControl: api.CacheControlNoStoreNoStore,
Response: consentRecordResponse(result.Record),
}, nil
}
func (handler *ConsentHandler) RevokeMyConsent(ctx context.Context, params api.RevokeMyConsentParams) (api.RevokeMyConsentRes, error) {
principal, session, ok := currentConsentSession(ctx)
if !ok {
return (*api.RevokeMyConsentUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
}
if session.User.Scenario != domain.ScenarioCandidate {
return (*api.RevokeMyConsentForbidden)(&problem.New(ctx, api.ProblemCodeForbidden).Response), nil
}
_, err := handler.commands.RevokeInSettingsInNewTransaction(ctx, consent.SettingsRevocationInput{
SubjectID: principal.UserID, Purpose: domain.ConsentPurpose(params.Purpose),
})
if err != nil {
return nil, err
}
return &api.RevokeMyConsentNoContent{}, nil
}
func (handler *ConsentHandler) RevokeMyOrganizationContactConsent(ctx context.Context, params api.RevokeMyOrganizationContactConsentParams) (api.RevokeMyOrganizationContactConsentRes, error) {
principal, session, ok := currentConsentSession(ctx)
if !ok {
return (*api.RevokeMyOrganizationContactConsentUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
}
if session.User.Scenario != domain.ScenarioCandidate {
return (*api.RevokeMyOrganizationContactConsentForbidden)(&problem.New(ctx, api.ProblemCodeForbidden).Response), nil
}
_, err := handler.commands.RevokeInSettingsInNewTransaction(ctx, consent.SettingsRevocationInput{
SubjectID: principal.UserID, Purpose: domain.ConsentPurposeContactDisclosure, OrganizationID: params.OrgID,
})
if err != nil {
return nil, err
}
return &api.RevokeMyOrganizationContactConsentNoContent{}, nil
}
func (handler *ConsentHandler) RequestMyAccountDeletion(ctx context.Context) (api.RequestMyAccountDeletionRes, error) {
principal, ok := currentConsentPrincipal(ctx)
if !ok {
return (*api.RequestMyAccountDeletionUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
}
request, err := handler.commands.RequestAccountDeletionInNewTransaction(ctx, principal.UserID)
if err != nil {
return nil, err
}
return &api.ConsentDeletionRequestHeaders{
CacheControl: api.CacheControlNoStoreNoStore,
Response: api.ConsentDeletionRequest{
ID: request.ID(), Status: api.ConsentDeletionRequestStatus(request.Status()), RequestedAt: api.Timestamp(request.RequestedAt()),
},
}, nil
}
func currentConsentPrincipal(ctx context.Context) (Principal, bool) {
principal, ok := PrincipalFromContext(ctx)
if !ok || !principal.EmailVerified {
return Principal{}, false
}
session, ok := sessionFromContext(ctx)
if !ok || session.Principal != principal || session.User.ID != principal.UserID || !session.User.EmailVerified() {
return Principal{}, false
}
return principal, true
}
func currentConsentSession(ctx context.Context) (Principal, authenticatedSession, bool) {
principal, ok := currentConsentPrincipal(ctx)
if !ok {
return Principal{}, authenticatedSession{}, false
}
session, ok := sessionFromContext(ctx)
return principal, session, ok
}
func candidateOnlyConsent(purpose domain.ConsentPurpose) bool {
return purpose == domain.ConsentPurposePublication || purpose == domain.ConsentPurposeAutoCategorization ||
purpose == domain.ConsentPurposeFSPImport
}
func consentTextResponse(text domain.ConsentText) api.ConsentText {
return api.ConsentText{
Purpose: api.ConsentPurposeCode(text.Purpose()), TextVersion: api.ConsentTextVersion(text.Version()),
Text: text.Body(), PublishedAt: api.Timestamp(text.PublishedAt()),
}
}
func consentRecordResponse(record domain.ConsentRecord) api.ConsentRecord {
response := api.ConsentRecord{
ID: record.ID(), Purpose: api.ConsentPurposeCode(record.Purpose()), State: api.ConsentState(record.State()),
TextVersion: api.ConsentTextVersion(record.TextVersion()), Source: api.ConsentSource(record.Source()),
GrantedAt: api.Timestamp(record.GrantedAt()), Fields: mapContactFields(record.Fields().Fields()),
}
if revokedAt, ok := record.RevokedAt(); ok {
response.RevokedAt.SetTo(api.Timestamp(revokedAt))
response.RevocationSource.SetTo(api.ConsentRevocationSource(record.RevocationSource()))
} else {
response.RevokedAt.SetToNull()
response.RevocationSource.SetToNull()
}
if record.Purpose().OrganizationScoped() {
response.Organization.SetTo(api.ConsentOrganization{ID: record.OrganizationID(), Name: record.OrganizationName()})
response.InvitationID.SetTo(record.InvitationID())
response.InvitationTermsVersion.SetTo(api.InvitationTermsVersion(record.InvitationTermsVersion()))
} else {
response.Organization.SetToNull()
response.InvitationID.SetToNull()
response.InvitationTermsVersion.SetToNull()
}
return response
}
func mapContactFields(fields []domain.ContactField) []api.ContactFieldKind {
if fields == nil {
return nil
}
mapped := make([]api.ContactFieldKind, 0, len(fields))
for _, field := range fields {
mapped = append(mapped, api.ContactFieldKind(field))
}
return mapped
}
func consentListQuery(subjectID uuid.UUID, params api.ListMyConsentsParams) (outbound.ConsentListQuery, error) {
query := outbound.ConsentListQuery{SubjectID: subjectID, Limit: defaultConsentPageLimit}
if state, ok := params.State.Get(); ok {
query.State = domain.ConsentState(state)
}
if limit, ok := params.Limit.Get(); ok {
query.Limit = limit
}
if cursor, ok := params.Cursor.Get(); ok {
position, state, err := decodeConsentCursor(cursor, subjectID)
if err != nil || state != query.State {
return outbound.ConsentListQuery{}, errors.New("consent cursor is invalid")
}
query.After = &position
}
return query, nil
}
func encodeConsentCursor(subjectID uuid.UUID, state domain.ConsentState, position outbound.ConsentListPosition) (string, error) {
nanos, inRange := consentCursorNanos(position.GrantedAt)
if subjectID == uuid.Nil || position.ID == uuid.Nil || !inRange {
return "", fmt.Errorf("encodeConsentCursor - subject and position are required: %w", domain.ErrInvalidConsent)
}
stateCode, ok := consentCursorStateCode(state)
if !ok {
return "", fmt.Errorf("encodeConsentCursor - state is invalid: %w", domain.ErrInvalidConsent)
}
var value [consentCursorBytes]byte
value[0] = consentCursorVersion
copy(value[1:17], subjectID[:])
value[17] = stateCode
binary.BigEndian.PutUint64(value[18:26], encodeConsentCursorNanos(nanos))
copy(value[26:], position.ID[:])
return base64.RawURLEncoding.EncodeToString(value[:]), nil
}
func decodeConsentCursor(cursor string, subjectID uuid.UUID) (outbound.ConsentListPosition, domain.ConsentState, error) {
value, err := base64.RawURLEncoding.DecodeString(cursor)
if err != nil || len(value) != consentCursorBytes || subjectID == uuid.Nil || value[0] != consentCursorVersion ||
base64.RawURLEncoding.EncodeToString(value) != cursor || uuid.UUID(value[1:17]) != subjectID {
return outbound.ConsentListPosition{}, "", errors.New("consent cursor is invalid")
}
state, ok := consentCursorState(value[17])
if !ok {
return outbound.ConsentListPosition{}, "", errors.New("consent cursor is invalid")
}
grantedAt := time.Unix(0, decodeConsentCursorNanos(binary.BigEndian.Uint64(value[18:26]))).UTC()
positionID := uuid.UUID(value[26:42])
if positionID == uuid.Nil || grantedAt.IsZero() {
return outbound.ConsentListPosition{}, "", errors.New("consent cursor is invalid")
}
return outbound.ConsentListPosition{GrantedAt: grantedAt, ID: positionID}, state, nil
}
func consentCursorNanos(at time.Time) (int64, bool) {
if at.IsZero() || at.Before(time.Unix(0, minConsentCursorNanos)) || at.After(time.Unix(0, maxConsentCursorNanos)) {
return 0, false
}
return at.UnixNano(), true
}
func decodeConsentCursorNanos(encoded uint64) int64 {
if encoded <= uint64(maxConsentCursorNanos) {
return int64(encoded)
}
complement := ^encoded & uint64(maxConsentCursorNanos)
if complement == uint64(maxConsentCursorNanos) {
return minConsentCursorNanos
}
return -int64(complement) - 1
}
func encodeConsentCursorNanos(nanos int64) uint64 {
if nanos >= 0 {
return uint64(nanos)
}
return uint64(nanos&maxConsentCursorNanos) | uint64(1)<<63
}
func consentCursorStateCode(state domain.ConsentState) (byte, bool) {
switch state {
case "":
return 0, true
case domain.ConsentStateActive:
return 1, true
case domain.ConsentStateSuperseded:
return 2, true
case domain.ConsentStateRevoked:
return 3, true
default:
return 0, false
}
}
func consentCursorState(code byte) (domain.ConsentState, bool) {
switch code {
case 0:
return "", true
case 1:
return domain.ConsentStateActive, true
case 2:
return domain.ConsentStateSuperseded, true
case 3:
return domain.ConsentStateRevoked, true
default:
return "", false
}
}
func consentListInvalid(ctx context.Context, _ error) *api.ListMyConsentsBadRequest {
return (*api.ListMyConsentsBadRequest)(&problem.InvalidField(ctx, api.ProblemFieldLocationQuery, "/cursor").Response)
}
func consentGrantInvalid(ctx context.Context, pointer string) *api.GrantMyConsentBadRequest {
return (*api.GrantMyConsentBadRequest)(&problem.InvalidField(ctx, api.ProblemFieldLocationBody, pointer).Response)
}
@@ -0,0 +1,46 @@
package v1
import (
"testing"
"time"
"github.com/google/uuid"
"lincodex/backend/internal/domain"
"lincodex/backend/internal/port/outbound"
)
func TestConsentCursorTimeBounds(t *testing.T) {
subjectID := uuid.New()
positionID := uuid.New()
for _, grantedAt := range []time.Time{
time.Unix(0, minConsentCursorNanos).UTC(),
time.Unix(0, -1).UTC(),
time.Unix(0, 0).UTC(),
time.Unix(0, maxConsentCursorNanos).UTC(),
} {
t.Run(grantedAt.String(), func(t *testing.T) {
cursor, err := encodeConsentCursor(subjectID, domain.ConsentStateActive, outbound.ConsentListPosition{
GrantedAt: grantedAt, ID: positionID,
})
if err != nil {
t.Fatalf("encode cursor at %s: %v", grantedAt, err)
}
position, state, err := decodeConsentCursor(cursor, subjectID)
if err != nil || !position.GrantedAt.Equal(grantedAt) || position.ID != positionID || state != domain.ConsentStateActive {
t.Fatalf("decode cursor = %#v, %q, %v; want time %s and matching position", position, state, err, grantedAt)
}
})
}
for _, grantedAt := range []time.Time{
time.Unix(0, minConsentCursorNanos).Add(-time.Nanosecond),
time.Unix(0, maxConsentCursorNanos).Add(time.Nanosecond),
} {
if _, err := encodeConsentCursor(subjectID, domain.ConsentStateActive, outbound.ConsentListPosition{
GrantedAt: grantedAt, ID: positionID,
}); err == nil {
t.Fatalf("encode cursor outside Unix-nanosecond range at %s: got nil error", grantedAt)
}
}
}
@@ -0,0 +1,358 @@
package v1
import (
"context"
"encoding/json"
"errors"
"github.com/google/uuid"
"lincodex/backend/internal/adapter/primary/http/api"
"lincodex/backend/internal/adapter/primary/http/problem"
"lincodex/backend/internal/domain"
"lincodex/backend/internal/port/outbound"
"lincodex/backend/internal/usecase/organization"
)
// OrganizationOperations are the organization commands and reads served by
// this HTTP adapter.
type OrganizationOperations interface {
Create(ctx context.Context, command organization.CreateCommand) (organization.CreateResult, error)
Get(ctx context.Context, actorID, organizationID uuid.UUID) (domain.Organization, error)
Update(ctx context.Context, command organization.UpdateCommand) (domain.Organization, error)
}
// CreateOrganization delegates company creation to its business-area handler.
func (handler *Handler) CreateOrganization(
ctx context.Context,
request *api.OrganizationCreate,
params api.CreateOrganizationParams,
) (api.CreateOrganizationRes, error) {
if handler.organization == nil {
return handler.UnimplementedHandler.CreateOrganization(ctx, request, params)
}
return handler.organization.CreateOrganization(ctx, request, params)
}
// GetOrganization delegates company reads to their business-area handler.
func (handler *Handler) GetOrganization(
ctx context.Context,
params api.GetOrganizationParams,
) (api.GetOrganizationRes, error) {
if handler.organization == nil {
return handler.UnimplementedHandler.GetOrganization(ctx, params)
}
return handler.organization.GetOrganization(ctx, params)
}
// UpdateOrganization delegates company edits to their business-area handler.
func (handler *Handler) UpdateOrganization(
ctx context.Context,
request *api.OrganizationUpdate,
params api.UpdateOrganizationParams,
) (api.UpdateOrganizationRes, error) {
if handler.organization == nil {
return handler.UnimplementedHandler.UpdateOrganization(ctx, request, params)
}
return handler.organization.UpdateOrganization(ctx, request, params)
}
// OrganizationHandler serves organization create, read, and profile update
// operations.
type OrganizationHandler struct {
operations OrganizationOperations
publicOrigin string
}
func NewOrganizationHandler(operations OrganizationOperations, publicOrigin string) *OrganizationHandler {
return &OrganizationHandler{operations: operations, publicOrigin: publicOrigin}
}
func (handler *OrganizationHandler) CreateOrganization(
ctx context.Context,
request *api.OrganizationCreate,
params api.CreateOrganizationParams,
) (api.CreateOrganizationRes, error) {
principal, ok := PrincipalFromContext(ctx)
if !ok {
return (*api.CreateOrganizationUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
}
if !originAllowed(ctx, handler.publicOrigin) {
return (*api.CreateOrganizationForbidden)(&problem.New(ctx, api.ProblemCodeCsrfCheckFailed).Response), nil
}
if request == nil {
return (*api.CreateOrganizationBadRequest)(&problem.InvalidField(ctx, api.ProblemFieldLocationBody, "").Response), nil
}
canonicalBody, err := json.Marshal(request)
if err != nil {
return nil, err
}
result, err := handler.operations.Create(ctx, organization.CreateCommand{
ActorID: principal.UserID, IdempotencyKey: params.IdempotencyKey, CanonicalBody: canonicalBody,
Profile: createProfileInput(request),
})
if err != nil {
return createOrganizationFailure(ctx, err)
}
return &api.OrganizationHeaders{
CacheControl: api.CacheControlNoStoreNoStore,
Response: organizationFromDomain(result.Organization),
}, nil
}
func (handler *OrganizationHandler) GetOrganization(
ctx context.Context,
params api.GetOrganizationParams,
) (api.GetOrganizationRes, error) {
principal, ok := PrincipalFromContext(ctx)
if !ok {
return (*api.GetOrganizationUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
}
company, err := handler.operations.Get(ctx, principal.UserID, params.OrgID)
if err != nil {
return getOrganizationFailure(ctx, err)
}
return &api.OrganizationHeaders{
CacheControl: api.CacheControlNoStoreNoStore,
Response: organizationFromDomain(company),
}, nil
}
func (handler *OrganizationHandler) UpdateOrganization(
ctx context.Context,
request *api.OrganizationUpdate,
params api.UpdateOrganizationParams,
) (api.UpdateOrganizationRes, error) {
principal, ok := PrincipalFromContext(ctx)
if !ok {
return (*api.UpdateOrganizationUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
}
if !originAllowed(ctx, handler.publicOrigin) {
return (*api.UpdateOrganizationForbidden)(&problem.New(ctx, api.ProblemCodeCsrfCheckFailed).Response), nil
}
if request == nil {
return (*api.UpdateOrganizationBadRequest)(&problem.InvalidField(ctx, api.ProblemFieldLocationBody, "").Response), nil
}
company, err := handler.operations.Update(ctx, organization.UpdateCommand{
ActorID: principal.UserID, OrganizationID: params.OrgID,
ExpectedVersion: int64(request.ExpectedVersion), Patch: updateProfilePatch(request),
})
if err != nil {
return updateOrganizationFailure(ctx, err)
}
return &api.OrganizationHeaders{
CacheControl: api.CacheControlNoStoreNoStore,
Response: organizationFromDomain(company),
}, nil
}
func createProfileInput(request *api.OrganizationCreate) domain.OrganizationProfileInput {
contacts := request.Contacts.Or(api.OrganizationContactChannels{})
description, _ := request.Description.Get()
sphere, _ := request.Sphere.Get()
representatives := make([]domain.OrganizationRepresentativeInput, 0, len(request.Representatives))
for _, representative := range request.Representatives {
representatives = append(representatives, domain.OrganizationRepresentativeInput{
Name: representative.Name, JobTitle: representative.JobTitle,
})
}
return domain.OrganizationProfileInput{
Name: string(request.Name), Description: string(description), Sphere: string(sphere),
Contacts: contactsToDomain(contacts), Representatives: representatives,
}
}
func updateProfilePatch(request *api.OrganizationUpdate) organization.ProfilePatch {
var patch organization.ProfilePatch
if request.Name.Set {
patch.Name = organization.OptionalString{Set: true, Value: string(request.Name.Value)}
}
if request.Description.Set {
value := ""
if !request.Description.Null {
value = string(request.Description.Value)
}
patch.Description = organization.OptionalString{Set: true, Value: value}
}
if request.Sphere.Set {
value := ""
if !request.Sphere.Null {
value = string(request.Sphere.Value)
}
patch.Sphere = organization.OptionalString{Set: true, Value: value}
}
if request.Contacts.Set {
contacts, _ := request.Contacts.Get()
input := contactsToDomain(contacts)
patch.Contacts = &input
}
if request.Representatives != nil {
representatives := make([]domain.OrganizationRepresentativeInput, 0, len(request.Representatives))
for _, representative := range request.Representatives {
representatives = append(representatives, domain.OrganizationRepresentativeInput{
Name: representative.Name, JobTitle: representative.JobTitle,
})
}
patch.Representatives = &representatives
}
return patch
}
func contactsToDomain(contacts api.OrganizationContactChannels) domain.OrganizationContactsInput {
website, _ := contacts.Website.Get()
email, _ := contacts.Email.Get()
phone, _ := contacts.Phone.Get()
telegram, _ := contacts.Telegram.Get()
return domain.OrganizationContactsInput{
Website: string(website), Email: string(email), Phone: string(phone), Telegram: string(telegram),
}
}
func organizationFromDomain(company domain.Organization) api.Organization {
profile := company.Profile()
verification := company.Verification()
representatives := representativesFromDomain(profile.Representatives())
card := company.CandidateCard()
return api.Organization{
ID: company.ID(), Version: api.OrganizationVersion(company.Version()),
Name: api.OrganizationName(profile.Name()), Description: nullableDescription(profile.Description()),
Sphere: nullableSphere(profile.Sphere()), Contacts: contactsFromDomain(profile.Contacts()),
Representatives: representatives,
Verification: api.OrganizationVerification{
Level: api.OrganizationVerificationLevel(verification.Level()),
Basis: api.OrganizationVerificationBasis(verification.Basis()),
ChangedAt: api.Timestamp(verification.ChangedAt()),
},
CandidateCard: candidateCardFromDomain(card),
CreatedAt: api.Timestamp(company.CreatedAt()),
UpdatedAt: api.Timestamp(company.UpdatedAt()),
}
}
func candidateCardFromDomain(card domain.OrganizationCandidateCard) api.CandidateOrganizationCard {
profile := card.Profile()
representatives := representativesFromDomain(profile.Representatives())
optionalRepresentatives := api.NewOptNilOrganizationRepresentativeArray(representatives)
return api.CandidateOrganizationCard{
ID: card.ID(), Name: api.OrganizationName(profile.Name()),
Description: nullableDescription(profile.Description()), Sphere: nullableSphere(profile.Sphere()),
Contacts: contactsFromDomain(profile.Contacts()), Representatives: optionalRepresentatives,
VerificationLevel: api.OrganizationVerificationLevel(card.VerificationLevel()),
}
}
func representativesFromDomain(source []domain.OrganizationRepresentative) []api.OrganizationRepresentative {
representatives := make([]api.OrganizationRepresentative, 0, len(source))
for _, representative := range source {
representatives = append(representatives, api.OrganizationRepresentative{
Name: representative.Name(), JobTitle: representative.JobTitle(),
})
}
return representatives
}
func nullableDescription(value string) api.NilOrganizationDescription {
if value == "" {
return api.NilOrganizationDescription{Null: true}
}
return api.NewNilOrganizationDescription(api.OrganizationDescription(value))
}
func nullableSphere(value string) api.NilOrganizationSphere {
if value == "" {
return api.NilOrganizationSphere{Null: true}
}
return api.NewNilOrganizationSphere(api.OrganizationSphere(value))
}
func contactsFromDomain(contacts domain.OrganizationContacts) api.OrganizationContactChannels {
return api.OrganizationContactChannels{
Website: nullableWebsite(contacts.Website()), Email: nullableEmail(contacts.Email()),
Phone: nullablePhone(contacts.Phone()), Telegram: nullableTelegram(contacts.Telegram()),
}
}
func nullableWebsite(value string) api.NilOrganizationWebsite {
if value == "" {
return api.NilOrganizationWebsite{Null: true}
}
return api.NewNilOrganizationWebsite(api.OrganizationWebsite(value))
}
func nullableEmail(value string) api.NilEmailAddress {
if value == "" {
return api.NilEmailAddress{Null: true}
}
return api.NewNilEmailAddress(api.EmailAddress(value))
}
func nullablePhone(value string) api.NilContactPhoneNumber {
if value == "" {
return api.NilContactPhoneNumber{Null: true}
}
return api.NewNilContactPhoneNumber(api.ContactPhoneNumber(value))
}
func nullableTelegram(value string) api.NilContactTelegramUsername {
if value == "" {
return api.NilContactTelegramUsername{Null: true}
}
return api.NewNilContactTelegramUsername(api.ContactTelegramUsername(value))
}
func createOrganizationFailure(ctx context.Context, err error) (api.CreateOrganizationRes, error) {
switch {
case errors.Is(err, organization.ErrForbidden):
return (*api.CreateOrganizationForbidden)(&problem.New(ctx, api.ProblemCodeForbidden).Response), nil
case errors.Is(err, organization.ErrEmailNotVerified):
return (*api.CreateOrganizationForbidden)(&problem.New(ctx, api.ProblemCodeEmailNotVerified).Response), nil
case errors.Is(err, organization.ErrIdempotencyKeyReused):
return (*api.CreateOrganizationUnprocessableEntity)(&problem.New(ctx, api.ProblemCodeIdempotencyKeyReused).Response), nil
case errors.Is(err, organization.ErrInvalidIdempotencyKey):
return (*api.CreateOrganizationBadRequest)(&problem.InvalidField(ctx, api.ProblemFieldLocationHeader, "/Idempotency-Key").Response), nil
case errors.Is(err, organization.ErrInvalidCreateRequest):
return (*api.CreateOrganizationBadRequest)(&problem.InvalidField(ctx, api.ProblemFieldLocationBody, "").Response), nil
case errors.Is(err, domain.ErrInvalidOrganization):
return (*api.CreateOrganizationBadRequest)(&organizationFieldProblem(ctx, err).Response), nil
default:
return nil, err
}
}
func getOrganizationFailure(ctx context.Context, err error) (api.GetOrganizationRes, error) {
switch {
case errors.Is(err, organization.ErrForbidden):
return (*api.GetOrganizationForbidden)(&problem.New(ctx, api.ProblemCodeForbidden).Response), nil
case errors.Is(err, organization.ErrEmailNotVerified):
return (*api.GetOrganizationForbidden)(&problem.New(ctx, api.ProblemCodeEmailNotVerified).Response), nil
case errors.Is(err, outbound.ErrOrganizationNotFound):
return (*api.GetOrganizationNotFound)(&problem.New(ctx, api.ProblemCodeNotFound).Response), nil
default:
return nil, err
}
}
func updateOrganizationFailure(ctx context.Context, err error) (api.UpdateOrganizationRes, error) {
switch {
case errors.Is(err, organization.ErrForbidden), errors.Is(err, outbound.ErrOrganizationManagerRequired):
return (*api.UpdateOrganizationForbidden)(&problem.New(ctx, api.ProblemCodeForbidden).Response), nil
case errors.Is(err, organization.ErrEmailNotVerified):
return (*api.UpdateOrganizationForbidden)(&problem.New(ctx, api.ProblemCodeEmailNotVerified).Response), nil
case errors.Is(err, outbound.ErrOrganizationNotFound):
return (*api.UpdateOrganizationNotFound)(&problem.New(ctx, api.ProblemCodeNotFound).Response), nil
case errors.Is(err, outbound.ErrOrganizationVersionConflict):
return (*api.UpdateOrganizationPreconditionFailed)(&problem.New(ctx, api.ProblemCodeVersionConflict).Response), nil
case errors.Is(err, domain.ErrInvalidOrganization):
return (*api.UpdateOrganizationBadRequest)(&organizationFieldProblem(ctx, err).Response), nil
default:
return nil, err
}
}
func organizationFieldProblem(ctx context.Context, err error) *api.ProblemStatusCode {
field, ok := errors.AsType[*domain.OrganizationFieldError](err)
if !ok {
return problem.InvalidField(ctx, api.ProblemFieldLocationBody, "")
}
return problem.InvalidField(ctx, api.ProblemFieldLocationBody, field.Pointer)
}