feat(visibility): add the candidate publication, hiding and search status contract
This commit is contained in:
1 parent
4436f626a3
commit
0529601021
87 files changed
+21456
-83
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -65,10 +65,18 @@ type GetMyAssessmentResultRes interface {
|
||||
getMyAssessmentResultRes()
|
||||
}
|
||||
|
||||
type GetMyCardPreviewRes interface {
|
||||
getMyCardPreviewRes()
|
||||
}
|
||||
|
||||
type GetMyInvitationRes interface {
|
||||
getMyInvitationRes()
|
||||
}
|
||||
|
||||
type GetMyPrivacySettingsRes interface {
|
||||
getMyPrivacySettingsRes()
|
||||
}
|
||||
|
||||
type GetMyProfileRes interface {
|
||||
getMyProfileRes()
|
||||
}
|
||||
@@ -97,10 +105,22 @@ type GetOrganizationRes interface {
|
||||
getOrganizationRes()
|
||||
}
|
||||
|
||||
type HideOrganizationRes interface {
|
||||
hideOrganizationRes()
|
||||
}
|
||||
|
||||
type ListMyCardAccessHistoryRes interface {
|
||||
listMyCardAccessHistoryRes()
|
||||
}
|
||||
|
||||
type ListMyConsentsRes interface {
|
||||
listMyConsentsRes()
|
||||
}
|
||||
|
||||
type ListMyHiddenOrganizationsRes interface {
|
||||
listMyHiddenOrganizationsRes()
|
||||
}
|
||||
|
||||
type ListMyInvitationsRes interface {
|
||||
listMyInvitationsRes()
|
||||
}
|
||||
@@ -109,6 +129,10 @@ type ListMyOrganizationsRes interface {
|
||||
listMyOrganizationsRes()
|
||||
}
|
||||
|
||||
type ListMyPrivacyHistoryRes interface {
|
||||
listMyPrivacyHistoryRes()
|
||||
}
|
||||
|
||||
type ListMySupportCasesRes interface {
|
||||
listMySupportCasesRes()
|
||||
}
|
||||
@@ -153,10 +177,22 @@ type SendOrganizationInvitationRes interface {
|
||||
sendOrganizationInvitationRes()
|
||||
}
|
||||
|
||||
type SetMyPublicationRes interface {
|
||||
setMyPublicationRes()
|
||||
}
|
||||
|
||||
type SetMySearchStatusRes interface {
|
||||
setMySearchStatusRes()
|
||||
}
|
||||
|
||||
type SubmitMyAssessmentAnswerRes interface {
|
||||
submitMyAssessmentAnswerRes()
|
||||
}
|
||||
|
||||
type UnhideOrganizationRes interface {
|
||||
unhideOrganizationRes()
|
||||
}
|
||||
|
||||
type UpdateOrganizationInvitationRes interface {
|
||||
updateOrganizationInvitationRes()
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -23,7 +23,9 @@ const (
|
||||
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"
|
||||
@@ -32,9 +34,13 @@ const (
|
||||
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"
|
||||
@@ -46,7 +52,10 @@ const (
|
||||
SaveMyProfileOperation OperationName = "SaveMyProfile"
|
||||
SaveMyQuestionnaireOperation OperationName = "SaveMyQuestionnaire"
|
||||
SendOrganizationInvitationOperation OperationName = "SendOrganizationInvitation"
|
||||
SetMyPublicationOperation OperationName = "SetMyPublication"
|
||||
SetMySearchStatusOperation OperationName = "SetMySearchStatus"
|
||||
SubmitMyAssessmentAnswerOperation OperationName = "SubmitMyAssessmentAnswer"
|
||||
UnhideOrganizationOperation OperationName = "UnhideOrganization"
|
||||
UpdateOrganizationOperation OperationName = "UpdateOrganization"
|
||||
UpdateOrganizationInvitationOperation OperationName = "UpdateOrganizationInvitation"
|
||||
UpdateOrganizationNeedOperation OperationName = "UpdateOrganizationNeed"
|
||||
|
||||
@@ -1982,6 +1982,252 @@ func decodeGetOrganizationNeedParams(args [2]string, argsEscaped bool, r *http.R
|
||||
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
|
||||
// names the target of a candidate's own setting and grants the candidate nothing about the
|
||||
// organization. Hiding answers the same 404 not_found for an organization that does not exist and for
|
||||
// one that the candidate cannot see, so organizations cannot be enumerated; lifting the hiding answers
|
||||
// 204 for any well-formed identifier.
|
||||
OrgID uuid.UUID
|
||||
}
|
||||
|
||||
func unpackHideOrganizationParams(packed middleware.Parameters) (params HideOrganizationParams) {
|
||||
{
|
||||
key := middleware.ParameterKey{
|
||||
Name: "org_id",
|
||||
In: "path",
|
||||
}
|
||||
params.OrgID = packed[key].(uuid.UUID)
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
func decodeHideOrganizationParams(args [1]string, argsEscaped bool, r *http.Request) (params HideOrganizationParams, _ 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
|
||||
}
|
||||
|
||||
// ListMyCardAccessHistoryParams is parameters of ListMyCardAccessHistory operation.
|
||||
type ListMyCardAccessHistoryParams struct {
|
||||
// Maximum number of items in the page. The server may return fewer items even when more remain; use
|
||||
// `page.has_more` to detect the end.
|
||||
Limit OptInt32 `json:",omitempty,omitzero"`
|
||||
// Opaque `page.next_cursor` value from the previous page of the same listing. Omit it to read the
|
||||
// first page. A malformed or foreign cursor returns 400 with code validation_failed.
|
||||
Cursor OptString `json:",omitempty,omitzero"`
|
||||
}
|
||||
|
||||
func unpackListMyCardAccessHistoryParams(packed middleware.Parameters) (params ListMyCardAccessHistoryParams) {
|
||||
{
|
||||
key := middleware.ParameterKey{
|
||||
Name: "limit",
|
||||
In: "query",
|
||||
}
|
||||
if v, ok := packed[key]; ok {
|
||||
params.Limit = v.(OptInt32)
|
||||
}
|
||||
}
|
||||
{
|
||||
key := middleware.ParameterKey{
|
||||
Name: "cursor",
|
||||
In: "query",
|
||||
}
|
||||
if v, ok := packed[key]; ok {
|
||||
params.Cursor = v.(OptString)
|
||||
}
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
func decodeListMyCardAccessHistoryParams(args [0]string, argsEscaped bool, r *http.Request) (params ListMyCardAccessHistoryParams, _ error) {
|
||||
q := uri.NewQueryDecoder(r.URL.Query())
|
||||
// Set default value for query: limit.
|
||||
{
|
||||
val := int32(20)
|
||||
params.Limit.SetTo(val)
|
||||
}
|
||||
// Decode query: limit.
|
||||
if err := func() error {
|
||||
cfg := uri.QueryParameterDecodingConfig{
|
||||
Name: "limit",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.HasParam(cfg); err == nil {
|
||||
if err := q.DecodeParam(cfg, func(d uri.Decoder) error {
|
||||
var paramsDotLimitVal int32
|
||||
if err := func() error {
|
||||
val, err := d.DecodeValue()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := conv.ToInt32(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
paramsDotLimitVal = c
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
params.Limit.SetTo(paramsDotLimitVal)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := func() error {
|
||||
if value, ok := params.Limit.Get(); ok {
|
||||
if err := func() error {
|
||||
if err := (validate.Int{
|
||||
MinSet: true,
|
||||
Min: 1,
|
||||
MaxSet: true,
|
||||
Max: 100,
|
||||
MinExclusive: false,
|
||||
MaxExclusive: false,
|
||||
MultipleOfSet: false,
|
||||
MultipleOf: 0,
|
||||
Pattern: nil,
|
||||
}).Validate(int64(value)); err != nil {
|
||||
return errors.Wrap(err, "int")
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return params, &ogenerrors.DecodeParamError{
|
||||
Name: "limit",
|
||||
In: "query",
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
// Decode query: cursor.
|
||||
if err := func() error {
|
||||
cfg := uri.QueryParameterDecodingConfig{
|
||||
Name: "cursor",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.HasParam(cfg); err == nil {
|
||||
if err := q.DecodeParam(cfg, func(d uri.Decoder) error {
|
||||
var paramsDotCursorVal string
|
||||
if err := func() error {
|
||||
val, err := d.DecodeValue()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := conv.ToString(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
paramsDotCursorVal = c
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
params.Cursor.SetTo(paramsDotCursorVal)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := func() error {
|
||||
if value, ok := params.Cursor.Get(); ok {
|
||||
if err := func() error {
|
||||
if err := (validate.String{
|
||||
MinLength: 1,
|
||||
MinLengthSet: true,
|
||||
MaxLength: 512,
|
||||
MaxLengthSet: true,
|
||||
Email: false,
|
||||
Hostname: false,
|
||||
Regex: regexMap["^[A-Za-z0-9_-]+$"],
|
||||
MinNumeric: 0,
|
||||
MinNumericSet: false,
|
||||
MaxNumeric: 0,
|
||||
MaxNumericSet: false,
|
||||
}).Validate(string(value)); err != nil {
|
||||
return errors.Wrap(err, "string")
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return params, &ogenerrors.DecodeParamError{
|
||||
Name: "cursor",
|
||||
In: "query",
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
return params, nil
|
||||
}
|
||||
|
||||
// ListMyConsentsParams is parameters of ListMyConsents operation.
|
||||
type ListMyConsentsParams struct {
|
||||
// Lists only the records in this state; omit it for the whole history.
|
||||
@@ -2225,6 +2471,182 @@ func decodeListMyConsentsParams(args [0]string, argsEscaped bool, r *http.Reques
|
||||
return params, nil
|
||||
}
|
||||
|
||||
// ListMyHiddenOrganizationsParams is parameters of ListMyHiddenOrganizations operation.
|
||||
type ListMyHiddenOrganizationsParams struct {
|
||||
// Maximum number of items in the page. The server may return fewer items even when more remain; use
|
||||
// `page.has_more` to detect the end.
|
||||
Limit OptInt32 `json:",omitempty,omitzero"`
|
||||
// Opaque `page.next_cursor` value from the previous page of the same listing. Omit it to read the
|
||||
// first page. A malformed or foreign cursor returns 400 with code validation_failed.
|
||||
Cursor OptString `json:",omitempty,omitzero"`
|
||||
}
|
||||
|
||||
func unpackListMyHiddenOrganizationsParams(packed middleware.Parameters) (params ListMyHiddenOrganizationsParams) {
|
||||
{
|
||||
key := middleware.ParameterKey{
|
||||
Name: "limit",
|
||||
In: "query",
|
||||
}
|
||||
if v, ok := packed[key]; ok {
|
||||
params.Limit = v.(OptInt32)
|
||||
}
|
||||
}
|
||||
{
|
||||
key := middleware.ParameterKey{
|
||||
Name: "cursor",
|
||||
In: "query",
|
||||
}
|
||||
if v, ok := packed[key]; ok {
|
||||
params.Cursor = v.(OptString)
|
||||
}
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
func decodeListMyHiddenOrganizationsParams(args [0]string, argsEscaped bool, r *http.Request) (params ListMyHiddenOrganizationsParams, _ error) {
|
||||
q := uri.NewQueryDecoder(r.URL.Query())
|
||||
// Set default value for query: limit.
|
||||
{
|
||||
val := int32(20)
|
||||
params.Limit.SetTo(val)
|
||||
}
|
||||
// Decode query: limit.
|
||||
if err := func() error {
|
||||
cfg := uri.QueryParameterDecodingConfig{
|
||||
Name: "limit",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.HasParam(cfg); err == nil {
|
||||
if err := q.DecodeParam(cfg, func(d uri.Decoder) error {
|
||||
var paramsDotLimitVal int32
|
||||
if err := func() error {
|
||||
val, err := d.DecodeValue()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := conv.ToInt32(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
paramsDotLimitVal = c
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
params.Limit.SetTo(paramsDotLimitVal)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := func() error {
|
||||
if value, ok := params.Limit.Get(); ok {
|
||||
if err := func() error {
|
||||
if err := (validate.Int{
|
||||
MinSet: true,
|
||||
Min: 1,
|
||||
MaxSet: true,
|
||||
Max: 100,
|
||||
MinExclusive: false,
|
||||
MaxExclusive: false,
|
||||
MultipleOfSet: false,
|
||||
MultipleOf: 0,
|
||||
Pattern: nil,
|
||||
}).Validate(int64(value)); err != nil {
|
||||
return errors.Wrap(err, "int")
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return params, &ogenerrors.DecodeParamError{
|
||||
Name: "limit",
|
||||
In: "query",
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
// Decode query: cursor.
|
||||
if err := func() error {
|
||||
cfg := uri.QueryParameterDecodingConfig{
|
||||
Name: "cursor",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.HasParam(cfg); err == nil {
|
||||
if err := q.DecodeParam(cfg, func(d uri.Decoder) error {
|
||||
var paramsDotCursorVal string
|
||||
if err := func() error {
|
||||
val, err := d.DecodeValue()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := conv.ToString(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
paramsDotCursorVal = c
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
params.Cursor.SetTo(paramsDotCursorVal)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := func() error {
|
||||
if value, ok := params.Cursor.Get(); ok {
|
||||
if err := func() error {
|
||||
if err := (validate.String{
|
||||
MinLength: 1,
|
||||
MinLengthSet: true,
|
||||
MaxLength: 512,
|
||||
MaxLengthSet: true,
|
||||
Email: false,
|
||||
Hostname: false,
|
||||
Regex: regexMap["^[A-Za-z0-9_-]+$"],
|
||||
MinNumeric: 0,
|
||||
MinNumericSet: false,
|
||||
MaxNumeric: 0,
|
||||
MaxNumericSet: false,
|
||||
}).Validate(string(value)); err != nil {
|
||||
return errors.Wrap(err, "string")
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return params, &ogenerrors.DecodeParamError{
|
||||
Name: "cursor",
|
||||
In: "query",
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
return params, nil
|
||||
}
|
||||
|
||||
// ListMyInvitationsParams is parameters of ListMyInvitations operation.
|
||||
type ListMyInvitationsParams struct {
|
||||
// Maximum number of items in the page. The server may return fewer items even when more remain; use
|
||||
@@ -2577,6 +2999,182 @@ func decodeListMyOrganizationsParams(args [0]string, argsEscaped bool, r *http.R
|
||||
return params, nil
|
||||
}
|
||||
|
||||
// ListMyPrivacyHistoryParams is parameters of ListMyPrivacyHistory operation.
|
||||
type ListMyPrivacyHistoryParams struct {
|
||||
// Maximum number of items in the page. The server may return fewer items even when more remain; use
|
||||
// `page.has_more` to detect the end.
|
||||
Limit OptInt32 `json:",omitempty,omitzero"`
|
||||
// Opaque `page.next_cursor` value from the previous page of the same listing. Omit it to read the
|
||||
// first page. A malformed or foreign cursor returns 400 with code validation_failed.
|
||||
Cursor OptString `json:",omitempty,omitzero"`
|
||||
}
|
||||
|
||||
func unpackListMyPrivacyHistoryParams(packed middleware.Parameters) (params ListMyPrivacyHistoryParams) {
|
||||
{
|
||||
key := middleware.ParameterKey{
|
||||
Name: "limit",
|
||||
In: "query",
|
||||
}
|
||||
if v, ok := packed[key]; ok {
|
||||
params.Limit = v.(OptInt32)
|
||||
}
|
||||
}
|
||||
{
|
||||
key := middleware.ParameterKey{
|
||||
Name: "cursor",
|
||||
In: "query",
|
||||
}
|
||||
if v, ok := packed[key]; ok {
|
||||
params.Cursor = v.(OptString)
|
||||
}
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
func decodeListMyPrivacyHistoryParams(args [0]string, argsEscaped bool, r *http.Request) (params ListMyPrivacyHistoryParams, _ error) {
|
||||
q := uri.NewQueryDecoder(r.URL.Query())
|
||||
// Set default value for query: limit.
|
||||
{
|
||||
val := int32(20)
|
||||
params.Limit.SetTo(val)
|
||||
}
|
||||
// Decode query: limit.
|
||||
if err := func() error {
|
||||
cfg := uri.QueryParameterDecodingConfig{
|
||||
Name: "limit",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.HasParam(cfg); err == nil {
|
||||
if err := q.DecodeParam(cfg, func(d uri.Decoder) error {
|
||||
var paramsDotLimitVal int32
|
||||
if err := func() error {
|
||||
val, err := d.DecodeValue()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := conv.ToInt32(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
paramsDotLimitVal = c
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
params.Limit.SetTo(paramsDotLimitVal)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := func() error {
|
||||
if value, ok := params.Limit.Get(); ok {
|
||||
if err := func() error {
|
||||
if err := (validate.Int{
|
||||
MinSet: true,
|
||||
Min: 1,
|
||||
MaxSet: true,
|
||||
Max: 100,
|
||||
MinExclusive: false,
|
||||
MaxExclusive: false,
|
||||
MultipleOfSet: false,
|
||||
MultipleOf: 0,
|
||||
Pattern: nil,
|
||||
}).Validate(int64(value)); err != nil {
|
||||
return errors.Wrap(err, "int")
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return params, &ogenerrors.DecodeParamError{
|
||||
Name: "limit",
|
||||
In: "query",
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
// Decode query: cursor.
|
||||
if err := func() error {
|
||||
cfg := uri.QueryParameterDecodingConfig{
|
||||
Name: "cursor",
|
||||
Style: uri.QueryStyleForm,
|
||||
Explode: true,
|
||||
}
|
||||
|
||||
if err := q.HasParam(cfg); err == nil {
|
||||
if err := q.DecodeParam(cfg, func(d uri.Decoder) error {
|
||||
var paramsDotCursorVal string
|
||||
if err := func() error {
|
||||
val, err := d.DecodeValue()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := conv.ToString(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
paramsDotCursorVal = c
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
params.Cursor.SetTo(paramsDotCursorVal)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := func() error {
|
||||
if value, ok := params.Cursor.Get(); ok {
|
||||
if err := func() error {
|
||||
if err := (validate.String{
|
||||
MinLength: 1,
|
||||
MinLengthSet: true,
|
||||
MaxLength: 512,
|
||||
MaxLengthSet: true,
|
||||
Email: false,
|
||||
Hostname: false,
|
||||
Regex: regexMap["^[A-Za-z0-9_-]+$"],
|
||||
MinNumeric: 0,
|
||||
MinNumericSet: false,
|
||||
MaxNumeric: 0,
|
||||
MaxNumericSet: false,
|
||||
}).Validate(string(value)); err != nil {
|
||||
return errors.Wrap(err, "string")
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return params, &ogenerrors.DecodeParamError{
|
||||
Name: "cursor",
|
||||
In: "query",
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
return params, nil
|
||||
}
|
||||
|
||||
// ListMySupportCasesParams is parameters of ListMySupportCases operation.
|
||||
type ListMySupportCasesParams struct {
|
||||
// Maximum number of items in the page. The server may return fewer items even when more remain; use
|
||||
@@ -3874,6 +4472,76 @@ func decodeSubmitMyAssessmentAnswerParams(args [1]string, argsEscaped bool, r *h
|
||||
return params, nil
|
||||
}
|
||||
|
||||
// UnhideOrganizationParams is parameters of UnhideOrganization operation.
|
||||
type UnhideOrganizationParams struct {
|
||||
// Identifier of the organization that the current candidate hides or stops hiding the profile from. It
|
||||
// names the target of a candidate's own setting and grants the candidate nothing about the
|
||||
// organization. Hiding answers the same 404 not_found for an organization that does not exist and for
|
||||
// one that the candidate cannot see, so organizations cannot be enumerated; lifting the hiding answers
|
||||
// 204 for any well-formed identifier.
|
||||
OrgID uuid.UUID
|
||||
}
|
||||
|
||||
func unpackUnhideOrganizationParams(packed middleware.Parameters) (params UnhideOrganizationParams) {
|
||||
{
|
||||
key := middleware.ParameterKey{
|
||||
Name: "org_id",
|
||||
In: "path",
|
||||
}
|
||||
params.OrgID = packed[key].(uuid.UUID)
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
func decodeUnhideOrganizationParams(args [1]string, argsEscaped bool, r *http.Request) (params UnhideOrganizationParams, _ 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
|
||||
}
|
||||
|
||||
// UpdateOrganizationParams is parameters of UpdateOrganization operation.
|
||||
type UpdateOrganizationParams struct {
|
||||
// Identifier of an organization. Access comes only from an active membership of the session account in
|
||||
|
||||
@@ -1357,6 +1357,164 @@ func (s *Server) decodeSendOrganizationInvitationRequest(r *http.Request) (
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) decodeSetMyPublicationRequest(r *http.Request) (
|
||||
req *PublicationUpdate,
|
||||
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 PublicationUpdate
|
||||
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) decodeSetMySearchStatusRequest(r *http.Request) (
|
||||
req *SearchStatusUpdate,
|
||||
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 SearchStatusUpdate
|
||||
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) decodeSubmitMyAssessmentAnswerRequest(r *http.Request) (
|
||||
req *AssessmentAnswerSubmission,
|
||||
rawBody []byte,
|
||||
|
||||
@@ -1683,6 +1683,65 @@ func encodeGetMyAssessmentResultResponse(response GetMyAssessmentResultRes, w ht
|
||||
}
|
||||
}
|
||||
|
||||
func encodeGetMyCardPreviewResponse(response GetMyCardPreviewRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *CardPreviewHeaders:
|
||||
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 *GetMyCardPreviewUnauthorized:
|
||||
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 *GetMyCardPreviewForbidden:
|
||||
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 encodeGetMyInvitationResponse(response GetMyInvitationRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *CandidateInvitationHeaders:
|
||||
@@ -1766,6 +1825,65 @@ func encodeGetMyInvitationResponse(response GetMyInvitationRes, w http.ResponseW
|
||||
}
|
||||
}
|
||||
|
||||
func encodeGetMyPrivacySettingsResponse(response GetMyPrivacySettingsRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *PrivacySettingsHeaders:
|
||||
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 *GetMyPrivacySettingsUnauthorized:
|
||||
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 *GetMyPrivacySettingsForbidden:
|
||||
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 encodeGetMyProfileResponse(response GetMyProfileRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *CandidateProfileHeaders:
|
||||
@@ -2300,6 +2418,204 @@ func encodeGetSpecializationCatalogResponse(response *SpecializationCatalog, w h
|
||||
return nil
|
||||
}
|
||||
|
||||
func encodeHideOrganizationResponse(response HideOrganizationRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *HiddenOrganizationHeaders:
|
||||
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 *HideOrganizationBadRequest:
|
||||
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 *HideOrganizationUnauthorized:
|
||||
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 *HideOrganizationForbidden:
|
||||
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
|
||||
|
||||
case *HideOrganizationNotFound:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(404)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *HideOrganizationConflict:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(409)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *TooManyRequestsHeaders:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.Header().Set("Access-Control-Expose-Headers", "Retry-After")
|
||||
// Encoding response headers.
|
||||
{
|
||||
h := uri.NewHeaderEncoder(w.Header())
|
||||
// Encode "Retry-After" header.
|
||||
{
|
||||
cfg := uri.HeaderParameterEncodingConfig{
|
||||
Name: "Retry-After",
|
||||
Explode: false,
|
||||
}
|
||||
if err := h.EncodeParam(cfg, func(e uri.Encoder) error {
|
||||
if val, ok := response.RetryAfter.Get(); ok {
|
||||
return e.EncodeValue(conv.Int32ToString(val))
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "encode Retry-After header")
|
||||
}
|
||||
}
|
||||
}
|
||||
w.WriteHeader(429)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.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 encodeListMyCardAccessHistoryResponse(response ListMyCardAccessHistoryRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *CardAccessListHeaders:
|
||||
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 *ListMyCardAccessHistoryBadRequest:
|
||||
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 *ListMyCardAccessHistoryUnauthorized:
|
||||
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 *ListMyCardAccessHistoryForbidden:
|
||||
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 encodeListMyConsentsResponse(response ListMyConsentsRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *ConsentRecordListHeaders:
|
||||
@@ -2359,6 +2675,77 @@ func encodeListMyConsentsResponse(response ListMyConsentsRes, w http.ResponseWri
|
||||
}
|
||||
}
|
||||
|
||||
func encodeListMyHiddenOrganizationsResponse(response ListMyHiddenOrganizationsRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *HiddenOrganizationListHeaders:
|
||||
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 *ListMyHiddenOrganizationsBadRequest:
|
||||
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 *ListMyHiddenOrganizationsUnauthorized:
|
||||
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 *ListMyHiddenOrganizationsForbidden:
|
||||
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 encodeListMyInvitationsResponse(response ListMyInvitationsRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *CandidateInvitationListHeaders:
|
||||
@@ -2501,6 +2888,77 @@ func encodeListMyOrganizationsResponse(response ListMyOrganizationsRes, w http.R
|
||||
}
|
||||
}
|
||||
|
||||
func encodeListMyPrivacyHistoryResponse(response ListMyPrivacyHistoryRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *PrivacyEventListHeaders:
|
||||
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 *ListMyPrivacyHistoryBadRequest:
|
||||
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 *ListMyPrivacyHistoryUnauthorized:
|
||||
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 *ListMyPrivacyHistoryForbidden:
|
||||
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 encodeListMySupportCasesResponse(response ListMySupportCasesRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *SupportCaseListHeaders:
|
||||
@@ -3554,6 +4012,184 @@ func encodeSendOrganizationInvitationResponse(response SendOrganizationInvitatio
|
||||
}
|
||||
}
|
||||
|
||||
func encodeSetMyPublicationResponse(response SetMyPublicationRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *PublicationHeaders:
|
||||
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 *SetMyPublicationBadRequest:
|
||||
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 *SetMyPublicationUnauthorized:
|
||||
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 *SetMyPublicationForbidden:
|
||||
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
|
||||
|
||||
case *SetMyPublicationConflict:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(409)
|
||||
|
||||
e := new(jx.Encoder)
|
||||
response.Encode(e)
|
||||
if _, err := e.WriteTo(w); err != nil {
|
||||
return errors.Wrap(err, "write")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
case *SetMyPublicationPreconditionFailed:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(412)
|
||||
|
||||
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 encodeSetMySearchStatusResponse(response SetMySearchStatusRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *SearchStatusHeaders:
|
||||
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 *SetMySearchStatusBadRequest:
|
||||
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 *SetMySearchStatusUnauthorized:
|
||||
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 *SetMySearchStatusForbidden:
|
||||
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
|
||||
|
||||
case *SetMySearchStatusPreconditionFailed:
|
||||
w.Header().Set("Content-Type", "application/problem+json")
|
||||
w.WriteHeader(412)
|
||||
|
||||
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 encodeSubmitMyAssessmentAnswerResponse(response SubmitMyAssessmentAnswerRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *AssessmentAttemptHeaders:
|
||||
@@ -3705,6 +4341,70 @@ func encodeSubmitMyAssessmentAnswerResponse(response SubmitMyAssessmentAnswerRes
|
||||
}
|
||||
}
|
||||
|
||||
func encodeUnhideOrganizationResponse(response UnhideOrganizationRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *UnhideOrganizationNoContent:
|
||||
// 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(204)
|
||||
|
||||
return nil
|
||||
|
||||
case *UnhideOrganizationBadRequest:
|
||||
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 *UnhideOrganizationUnauthorized:
|
||||
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 *UnhideOrganizationForbidden:
|
||||
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 encodeUpdateOrganizationResponse(response UpdateOrganizationRes, w http.ResponseWriter, span trace.Span) error {
|
||||
switch response := response.(type) {
|
||||
case *OrganizationHeaders:
|
||||
|
||||
@@ -11,16 +11,16 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
rn49AllowedHeaders = map[string]string{
|
||||
rn59AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type",
|
||||
}
|
||||
rn7AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type",
|
||||
}
|
||||
rn47AllowedHeaders = map[string]string{
|
||||
rn57AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type,Idempotency-Key",
|
||||
}
|
||||
rn44AllowedHeaders = map[string]string{
|
||||
rn54AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type",
|
||||
}
|
||||
rn25AllowedHeaders = map[string]string{
|
||||
@@ -29,7 +29,7 @@ var (
|
||||
rn9AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type,Idempotency-Key,X-Csrf-Token",
|
||||
}
|
||||
rn52AllowedHeaders = map[string]string{
|
||||
rn65AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type,Idempotency-Key,X-Csrf-Token",
|
||||
}
|
||||
rn20AllowedHeaders = map[string]string{
|
||||
@@ -44,13 +44,23 @@ var (
|
||||
rn17AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type,Idempotency-Key,X-Csrf-Token",
|
||||
}
|
||||
rn53AllowedHeaders = map[string]string{
|
||||
rn66AllowedHeaders = map[string]string{
|
||||
"POST": "X-Csrf-Token",
|
||||
}
|
||||
rn31AllowedHeaders = map[string]string{
|
||||
rn46AllowedHeaders = map[string]string{
|
||||
"DELETE": "X-Csrf-Token",
|
||||
"PUT": "X-Csrf-Token",
|
||||
}
|
||||
rn63AllowedHeaders = map[string]string{
|
||||
"PUT": "Content-Type,X-Csrf-Token",
|
||||
}
|
||||
rn32AllowedHeaders = map[string]string{
|
||||
rn64AllowedHeaders = map[string]string{
|
||||
"PUT": "Content-Type,X-Csrf-Token",
|
||||
}
|
||||
rn34AllowedHeaders = map[string]string{
|
||||
"PUT": "Content-Type,X-Csrf-Token",
|
||||
}
|
||||
rn35AllowedHeaders = map[string]string{
|
||||
"PUT": "Content-Type,X-Csrf-Token",
|
||||
}
|
||||
rn10AllowedHeaders = map[string]string{
|
||||
@@ -65,22 +75,22 @@ var (
|
||||
rn14AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type,Idempotency-Key,X-Csrf-Token",
|
||||
}
|
||||
rn36AllowedHeaders = map[string]string{
|
||||
rn39AllowedHeaders = map[string]string{
|
||||
"PATCH": "Content-Type,X-Csrf-Token",
|
||||
}
|
||||
rn46AllowedHeaders = map[string]string{
|
||||
rn56AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type,Idempotency-Key,X-Csrf-Token",
|
||||
}
|
||||
rn51AllowedHeaders = map[string]string{
|
||||
rn61AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type,Idempotency-Key,X-Csrf-Token",
|
||||
}
|
||||
rn54AllowedHeaders = map[string]string{
|
||||
rn67AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type,Idempotency-Key,X-Csrf-Token",
|
||||
}
|
||||
rn16AllowedHeaders = map[string]string{
|
||||
"POST": "Content-Type,Idempotency-Key,X-Csrf-Token",
|
||||
}
|
||||
rn39AllowedHeaders = map[string]string{
|
||||
rn42AllowedHeaders = map[string]string{
|
||||
"PATCH": "Content-Type,X-Csrf-Token",
|
||||
}
|
||||
)
|
||||
@@ -237,7 +247,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "POST",
|
||||
allowedHeaders: rn49AllowedHeaders,
|
||||
allowedHeaders: rn59AllowedHeaders,
|
||||
acceptPost: "application/json",
|
||||
acceptPatch: "",
|
||||
})
|
||||
@@ -314,7 +324,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "POST",
|
||||
allowedHeaders: rn47AllowedHeaders,
|
||||
allowedHeaders: rn57AllowedHeaders,
|
||||
acceptPost: "application/json",
|
||||
acceptPatch: "",
|
||||
})
|
||||
@@ -338,7 +348,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "POST",
|
||||
allowedHeaders: rn44AllowedHeaders,
|
||||
allowedHeaders: rn54AllowedHeaders,
|
||||
acceptPost: "application/json",
|
||||
acceptPatch: "",
|
||||
})
|
||||
@@ -491,7 +501,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "POST",
|
||||
allowedHeaders: rn52AllowedHeaders,
|
||||
allowedHeaders: rn65AllowedHeaders,
|
||||
acceptPost: "application/json",
|
||||
acceptPatch: "",
|
||||
})
|
||||
@@ -782,7 +792,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "POST",
|
||||
allowedHeaders: rn53AllowedHeaders,
|
||||
allowedHeaders: rn66AllowedHeaders,
|
||||
acceptPost: "",
|
||||
acceptPatch: "",
|
||||
})
|
||||
@@ -822,31 +832,304 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
case 'p': // Prefix: "profile"
|
||||
case 'p': // Prefix: "pr"
|
||||
|
||||
if l := len("profile"); len(elem) >= l && elem[0:l] == "profile" {
|
||||
if l := len("pr"); len(elem) >= l && elem[0:l] == "pr" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
// Leaf node.
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
s.handleGetMyProfileRequest([0]string{}, elemIsEscaped, w, r)
|
||||
case "PUT":
|
||||
s.handleSaveMyProfileRequest([0]string{}, elemIsEscaped, w, r)
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "GET,PUT",
|
||||
allowedHeaders: rn31AllowedHeaders,
|
||||
acceptPost: "",
|
||||
acceptPatch: "",
|
||||
})
|
||||
break
|
||||
}
|
||||
switch elem[0] {
|
||||
case 'i': // Prefix: "ivacy"
|
||||
|
||||
if l := len("ivacy"); len(elem) >= l && elem[0:l] == "ivacy" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
s.handleGetMyPrivacySettingsRequest([0]string{}, elemIsEscaped, w, r)
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "GET",
|
||||
allowedHeaders: nil,
|
||||
acceptPost: "",
|
||||
acceptPatch: "",
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
switch elem[0] {
|
||||
case '/': // Prefix: "/"
|
||||
|
||||
if l := len("/"); len(elem) >= l && elem[0:l] == "/" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
break
|
||||
}
|
||||
switch elem[0] {
|
||||
case 'a': // Prefix: "access-history"
|
||||
|
||||
if l := len("access-history"); len(elem) >= l && elem[0:l] == "access-history" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
// Leaf node.
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
s.handleListMyCardAccessHistoryRequest([0]string{}, elemIsEscaped, w, r)
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "GET",
|
||||
allowedHeaders: nil,
|
||||
acceptPost: "",
|
||||
acceptPatch: "",
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
case 'h': // Prefix: "hi"
|
||||
|
||||
if l := len("hi"); len(elem) >= l && elem[0:l] == "hi" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
break
|
||||
}
|
||||
switch elem[0] {
|
||||
case 'd': // Prefix: "dden-organizations"
|
||||
|
||||
if l := len("dden-organizations"); len(elem) >= l && elem[0:l] == "dden-organizations" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
s.handleListMyHiddenOrganizationsRequest([0]string{}, elemIsEscaped, w, r)
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "GET",
|
||||
allowedHeaders: nil,
|
||||
acceptPost: "",
|
||||
acceptPatch: "",
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
switch elem[0] {
|
||||
case '/': // Prefix: "/"
|
||||
|
||||
if l := len("/"); len(elem) >= l && elem[0:l] == "/" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
// Param: "org_id"
|
||||
// Leaf parameter, slashes are prohibited
|
||||
idx := strings.IndexByte(elem, '/')
|
||||
if idx >= 0 {
|
||||
break
|
||||
}
|
||||
args[0] = elem
|
||||
elem = ""
|
||||
|
||||
if len(elem) == 0 {
|
||||
// Leaf node.
|
||||
switch r.Method {
|
||||
case "DELETE":
|
||||
s.handleUnhideOrganizationRequest([1]string{
|
||||
args[0],
|
||||
}, elemIsEscaped, w, r)
|
||||
case "PUT":
|
||||
s.handleHideOrganizationRequest([1]string{
|
||||
args[0],
|
||||
}, elemIsEscaped, w, r)
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "DELETE,PUT",
|
||||
allowedHeaders: rn46AllowedHeaders,
|
||||
acceptPost: "",
|
||||
acceptPatch: "",
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case 's': // Prefix: "story"
|
||||
|
||||
if l := len("story"); len(elem) >= l && elem[0:l] == "story" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
// Leaf node.
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
s.handleListMyPrivacyHistoryRequest([0]string{}, elemIsEscaped, w, r)
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "GET",
|
||||
allowedHeaders: nil,
|
||||
acceptPost: "",
|
||||
acceptPatch: "",
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case 'p': // Prefix: "p"
|
||||
|
||||
if l := len("p"); len(elem) >= l && elem[0:l] == "p" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
break
|
||||
}
|
||||
switch elem[0] {
|
||||
case 'r': // Prefix: "review"
|
||||
|
||||
if l := len("review"); len(elem) >= l && elem[0:l] == "review" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
// Leaf node.
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
s.handleGetMyCardPreviewRequest([0]string{}, elemIsEscaped, w, r)
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "GET",
|
||||
allowedHeaders: nil,
|
||||
acceptPost: "",
|
||||
acceptPatch: "",
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
case 'u': // Prefix: "ublication"
|
||||
|
||||
if l := len("ublication"); len(elem) >= l && elem[0:l] == "ublication" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
// Leaf node.
|
||||
switch r.Method {
|
||||
case "PUT":
|
||||
s.handleSetMyPublicationRequest([0]string{}, elemIsEscaped, w, r)
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "PUT",
|
||||
allowedHeaders: rn63AllowedHeaders,
|
||||
acceptPost: "",
|
||||
acceptPatch: "",
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case 's': // Prefix: "search-status"
|
||||
|
||||
if l := len("search-status"); len(elem) >= l && elem[0:l] == "search-status" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
// Leaf node.
|
||||
switch r.Method {
|
||||
case "PUT":
|
||||
s.handleSetMySearchStatusRequest([0]string{}, elemIsEscaped, w, r)
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "PUT",
|
||||
allowedHeaders: rn64AllowedHeaders,
|
||||
acceptPost: "",
|
||||
acceptPatch: "",
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case 'o': // Prefix: "ofile"
|
||||
|
||||
if l := len("ofile"); len(elem) >= l && elem[0:l] == "ofile" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
// Leaf node.
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
s.handleGetMyProfileRequest([0]string{}, elemIsEscaped, w, r)
|
||||
case "PUT":
|
||||
s.handleSaveMyProfileRequest([0]string{}, elemIsEscaped, w, r)
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "GET,PUT",
|
||||
allowedHeaders: rn34AllowedHeaders,
|
||||
acceptPost: "",
|
||||
acceptPatch: "",
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
case 'q': // Prefix: "questionnaire"
|
||||
@@ -867,7 +1150,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "GET,PUT",
|
||||
allowedHeaders: rn32AllowedHeaders,
|
||||
allowedHeaders: rn35AllowedHeaders,
|
||||
acceptPost: "",
|
||||
acceptPatch: "",
|
||||
})
|
||||
@@ -1079,7 +1362,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "GET,PATCH",
|
||||
allowedHeaders: rn36AllowedHeaders,
|
||||
allowedHeaders: rn39AllowedHeaders,
|
||||
acceptPost: "",
|
||||
acceptPatch: "application/json",
|
||||
})
|
||||
@@ -1159,7 +1442,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "POST",
|
||||
allowedHeaders: rn46AllowedHeaders,
|
||||
allowedHeaders: rn56AllowedHeaders,
|
||||
acceptPost: "application/json",
|
||||
acceptPatch: "",
|
||||
})
|
||||
@@ -1187,7 +1470,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "POST",
|
||||
allowedHeaders: rn51AllowedHeaders,
|
||||
allowedHeaders: rn61AllowedHeaders,
|
||||
acceptPost: "application/json",
|
||||
acceptPatch: "",
|
||||
})
|
||||
@@ -1217,7 +1500,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "POST",
|
||||
allowedHeaders: rn54AllowedHeaders,
|
||||
allowedHeaders: rn67AllowedHeaders,
|
||||
acceptPost: "application/json",
|
||||
acceptPatch: "",
|
||||
})
|
||||
@@ -1295,7 +1578,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
default:
|
||||
s.notAllowed(w, r, notAllowedParams{
|
||||
allowedMethods: "GET,PATCH",
|
||||
allowedHeaders: rn39AllowedHeaders,
|
||||
allowedHeaders: rn42AllowedHeaders,
|
||||
acceptPost: "",
|
||||
acceptPatch: "application/json",
|
||||
})
|
||||
@@ -2110,38 +2393,314 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
|
||||
}
|
||||
}
|
||||
|
||||
case 'p': // Prefix: "profile"
|
||||
case 'p': // Prefix: "pr"
|
||||
|
||||
if l := len("profile"); len(elem) >= l && elem[0:l] == "profile" {
|
||||
if l := len("pr"); len(elem) >= l && elem[0:l] == "pr" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
// Leaf node.
|
||||
switch method {
|
||||
case "GET":
|
||||
r.name = GetMyProfileOperation
|
||||
r.summary = "Read the private profile of the current candidate."
|
||||
r.operationID = "GetMyProfile"
|
||||
r.operationGroup = ""
|
||||
r.pathPattern = "/api/v1/me/profile"
|
||||
r.args = args
|
||||
r.count = 0
|
||||
return r, true
|
||||
case "PUT":
|
||||
r.name = SaveMyProfileOperation
|
||||
r.summary = "Replace the private profile of the current candidate."
|
||||
r.operationID = "SaveMyProfile"
|
||||
r.operationGroup = ""
|
||||
r.pathPattern = "/api/v1/me/profile"
|
||||
r.args = args
|
||||
r.count = 0
|
||||
return r, true
|
||||
default:
|
||||
return
|
||||
break
|
||||
}
|
||||
switch elem[0] {
|
||||
case 'i': // Prefix: "ivacy"
|
||||
|
||||
if l := len("ivacy"); len(elem) >= l && elem[0:l] == "ivacy" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
switch method {
|
||||
case "GET":
|
||||
r.name = GetMyPrivacySettingsOperation
|
||||
r.summary = "Read the visibility settings of the current candidate."
|
||||
r.operationID = "GetMyPrivacySettings"
|
||||
r.operationGroup = ""
|
||||
r.pathPattern = "/api/v1/me/privacy"
|
||||
r.args = args
|
||||
r.count = 0
|
||||
return r, true
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
switch elem[0] {
|
||||
case '/': // Prefix: "/"
|
||||
|
||||
if l := len("/"); len(elem) >= l && elem[0:l] == "/" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
break
|
||||
}
|
||||
switch elem[0] {
|
||||
case 'a': // Prefix: "access-history"
|
||||
|
||||
if l := len("access-history"); len(elem) >= l && elem[0:l] == "access-history" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
// Leaf node.
|
||||
switch method {
|
||||
case "GET":
|
||||
r.name = ListMyCardAccessHistoryOperation
|
||||
r.summary = "List the accesses of organizations to the card of the current candidate."
|
||||
r.operationID = "ListMyCardAccessHistory"
|
||||
r.operationGroup = ""
|
||||
r.pathPattern = "/api/v1/me/privacy/access-history"
|
||||
r.args = args
|
||||
r.count = 0
|
||||
return r, true
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
case 'h': // Prefix: "hi"
|
||||
|
||||
if l := len("hi"); len(elem) >= l && elem[0:l] == "hi" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
break
|
||||
}
|
||||
switch elem[0] {
|
||||
case 'd': // Prefix: "dden-organizations"
|
||||
|
||||
if l := len("dden-organizations"); len(elem) >= l && elem[0:l] == "dden-organizations" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
switch method {
|
||||
case "GET":
|
||||
r.name = ListMyHiddenOrganizationsOperation
|
||||
r.summary = "List the organizations that the candidate hides the profile from."
|
||||
r.operationID = "ListMyHiddenOrganizations"
|
||||
r.operationGroup = ""
|
||||
r.pathPattern = "/api/v1/me/privacy/hidden-organizations"
|
||||
r.args = args
|
||||
r.count = 0
|
||||
return r, true
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
switch elem[0] {
|
||||
case '/': // Prefix: "/"
|
||||
|
||||
if l := len("/"); len(elem) >= l && elem[0:l] == "/" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
// Param: "org_id"
|
||||
// Leaf parameter, slashes are prohibited
|
||||
idx := strings.IndexByte(elem, '/')
|
||||
if idx >= 0 {
|
||||
break
|
||||
}
|
||||
args[0] = elem
|
||||
elem = ""
|
||||
|
||||
if len(elem) == 0 {
|
||||
// Leaf node.
|
||||
switch method {
|
||||
case "DELETE":
|
||||
r.name = UnhideOrganizationOperation
|
||||
r.summary = "Lift the hiding of the candidate profile from one organization."
|
||||
r.operationID = "UnhideOrganization"
|
||||
r.operationGroup = ""
|
||||
r.pathPattern = "/api/v1/me/privacy/hidden-organizations/{org_id}"
|
||||
r.args = args
|
||||
r.count = 1
|
||||
return r, true
|
||||
case "PUT":
|
||||
r.name = HideOrganizationOperation
|
||||
r.summary = "Hide the candidate profile from one organization."
|
||||
r.operationID = "HideOrganization"
|
||||
r.operationGroup = ""
|
||||
r.pathPattern = "/api/v1/me/privacy/hidden-organizations/{org_id}"
|
||||
r.args = args
|
||||
r.count = 1
|
||||
return r, true
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case 's': // Prefix: "story"
|
||||
|
||||
if l := len("story"); len(elem) >= l && elem[0:l] == "story" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
// Leaf node.
|
||||
switch method {
|
||||
case "GET":
|
||||
r.name = ListMyPrivacyHistoryOperation
|
||||
r.summary = "List the changes of the visibility settings of the current candidate."
|
||||
r.operationID = "ListMyPrivacyHistory"
|
||||
r.operationGroup = ""
|
||||
r.pathPattern = "/api/v1/me/privacy/history"
|
||||
r.args = args
|
||||
r.count = 0
|
||||
return r, true
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case 'p': // Prefix: "p"
|
||||
|
||||
if l := len("p"); len(elem) >= l && elem[0:l] == "p" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
break
|
||||
}
|
||||
switch elem[0] {
|
||||
case 'r': // Prefix: "review"
|
||||
|
||||
if l := len("review"); len(elem) >= l && elem[0:l] == "review" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
// Leaf node.
|
||||
switch method {
|
||||
case "GET":
|
||||
r.name = GetMyCardPreviewOperation
|
||||
r.summary = "Preview the anonymous card that organizations would read."
|
||||
r.operationID = "GetMyCardPreview"
|
||||
r.operationGroup = ""
|
||||
r.pathPattern = "/api/v1/me/privacy/preview"
|
||||
r.args = args
|
||||
r.count = 0
|
||||
return r, true
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
case 'u': // Prefix: "ublication"
|
||||
|
||||
if l := len("ublication"); len(elem) >= l && elem[0:l] == "ublication" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
// Leaf node.
|
||||
switch method {
|
||||
case "PUT":
|
||||
r.name = SetMyPublicationOperation
|
||||
r.summary = "Publish or close the anonymous candidate card."
|
||||
r.operationID = "SetMyPublication"
|
||||
r.operationGroup = ""
|
||||
r.pathPattern = "/api/v1/me/privacy/publication"
|
||||
r.args = args
|
||||
r.count = 0
|
||||
return r, true
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case 's': // Prefix: "search-status"
|
||||
|
||||
if l := len("search-status"); len(elem) >= l && elem[0:l] == "search-status" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
// Leaf node.
|
||||
switch method {
|
||||
case "PUT":
|
||||
r.name = SetMySearchStatusOperation
|
||||
r.summary = "Set or confirm the search status of the current candidate."
|
||||
r.operationID = "SetMySearchStatus"
|
||||
r.operationGroup = ""
|
||||
r.pathPattern = "/api/v1/me/privacy/search-status"
|
||||
r.args = args
|
||||
r.count = 0
|
||||
return r, true
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case 'o': // Prefix: "ofile"
|
||||
|
||||
if l := len("ofile"); len(elem) >= l && elem[0:l] == "ofile" {
|
||||
elem = elem[l:]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
if len(elem) == 0 {
|
||||
// Leaf node.
|
||||
switch method {
|
||||
case "GET":
|
||||
r.name = GetMyProfileOperation
|
||||
r.summary = "Read the private profile of the current candidate."
|
||||
r.operationID = "GetMyProfile"
|
||||
r.operationGroup = ""
|
||||
r.pathPattern = "/api/v1/me/profile"
|
||||
r.args = args
|
||||
r.count = 0
|
||||
return r, true
|
||||
case "PUT":
|
||||
r.name = SaveMyProfileOperation
|
||||
r.summary = "Replace the private profile of the current candidate."
|
||||
r.operationID = "SaveMyProfile"
|
||||
r.operationGroup = ""
|
||||
r.pathPattern = "/api/v1/me/profile"
|
||||
r.args = args
|
||||
r.count = 0
|
||||
return r, true
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case 'q': // Prefix: "questionnaire"
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -70,7 +70,9 @@ var operationRolesSessionCookie = map[string][]string{
|
||||
GetMyAssessmentAttemptOperation: []string{},
|
||||
GetMyAssessmentAvailabilityOperation: []string{},
|
||||
GetMyAssessmentResultOperation: []string{},
|
||||
GetMyCardPreviewOperation: []string{},
|
||||
GetMyInvitationOperation: []string{},
|
||||
GetMyPrivacySettingsOperation: []string{},
|
||||
GetMyProfileOperation: []string{},
|
||||
GetMyQuestionnaireOperation: []string{},
|
||||
GetMySupportCaseOperation: []string{},
|
||||
@@ -78,9 +80,13 @@ var operationRolesSessionCookie = map[string][]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{},
|
||||
@@ -89,7 +95,10 @@ var operationRolesSessionCookie = map[string][]string{
|
||||
SaveMyProfileOperation: []string{},
|
||||
SaveMyQuestionnaireOperation: []string{},
|
||||
SendOrganizationInvitationOperation: []string{},
|
||||
SetMyPublicationOperation: []string{},
|
||||
SetMySearchStatusOperation: []string{},
|
||||
SubmitMyAssessmentAnswerOperation: []string{},
|
||||
UnhideOrganizationOperation: []string{},
|
||||
UpdateOrganizationOperation: []string{},
|
||||
UpdateOrganizationInvitationOperation: []string{},
|
||||
UpdateOrganizationNeedOperation: []string{},
|
||||
@@ -129,12 +138,16 @@ var operationRolesSessionCsrf = map[string][]string{
|
||||
CreateOrganizationNeedOperation: []string{},
|
||||
DeclineMyInvitationOperation: []string{},
|
||||
FinalizeMyAssessmentAttemptOperation: []string{},
|
||||
HideOrganizationOperation: []string{},
|
||||
LogoutOperation: []string{},
|
||||
RaiseOrganizationInvitationSalaryOperation: []string{},
|
||||
SaveMyProfileOperation: []string{},
|
||||
SaveMyQuestionnaireOperation: []string{},
|
||||
SendOrganizationInvitationOperation: []string{},
|
||||
SetMyPublicationOperation: []string{},
|
||||
SetMySearchStatusOperation: []string{},
|
||||
SubmitMyAssessmentAnswerOperation: []string{},
|
||||
UnhideOrganizationOperation: []string{},
|
||||
UpdateOrganizationOperation: []string{},
|
||||
UpdateOrganizationInvitationOperation: []string{},
|
||||
UpdateOrganizationNeedOperation: []string{},
|
||||
|
||||
@@ -572,6 +572,29 @@ type Handler interface {
|
||||
//
|
||||
// GET /api/v1/me/assessment-attempts/{attempt_id}/result
|
||||
GetMyAssessmentResult(ctx context.Context, params GetMyAssessmentResultParams) (GetMyAssessmentResultRes, error)
|
||||
// GetMyCardPreview implements GetMyCardPreview operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account. Returns the card exactly as an organization that
|
||||
// the candidate does not hide the profile from would read it now, built from the current profile, the
|
||||
// current publication, and the consent ledger. The response is `Cache-Control: no-store`.
|
||||
//
|
||||
// The preview is a private read for the candidate: it creates no view, leaves no access record, and is
|
||||
// never shown to an organization. While the profile is closed `card` is null. `card` is
|
||||
// `AnonymousCardContent`, whose schema reaches no private profile schema, no contact, and no
|
||||
// identifier of the candidate: it has no name, email, phone, Telegram name, employer, salary figure,
|
||||
// or account or profile identifier, and each property is null when it is not published or has no
|
||||
// value, so a reader cannot tell the two apart. Only the fields in `fields` are filled, and only with
|
||||
// values that the candidate confirmed: an unconfirmed suggestion and an unknown value never appear. A
|
||||
// free text value that looks like a contact (an email address, a phone number, a URL, a Telegram link,
|
||||
// an @handle) is dropped from the card, so the preview shows exactly what an organization would read.
|
||||
// The self-assessed grade is not a category and never appears; categories come only from assessment
|
||||
// results.
|
||||
//
|
||||
// A missing, unknown, expired, or revoked session answers 401 unauthenticated; an employer account
|
||||
// answers 403 forbidden.
|
||||
//
|
||||
// GET /api/v1/me/privacy/preview
|
||||
GetMyCardPreview(ctx context.Context) (GetMyCardPreviewRes, error)
|
||||
// GetMyInvitation implements GetMyInvitation operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account. The candidate comes from the session; the
|
||||
@@ -603,6 +626,27 @@ type Handler interface {
|
||||
//
|
||||
// GET /api/v1/me/invitations/{invitation_id}
|
||||
GetMyInvitation(ctx context.Context, params GetMyInvitationParams) (GetMyInvitationRes, error)
|
||||
// GetMyPrivacySettings implements GetMyPrivacySettings operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account. The candidate comes from the session, never from
|
||||
// a request parameter. Returns the publication of the candidate card, the search status, and the
|
||||
// number of hidden organizations in one read. The response is `Cache-Control: no-store`.
|
||||
//
|
||||
// A profile is closed by default. A candidate who never published reads `publication.state` `closed`
|
||||
// with `closed_reason` `never_published`, an empty field set, and version 0; creating or saving the
|
||||
// profile (`SaveMyProfile`) never publishes it, and no operation of the profile, the questionnaire, or
|
||||
// an assessment changes these settings. The C2 consent, the search status, and the hidden
|
||||
// organizations are three independent settings: the C2 record in the consent ledger proves that the
|
||||
// candidate accepted the publication text, the publication records which fields are published, and the
|
||||
// search status is a statement of the candidate that is not a consent. A change of one never changes
|
||||
// another, and none of them ever makes the candidate more visible by itself: the search status lapses
|
||||
// to the non-public `not_looking`, a revoked C2 closes the card, and a new C2 grant publishes nothing.
|
||||
//
|
||||
// A missing, unknown, expired, or revoked session answers 401 unauthenticated; an employer account
|
||||
// answers 403 forbidden.
|
||||
//
|
||||
// GET /api/v1/me/privacy
|
||||
GetMyPrivacySettings(ctx context.Context) (GetMyPrivacySettingsRes, error)
|
||||
// GetMyProfile implements GetMyProfile operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account. The candidate comes from the session, never from
|
||||
@@ -795,6 +839,66 @@ type Handler interface {
|
||||
//
|
||||
// GET /api/v1/specializations
|
||||
GetSpecializationCatalog(ctx context.Context) (*SpecializationCatalog, error)
|
||||
// HideOrganization implements HideOrganization operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token,
|
||||
// and an allowed Origin. The request has no body: the path names the organization and the candidate
|
||||
// comes from the session. The hiding is a record that belongs to the candidate and references the
|
||||
// organization; it changes neither the C2 consent, nor the publication, nor the search status.
|
||||
//
|
||||
// The operation sets a state, so it is idempotent and needs no Idempotency-Key: hiding an organization
|
||||
// that is already hidden answers 200 with the existing record and its original `hidden_at`, changes
|
||||
// nothing, and writes no history record. There is one record per candidate and organization.
|
||||
//
|
||||
// Anti-enumeration: an organization that does not exist and an organization that the candidate cannot
|
||||
// see answer the same 404 not_found, with the same body and without a timing or an error code that
|
||||
// tells them apart, so the operation is not a way to ask whether an identifier belongs to an
|
||||
// organization. The candidate can see an organization that has sent them an invitation, and the
|
||||
// organizations that a candidate lookup will list (planned; see the open questions of the contract).
|
||||
// The response names the organization only after that check, with its current name. The identifiers
|
||||
// are random, the general rate limit applies and can answer 429 with Retry-After before any check, and
|
||||
// the record never reveals to an organization that a candidate hides it.
|
||||
//
|
||||
// A candidate hides at most 1000 organizations; hiding one more answers 409 state_conflict with the
|
||||
// entry `{in: path, pointer: /org_id, code: limit_reached}` in `errors`, which tells it apart from
|
||||
// other conflicts, and changes nothing, and a repeat of an existing hiding is never refused for the
|
||||
// limit.
|
||||
//
|
||||
// Hiding an organization that holds an active contact grant of the candidate revokes that grant with
|
||||
// the reason `visibility_closed` in the same transaction (planned together with the invitation
|
||||
// operations). Lifting the hiding never reopens a grant.
|
||||
//
|
||||
// Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation of the
|
||||
// path (400), account scenario (403 forbidden for an employer), the organization and its visibility to
|
||||
// the candidate (404 not_found), then the repeat (200), then the limit (409 state_conflict). Like
|
||||
// every visibility change, hiding needs a verified email (a usecase requirement).
|
||||
//
|
||||
// PUT /api/v1/me/privacy/hidden-organizations/{org_id}
|
||||
HideOrganization(ctx context.Context, params HideOrganizationParams) (HideOrganizationRes, error)
|
||||
// ListMyCardAccessHistory implements ListMyCardAccessHistory operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account. The candidate comes from the session, so the
|
||||
// response holds only accesses to the caller's own card. Returns a page, newest first with the record
|
||||
// identifier as the tie-breaker, with cursor pagination. The response is `Cache-Control: no-store`.
|
||||
//
|
||||
// An access is a view of the anonymous card by an organization (`card_viewed`) or a read of the
|
||||
// contacts through an active contact grant (`contact_read`). Reading the history is not an access and
|
||||
// writes nothing. A view of the card by an organization that has no invitation relation with the
|
||||
// candidate carries `organization` null, so the candidate sees that the card was viewed without
|
||||
// learning a company that they cannot otherwise see; a contact read always names the organization,
|
||||
// because the candidate accepted its invitation. The entries carry no search query, filter, or ranking
|
||||
// of the organization, and no organization the candidate hides ever appears as a viewer, because a
|
||||
// hidden organization cannot read the card.
|
||||
//
|
||||
// The storage of accesses is planned with the card and contact operations of the organization side
|
||||
// (TASK-185 and the contact read of the invitation contract); until then the operation answers 501
|
||||
// not_implemented after the session and request checks.
|
||||
//
|
||||
// A missing, unknown, expired, or revoked session answers 401 unauthenticated; an employer account
|
||||
// answers 403 forbidden. A malformed `limit` or `cursor` answers 400 validation_failed.
|
||||
//
|
||||
// GET /api/v1/me/privacy/access-history
|
||||
ListMyCardAccessHistory(ctx context.Context, params ListMyCardAccessHistoryParams) (ListMyCardAccessHistoryRes, error)
|
||||
// ListMyConsents implements ListMyConsents operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate or an employer account. The subject comes from the
|
||||
@@ -824,6 +928,22 @@ type Handler interface {
|
||||
//
|
||||
// GET /api/v1/me/consents
|
||||
ListMyConsents(ctx context.Context, params ListMyConsentsParams) (ListMyConsentsRes, error)
|
||||
// ListMyHiddenOrganizations implements ListMyHiddenOrganizations operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account. The candidate comes from the session, so the
|
||||
// response holds only the caller's own records and no request can name another account. Returns a page
|
||||
// of the hidden organizations, newest first with the organization identifier as the tie-breaker, with
|
||||
// cursor pagination. The response is `Cache-Control: no-store`.
|
||||
//
|
||||
// The records belong to the candidate. An organization never reads them, never learns that it is
|
||||
// hidden, and sees a hidden candidate exactly as it sees one who is not published: no search result,
|
||||
// no card, no contact read.
|
||||
//
|
||||
// A missing, unknown, expired, or revoked session answers 401 unauthenticated; an employer account
|
||||
// answers 403 forbidden. A malformed `limit` or `cursor` answers 400 validation_failed.
|
||||
//
|
||||
// GET /api/v1/me/privacy/hidden-organizations
|
||||
ListMyHiddenOrganizations(ctx context.Context, params ListMyHiddenOrganizationsParams) (ListMyHiddenOrganizationsRes, error)
|
||||
// ListMyInvitations implements ListMyInvitations operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account. The candidate comes from the session, never from
|
||||
@@ -871,6 +991,24 @@ type Handler interface {
|
||||
//
|
||||
// GET /api/v1/me/organizations
|
||||
ListMyOrganizations(ctx context.Context, params ListMyOrganizationsParams) (ListMyOrganizationsRes, error)
|
||||
// ListMyPrivacyHistory implements ListMyPrivacyHistory operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account. The candidate comes from the session, so the
|
||||
// response holds only the caller's own records. Returns a page of the settings history, newest first
|
||||
// with the event identifier as the tie-breaker, with cursor pagination. The response is
|
||||
// `Cache-Control: no-store`.
|
||||
//
|
||||
// The history is append-only evidence of what the candidate published, hid, and announced, and when. A
|
||||
// publication event keeps the published fields and the C2 record behind them, which is what the
|
||||
// consent ledger deliberately does not carry (the C2 record proves the consent to the text, not the
|
||||
// field set). A revocation of C2 and a lapse of the search status are computed and are not events
|
||||
// here; the consent history shows the revocation. The history never contains a profile value.
|
||||
//
|
||||
// A missing, unknown, expired, or revoked session answers 401 unauthenticated; an employer account
|
||||
// answers 403 forbidden. A malformed `limit` or `cursor` answers 400 validation_failed.
|
||||
//
|
||||
// GET /api/v1/me/privacy/history
|
||||
ListMyPrivacyHistory(ctx context.Context, params ListMyPrivacyHistoryParams) (ListMyPrivacyHistoryRes, error)
|
||||
// ListMySupportCases implements ListMySupportCases operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate or an employer account. Returns a page of the cases that
|
||||
@@ -1186,6 +1324,90 @@ type Handler interface {
|
||||
//
|
||||
// POST /api/v1/organizations/{org_id}/invitations/{invitation_id}/send
|
||||
SendOrganizationInvitation(ctx context.Context, req *InvitationCommand, params SendOrganizationInvitationParams) (SendOrganizationInvitationRes, error)
|
||||
// SetMyPublication implements SetMyPublication operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token,
|
||||
// and an allowed Origin. The body is the complete new publication setting: `state` `published` with
|
||||
// the non-empty set of card fields, or `closed` with an empty set. It changes only the publication;
|
||||
// the search status and the hidden organizations stay as they were.
|
||||
//
|
||||
// Publication is not a consent and does not duplicate one. The consent C2 lives in the consent ledger
|
||||
// (`ListMyConsents`); this setting refers to it. Publishing requires an active, unrevoked C2 record of
|
||||
// the account and binds the publication to that record, so a client sends no consent identifier and
|
||||
// cannot forge one. Without one the server answers 409 state_conflict with the entry
|
||||
// `{in: body, pointer: /state, code: consent_required}` in `errors`, which tells it apart from every
|
||||
// other conflict, and changes nothing: the client gives C2 first (planned in the consent settings,
|
||||
// TASK-063) and then publishes. The server takes the C2 record under a share lock in the transaction
|
||||
// that writes the publication, so a revocation that races with a publication either commits first (the
|
||||
// publication is refused) or closes the card right after. A revocation of C2 closes the card at once,
|
||||
// because `state` is computed from the unrevoked record; a later C2 grant never reopens it, and the
|
||||
// candidate publishes again under the new record. The revocation path itself (TASK-064) closes the
|
||||
// stored publication and revokes the contact grants in its own transaction. A closing sent over a
|
||||
// stored publication whose C2 was revoked is a real change: it stores the closing, records
|
||||
// `publication_closed`, and revokes the grants as any closing does. Publishing, like every visibility
|
||||
// change, needs a verified email (a usecase requirement; the unverified account cleanup deletes only
|
||||
// accounts without such records). Publishing never adds a field that the body did not name, and a new
|
||||
// `CardField` value is never published for a candidate who did not choose it.
|
||||
//
|
||||
// The field set contains only the groups of `CardField`. The full name, contacts, and the lowest
|
||||
// salary have no value there, so no body can publish them. Only values that the candidate confirmed
|
||||
// ever reach the card. Contacts reach an organization only through the contact grant (C4), and a
|
||||
// profile that is published or closed changes none of the grants that exist; closing the publication,
|
||||
// and hiding an organization that holds a grant, revoke the contact grants concerned with the reason
|
||||
// `visibility_closed` in the same transaction as the change (planned together with the operations, see
|
||||
// the invitation contract).
|
||||
//
|
||||
// Optimistic concurrency uses `expected_version` in the body: the client sends the `version` it read,
|
||||
// 0 for the first publication. If it is not the current version the server answers 412
|
||||
// version_conflict and changes nothing. The version travels in the body rather than in If-Match
|
||||
// because the generated client cannot read the ETag header yet. A body that equals the stored setting
|
||||
// changes nothing, keeps the version, and answers 200 even when `expected_version` is older, so a
|
||||
// retry after a lost response succeeds without an Idempotency-Key. A version above the current one
|
||||
// never existed and always answers 412. Every change is recorded in the settings history with its
|
||||
// time, the fields, and the C2 record.
|
||||
//
|
||||
// Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400),
|
||||
// account scenario (403 forbidden for an employer), a version above the current one (412), rules that
|
||||
// depend on the body alone (400), an unchanged body (200), a stale version (412), then the active C2
|
||||
// for a publication (409 state_conflict). The schema rejects an unknown field, a repeated or unknown
|
||||
// card field, and more fields than there are groups; a published state with no field, and a closed
|
||||
// state with a field, answer 400 validation_failed with the pointer `/fields`. Error bodies never
|
||||
// repeat a submitted value.
|
||||
//
|
||||
// PUT /api/v1/me/privacy/publication
|
||||
SetMyPublication(ctx context.Context, req *PublicationUpdate) (SetMyPublicationRes, error)
|
||||
// SetMySearchStatus implements SetMySearchStatus operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token,
|
||||
// and an allowed Origin. The body is the complete new status: `looking` ("Ищу") or `not_looking`.
|
||||
// The status is a statement of the candidate and never a consent. It changes neither the C2 consent,
|
||||
// nor the publication, nor the hidden organizations, and it does not close or open any contact grant;
|
||||
// a candidate whose profile is closed who sets `looking` becomes visible to no one.
|
||||
//
|
||||
// `looking` stores the moment of the confirmation and a lapse time. The server takes the interval from
|
||||
// the `search_status` section of the effective product policy (30 days in the demo policy,
|
||||
// `searching_confirmation_interval_days`), stores the policy version it used, and fixes the lapse time
|
||||
// then, so a later policy change moves no stored time. Setting `looking` again is the confirmation: it
|
||||
// replaces the confirmation time with now and advances the version, also after a lapse. The body
|
||||
// carries no time, interval, or policy version.
|
||||
//
|
||||
// After the lapse time the status holds as `not_looking` with `lapsed` true on the next read. The
|
||||
// lapse is computed and written nowhere, so it needs no job, it can never make the candidate more
|
||||
// visible, and it never touches the publication or the hidden organizations. A reminder before the
|
||||
// lapse is a planned notification, not a part of this operation.
|
||||
//
|
||||
// Optimistic concurrency uses `expected_version` in the body, 0 for a candidate who never set the
|
||||
// status; a stale or non-existent version answers 412 version_conflict and changes nothing.
|
||||
// `not_looking` over a stored `not_looking` changes nothing and answers 200 even with a stale version.
|
||||
// `looking` always changes the stored confirmation, so a retry of a confirmation whose response was
|
||||
// lost with the old version answers 412 and the client reads the status again.
|
||||
//
|
||||
// Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400),
|
||||
// account scenario (403 forbidden for an employer), a version above the current one (412), an
|
||||
// unchanged `not_looking` (200), then a stale version (412).
|
||||
//
|
||||
// PUT /api/v1/me/privacy/search-status
|
||||
SetMySearchStatus(ctx context.Context, req *SearchStatusUpdate) (SetMySearchStatusRes, error)
|
||||
// SubmitMyAssessmentAnswer implements SubmitMyAssessmentAnswer operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token,
|
||||
@@ -1243,6 +1465,24 @@ type Handler interface {
|
||||
//
|
||||
// POST /api/v1/me/assessment-attempts/{attempt_id}/answers
|
||||
SubmitMyAssessmentAnswer(ctx context.Context, req *AssessmentAnswerSubmission, params SubmitMyAssessmentAnswerParams) (SubmitMyAssessmentAnswerRes, error)
|
||||
// UnhideOrganization implements UnhideOrganization operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token,
|
||||
// and an allowed Origin. Deletes the hiding record of the candidate for the organization in the path.
|
||||
// The request is idempotent: it answers 204 whether the organization was hidden, was not hidden, or
|
||||
// does not exist, so the operation reveals nothing about the organization, and a repeat after a lost
|
||||
// response succeeds. The record is deleted, the settings history keeps the event
|
||||
// `organization_unhidden` only when a record was deleted.
|
||||
//
|
||||
// Lifting the hiding makes the candidate readable by that organization again only if the profile is
|
||||
// published and the organization otherwise may read it. It changes neither the C2 consent, nor the
|
||||
// publication, nor the search status, and it never reopens a contact grant that the hiding closed.
|
||||
//
|
||||
// Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation of the
|
||||
// path (400), account scenario (403 forbidden for an employer), then the deletion (204).
|
||||
//
|
||||
// DELETE /api/v1/me/privacy/hidden-organizations/{org_id}
|
||||
UnhideOrganization(ctx context.Context, params UnhideOrganizationParams) (UnhideOrganizationRes, error)
|
||||
// UpdateOrganization implements UpdateOrganization operation.
|
||||
//
|
||||
// Requires the session cookie of an employer account with an active membership in `org_id`, the CSRF
|
||||
|
||||
@@ -628,6 +628,32 @@ func (UnimplementedHandler) GetMyAssessmentResult(ctx context.Context, params Ge
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// GetMyCardPreview implements GetMyCardPreview operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account. Returns the card exactly as an organization that
|
||||
// the candidate does not hide the profile from would read it now, built from the current profile, the
|
||||
// current publication, and the consent ledger. The response is `Cache-Control: no-store`.
|
||||
//
|
||||
// The preview is a private read for the candidate: it creates no view, leaves no access record, and is
|
||||
// never shown to an organization. While the profile is closed `card` is null. `card` is
|
||||
// `AnonymousCardContent`, whose schema reaches no private profile schema, no contact, and no
|
||||
// identifier of the candidate: it has no name, email, phone, Telegram name, employer, salary figure,
|
||||
// or account or profile identifier, and each property is null when it is not published or has no
|
||||
// value, so a reader cannot tell the two apart. Only the fields in `fields` are filled, and only with
|
||||
// values that the candidate confirmed: an unconfirmed suggestion and an unknown value never appear. A
|
||||
// free text value that looks like a contact (an email address, a phone number, a URL, a Telegram link,
|
||||
// an @handle) is dropped from the card, so the preview shows exactly what an organization would read.
|
||||
// The self-assessed grade is not a category and never appears; categories come only from assessment
|
||||
// results.
|
||||
//
|
||||
// A missing, unknown, expired, or revoked session answers 401 unauthenticated; an employer account
|
||||
// answers 403 forbidden.
|
||||
//
|
||||
// GET /api/v1/me/privacy/preview
|
||||
func (UnimplementedHandler) GetMyCardPreview(ctx context.Context) (r GetMyCardPreviewRes, _ error) {
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// GetMyInvitation implements GetMyInvitation operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account. The candidate comes from the session; the
|
||||
@@ -662,6 +688,30 @@ func (UnimplementedHandler) GetMyInvitation(ctx context.Context, params GetMyInv
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// GetMyPrivacySettings implements GetMyPrivacySettings operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account. The candidate comes from the session, never from
|
||||
// a request parameter. Returns the publication of the candidate card, the search status, and the
|
||||
// number of hidden organizations in one read. The response is `Cache-Control: no-store`.
|
||||
//
|
||||
// A profile is closed by default. A candidate who never published reads `publication.state` `closed`
|
||||
// with `closed_reason` `never_published`, an empty field set, and version 0; creating or saving the
|
||||
// profile (`SaveMyProfile`) never publishes it, and no operation of the profile, the questionnaire, or
|
||||
// an assessment changes these settings. The C2 consent, the search status, and the hidden
|
||||
// organizations are three independent settings: the C2 record in the consent ledger proves that the
|
||||
// candidate accepted the publication text, the publication records which fields are published, and the
|
||||
// search status is a statement of the candidate that is not a consent. A change of one never changes
|
||||
// another, and none of them ever makes the candidate more visible by itself: the search status lapses
|
||||
// to the non-public `not_looking`, a revoked C2 closes the card, and a new C2 grant publishes nothing.
|
||||
//
|
||||
// A missing, unknown, expired, or revoked session answers 401 unauthenticated; an employer account
|
||||
// answers 403 forbidden.
|
||||
//
|
||||
// GET /api/v1/me/privacy
|
||||
func (UnimplementedHandler) GetMyPrivacySettings(ctx context.Context) (r GetMyPrivacySettingsRes, _ error) {
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// GetMyProfile implements GetMyProfile operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account. The candidate comes from the session, never from
|
||||
@@ -878,6 +928,72 @@ func (UnimplementedHandler) GetSpecializationCatalog(ctx context.Context) (r *Sp
|
||||
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,
|
||||
// and an allowed Origin. The request has no body: the path names the organization and the candidate
|
||||
// comes from the session. The hiding is a record that belongs to the candidate and references the
|
||||
// organization; it changes neither the C2 consent, nor the publication, nor the search status.
|
||||
//
|
||||
// The operation sets a state, so it is idempotent and needs no Idempotency-Key: hiding an organization
|
||||
// that is already hidden answers 200 with the existing record and its original `hidden_at`, changes
|
||||
// nothing, and writes no history record. There is one record per candidate and organization.
|
||||
//
|
||||
// Anti-enumeration: an organization that does not exist and an organization that the candidate cannot
|
||||
// see answer the same 404 not_found, with the same body and without a timing or an error code that
|
||||
// tells them apart, so the operation is not a way to ask whether an identifier belongs to an
|
||||
// organization. The candidate can see an organization that has sent them an invitation, and the
|
||||
// organizations that a candidate lookup will list (planned; see the open questions of the contract).
|
||||
// The response names the organization only after that check, with its current name. The identifiers
|
||||
// are random, the general rate limit applies and can answer 429 with Retry-After before any check, and
|
||||
// the record never reveals to an organization that a candidate hides it.
|
||||
//
|
||||
// A candidate hides at most 1000 organizations; hiding one more answers 409 state_conflict with the
|
||||
// entry `{in: path, pointer: /org_id, code: limit_reached}` in `errors`, which tells it apart from
|
||||
// other conflicts, and changes nothing, and a repeat of an existing hiding is never refused for the
|
||||
// limit.
|
||||
//
|
||||
// Hiding an organization that holds an active contact grant of the candidate revokes that grant with
|
||||
// the reason `visibility_closed` in the same transaction (planned together with the invitation
|
||||
// operations). Lifting the hiding never reopens a grant.
|
||||
//
|
||||
// Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation of the
|
||||
// path (400), account scenario (403 forbidden for an employer), the organization and its visibility to
|
||||
// the candidate (404 not_found), then the repeat (200), then the limit (409 state_conflict). Like
|
||||
// every visibility change, hiding needs a verified email (a usecase requirement).
|
||||
//
|
||||
// PUT /api/v1/me/privacy/hidden-organizations/{org_id}
|
||||
func (UnimplementedHandler) HideOrganization(ctx context.Context, params HideOrganizationParams) (r HideOrganizationRes, _ error) {
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// ListMyCardAccessHistory implements ListMyCardAccessHistory operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account. The candidate comes from the session, so the
|
||||
// response holds only accesses to the caller's own card. Returns a page, newest first with the record
|
||||
// identifier as the tie-breaker, with cursor pagination. The response is `Cache-Control: no-store`.
|
||||
//
|
||||
// An access is a view of the anonymous card by an organization (`card_viewed`) or a read of the
|
||||
// contacts through an active contact grant (`contact_read`). Reading the history is not an access and
|
||||
// writes nothing. A view of the card by an organization that has no invitation relation with the
|
||||
// candidate carries `organization` null, so the candidate sees that the card was viewed without
|
||||
// learning a company that they cannot otherwise see; a contact read always names the organization,
|
||||
// because the candidate accepted its invitation. The entries carry no search query, filter, or ranking
|
||||
// of the organization, and no organization the candidate hides ever appears as a viewer, because a
|
||||
// hidden organization cannot read the card.
|
||||
//
|
||||
// The storage of accesses is planned with the card and contact operations of the organization side
|
||||
// (TASK-185 and the contact read of the invitation contract); until then the operation answers 501
|
||||
// not_implemented after the session and request checks.
|
||||
//
|
||||
// A missing, unknown, expired, or revoked session answers 401 unauthenticated; an employer account
|
||||
// answers 403 forbidden. A malformed `limit` or `cursor` answers 400 validation_failed.
|
||||
//
|
||||
// GET /api/v1/me/privacy/access-history
|
||||
func (UnimplementedHandler) ListMyCardAccessHistory(ctx context.Context, params ListMyCardAccessHistoryParams) (r ListMyCardAccessHistoryRes, _ error) {
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// ListMyConsents implements ListMyConsents operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate or an employer account. The subject comes from the
|
||||
@@ -910,6 +1026,25 @@ func (UnimplementedHandler) ListMyConsents(ctx context.Context, params ListMyCon
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// ListMyHiddenOrganizations implements ListMyHiddenOrganizations operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account. The candidate comes from the session, so the
|
||||
// response holds only the caller's own records and no request can name another account. Returns a page
|
||||
// of the hidden organizations, newest first with the organization identifier as the tie-breaker, with
|
||||
// cursor pagination. The response is `Cache-Control: no-store`.
|
||||
//
|
||||
// The records belong to the candidate. An organization never reads them, never learns that it is
|
||||
// hidden, and sees a hidden candidate exactly as it sees one who is not published: no search result,
|
||||
// no card, no contact read.
|
||||
//
|
||||
// A missing, unknown, expired, or revoked session answers 401 unauthenticated; an employer account
|
||||
// answers 403 forbidden. A malformed `limit` or `cursor` answers 400 validation_failed.
|
||||
//
|
||||
// GET /api/v1/me/privacy/hidden-organizations
|
||||
func (UnimplementedHandler) ListMyHiddenOrganizations(ctx context.Context, params ListMyHiddenOrganizationsParams) (r ListMyHiddenOrganizationsRes, _ error) {
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// ListMyInvitations implements ListMyInvitations operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account. The candidate comes from the session, never from
|
||||
@@ -963,6 +1098,27 @@ func (UnimplementedHandler) ListMyOrganizations(ctx context.Context, params List
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// ListMyPrivacyHistory implements ListMyPrivacyHistory operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account. The candidate comes from the session, so the
|
||||
// response holds only the caller's own records. Returns a page of the settings history, newest first
|
||||
// with the event identifier as the tie-breaker, with cursor pagination. The response is
|
||||
// `Cache-Control: no-store`.
|
||||
//
|
||||
// The history is append-only evidence of what the candidate published, hid, and announced, and when. A
|
||||
// publication event keeps the published fields and the C2 record behind them, which is what the
|
||||
// consent ledger deliberately does not carry (the C2 record proves the consent to the text, not the
|
||||
// field set). A revocation of C2 and a lapse of the search status are computed and are not events
|
||||
// here; the consent history shows the revocation. The history never contains a profile value.
|
||||
//
|
||||
// A missing, unknown, expired, or revoked session answers 401 unauthenticated; an employer account
|
||||
// answers 403 forbidden. A malformed `limit` or `cursor` answers 400 validation_failed.
|
||||
//
|
||||
// GET /api/v1/me/privacy/history
|
||||
func (UnimplementedHandler) ListMyPrivacyHistory(ctx context.Context, params ListMyPrivacyHistoryParams) (r ListMyPrivacyHistoryRes, _ error) {
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// ListMySupportCases implements ListMySupportCases operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate or an employer account. Returns a page of the cases that
|
||||
@@ -1311,6 +1467,96 @@ func (UnimplementedHandler) SendOrganizationInvitation(ctx context.Context, req
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// SetMyPublication implements SetMyPublication operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token,
|
||||
// and an allowed Origin. The body is the complete new publication setting: `state` `published` with
|
||||
// the non-empty set of card fields, or `closed` with an empty set. It changes only the publication;
|
||||
// the search status and the hidden organizations stay as they were.
|
||||
//
|
||||
// Publication is not a consent and does not duplicate one. The consent C2 lives in the consent ledger
|
||||
// (`ListMyConsents`); this setting refers to it. Publishing requires an active, unrevoked C2 record of
|
||||
// the account and binds the publication to that record, so a client sends no consent identifier and
|
||||
// cannot forge one. Without one the server answers 409 state_conflict with the entry
|
||||
// `{in: body, pointer: /state, code: consent_required}` in `errors`, which tells it apart from every
|
||||
// other conflict, and changes nothing: the client gives C2 first (planned in the consent settings,
|
||||
// TASK-063) and then publishes. The server takes the C2 record under a share lock in the transaction
|
||||
// that writes the publication, so a revocation that races with a publication either commits first (the
|
||||
// publication is refused) or closes the card right after. A revocation of C2 closes the card at once,
|
||||
// because `state` is computed from the unrevoked record; a later C2 grant never reopens it, and the
|
||||
// candidate publishes again under the new record. The revocation path itself (TASK-064) closes the
|
||||
// stored publication and revokes the contact grants in its own transaction. A closing sent over a
|
||||
// stored publication whose C2 was revoked is a real change: it stores the closing, records
|
||||
// `publication_closed`, and revokes the grants as any closing does. Publishing, like every visibility
|
||||
// change, needs a verified email (a usecase requirement; the unverified account cleanup deletes only
|
||||
// accounts without such records). Publishing never adds a field that the body did not name, and a new
|
||||
// `CardField` value is never published for a candidate who did not choose it.
|
||||
//
|
||||
// The field set contains only the groups of `CardField`. The full name, contacts, and the lowest
|
||||
// salary have no value there, so no body can publish them. Only values that the candidate confirmed
|
||||
// ever reach the card. Contacts reach an organization only through the contact grant (C4), and a
|
||||
// profile that is published or closed changes none of the grants that exist; closing the publication,
|
||||
// and hiding an organization that holds a grant, revoke the contact grants concerned with the reason
|
||||
// `visibility_closed` in the same transaction as the change (planned together with the operations, see
|
||||
// the invitation contract).
|
||||
//
|
||||
// Optimistic concurrency uses `expected_version` in the body: the client sends the `version` it read,
|
||||
// 0 for the first publication. If it is not the current version the server answers 412
|
||||
// version_conflict and changes nothing. The version travels in the body rather than in If-Match
|
||||
// because the generated client cannot read the ETag header yet. A body that equals the stored setting
|
||||
// changes nothing, keeps the version, and answers 200 even when `expected_version` is older, so a
|
||||
// retry after a lost response succeeds without an Idempotency-Key. A version above the current one
|
||||
// never existed and always answers 412. Every change is recorded in the settings history with its
|
||||
// time, the fields, and the C2 record.
|
||||
//
|
||||
// Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400),
|
||||
// account scenario (403 forbidden for an employer), a version above the current one (412), rules that
|
||||
// depend on the body alone (400), an unchanged body (200), a stale version (412), then the active C2
|
||||
// for a publication (409 state_conflict). The schema rejects an unknown field, a repeated or unknown
|
||||
// card field, and more fields than there are groups; a published state with no field, and a closed
|
||||
// state with a field, answer 400 validation_failed with the pointer `/fields`. Error bodies never
|
||||
// repeat a submitted value.
|
||||
//
|
||||
// PUT /api/v1/me/privacy/publication
|
||||
func (UnimplementedHandler) SetMyPublication(ctx context.Context, req *PublicationUpdate) (r SetMyPublicationRes, _ error) {
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// SetMySearchStatus implements SetMySearchStatus operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token,
|
||||
// and an allowed Origin. The body is the complete new status: `looking` ("Ищу") or `not_looking`.
|
||||
// The status is a statement of the candidate and never a consent. It changes neither the C2 consent,
|
||||
// nor the publication, nor the hidden organizations, and it does not close or open any contact grant;
|
||||
// a candidate whose profile is closed who sets `looking` becomes visible to no one.
|
||||
//
|
||||
// `looking` stores the moment of the confirmation and a lapse time. The server takes the interval from
|
||||
// the `search_status` section of the effective product policy (30 days in the demo policy,
|
||||
// `searching_confirmation_interval_days`), stores the policy version it used, and fixes the lapse time
|
||||
// then, so a later policy change moves no stored time. Setting `looking` again is the confirmation: it
|
||||
// replaces the confirmation time with now and advances the version, also after a lapse. The body
|
||||
// carries no time, interval, or policy version.
|
||||
//
|
||||
// After the lapse time the status holds as `not_looking` with `lapsed` true on the next read. The
|
||||
// lapse is computed and written nowhere, so it needs no job, it can never make the candidate more
|
||||
// visible, and it never touches the publication or the hidden organizations. A reminder before the
|
||||
// lapse is a planned notification, not a part of this operation.
|
||||
//
|
||||
// Optimistic concurrency uses `expected_version` in the body, 0 for a candidate who never set the
|
||||
// status; a stale or non-existent version answers 412 version_conflict and changes nothing.
|
||||
// `not_looking` over a stored `not_looking` changes nothing and answers 200 even with a stale version.
|
||||
// `looking` always changes the stored confirmation, so a retry of a confirmation whose response was
|
||||
// lost with the old version answers 412 and the client reads the status again.
|
||||
//
|
||||
// Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400),
|
||||
// account scenario (403 forbidden for an employer), a version above the current one (412), an
|
||||
// unchanged `not_looking` (200), then a stale version (412).
|
||||
//
|
||||
// PUT /api/v1/me/privacy/search-status
|
||||
func (UnimplementedHandler) SetMySearchStatus(ctx context.Context, req *SearchStatusUpdate) (r SetMySearchStatusRes, _ error) {
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// SubmitMyAssessmentAnswer implements SubmitMyAssessmentAnswer operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token,
|
||||
@@ -1371,6 +1617,27 @@ func (UnimplementedHandler) SubmitMyAssessmentAnswer(ctx context.Context, req *A
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// UnhideOrganization implements UnhideOrganization operation.
|
||||
//
|
||||
// Requires the session cookie of a candidate account, the CSRF token of that session in X-CSRF-Token,
|
||||
// and an allowed Origin. Deletes the hiding record of the candidate for the organization in the path.
|
||||
// The request is idempotent: it answers 204 whether the organization was hidden, was not hidden, or
|
||||
// does not exist, so the operation reveals nothing about the organization, and a repeat after a lost
|
||||
// response succeeds. The record is deleted, the settings history keeps the event
|
||||
// `organization_unhidden` only when a record was deleted.
|
||||
//
|
||||
// Lifting the hiding makes the candidate readable by that organization again only if the profile is
|
||||
// published and the organization otherwise may read it. It changes neither the C2 consent, nor the
|
||||
// publication, nor the search status, and it never reopens a contact grant that the hiding closed.
|
||||
//
|
||||
// Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation of the
|
||||
// path (400), account scenario (403 forbidden for an employer), then the deletion (204).
|
||||
//
|
||||
// DELETE /api/v1/me/privacy/hidden-organizations/{org_id}
|
||||
func (UnimplementedHandler) UnhideOrganization(ctx context.Context, params UnhideOrganizationParams) (r UnhideOrganizationRes, _ error) {
|
||||
return r, ht.ErrNotImplemented
|
||||
}
|
||||
|
||||
// UpdateOrganization implements UpdateOrganization operation.
|
||||
//
|
||||
// Requires the session cookie of an employer account with an active membership in `org_id`, the CSRF
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,408 @@
|
||||
package httpadapter
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/ogen-go/ogen"
|
||||
|
||||
"lincodex/backend/internal/adapter/primary/http/api"
|
||||
"lincodex/backend/internal/adapter/primary/http/problem"
|
||||
v1 "lincodex/backend/internal/adapter/primary/http/v1"
|
||||
metrics "lincodex/backend/internal/adapter/secondary/prometheus"
|
||||
)
|
||||
|
||||
const (
|
||||
privacyBasePath = "/api/v1/me/privacy"
|
||||
privacyPublicationPath = privacyBasePath + "/publication"
|
||||
privacySearchStatusPath = privacyBasePath + "/search-status"
|
||||
privacyHiddenPath = privacyBasePath + "/hidden-organizations"
|
||||
privacyOrganizationID = "01928f7a-1a2b-7c3d-8e4f-5a6b7c8d9e01"
|
||||
)
|
||||
|
||||
// Each visibility setting is its own family of schemas. The three never
|
||||
// refer to one another, so a client cannot read or write one setting through
|
||||
// the DTO of another, and the search status is not a consent.
|
||||
var (
|
||||
publicationSchemas = []string{"Publication", "PublicationUpdate", "PublicationVersion", "PublicationState", "PublicationClosedReason", "CardField", "CardFieldSet"}
|
||||
searchStatusSchemas = []string{"SearchStatus", "SearchStatusUpdate", "SearchStatusVersion", "SearchStatusValue"}
|
||||
hiddenSchemas = []string{"HiddenOrganization", "HiddenOrganizationList", "PrivacyOrganization"}
|
||||
privacyOnlySchemas = []string{"PrivacySettings", "CardPreview", "AnonymousCardContent", "CardCategory", "PrivacyEvent", "PrivacyEventKind", "PrivacyEventList", "CardAccess", "CardAccessKind", "CardAccessList"}
|
||||
// sharedLeafSchemas are the reusable leaves that the privacy family may
|
||||
// refer to; none of them identifies a person or carries a contact.
|
||||
sharedLeafSchemas = []string{"Timestamp", "PageInfo", "SpecializationCode", "GradeCode", "StackTag"}
|
||||
)
|
||||
|
||||
func isPrivacySchema(name string) bool {
|
||||
return slices.Contains(publicationSchemas, name) || slices.Contains(searchStatusSchemas, name) ||
|
||||
slices.Contains(hiddenSchemas, name) || slices.Contains(privacyOnlySchemas, name)
|
||||
}
|
||||
|
||||
// parameterName names a parameter by its component when it is a reference.
|
||||
func parameterName(parameter *ogen.Parameter) string {
|
||||
if parameter.Ref != "" {
|
||||
return parameter.Ref[strings.LastIndex(parameter.Ref, "/")+1:]
|
||||
}
|
||||
return parameter.Name
|
||||
}
|
||||
|
||||
func privacyOperations(t *testing.T, spec *ogen.Spec) []*ogen.Operation {
|
||||
t.Helper()
|
||||
operations := make([]*ogen.Operation, 0, 9)
|
||||
for _, id := range []string{
|
||||
"GetMyPrivacySettings", "SetMyPublication", "GetMyCardPreview", "SetMySearchStatus", "ListMyHiddenOrganizations",
|
||||
"HideOrganization", "UnhideOrganization", "ListMyPrivacyHistory", "ListMyCardAccessHistory",
|
||||
} {
|
||||
operations = append(operations, operationByID(t, spec, id))
|
||||
}
|
||||
return operations
|
||||
}
|
||||
|
||||
// Every visibility operation follows the project conventions: the session
|
||||
// only for reads, the session and the CSRF token for changes, the version in
|
||||
// the body with 412, 409 for a state that does not allow the change, 404
|
||||
// without a distinction, and no new problem code.
|
||||
func TestPrivacyOperationsFollowTheConventions(t *testing.T) {
|
||||
spec := parsePublicContract(t)
|
||||
unsafe := map[string]bool{"SetMyPublication": true, "SetMySearchStatus": true, "HideOrganization": true, "UnhideOrganization": true}
|
||||
for _, operation := range privacyOperations(t, spec) {
|
||||
if !slices.Contains(operation.Tags, "privacy") {
|
||||
t.Errorf("%s is not in the privacy tag", operation.OperationID)
|
||||
}
|
||||
if !hasSecurity(operation, "sessionCookie") || hasSecurity(operation, "sessionCsrf") != unsafe[operation.OperationID] {
|
||||
t.Errorf("%s security = %v, want the session cookie, and the CSRF token exactly for a change", operation.OperationID, operation.Security)
|
||||
}
|
||||
for _, status := range []string{"401", "403"} {
|
||||
if operation.Responses[status] == nil {
|
||||
t.Errorf("%s does not declare %s", operation.OperationID, status)
|
||||
}
|
||||
}
|
||||
for _, parameter := range operation.Parameters {
|
||||
name := parameterName(parameter)
|
||||
if strings.EqualFold(name, "IdempotencyKey") || strings.EqualFold(name, "IfMatch") || strings.EqualFold(name, "Idempotency-Key") || strings.EqualFold(name, "If-Match") {
|
||||
t.Errorf("%s takes %s, but every setting is a replaced state with its version in the body", operation.OperationID, name)
|
||||
}
|
||||
}
|
||||
if success := operation.Responses["200"]; success != nil && success.Headers["Cache-Control"] == nil {
|
||||
t.Errorf("%s does not mark its 200 response no-store", operation.OperationID)
|
||||
}
|
||||
if operation.Responses["default"] == nil {
|
||||
t.Errorf("%s does not declare the problem default", operation.OperationID)
|
||||
}
|
||||
}
|
||||
for _, id := range []string{"SetMyPublication", "SetMySearchStatus"} {
|
||||
operation := operationByID(t, spec, id)
|
||||
if operation.Responses["412"] == nil || operation.Responses["400"] == nil {
|
||||
t.Errorf("%s does not declare 400 and 412", id)
|
||||
}
|
||||
update := resolveSchema(t, spec, operation.RequestBody.Content["application/json"].Schema)
|
||||
if !slices.Contains(update.Required, "expected_version") {
|
||||
t.Errorf("%s does not require expected_version", id)
|
||||
}
|
||||
}
|
||||
// Publishing needs the C2 consent, and a missing one is a state conflict.
|
||||
if operationByID(t, spec, "SetMyPublication").Responses["409"] == nil {
|
||||
t.Error("SetMyPublication does not declare 409 state_conflict for a missing C2 consent")
|
||||
}
|
||||
if operationByID(t, spec, "SetMySearchStatus").Responses["409"] != nil {
|
||||
t.Error("SetMySearchStatus declares 409: the status never depends on a consent")
|
||||
}
|
||||
// Hiding uses the same 404 for an unknown organization and one the
|
||||
// candidate cannot see; lifting the hiding reveals nothing and has no 404.
|
||||
hide := operationByID(t, spec, "HideOrganization")
|
||||
if hide.Responses["404"] == nil || hide.Responses["409"] == nil || hide.Responses["429"] == nil || hide.RequestBody != nil {
|
||||
t.Error("HideOrganization must declare 404, 409, and 429 and take no body")
|
||||
}
|
||||
unhide := operationByID(t, spec, "UnhideOrganization")
|
||||
if unhide.Responses["204"] == nil || unhide.Responses["404"] != nil {
|
||||
t.Error("UnhideOrganization must answer 204 and declare no 404: it reveals nothing about the organization")
|
||||
}
|
||||
// Lists page with the shared cursor parameters.
|
||||
for _, id := range []string{"ListMyHiddenOrganizations", "ListMyPrivacyHistory", "ListMyCardAccessHistory"} {
|
||||
names := []string{}
|
||||
for _, parameter := range operationByID(t, spec, id).Parameters {
|
||||
names = append(names, parameterName(parameter))
|
||||
}
|
||||
if !slices.Contains(names, "PageLimit") || !slices.Contains(names, "PageCursor") {
|
||||
t.Errorf("%s parameters = %v, want the shared PageLimit and PageCursor", id, names)
|
||||
}
|
||||
}
|
||||
|
||||
// No new problem code: every code of the privacy responses already exists.
|
||||
codes := enumValues(t, resolveSchema(t, spec, &ogen.Schema{Ref: "#/components/schemas/ProblemCode"}))
|
||||
for _, code := range []string{"state_conflict", "version_conflict", "not_found", "rate_limited", "validation_failed"} {
|
||||
if !slices.Contains(codes, code) {
|
||||
t.Errorf("ProblemCode has no %s", code)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The publication stores which fields are published and refers to the C2
|
||||
// consent of the ledger; it neither carries nor changes a consent. The search
|
||||
// status is not a consent either.
|
||||
func TestPublicationAndSearchStatusAreNotConsents(t *testing.T) {
|
||||
spec := parsePublicContract(t)
|
||||
index := componentsIndex(t, spec)
|
||||
|
||||
for _, pair := range []struct {
|
||||
name string
|
||||
want []string
|
||||
}{
|
||||
// The body names no consent: the server binds the active C2 record.
|
||||
{"PublicationUpdate", []string{"expected_version", "fields", "state"}},
|
||||
{"SearchStatusUpdate", []string{"expected_version", "value"}},
|
||||
{"Publication", []string{"closed_reason", "consent_id", "fields", "published_at", "state", "version"}},
|
||||
{"SearchStatus", []string{"confirmed_at", "lapsed", "lapses_at", "value", "version"}},
|
||||
{"HiddenOrganization", []string{"hidden_at", "organization"}},
|
||||
{"PrivacySettings", []string{"hidden_organizations_total", "publication", "search_status"}},
|
||||
} {
|
||||
schema := spec.Components.Schemas[pair.name]
|
||||
if schema == nil {
|
||||
t.Fatalf("the contract has no schema %s", pair.name)
|
||||
}
|
||||
if got := propertyNames(schema); !slices.Equal(got, pair.want) {
|
||||
t.Errorf("%s properties = %v, want %v", pair.name, got, pair.want)
|
||||
}
|
||||
if schema.AdditionalProperties.Bool == nil || *schema.AdditionalProperties.Bool {
|
||||
t.Errorf("%s accepts unknown fields", pair.name)
|
||||
}
|
||||
}
|
||||
|
||||
// The families do not reach one another. PrivacySettings is the one place
|
||||
// that reads the three together.
|
||||
families := map[string][]string{"publication": publicationSchemas, "search status": searchStatusSchemas, "hidden organizations": hiddenSchemas}
|
||||
for name, members := range families {
|
||||
for _, member := range members {
|
||||
for reached := range reachableSchemas(index, mustJSONValue(t, spec.Components.Schemas[member])) {
|
||||
for otherName, others := range families {
|
||||
if otherName != name && slices.Contains(others, reached) {
|
||||
t.Errorf("the %s schema %s reaches the %s schema %s", name, member, otherName, reached)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A consent, a profile, an account, or an invitation is reachable from
|
||||
// none of the settings: the status is a statement, never a consent.
|
||||
for _, name := range slices.Concat(publicationSchemas, searchStatusSchemas, hiddenSchemas, privacyOnlySchemas) {
|
||||
for reached := range reachableSchemas(index, mustJSONValue(t, spec.Components.Schemas[name])) {
|
||||
if strings.HasPrefix(reached, "Consent") || strings.HasPrefix(reached, "Profile") || strings.HasPrefix(reached, "CandidateProfile") ||
|
||||
strings.HasPrefix(reached, "Invitation") || strings.HasPrefix(reached, "Contact") || reached == "Session" || reached == "User" {
|
||||
t.Errorf("%s reaches %s", name, reached)
|
||||
}
|
||||
}
|
||||
}
|
||||
// The search status operation reaches no publication or hidden schema.
|
||||
statusOperation := reachableSchemas(index, mustJSONValue(t, spec.Paths[privacySearchStatusPath]))
|
||||
for _, name := range slices.Concat(publicationSchemas, hiddenSchemas, privacyOnlySchemas) {
|
||||
if statusOperation[name] {
|
||||
t.Errorf("the search status path reaches %s", name)
|
||||
}
|
||||
}
|
||||
|
||||
// The published field set cannot name a name, a contact, or the salary.
|
||||
fields := enumValues(t, resolveSchema(t, spec, &ogen.Schema{Ref: "#/components/schemas/CardField"}))
|
||||
want := []string{"categories", "stack", "experience", "soft_skills", "location", "relocation"}
|
||||
slices.Sort(fields)
|
||||
slices.Sort(want)
|
||||
if !slices.Equal(fields, want) {
|
||||
t.Errorf("CardField = %v, want %v", fields, want)
|
||||
}
|
||||
if update := spec.Components.Schemas["CardFieldSet"]; update.UniqueItems != true || update.MaxItems == nil || *update.MaxItems != uint64(len(want)) {
|
||||
t.Error("CardFieldSet must hold distinct items and at most one per field")
|
||||
}
|
||||
status := enumValues(t, resolveSchema(t, spec, &ogen.Schema{Ref: "#/components/schemas/SearchStatusValue"}))
|
||||
if !slices.Equal(status, []string{"looking", "not_looking"}) {
|
||||
t.Errorf("SearchStatusValue = %v, want looking and not_looking", status)
|
||||
}
|
||||
}
|
||||
|
||||
// The anonymous card never reaches a profile, a contact, or an identifier:
|
||||
// whatever an organization reads of a candidate before an accepted invitation
|
||||
// is limited to its own closed set of properties.
|
||||
func TestAnonymousCardReachesNoProfileOrContactSchema(t *testing.T) {
|
||||
spec := parsePublicContract(t)
|
||||
index := componentsIndex(t, spec)
|
||||
|
||||
card := spec.Components.Schemas["AnonymousCardContent"]
|
||||
if card == nil {
|
||||
t.Fatal("the contract has no AnonymousCardContent")
|
||||
}
|
||||
if got, want := propertyNames(card), []string{"categories", "experience_months", "location", "relocation", "soft_skills", "stack"}; !slices.Equal(got, want) {
|
||||
t.Errorf("AnonymousCardContent properties = %v, want %v", got, want)
|
||||
}
|
||||
if card.AdditionalProperties.Bool == nil || *card.AdditionalProperties.Bool {
|
||||
t.Error("AnonymousCardContent accepts unknown properties")
|
||||
}
|
||||
// Each property is a card field and nothing else; a null is a hidden or
|
||||
// missing value, never a flag that tells which.
|
||||
for _, forbidden := range []string{"email", "phone", "telegram", "contact", "name", "salary", "user", "account", "profile", "employer", "id", "url", "link", "github", "resume"} {
|
||||
for _, name := range propertyNames(card) {
|
||||
if strings.Contains(name, forbidden) {
|
||||
t.Errorf("AnonymousCardContent has the property %q, which looks like %q", name, forbidden)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// What the card and the preview reach is a small closed list of leaves.
|
||||
allowed := []string{"AnonymousCardContent", "CardCategory", "CardField", "CardFieldSet", "PublicationState", "SpecializationCode", "GradeCode", "StackTag", "Timestamp", "CardPreview"}
|
||||
for _, name := range []string{"AnonymousCardContent", "CardPreview"} {
|
||||
for reached := range reachableSchemas(index, mustJSONValue(t, spec.Components.Schemas[name])) {
|
||||
if !slices.Contains(allowed, reached) {
|
||||
t.Errorf("%s reaches %s, which the anonymous card must not carry", name, reached)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The private profile, the contact formats, and the contact disclosure
|
||||
// are not reachable from any privacy schema or operation.
|
||||
for path, item := range spec.Paths {
|
||||
if !strings.HasPrefix(path, privacyBasePath) {
|
||||
continue
|
||||
}
|
||||
for reached := range reachableSchemas(index, mustJSONValue(t, item)) {
|
||||
if isProfileSchema(reached) || strings.HasPrefix(reached, "Contact") || reached == "EmailAddress" || reached == "PhoneNumber" ||
|
||||
strings.HasPrefix(reached, "Invitation") || strings.HasPrefix(reached, "Need") || strings.HasPrefix(reached, "Consent") {
|
||||
t.Errorf("%s reaches %s", path, reached)
|
||||
}
|
||||
if !isPrivacySchema(reached) && !slices.Contains(sharedLeafSchemas, reached) && !strings.HasPrefix(reached, "Problem") &&
|
||||
reached != "Problem" && reached != "ProblemCode" {
|
||||
t.Errorf("%s reaches %s, which is neither a privacy schema nor a shared leaf", path, reached)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The reverse: the private profile family does not reach the card or any
|
||||
// visibility schema, and an organization path reaches no setting of a
|
||||
// candidate. The card content stays the only privacy schema meant for
|
||||
// organization-visible operations later (TASK-185).
|
||||
for name, schema := range spec.Components.Schemas {
|
||||
if isPrivacySchema(name) {
|
||||
continue
|
||||
}
|
||||
for reached := range reachableSchemas(index, mustJSONValue(t, schema)) {
|
||||
if isPrivacySchema(reached) && reached != "AnonymousCardContent" && reached != "CardCategory" && reached != "CardField" && reached != "CardFieldSet" {
|
||||
t.Errorf("%s reaches the candidate-private schema %s", name, reached)
|
||||
}
|
||||
}
|
||||
}
|
||||
for path, item := range spec.Paths {
|
||||
if !strings.HasPrefix(path, "/api/v1/organizations") {
|
||||
continue
|
||||
}
|
||||
for reached := range reachableSchemas(index, mustJSONValue(t, item)) {
|
||||
if isPrivacySchema(reached) {
|
||||
t.Errorf("%s reaches the candidate-private schema %s", path, reached)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, dto := range []any{api.AnonymousCardContent{}, api.CardCategory{}, api.CardPreview{}} {
|
||||
assertNoJSONFields(t, dto, []string{
|
||||
"full_name", "name", "email", "phone", "telegram", "contacts", "salary_minimum", "user_id", "account_id", "profile_id", "employer", "resume",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// The generated request DTOs carry only what the candidate may choose: no
|
||||
// consent identifier, time, interval, or policy version.
|
||||
func TestGeneratedPrivacyDTOsCarryNoServerOwnedFields(t *testing.T) {
|
||||
assertNoJSONFields(t, api.PublicationUpdate{}, []string{"consent_id", "consent", "published_at", "version", "user_id", "contacts", "full_name", "salary_minimum"})
|
||||
assertNoJSONFields(t, api.SearchStatusUpdate{}, []string{"confirmed_at", "lapses_at", "lapsed", "interval", "policy_version", "policy_version_id", "consent_id", "version"})
|
||||
assertNoJSONFields(t, api.SearchStatus{}, []string{"consent_id", "published", "fields", "hidden_organizations", "policy_version_id"})
|
||||
assertNoJSONFields(t, api.HiddenOrganization{}, []string{"user_id", "candidate_id", "candidate", "reason"})
|
||||
}
|
||||
|
||||
func newPrivacyRouter(t *testing.T) http.Handler {
|
||||
t.Helper()
|
||||
logger := slog.New(slog.DiscardHandler)
|
||||
healthHandler := newTestHealthHandler(func(context.Context) error { return nil })
|
||||
router, err := NewRouter(healthHandler, v1.NewHandler(healthHandler, problem.NewResponder(logger)), &recordingSecurity{}, problem.NewResponder(logger), metrics.New(), logger, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("NewRouter() error = %v", err)
|
||||
}
|
||||
return router
|
||||
}
|
||||
|
||||
// The operations are in the contract before their business logic: a schema
|
||||
// failure answers 400 before anything else, a valid request with an accepted
|
||||
// session answers 501, and no body reaches the handler without validation.
|
||||
func TestPrivacySchemaValidationPrecedesImplementation(t *testing.T) {
|
||||
session := map[string]string{"Cookie": testSessionCookie, "X-CSRF-Token": testCSRFToken}
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
method string
|
||||
path string
|
||||
body string
|
||||
statusCode int
|
||||
location api.ProblemFieldLocation
|
||||
pointer string
|
||||
code string
|
||||
}{
|
||||
{name: "a valid publication", method: http.MethodPut, path: privacyPublicationPath, body: `{"expected_version":0,"state":"published","fields":["categories","stack"]}`, statusCode: http.StatusNotImplemented},
|
||||
{name: "a valid closing", method: http.MethodPut, path: privacyPublicationPath, body: `{"expected_version":3,"state":"closed","fields":[]}`, statusCode: http.StatusNotImplemented},
|
||||
{name: "a missing version", method: http.MethodPut, path: privacyPublicationPath, body: `{"state":"closed","fields":[]}`, statusCode: http.StatusBadRequest, location: api.ProblemFieldLocationBody, pointer: "/expected_version", code: "required"},
|
||||
{name: "a negative version", method: http.MethodPut, path: privacyPublicationPath, body: `{"expected_version":-1,"state":"closed","fields":[]}`, statusCode: http.StatusBadRequest, location: api.ProblemFieldLocationBody, pointer: "/expected_version", code: "invalid"},
|
||||
{name: "a contact as a card field", method: http.MethodPut, path: privacyPublicationPath, body: `{"expected_version":0,"state":"published","fields":["phone"]}`, statusCode: http.StatusBadRequest, location: api.ProblemFieldLocationBody, pointer: "/fields/0", code: "invalid"},
|
||||
{name: "the full name as a card field", method: http.MethodPut, path: privacyPublicationPath, body: `{"expected_version":0,"state":"published","fields":["full_name"]}`, statusCode: http.StatusBadRequest, location: api.ProblemFieldLocationBody, pointer: "/fields/0", code: "invalid"},
|
||||
{name: "a repeated card field", method: http.MethodPut, path: privacyPublicationPath, body: `{"expected_version":0,"state":"published","fields":["stack","stack"]}`, statusCode: http.StatusBadRequest, location: api.ProblemFieldLocationBody, pointer: "/fields", code: "invalid"},
|
||||
{name: "a state outside the enum", method: http.MethodPut, path: privacyPublicationPath, body: `{"expected_version":0,"state":"draft","fields":[]}`, statusCode: http.StatusBadRequest, location: api.ProblemFieldLocationBody, pointer: "/state", code: "invalid"},
|
||||
{name: "a consent identifier from the client", method: http.MethodPut, path: privacyPublicationPath, body: `{"expected_version":0,"state":"published","fields":["stack"],"consent_id":"01928f7a-7a8b-7c9d-8e0f-1a2b3c4d5e60"}`, statusCode: http.StatusBadRequest, location: api.ProblemFieldLocationBody, pointer: "", code: "invalid"},
|
||||
{name: "a valid status", method: http.MethodPut, path: privacySearchStatusPath, body: `{"expected_version":0,"value":"looking"}`, statusCode: http.StatusNotImplemented},
|
||||
{name: "a status outside the enum", method: http.MethodPut, path: privacySearchStatusPath, body: `{"expected_version":0,"value":"open"}`, statusCode: http.StatusBadRequest, location: api.ProblemFieldLocationBody, pointer: "/value", code: "invalid"},
|
||||
{name: "a confirmation time from the client", method: http.MethodPut, path: privacySearchStatusPath, body: `{"expected_version":0,"value":"looking","confirmed_at":"2026-10-06T09:00:00Z"}`, statusCode: http.StatusBadRequest, location: api.ProblemFieldLocationBody, pointer: "", code: "invalid"},
|
||||
{name: "hiding an organization", method: http.MethodPut, path: privacyHiddenPath + "/" + privacyOrganizationID, statusCode: http.StatusNotImplemented},
|
||||
{name: "hiding a malformed identifier", method: http.MethodPut, path: privacyHiddenPath + "/not-a-uuid", statusCode: http.StatusBadRequest, location: api.ProblemFieldLocationPath, pointer: "/org_id", code: "invalid"},
|
||||
{name: "lifting a hiding", method: http.MethodDelete, path: privacyHiddenPath + "/" + privacyOrganizationID, statusCode: http.StatusNotImplemented},
|
||||
{name: "lifting a malformed identifier", method: http.MethodDelete, path: privacyHiddenPath + "/not-a-uuid", statusCode: http.StatusBadRequest, location: api.ProblemFieldLocationPath, pointer: "/org_id", code: "invalid"},
|
||||
{name: "the settings", method: http.MethodGet, path: privacyBasePath, statusCode: http.StatusNotImplemented},
|
||||
{name: "the preview", method: http.MethodGet, path: privacyBasePath + "/preview", statusCode: http.StatusNotImplemented},
|
||||
{name: "the hidden list", method: http.MethodGet, path: privacyHiddenPath + "?limit=50", statusCode: http.StatusNotImplemented},
|
||||
{name: "a hidden list limit over 100", method: http.MethodGet, path: privacyHiddenPath + "?limit=101", statusCode: http.StatusBadRequest, location: api.ProblemFieldLocationQuery, pointer: "/limit", code: "invalid"},
|
||||
{name: "the history", method: http.MethodGet, path: privacyBasePath + "/history", statusCode: http.StatusNotImplemented},
|
||||
{name: "a malformed history cursor", method: http.MethodGet, path: privacyBasePath + "/history?cursor=not%20a%20cursor", statusCode: http.StatusBadRequest, location: api.ProblemFieldLocationQuery, pointer: "/cursor", code: "invalid"},
|
||||
{name: "the access history", method: http.MethodGet, path: privacyBasePath + "/access-history", statusCode: http.StatusNotImplemented},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
response := serveIdentityRequest(t, newPrivacyRouter(t), identityRequest{method: test.method, path: test.path, body: test.body, headers: session})
|
||||
if test.statusCode == http.StatusNotImplemented {
|
||||
requireProblem(t, response, http.StatusNotImplemented, api.ProblemCodeNotImplemented)
|
||||
return
|
||||
}
|
||||
problemBody := requireProblem(t, response, test.statusCode, api.ProblemCodeValidationFailed)
|
||||
want := api.ProblemFieldError{In: test.location, Pointer: test.pointer, Code: test.code}
|
||||
for _, field := range problemBody.Errors {
|
||||
if field.In == want.In && field.Pointer == want.Pointer && field.Code == want.Code {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Fatalf("errors = %+v, want an entry %+v", problemBody.Errors, want)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Nothing here is reachable without a session: the deny-all security of the
|
||||
// scaffold answers 401 for every operation, with or without a cookie.
|
||||
func TestPrivacyAccessBeforeImplementation(t *testing.T) {
|
||||
session := map[string]string{"Cookie": testSessionCookie, "X-CSRF-Token": testCSRFToken}
|
||||
for _, test := range []identityRequest{
|
||||
{method: http.MethodGet, path: privacyBasePath},
|
||||
{method: http.MethodGet, path: privacyBasePath + "/preview"},
|
||||
{method: http.MethodGet, path: privacyBasePath + "/history", headers: session},
|
||||
{method: http.MethodGet, path: privacyBasePath + "/access-history"},
|
||||
{method: http.MethodGet, path: privacyHiddenPath},
|
||||
{method: http.MethodPut, path: privacyPublicationPath, body: `{"expected_version":0,"state":"closed","fields":[]}`, headers: session},
|
||||
{method: http.MethodPut, path: privacySearchStatusPath, body: `{"expected_version":0,"value":"not_looking"}`, headers: session},
|
||||
{method: http.MethodPut, path: privacyHiddenPath + "/" + privacyOrganizationID, headers: session},
|
||||
{method: http.MethodDelete, path: privacyHiddenPath + "/" + privacyOrganizationID, headers: session},
|
||||
} {
|
||||
t.Run(test.method+" "+test.path, func(t *testing.T) {
|
||||
router := newTestRouter(t, func(context.Context) error { return nil })
|
||||
requireProblem(t, serveIdentityRequest(t, router, test), http.StatusUnauthorized, api.ProblemCodeUnauthenticated)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,30 @@ type AssessmentFamily struct {
|
||||
RetiredBy pgtype.Text
|
||||
}
|
||||
|
||||
type CandidateEffectivePublication struct {
|
||||
UserID pgtype.UUID
|
||||
Fields []string
|
||||
PublishedAt pgtype.Timestamptz
|
||||
Version int64
|
||||
}
|
||||
|
||||
type CandidateHiddenOrganization struct {
|
||||
UserID pgtype.UUID
|
||||
OrganizationID pgtype.UUID
|
||||
HiddenAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type CandidatePrivacyEvent struct {
|
||||
ID pgtype.UUID
|
||||
UserID pgtype.UUID
|
||||
Kind string
|
||||
OccurredAt pgtype.Timestamptz
|
||||
Fields []string
|
||||
ConsentRecordID pgtype.UUID
|
||||
ConsentPurpose pgtype.Text
|
||||
OrganizationID pgtype.UUID
|
||||
}
|
||||
|
||||
type CandidateProfile struct {
|
||||
UserID pgtype.UUID
|
||||
Version int64
|
||||
@@ -62,6 +86,30 @@ type CandidateProfileClaim struct {
|
||||
ConfirmedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type CandidatePublication struct {
|
||||
UserID pgtype.UUID
|
||||
State string
|
||||
Fields []string
|
||||
ConsentRecordID pgtype.UUID
|
||||
ConsentPurpose pgtype.Text
|
||||
PublishedAt pgtype.Timestamptz
|
||||
ClosedAt pgtype.Timestamptz
|
||||
Version int64
|
||||
CreatedAt pgtype.Timestamptz
|
||||
UpdatedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type CandidateSearchStatus struct {
|
||||
UserID pgtype.UUID
|
||||
Status string
|
||||
ConfirmedAt pgtype.Timestamptz
|
||||
LapsesAt pgtype.Timestamptz
|
||||
PolicyVersionID pgtype.UUID
|
||||
Version int64
|
||||
CreatedAt pgtype.Timestamptz
|
||||
UpdatedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type ConsentRecord struct {
|
||||
ID pgtype.UUID
|
||||
SubjectID pgtype.UUID
|
||||
|
||||
@@ -0,0 +1,683 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: privacy.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const countCandidateHiddenOrganizations = `-- name: CountCandidateHiddenOrganizations :one
|
||||
SELECT count(*) AS total
|
||||
FROM candidate_hidden_organizations
|
||||
WHERE user_id = $1
|
||||
`
|
||||
|
||||
// Counts the hiding records of one candidate for the settings read.
|
||||
func (q *Queries) CountCandidateHiddenOrganizations(ctx context.Context, userID pgtype.UUID) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, countCandidateHiddenOrganizations, userID)
|
||||
var total int64
|
||||
err := row.Scan(&total)
|
||||
return total, err
|
||||
}
|
||||
|
||||
const deleteCandidateHiddenOrganization = `-- name: DeleteCandidateHiddenOrganization :one
|
||||
DELETE FROM candidate_hidden_organizations
|
||||
WHERE user_id = $1 AND organization_id = $2
|
||||
RETURNING organization_id
|
||||
`
|
||||
|
||||
type DeleteCandidateHiddenOrganizationParams struct {
|
||||
UserID pgtype.UUID
|
||||
OrganizationID pgtype.UUID
|
||||
}
|
||||
|
||||
// Lifts one hiding. No row returns when the organization was not hidden, so
|
||||
// the caller writes the history event only for a real deletion and answers
|
||||
// 204 either way.
|
||||
func (q *Queries) DeleteCandidateHiddenOrganization(ctx context.Context, arg DeleteCandidateHiddenOrganizationParams) (pgtype.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, deleteCandidateHiddenOrganization, arg.UserID, arg.OrganizationID)
|
||||
var organization_id pgtype.UUID
|
||||
err := row.Scan(&organization_id)
|
||||
return organization_id, err
|
||||
}
|
||||
|
||||
const getCandidateHiddenOrganization = `-- name: GetCandidateHiddenOrganization :one
|
||||
SELECT
|
||||
candidate_hidden_organizations.organization_id,
|
||||
organizations.name AS organization_name,
|
||||
candidate_hidden_organizations.hidden_at
|
||||
FROM candidate_hidden_organizations
|
||||
INNER JOIN organizations
|
||||
ON organizations.id = candidate_hidden_organizations.organization_id
|
||||
WHERE
|
||||
candidate_hidden_organizations.user_id = $1
|
||||
AND candidate_hidden_organizations.organization_id = $2
|
||||
`
|
||||
|
||||
type GetCandidateHiddenOrganizationParams struct {
|
||||
UserID pgtype.UUID
|
||||
OrganizationID pgtype.UUID
|
||||
}
|
||||
|
||||
type GetCandidateHiddenOrganizationRow struct {
|
||||
OrganizationID pgtype.UUID
|
||||
OrganizationName string
|
||||
HiddenAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
// Reads one hiding of the candidate with the current name of the
|
||||
// organization.
|
||||
func (q *Queries) GetCandidateHiddenOrganization(ctx context.Context, arg GetCandidateHiddenOrganizationParams) (GetCandidateHiddenOrganizationRow, error) {
|
||||
row := q.db.QueryRow(ctx, getCandidateHiddenOrganization, arg.UserID, arg.OrganizationID)
|
||||
var i GetCandidateHiddenOrganizationRow
|
||||
err := row.Scan(&i.OrganizationID, &i.OrganizationName, &i.HiddenAt)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertCandidateHiddenOrganization = `-- name: InsertCandidateHiddenOrganization :one
|
||||
INSERT INTO candidate_hidden_organizations (
|
||||
user_id,
|
||||
organization_id,
|
||||
hidden_at
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3
|
||||
)
|
||||
ON CONFLICT (user_id, organization_id) DO NOTHING
|
||||
RETURNING user_id, organization_id, hidden_at
|
||||
`
|
||||
|
||||
type InsertCandidateHiddenOrganizationParams struct {
|
||||
UserID pgtype.UUID
|
||||
OrganizationID pgtype.UUID
|
||||
At pgtype.Timestamptz
|
||||
}
|
||||
|
||||
// Hides one organization. No row returns when the pair already exists, and
|
||||
// the caller reads the existing record with its original time. The foreign key
|
||||
// refuses an unknown organization (SQLSTATE 23503); the caller answers it
|
||||
// exactly like an organization the candidate cannot see. The trigger refuses
|
||||
// the 1001st record (candidate_hidden_organizations_limit). The trigger runs
|
||||
// before the conflict check, so the caller reads the existing record first
|
||||
// and a repeat at the limit is never refused.
|
||||
func (q *Queries) InsertCandidateHiddenOrganization(ctx context.Context, arg InsertCandidateHiddenOrganizationParams) (CandidateHiddenOrganization, error) {
|
||||
row := q.db.QueryRow(ctx, insertCandidateHiddenOrganization, arg.UserID, arg.OrganizationID, arg.At)
|
||||
var i CandidateHiddenOrganization
|
||||
err := row.Scan(&i.UserID, &i.OrganizationID, &i.HiddenAt)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertCandidatePrivacyEvent = `-- name: InsertCandidatePrivacyEvent :exec
|
||||
INSERT INTO candidate_privacy_events (
|
||||
id,
|
||||
user_id,
|
||||
kind,
|
||||
occurred_at,
|
||||
fields,
|
||||
consent_record_id,
|
||||
organization_id
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6,
|
||||
$7
|
||||
)
|
||||
`
|
||||
|
||||
type InsertCandidatePrivacyEventParams struct {
|
||||
ID pgtype.UUID
|
||||
UserID pgtype.UUID
|
||||
Kind string
|
||||
OccurredAt pgtype.Timestamptz
|
||||
Fields []string
|
||||
ConsentRecordID pgtype.UUID
|
||||
OrganizationID pgtype.UUID
|
||||
}
|
||||
|
||||
// Appends one event to the settings history. The row holds identifiers, card
|
||||
// field codes, and times, never a name; the caller
|
||||
// writes it in the transaction of the change it records.
|
||||
func (q *Queries) InsertCandidatePrivacyEvent(ctx context.Context, arg InsertCandidatePrivacyEventParams) error {
|
||||
_, err := q.db.Exec(ctx, insertCandidatePrivacyEvent,
|
||||
arg.ID,
|
||||
arg.UserID,
|
||||
arg.Kind,
|
||||
arg.OccurredAt,
|
||||
arg.Fields,
|
||||
arg.ConsentRecordID,
|
||||
arg.OrganizationID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const insertCandidatePublication = `-- name: InsertCandidatePublication :one
|
||||
INSERT INTO candidate_publications (
|
||||
user_id,
|
||||
state,
|
||||
fields,
|
||||
consent_record_id,
|
||||
published_at,
|
||||
closed_at,
|
||||
version,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6,
|
||||
1,
|
||||
$7,
|
||||
$7
|
||||
)
|
||||
ON CONFLICT (user_id) DO NOTHING
|
||||
RETURNING user_id, version
|
||||
`
|
||||
|
||||
type InsertCandidatePublicationParams struct {
|
||||
UserID pgtype.UUID
|
||||
State string
|
||||
Fields []string
|
||||
ConsentRecordID pgtype.UUID
|
||||
PublishedAt pgtype.Timestamptz
|
||||
ClosedAt pgtype.Timestamptz
|
||||
At pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type InsertCandidatePublicationRow struct {
|
||||
UserID pgtype.UUID
|
||||
Version int64
|
||||
}
|
||||
|
||||
// Stores the first publication at version 1. No row returns when the account
|
||||
// already has a row, so a first publication that lost a race with another
|
||||
// one is answered as a version conflict. The foreign key refuses a record
|
||||
// that is not a C2 record of this account.
|
||||
func (q *Queries) InsertCandidatePublication(ctx context.Context, arg InsertCandidatePublicationParams) (InsertCandidatePublicationRow, error) {
|
||||
row := q.db.QueryRow(ctx, insertCandidatePublication,
|
||||
arg.UserID,
|
||||
arg.State,
|
||||
arg.Fields,
|
||||
arg.ConsentRecordID,
|
||||
arg.PublishedAt,
|
||||
arg.ClosedAt,
|
||||
arg.At,
|
||||
)
|
||||
var i InsertCandidatePublicationRow
|
||||
err := row.Scan(&i.UserID, &i.Version)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertCandidateSearchStatus = `-- name: InsertCandidateSearchStatus :one
|
||||
INSERT INTO candidate_search_statuses (
|
||||
user_id,
|
||||
status,
|
||||
confirmed_at,
|
||||
lapses_at,
|
||||
policy_version_id,
|
||||
version,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
1,
|
||||
$6,
|
||||
$6
|
||||
)
|
||||
ON CONFLICT (user_id) DO NOTHING
|
||||
RETURNING user_id, version
|
||||
`
|
||||
|
||||
type InsertCandidateSearchStatusParams struct {
|
||||
UserID pgtype.UUID
|
||||
Status string
|
||||
ConfirmedAt pgtype.Timestamptz
|
||||
LapsesAt pgtype.Timestamptz
|
||||
PolicyVersionID pgtype.UUID
|
||||
At pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type InsertCandidateSearchStatusRow struct {
|
||||
UserID pgtype.UUID
|
||||
Version int64
|
||||
}
|
||||
|
||||
// Stores the first status at version 1; no row returns when one exists.
|
||||
func (q *Queries) InsertCandidateSearchStatus(ctx context.Context, arg InsertCandidateSearchStatusParams) (InsertCandidateSearchStatusRow, error) {
|
||||
row := q.db.QueryRow(ctx, insertCandidateSearchStatus,
|
||||
arg.UserID,
|
||||
arg.Status,
|
||||
arg.ConfirmedAt,
|
||||
arg.LapsesAt,
|
||||
arg.PolicyVersionID,
|
||||
arg.At,
|
||||
)
|
||||
var i InsertCandidateSearchStatusRow
|
||||
err := row.Scan(&i.UserID, &i.Version)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listCandidateHiddenOrganizations = `-- name: ListCandidateHiddenOrganizations :many
|
||||
SELECT
|
||||
candidate_hidden_organizations.organization_id,
|
||||
organizations.name AS organization_name,
|
||||
candidate_hidden_organizations.hidden_at
|
||||
FROM candidate_hidden_organizations
|
||||
INNER JOIN organizations
|
||||
ON organizations.id = candidate_hidden_organizations.organization_id
|
||||
WHERE
|
||||
candidate_hidden_organizations.user_id = $1
|
||||
AND (
|
||||
$2::timestamptz IS NULL
|
||||
OR (
|
||||
candidate_hidden_organizations.hidden_at,
|
||||
candidate_hidden_organizations.organization_id
|
||||
) < (
|
||||
$2::timestamptz,
|
||||
$3::uuid
|
||||
)
|
||||
)
|
||||
ORDER BY
|
||||
candidate_hidden_organizations.hidden_at DESC,
|
||||
candidate_hidden_organizations.organization_id DESC
|
||||
LIMIT $4
|
||||
`
|
||||
|
||||
type ListCandidateHiddenOrganizationsParams struct {
|
||||
UserID pgtype.UUID
|
||||
AfterHiddenAt pgtype.Timestamptz
|
||||
AfterOrganizationID pgtype.UUID
|
||||
RowLimit int32
|
||||
}
|
||||
|
||||
type ListCandidateHiddenOrganizationsRow struct {
|
||||
OrganizationID pgtype.UUID
|
||||
OrganizationName string
|
||||
HiddenAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
// One page of the candidate's hidden organizations, newest first with the
|
||||
// organization identifier as the tie-breaker. The page continues after the
|
||||
// (hidden_at, organization_id) position of the last record of the previous
|
||||
// page.
|
||||
func (q *Queries) ListCandidateHiddenOrganizations(ctx context.Context, arg ListCandidateHiddenOrganizationsParams) ([]ListCandidateHiddenOrganizationsRow, error) {
|
||||
rows, err := q.db.Query(ctx, listCandidateHiddenOrganizations,
|
||||
arg.UserID,
|
||||
arg.AfterHiddenAt,
|
||||
arg.AfterOrganizationID,
|
||||
arg.RowLimit,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListCandidateHiddenOrganizationsRow
|
||||
for rows.Next() {
|
||||
var i ListCandidateHiddenOrganizationsRow
|
||||
if err := rows.Scan(&i.OrganizationID, &i.OrganizationName, &i.HiddenAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listCandidatePrivacyEvents = `-- name: ListCandidatePrivacyEvents :many
|
||||
SELECT
|
||||
candidate_privacy_events.id,
|
||||
candidate_privacy_events.kind,
|
||||
candidate_privacy_events.occurred_at,
|
||||
candidate_privacy_events.fields,
|
||||
candidate_privacy_events.consent_record_id,
|
||||
candidate_privacy_events.organization_id,
|
||||
organizations.name AS organization_name
|
||||
FROM candidate_privacy_events
|
||||
LEFT JOIN organizations
|
||||
ON organizations.id = candidate_privacy_events.organization_id
|
||||
WHERE
|
||||
candidate_privacy_events.user_id = $1
|
||||
AND (
|
||||
$2::timestamptz IS NULL
|
||||
OR (candidate_privacy_events.occurred_at, candidate_privacy_events.id) < (
|
||||
$2::timestamptz,
|
||||
$3::uuid
|
||||
)
|
||||
)
|
||||
ORDER BY
|
||||
candidate_privacy_events.occurred_at DESC,
|
||||
candidate_privacy_events.id DESC
|
||||
LIMIT $4
|
||||
`
|
||||
|
||||
type ListCandidatePrivacyEventsParams struct {
|
||||
UserID pgtype.UUID
|
||||
AfterOccurredAt pgtype.Timestamptz
|
||||
AfterID pgtype.UUID
|
||||
RowLimit int32
|
||||
}
|
||||
|
||||
type ListCandidatePrivacyEventsRow struct {
|
||||
ID pgtype.UUID
|
||||
Kind string
|
||||
OccurredAt pgtype.Timestamptz
|
||||
Fields []string
|
||||
ConsentRecordID pgtype.UUID
|
||||
OrganizationID pgtype.UUID
|
||||
OrganizationName pgtype.Text
|
||||
}
|
||||
|
||||
// One page of the candidate's settings history, newest first with the event
|
||||
// identifier as the tie-breaker. The organization name is resolved here, at
|
||||
// read time, and is the current name. The page continues after the
|
||||
// (occurred_at, id) position of the last event of the previous page.
|
||||
func (q *Queries) ListCandidatePrivacyEvents(ctx context.Context, arg ListCandidatePrivacyEventsParams) ([]ListCandidatePrivacyEventsRow, error) {
|
||||
rows, err := q.db.Query(ctx, listCandidatePrivacyEvents,
|
||||
arg.UserID,
|
||||
arg.AfterOccurredAt,
|
||||
arg.AfterID,
|
||||
arg.RowLimit,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListCandidatePrivacyEventsRow
|
||||
for rows.Next() {
|
||||
var i ListCandidatePrivacyEventsRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Kind,
|
||||
&i.OccurredAt,
|
||||
&i.Fields,
|
||||
&i.ConsentRecordID,
|
||||
&i.OrganizationID,
|
||||
&i.OrganizationName,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const lockCurrentC2Record = `-- name: LockCurrentC2Record :one
|
||||
SELECT id
|
||||
FROM consent_records
|
||||
WHERE
|
||||
subject_id = $1
|
||||
AND purpose = 'c2'
|
||||
AND revoked_at IS NULL
|
||||
ORDER BY granted_at DESC, id DESC
|
||||
LIMIT 1
|
||||
FOR SHARE
|
||||
`
|
||||
|
||||
// Takes the candidate's current unrevoked C2 record for a publication and
|
||||
// keeps it locked until the transaction ends. The share lock conflicts with
|
||||
// the revocation stamp (an UPDATE of the row), so a revocation either commits
|
||||
// before this statement, which then returns no row and the publication is
|
||||
// refused, or waits until the publication transaction commits and closes the
|
||||
// card right after. The caller must run it in the transaction that writes the
|
||||
// publication and must re-read the effective state (ReadCandidatePublication)
|
||||
// in that transaction to build its response.
|
||||
func (q *Queries) LockCurrentC2Record(ctx context.Context, subjectID pgtype.UUID) (pgtype.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, lockCurrentC2Record, subjectID)
|
||||
var id pgtype.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const readCandidatePublication = `-- name: ReadCandidatePublication :one
|
||||
|
||||
SELECT
|
||||
candidate_publications.user_id,
|
||||
candidate_publications.state,
|
||||
candidate_publications.fields,
|
||||
candidate_publications.consent_record_id,
|
||||
candidate_publications.published_at,
|
||||
candidate_publications.closed_at,
|
||||
candidate_publications.version,
|
||||
candidate_publications.created_at,
|
||||
candidate_publications.updated_at,
|
||||
consent_records.revoked_at AS consent_revoked_at
|
||||
FROM candidate_publications
|
||||
INNER JOIN consent_records
|
||||
ON consent_records.id = candidate_publications.consent_record_id
|
||||
WHERE candidate_publications.user_id = $1
|
||||
`
|
||||
|
||||
type ReadCandidatePublicationRow struct {
|
||||
UserID pgtype.UUID
|
||||
State string
|
||||
Fields []string
|
||||
ConsentRecordID pgtype.UUID
|
||||
PublishedAt pgtype.Timestamptz
|
||||
ClosedAt pgtype.Timestamptz
|
||||
Version int64
|
||||
CreatedAt pgtype.Timestamptz
|
||||
UpdatedAt pgtype.Timestamptz
|
||||
ConsentRevokedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
// Queries of the candidate visibility settings (TASK-088): the publication of
|
||||
// the card, the search status, the hidden organizations, and the history of
|
||||
// these settings. Every statement is scoped by the candidate's user_id, and
|
||||
// no statement selects another account's row. No statement reads or writes a
|
||||
// profile value, a name, or a contact. A candidate with no row is closed, not
|
||||
// looking, and hides nobody; no statement creates a row except an explicit
|
||||
// act of the candidate.
|
||||
// Reads the publication with the revocation state of the C2 record behind it
|
||||
// in one statement, so the stored setting and the ledger come from one
|
||||
// snapshot. The effective state is computed from them: published only while
|
||||
// consent_revoked_at is NULL. No row means the candidate never published.
|
||||
func (q *Queries) ReadCandidatePublication(ctx context.Context, userID pgtype.UUID) (ReadCandidatePublicationRow, error) {
|
||||
row := q.db.QueryRow(ctx, readCandidatePublication, userID)
|
||||
var i ReadCandidatePublicationRow
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.State,
|
||||
&i.Fields,
|
||||
&i.ConsentRecordID,
|
||||
&i.PublishedAt,
|
||||
&i.ClosedAt,
|
||||
&i.Version,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.ConsentRevokedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const readCandidateSearchStatus = `-- name: ReadCandidateSearchStatus :one
|
||||
SELECT
|
||||
user_id,
|
||||
status,
|
||||
confirmed_at,
|
||||
lapses_at,
|
||||
policy_version_id,
|
||||
version,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM candidate_search_statuses
|
||||
WHERE user_id = $1
|
||||
`
|
||||
|
||||
// No row means the status was never set, which reads as not looking. The
|
||||
// lapse is computed by the caller from lapses_at and its clock and is never
|
||||
// written.
|
||||
func (q *Queries) ReadCandidateSearchStatus(ctx context.Context, userID pgtype.UUID) (CandidateSearchStatus, error) {
|
||||
row := q.db.QueryRow(ctx, readCandidateSearchStatus, userID)
|
||||
var i CandidateSearchStatus
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.Status,
|
||||
&i.ConfirmedAt,
|
||||
&i.LapsesAt,
|
||||
&i.PolicyVersionID,
|
||||
&i.Version,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const readPublicationVisibleToOrganization = `-- name: ReadPublicationVisibleToOrganization :one
|
||||
SELECT
|
||||
effective.user_id,
|
||||
effective.fields,
|
||||
effective.published_at
|
||||
FROM candidate_effective_publications AS effective
|
||||
WHERE
|
||||
effective.user_id = $1
|
||||
AND NOT exists(
|
||||
SELECT 1 FROM candidate_hidden_organizations AS hidden
|
||||
WHERE
|
||||
hidden.user_id = effective.user_id
|
||||
AND hidden.organization_id = $2
|
||||
)
|
||||
`
|
||||
|
||||
type ReadPublicationVisibleToOrganizationParams struct {
|
||||
UserID pgtype.UUID
|
||||
OrganizationID pgtype.UUID
|
||||
}
|
||||
|
||||
type ReadPublicationVisibleToOrganizationRow struct {
|
||||
UserID pgtype.UUID
|
||||
Fields []string
|
||||
PublishedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
// The organization-facing read of a candidate's publication: the effective
|
||||
// view (published and backed by an unrevoked C2) and no hiding of the reading
|
||||
// organization. No row means the organization reads nothing, whichever of
|
||||
// the reasons applies, so it cannot tell a hidden candidate from an
|
||||
// unpublished one. Every organization-facing read of a publication starts
|
||||
// from this shape (TASK-185, TASK-089, TASK-090).
|
||||
func (q *Queries) ReadPublicationVisibleToOrganization(ctx context.Context, arg ReadPublicationVisibleToOrganizationParams) (ReadPublicationVisibleToOrganizationRow, error) {
|
||||
row := q.db.QueryRow(ctx, readPublicationVisibleToOrganization, arg.UserID, arg.OrganizationID)
|
||||
var i ReadPublicationVisibleToOrganizationRow
|
||||
err := row.Scan(&i.UserID, &i.Fields, &i.PublishedAt)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateCandidatePublication = `-- name: UpdateCandidatePublication :one
|
||||
UPDATE candidate_publications
|
||||
SET
|
||||
state = $1,
|
||||
fields = $2,
|
||||
consent_record_id = $3,
|
||||
published_at = $4,
|
||||
closed_at = $5,
|
||||
version = candidate_publications.version + 1,
|
||||
updated_at = greatest(candidate_publications.updated_at, $6)
|
||||
WHERE
|
||||
candidate_publications.user_id = $7
|
||||
AND candidate_publications.version = $8
|
||||
RETURNING user_id, version
|
||||
`
|
||||
|
||||
type UpdateCandidatePublicationParams struct {
|
||||
State string
|
||||
Fields []string
|
||||
ConsentRecordID pgtype.UUID
|
||||
PublishedAt pgtype.Timestamptz
|
||||
ClosedAt pgtype.Timestamptz
|
||||
At pgtype.Timestamptz
|
||||
UserID pgtype.UUID
|
||||
ExpectedVersion int64
|
||||
}
|
||||
|
||||
type UpdateCandidatePublicationRow struct {
|
||||
UserID pgtype.UUID
|
||||
Version int64
|
||||
}
|
||||
|
||||
// Replaces the publication over the version the caller read and advances the
|
||||
// version in the same statement. No row returns for a stale version, which
|
||||
// the caller answers as a version conflict. The update time never moves back,
|
||||
// as in the profile.
|
||||
func (q *Queries) UpdateCandidatePublication(ctx context.Context, arg UpdateCandidatePublicationParams) (UpdateCandidatePublicationRow, error) {
|
||||
row := q.db.QueryRow(ctx, updateCandidatePublication,
|
||||
arg.State,
|
||||
arg.Fields,
|
||||
arg.ConsentRecordID,
|
||||
arg.PublishedAt,
|
||||
arg.ClosedAt,
|
||||
arg.At,
|
||||
arg.UserID,
|
||||
arg.ExpectedVersion,
|
||||
)
|
||||
var i UpdateCandidatePublicationRow
|
||||
err := row.Scan(&i.UserID, &i.Version)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateCandidateSearchStatus = `-- name: UpdateCandidateSearchStatus :one
|
||||
UPDATE candidate_search_statuses
|
||||
SET
|
||||
status = $1,
|
||||
confirmed_at = $2,
|
||||
lapses_at = $3,
|
||||
policy_version_id = $4,
|
||||
version = candidate_search_statuses.version + 1,
|
||||
updated_at = greatest(candidate_search_statuses.updated_at, $5)
|
||||
WHERE
|
||||
candidate_search_statuses.user_id = $6
|
||||
AND candidate_search_statuses.version = $7
|
||||
RETURNING user_id, version
|
||||
`
|
||||
|
||||
type UpdateCandidateSearchStatusParams struct {
|
||||
Status string
|
||||
ConfirmedAt pgtype.Timestamptz
|
||||
LapsesAt pgtype.Timestamptz
|
||||
PolicyVersionID pgtype.UUID
|
||||
At pgtype.Timestamptz
|
||||
UserID pgtype.UUID
|
||||
ExpectedVersion int64
|
||||
}
|
||||
|
||||
type UpdateCandidateSearchStatusRow struct {
|
||||
UserID pgtype.UUID
|
||||
Version int64
|
||||
}
|
||||
|
||||
// Replaces the status over the version the caller read. Looking also stores
|
||||
// the new confirmation, lapse time, and policy version; not looking clears
|
||||
// them. It never names the publication or the hidden organizations.
|
||||
func (q *Queries) UpdateCandidateSearchStatus(ctx context.Context, arg UpdateCandidateSearchStatusParams) (UpdateCandidateSearchStatusRow, error) {
|
||||
row := q.db.QueryRow(ctx, updateCandidateSearchStatus,
|
||||
arg.Status,
|
||||
arg.ConfirmedAt,
|
||||
arg.LapsesAt,
|
||||
arg.PolicyVersionID,
|
||||
arg.At,
|
||||
arg.UserID,
|
||||
arg.ExpectedVersion,
|
||||
)
|
||||
var i UpdateCandidateSearchStatusRow
|
||||
err := row.Scan(&i.UserID, &i.Version)
|
||||
return i, err
|
||||
}
|
||||
@@ -88,9 +88,15 @@ type Querier interface {
|
||||
// returned registration version in the same transaction, rolled back when it
|
||||
// matches no row.
|
||||
ConsumeEmailToken(ctx context.Context, arg ConsumeEmailTokenParams) (EmailToken, error)
|
||||
// Counts the hiding records of one candidate for the settings read.
|
||||
CountCandidateHiddenOrganizations(ctx context.Context, userID pgtype.UUID) (int64, error)
|
||||
// Counts the families of a category that have at least one published
|
||||
// version, however many versions each has.
|
||||
CountPublishedAssessmentFamilies(ctx context.Context, category string) (int32, error)
|
||||
// Lifts one hiding. No row returns when the organization was not hidden, so
|
||||
// the caller writes the history event only for a real deletion and answers
|
||||
// 204 either way.
|
||||
DeleteCandidateHiddenOrganization(ctx context.Context, arg DeleteCandidateHiddenOrganizationParams) (pgtype.UUID, error)
|
||||
// Removes the claims that a save replaces. The adapter calls it after the
|
||||
// version advanced and before it inserts the new set, in one transaction.
|
||||
DeleteCandidateProfileClaims(ctx context.Context, userID pgtype.UUID) error
|
||||
@@ -139,6 +145,9 @@ type Querier interface {
|
||||
GetActiveSessionByTokenHash(ctx context.Context, arg GetActiveSessionByTokenHashParams) (Session, error)
|
||||
GetAssessmentFamilyByID(ctx context.Context, id pgtype.UUID) (AssessmentFamily, error)
|
||||
GetAssessmentFamilyVersion(ctx context.Context, arg GetAssessmentFamilyVersionParams) (AssessmentFamily, error)
|
||||
// Reads one hiding of the candidate with the current name of the
|
||||
// organization.
|
||||
GetCandidateHiddenOrganization(ctx context.Context, arg GetCandidateHiddenOrganizationParams) (GetCandidateHiddenOrganizationRow, error)
|
||||
GetConsentText(ctx context.Context, arg GetConsentTextParams) (ConsentText, error)
|
||||
GetContactConsentRecordByInvitation(ctx context.Context, arg GetContactConsentRecordByInvitationParams) (GetContactConsentRecordByInvitationRow, error)
|
||||
GetCurrentAssessmentCategoryOpening(ctx context.Context, category string) (AssessmentCategoryOpening, error)
|
||||
@@ -222,6 +231,18 @@ type Querier interface {
|
||||
// returns no row instead of an error, so a conflict does not abort the
|
||||
// surrounding transaction.
|
||||
InsertAssessmentFamily(ctx context.Context, arg InsertAssessmentFamilyParams) (AssessmentFamily, error)
|
||||
// Hides one organization. No row returns when the pair already exists, and
|
||||
// the caller reads the existing record with its original time. The foreign key
|
||||
// refuses an unknown organization (SQLSTATE 23503); the caller answers it
|
||||
// exactly like an organization the candidate cannot see. The trigger refuses
|
||||
// the 1001st record (candidate_hidden_organizations_limit). The trigger runs
|
||||
// before the conflict check, so the caller reads the existing record first
|
||||
// and a repeat at the limit is never refused.
|
||||
InsertCandidateHiddenOrganization(ctx context.Context, arg InsertCandidateHiddenOrganizationParams) (CandidateHiddenOrganization, error)
|
||||
// Appends one event to the settings history. The row holds identifiers, card
|
||||
// field codes, and times, never a name; the caller
|
||||
// writes it in the transaction of the change it records.
|
||||
InsertCandidatePrivacyEvent(ctx context.Context, arg InsertCandidatePrivacyEventParams) error
|
||||
// Queries of the manual candidate profile (TASK-066). The profile is personal
|
||||
// data of the account that owns it: every statement is scoped by user_id, and
|
||||
// no statement selects another account's row. None of them names a file, the
|
||||
@@ -235,6 +256,13 @@ type Querier interface {
|
||||
// statement never takes a trust level from the caller, because every claim
|
||||
// has level 0.
|
||||
InsertCandidateProfileClaim(ctx context.Context, arg InsertCandidateProfileClaimParams) error
|
||||
// Stores the first publication at version 1. No row returns when the account
|
||||
// already has a row, so a first publication that lost a race with another
|
||||
// one is answered as a version conflict. The foreign key refuses a record
|
||||
// that is not a C2 record of this account.
|
||||
InsertCandidatePublication(ctx context.Context, arg InsertCandidatePublicationParams) (InsertCandidatePublicationRow, error)
|
||||
// Stores the first status at version 1; no row returns when one exists.
|
||||
InsertCandidateSearchStatus(ctx context.Context, arg InsertCandidateSearchStatusParams) (InsertCandidateSearchStatusRow, error)
|
||||
// Records a grant of C1, C2, C3, or C5. An unrevoked record of the same
|
||||
// subject, purpose, and text version already exists when no row returns;
|
||||
// the insert then changes nothing and does not abort the transaction.
|
||||
@@ -297,6 +325,16 @@ type Querier interface {
|
||||
// given position; an empty key and version 0 start at the beginning. The
|
||||
// (family_key, version) unique index serves the scan.
|
||||
ListAssessmentFamiliesByCategory(ctx context.Context, arg ListAssessmentFamiliesByCategoryParams) ([]AssessmentFamily, error)
|
||||
// One page of the candidate's hidden organizations, newest first with the
|
||||
// organization identifier as the tie-breaker. The page continues after the
|
||||
// (hidden_at, organization_id) position of the last record of the previous
|
||||
// page.
|
||||
ListCandidateHiddenOrganizations(ctx context.Context, arg ListCandidateHiddenOrganizationsParams) ([]ListCandidateHiddenOrganizationsRow, error)
|
||||
// One page of the candidate's settings history, newest first with the event
|
||||
// identifier as the tie-breaker. The organization name is resolved here, at
|
||||
// read time, and is the current name. The page continues after the
|
||||
// (occurred_at, id) position of the last event of the previous page.
|
||||
ListCandidatePrivacyEvents(ctx context.Context, arg ListCandidatePrivacyEventsParams) ([]ListCandidatePrivacyEventsRow, error)
|
||||
// One page of the subject's ledger, newest grant first, optionally limited
|
||||
// to one state. Every record query is scoped by the subject, so a caller
|
||||
// never reads or revokes another subject's consent. The state is computed,
|
||||
@@ -329,6 +367,15 @@ type Querier interface {
|
||||
// canceled, or reclaimed after the lease expired. While the lock is held,
|
||||
// other workers skip the row, so the handler never runs twice at once.
|
||||
LockClaimedScheduledJob(ctx context.Context, arg LockClaimedScheduledJobParams) (int64, error)
|
||||
// Takes the candidate's current unrevoked C2 record for a publication and
|
||||
// keeps it locked until the transaction ends. The share lock conflicts with
|
||||
// the revocation stamp (an UPDATE of the row), so a revocation either commits
|
||||
// before this statement, which then returns no row and the publication is
|
||||
// refused, or waits until the publication transaction commits and closes the
|
||||
// card right after. The caller must run it in the transaction that writes the
|
||||
// publication and must re-read the effective state (ReadCandidatePublication)
|
||||
// in that transaction to build its response.
|
||||
LockCurrentC2Record(ctx context.Context, subjectID pgtype.UUID) (pgtype.UUID, error)
|
||||
// Locks the listed window rows until the transaction ends, in
|
||||
// (period_kind, period_start) order, the same order for every caller, and
|
||||
// returns their usage. Under READ COMMITTED a waiting caller reads the usage
|
||||
@@ -387,6 +434,29 @@ type Querier interface {
|
||||
// 0). Claims come in a stable order: single fields by kind, list items by
|
||||
// position. Never replace this with two statements.
|
||||
ReadCandidateProfile(ctx context.Context, userID pgtype.UUID) ([]ReadCandidateProfileRow, error)
|
||||
// Queries of the candidate visibility settings (TASK-088): the publication of
|
||||
// the card, the search status, the hidden organizations, and the history of
|
||||
// these settings. Every statement is scoped by the candidate's user_id, and
|
||||
// no statement selects another account's row. No statement reads or writes a
|
||||
// profile value, a name, or a contact. A candidate with no row is closed, not
|
||||
// looking, and hides nobody; no statement creates a row except an explicit
|
||||
// act of the candidate.
|
||||
// Reads the publication with the revocation state of the C2 record behind it
|
||||
// in one statement, so the stored setting and the ledger come from one
|
||||
// snapshot. The effective state is computed from them: published only while
|
||||
// consent_revoked_at is NULL. No row means the candidate never published.
|
||||
ReadCandidatePublication(ctx context.Context, userID pgtype.UUID) (ReadCandidatePublicationRow, error)
|
||||
// No row means the status was never set, which reads as not looking. The
|
||||
// lapse is computed by the caller from lapses_at and its clock and is never
|
||||
// written.
|
||||
ReadCandidateSearchStatus(ctx context.Context, userID pgtype.UUID) (CandidateSearchStatus, error)
|
||||
// The organization-facing read of a candidate's publication: the effective
|
||||
// view (published and backed by an unrevoked C2) and no hiding of the reading
|
||||
// organization. No row means the organization reads nothing, whichever of
|
||||
// the reasons applies, so it cannot tell a hidden candidate from an
|
||||
// unpublished one. Every organization-facing read of a publication starts
|
||||
// from this shape (TASK-185, TASK-089, TASK-090).
|
||||
ReadPublicationVisibleToOrganization(ctx context.Context, arg ReadPublicationVisibleToOrganizationParams) (ReadPublicationVisibleToOrganizationRow, error)
|
||||
// Advances a delivery past one attempt and appends the attempt in one
|
||||
// statement, so both happen or neither does, inside or outside a
|
||||
// transaction. The update applies only while the stored version still
|
||||
@@ -480,6 +550,15 @@ type Querier interface {
|
||||
// revoked, expired, or idle session is not revived; the update re-checks
|
||||
// those conditions against a concurrent change.
|
||||
TouchSession(ctx context.Context, arg TouchSessionParams) (TouchSessionRow, error)
|
||||
// Replaces the publication over the version the caller read and advances the
|
||||
// version in the same statement. No row returns for a stale version, which
|
||||
// the caller answers as a version conflict. The update time never moves back,
|
||||
// as in the profile.
|
||||
UpdateCandidatePublication(ctx context.Context, arg UpdateCandidatePublicationParams) (UpdateCandidatePublicationRow, error)
|
||||
// Replaces the status over the version the caller read. Looking also stores
|
||||
// the new confirmation, lapse time, and policy version; not looking clears
|
||||
// them. It never names the publication or the hidden organizations.
|
||||
UpdateCandidateSearchStatus(ctx context.Context, arg UpdateCandidateSearchStatusParams) (UpdateCandidateSearchStatusRow, error)
|
||||
// Stores a change of the delivery state that is not an attempt: a quota wait,
|
||||
// a cancellation, or a new provider account before the first attempt. It
|
||||
// applies only while the stored version still equals expected_version and
|
||||
|
||||
@@ -0,0 +1,837 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/text/unicode/norm"
|
||||
)
|
||||
|
||||
// This file holds the visibility settings of a candidate (PRD FR02 and FR12,
|
||||
// TASK-088): the publication of the anonymous card, the search status, and the
|
||||
// organizations the candidate hides the profile from.
|
||||
//
|
||||
// The rules that shape every type here:
|
||||
// - A candidate is closed by default. A new account has version 0 of every
|
||||
// setting, and no value in this file opens anything by itself.
|
||||
// - The consent C2 stays in the consent ledger. A publication refers to the
|
||||
// C2 record that backs it and is effective only while that record is
|
||||
// unrevoked; the search status is a statement and never a consent, so no
|
||||
// function of one setting reads or changes another.
|
||||
// - Nothing becomes more public automatically: a lapse of the search status
|
||||
// only narrows it, a revoked C2 closes the card, and a new C2 publishes
|
||||
// nothing.
|
||||
|
||||
var (
|
||||
// ErrInvalidVisibility reports a visibility setting, request, or stored
|
||||
// row that breaks a rule.
|
||||
ErrInvalidVisibility = errors.New("invalid visibility setting")
|
||||
|
||||
// ErrVisibilityVersionConflict reports that the expected version of a
|
||||
// setting is not the current one: another change advanced it, or the
|
||||
// client named a version that does not exist. Nothing was changed; the
|
||||
// client reads the settings again.
|
||||
ErrVisibilityVersionConflict = errors.New("visibility setting changed concurrently")
|
||||
|
||||
// ErrPublicationConsentRequired reports a publication without an active
|
||||
// C2 consent of the account. The candidate gives C2 first.
|
||||
ErrPublicationConsentRequired = errors.New("publication needs an active C2 consent")
|
||||
)
|
||||
|
||||
// VisibilityFieldError reports the request field that broke a visibility
|
||||
// rule. It matches ErrInvalidVisibility with errors.Is, and an HTTP adapter
|
||||
// reads Pointer with errors.As to answer 400 with the pointer of the field.
|
||||
// Neither field quotes the submitted value.
|
||||
type VisibilityFieldError struct {
|
||||
// Pointer is the JSON Pointer of the field in the request body, such as
|
||||
// "/fields".
|
||||
Pointer string
|
||||
// Reason says which rule the field broke.
|
||||
Reason string
|
||||
}
|
||||
|
||||
func (err *VisibilityFieldError) Error() string {
|
||||
return "visibility field " + err.Pointer + " " + err.Reason
|
||||
}
|
||||
|
||||
func (err *VisibilityFieldError) Unwrap() error { return ErrInvalidVisibility }
|
||||
|
||||
func invalidVisibilityField(location, pointer, reason string) error {
|
||||
return fmt.Errorf("%s - %w", location, &VisibilityFieldError{Pointer: pointer, Reason: reason})
|
||||
}
|
||||
|
||||
// MaxHiddenOrganizations is the number of organizations one candidate can
|
||||
// hide the profile from. The database trigger
|
||||
// candidate_hidden_organizations_enforce_limit enforces the same bound, and
|
||||
// the contract's hidden_organizations_total maximum equals it.
|
||||
const MaxHiddenOrganizations = 1000
|
||||
|
||||
// CardField is a group of values of the anonymous candidate card that a
|
||||
// candidate chooses to publish. The set is closed and has no member for the
|
||||
// full name, a contact, or the lowest salary: the card never carries them, so
|
||||
// no choice can publish them.
|
||||
type CardField string
|
||||
|
||||
const (
|
||||
CardFieldCategories CardField = "categories"
|
||||
CardFieldStack CardField = "stack"
|
||||
CardFieldExperience CardField = "experience"
|
||||
CardFieldSoftSkills CardField = "soft_skills"
|
||||
CardFieldLocation CardField = "location"
|
||||
CardFieldRelocation CardField = "relocation"
|
||||
)
|
||||
|
||||
const (
|
||||
// cardFieldsPointer is the request pointer of the field set.
|
||||
cardFieldsPointer = "/fields"
|
||||
// firstStoredVersion is the version of the first saved row of a setting;
|
||||
// the contract's version 0 is the absence of a row.
|
||||
firstStoredVersion int64 = 1
|
||||
)
|
||||
|
||||
var cardFields = []CardField{
|
||||
CardFieldCategories, CardFieldStack, CardFieldExperience,
|
||||
CardFieldSoftSkills, CardFieldLocation, CardFieldRelocation,
|
||||
}
|
||||
|
||||
// CardFields returns every card field the contract defines.
|
||||
func CardFields() []CardField { return slices.Clone(cardFields) }
|
||||
|
||||
// Valid reports whether the field is one of the contract's codes.
|
||||
func (field CardField) Valid() bool { return slices.Contains(cardFields, field) }
|
||||
|
||||
// CardFieldSet is a set of distinct card fields in the canonical order that
|
||||
// the database stores: ascending order of the codes. The zero value is the
|
||||
// empty set. Equal sets are equal arrays.
|
||||
type CardFieldSet struct {
|
||||
fields []CardField
|
||||
}
|
||||
|
||||
// NewCardFieldSet validates the fields and returns them in canonical order. A
|
||||
// repeated or unknown field is invalid, because the contract requires unique
|
||||
// items from the closed enum.
|
||||
func NewCardFieldSet(fields []CardField) (CardFieldSet, error) {
|
||||
const location = "domain.NewCardFieldSet"
|
||||
if len(fields) > len(cardFields) {
|
||||
return CardFieldSet{}, invalidVisibilityField(location, cardFieldsPointer, "has more items than card fields exist")
|
||||
}
|
||||
// Unknown values are reported at their position in the request.
|
||||
for index, field := range fields {
|
||||
if !field.Valid() {
|
||||
return CardFieldSet{}, invalidVisibilityField(location, fmt.Sprintf("%s/%d", cardFieldsPointer, index), "is not a card field")
|
||||
}
|
||||
}
|
||||
ordered := slices.Clone(fields)
|
||||
slices.Sort(ordered)
|
||||
if len(slices.Compact(slices.Clone(ordered))) != len(ordered) {
|
||||
return CardFieldSet{}, invalidVisibilityField(location, cardFieldsPointer, "repeats a card field")
|
||||
}
|
||||
return CardFieldSet{fields: ordered}, nil
|
||||
}
|
||||
|
||||
// Fields returns a copy of the fields in canonical order.
|
||||
func (set CardFieldSet) Fields() []CardField { return slices.Clone(set.fields) }
|
||||
|
||||
// Codes returns the field codes in canonical order, the form that the storage
|
||||
// column holds. It is never nil, so an empty set is stored as an empty array.
|
||||
func (set CardFieldSet) Codes() []string {
|
||||
codes := make([]string, 0, len(set.fields))
|
||||
for _, field := range set.fields {
|
||||
codes = append(codes, string(field))
|
||||
}
|
||||
return codes
|
||||
}
|
||||
|
||||
func (set CardFieldSet) IsEmpty() bool { return len(set.fields) == 0 }
|
||||
|
||||
func (set CardFieldSet) Contains(field CardField) bool { return slices.Contains(set.fields, field) }
|
||||
|
||||
func (set CardFieldSet) Equal(other CardFieldSet) bool { return slices.Equal(set.fields, other.fields) }
|
||||
|
||||
// PublicationState says whether organizations can read the card at all.
|
||||
type PublicationState string
|
||||
|
||||
const (
|
||||
PublicationClosed PublicationState = "closed"
|
||||
PublicationPublished PublicationState = "published"
|
||||
)
|
||||
|
||||
// PublicationClosedReason explains a closed profile to its candidate.
|
||||
type PublicationClosedReason string
|
||||
|
||||
const (
|
||||
ClosedNeverPublished PublicationClosedReason = "never_published"
|
||||
ClosedByCandidate PublicationClosedReason = "closed_by_candidate"
|
||||
ClosedConsentRevoked PublicationClosedReason = "consent_revoked"
|
||||
)
|
||||
|
||||
// StoredPublication is a candidate_publications row joined with the
|
||||
// revocation state of its C2 record, as one read returns them.
|
||||
type StoredPublication struct {
|
||||
UserID uuid.UUID
|
||||
State string
|
||||
Fields []string
|
||||
ConsentRecordID uuid.UUID
|
||||
PublishedAt time.Time
|
||||
ClosedAt time.Time
|
||||
Version int64
|
||||
// ConsentRevoked is true when the referenced C2 record has been revoked.
|
||||
ConsentRevoked bool
|
||||
}
|
||||
|
||||
// Publication is the publication setting of one candidate. The zero state of
|
||||
// a candidate who never published is built by NewPublication: closed, version
|
||||
// 0, no consent record. The stored state is not the effective state: the card
|
||||
// is readable only while the stored setting is published and its C2 record is
|
||||
// unrevoked.
|
||||
type Publication struct {
|
||||
userID uuid.UUID
|
||||
state PublicationState
|
||||
fields CardFieldSet
|
||||
consentRecordID uuid.UUID
|
||||
publishedAt time.Time
|
||||
closedAt time.Time
|
||||
version int64
|
||||
consentRevoked bool
|
||||
}
|
||||
|
||||
// NewPublication returns the setting of a candidate who never published: the
|
||||
// profile is closed. A new account starts here, and nothing in the account,
|
||||
// profile, or questionnaire flows leaves it.
|
||||
func NewPublication(userID uuid.UUID) (Publication, error) {
|
||||
if userID == uuid.Nil {
|
||||
return Publication{}, fmt.Errorf("domain.NewPublication - %w: user ID is empty", ErrInvalidVisibility)
|
||||
}
|
||||
return Publication{userID: userID, state: PublicationClosed}, nil
|
||||
}
|
||||
|
||||
// RestorePublication rebuilds a setting from a stored row and rejects a row
|
||||
// that breaks the invariants the database also enforces.
|
||||
func RestorePublication(stored StoredPublication) (Publication, error) {
|
||||
const location = "domain.RestorePublication"
|
||||
if stored.UserID == uuid.Nil || stored.ConsentRecordID == uuid.Nil || stored.Version < firstStoredVersion || stored.PublishedAt.IsZero() {
|
||||
return Publication{}, fmt.Errorf("%s - %w: identifiers, version, or time are missing", location, ErrInvalidVisibility)
|
||||
}
|
||||
state := PublicationState(stored.State)
|
||||
fields, err := restoreCardFieldSet(location, stored.Fields)
|
||||
if err != nil {
|
||||
return Publication{}, err
|
||||
}
|
||||
switch {
|
||||
case state == PublicationPublished && !fields.IsEmpty() && stored.ClosedAt.IsZero():
|
||||
case state == PublicationClosed && fields.IsEmpty() && !stored.ClosedAt.IsZero() && !stored.ClosedAt.Before(stored.PublishedAt):
|
||||
default:
|
||||
return Publication{}, fmt.Errorf("%s - %w: state, fields, and closing time disagree", location, ErrInvalidVisibility)
|
||||
}
|
||||
return Publication{
|
||||
userID: stored.UserID, state: state, fields: fields, consentRecordID: stored.ConsentRecordID,
|
||||
publishedAt: stored.PublishedAt, closedAt: stored.ClosedAt, version: stored.Version, consentRevoked: stored.ConsentRevoked,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// restoreCardFieldSet decodes the stored codes and requires the canonical
|
||||
// form, so a row changed outside the application is rejected.
|
||||
func restoreCardFieldSet(location string, codes []string) (CardFieldSet, error) {
|
||||
fields := make([]CardField, 0, len(codes))
|
||||
for _, code := range codes {
|
||||
fields = append(fields, CardField(code))
|
||||
}
|
||||
set, err := NewCardFieldSet(fields)
|
||||
if err != nil {
|
||||
return CardFieldSet{}, fmt.Errorf("%s - stored card fields: %w", location, err)
|
||||
}
|
||||
if !slices.Equal(set.Codes(), codes) && len(codes) > 0 {
|
||||
return CardFieldSet{}, fmt.Errorf("%s - %w: stored card fields are not in canonical order", location, ErrInvalidVisibility)
|
||||
}
|
||||
return set, nil
|
||||
}
|
||||
|
||||
func (publication Publication) UserID() uuid.UUID { return publication.userID }
|
||||
|
||||
// Version is 0 for a candidate who never published.
|
||||
func (publication Publication) Version() int64 { return publication.version }
|
||||
|
||||
// ConsentRecordID is the C2 record behind the latest publication, or the zero
|
||||
// UUID when the candidate never published.
|
||||
func (publication Publication) ConsentRecordID() uuid.UUID { return publication.consentRecordID }
|
||||
|
||||
// PublishedAt is the time of the latest change that published the card, and
|
||||
// the zero time when the candidate never published.
|
||||
func (publication Publication) PublishedAt() time.Time { return publication.publishedAt }
|
||||
|
||||
// State is the effective state: published only while the stored setting is
|
||||
// published and the C2 record behind it is unrevoked.
|
||||
func (publication Publication) State() PublicationState {
|
||||
if publication.state == PublicationPublished && !publication.consentRevoked {
|
||||
return PublicationPublished
|
||||
}
|
||||
return PublicationClosed
|
||||
}
|
||||
|
||||
// Fields are the fields organizations may read now; empty while closed.
|
||||
func (publication Publication) Fields() CardFieldSet {
|
||||
if publication.State() == PublicationClosed {
|
||||
return CardFieldSet{}
|
||||
}
|
||||
return publication.fields
|
||||
}
|
||||
|
||||
// ClosedReason says why a closed profile is closed. It is empty while the
|
||||
// profile is published.
|
||||
func (publication Publication) ClosedReason() PublicationClosedReason {
|
||||
switch {
|
||||
case publication.State() == PublicationPublished:
|
||||
return ""
|
||||
case publication.version == 0:
|
||||
return ClosedNeverPublished
|
||||
case publication.state == PublicationPublished:
|
||||
return ClosedConsentRevoked
|
||||
default:
|
||||
return ClosedByCandidate
|
||||
}
|
||||
}
|
||||
|
||||
// PublicationRequest is the complete new publication setting a candidate
|
||||
// sends. Build it with NewPublicationRequest.
|
||||
type PublicationRequest struct {
|
||||
state PublicationState
|
||||
fields CardFieldSet
|
||||
}
|
||||
|
||||
// NewPublicationRequest validates the rules that depend on the body alone: a
|
||||
// published state needs at least one field and a closed state none.
|
||||
func NewPublicationRequest(state PublicationState, fields []CardField) (PublicationRequest, error) {
|
||||
const location = "domain.NewPublicationRequest"
|
||||
set, err := NewCardFieldSet(fields)
|
||||
if err != nil {
|
||||
return PublicationRequest{}, err
|
||||
}
|
||||
switch state {
|
||||
case PublicationPublished:
|
||||
if set.IsEmpty() {
|
||||
return PublicationRequest{}, invalidVisibilityField(location, cardFieldsPointer, "needs at least one card field to publish")
|
||||
}
|
||||
case PublicationClosed:
|
||||
if !set.IsEmpty() {
|
||||
return PublicationRequest{}, invalidVisibilityField(location, cardFieldsPointer, "must be empty when the profile is closed")
|
||||
}
|
||||
default:
|
||||
return PublicationRequest{}, invalidVisibilityField(location, "/state", "is not a publication state")
|
||||
}
|
||||
return PublicationRequest{state: state, fields: set}, nil
|
||||
}
|
||||
|
||||
// PublicationChange is the outcome of applying a request.
|
||||
type PublicationChange struct {
|
||||
// Publication is the setting after the request. It equals the current one
|
||||
// when Changed is false.
|
||||
Publication Publication
|
||||
// Changed is false when the request left the effective setting as it was:
|
||||
// nothing is stored, the version stays, and no event is recorded.
|
||||
Changed bool
|
||||
// Event is the kind of history record the change needs; empty when
|
||||
// Changed is false.
|
||||
Event PrivacyEventKind
|
||||
}
|
||||
|
||||
// Apply applies a request over the version the client read. activeConsent is
|
||||
// the identifier of the account's current unrevoked C2 record, or the zero
|
||||
// UUID when it has none. The order follows the contract: a version above the
|
||||
// current one is a conflict, an unchanged effective setting is not a change,
|
||||
// any other change over a stale version is a conflict, and a publication needs
|
||||
// an active C2.
|
||||
func (publication Publication) Apply(request PublicationRequest, expectedVersion int64, activeConsent uuid.UUID, at time.Time) (PublicationChange, error) {
|
||||
const location = "domain.Publication.Apply"
|
||||
if publication.userID == uuid.Nil || request.state == "" {
|
||||
return PublicationChange{}, fmt.Errorf("%s - %w: setting or request is not initialized", location, ErrInvalidVisibility)
|
||||
}
|
||||
if expectedVersion > publication.version {
|
||||
return PublicationChange{}, fmt.Errorf("%s - version %d does not exist: %w", location, expectedVersion, ErrVisibilityVersionConflict)
|
||||
}
|
||||
effective := publication.State()
|
||||
if publication.repeats(request, effective) {
|
||||
return PublicationChange{Publication: publication}, nil
|
||||
}
|
||||
if expectedVersion < publication.version {
|
||||
return PublicationChange{}, fmt.Errorf("%s - expected version is not current: %w", location, ErrVisibilityVersionConflict)
|
||||
}
|
||||
|
||||
next := publication
|
||||
next.version = publication.version + 1
|
||||
next.consentRevoked = false
|
||||
if request.state == PublicationClosed {
|
||||
next.close(at)
|
||||
return PublicationChange{Publication: next, Changed: true, Event: PrivacyEventPublicationClosed}, nil
|
||||
}
|
||||
if activeConsent == uuid.Nil {
|
||||
return PublicationChange{}, fmt.Errorf("%s - no active C2 record: %w", location, ErrPublicationConsentRequired)
|
||||
}
|
||||
next.state = PublicationPublished
|
||||
next.fields = request.fields
|
||||
next.consentRecordID = activeConsent
|
||||
next.publishedAt = at
|
||||
next.closedAt = time.Time{}
|
||||
event := PrivacyEventPublicationChanged
|
||||
if effective == PublicationClosed {
|
||||
event = PrivacyEventPublicationOpened
|
||||
}
|
||||
return PublicationChange{Publication: next, Changed: true, Event: event}, nil
|
||||
}
|
||||
|
||||
// repeats reports a request that leaves the setting as it is. A closing over
|
||||
// a stored publication whose C2 was revoked is a real change: the card is
|
||||
// already closed in effect, but the stored setting still says published, so
|
||||
// the request normalizes the row to closed and records the closing (and the
|
||||
// usecase revokes the contact grants it closes). Only a stored closed setting,
|
||||
// or a profile that never published, makes a closing a repeat.
|
||||
func (publication Publication) repeats(request PublicationRequest, effective PublicationState) bool {
|
||||
if request.state == PublicationClosed {
|
||||
return publication.state == PublicationClosed
|
||||
}
|
||||
return effective == PublicationPublished && request.fields.Equal(publication.Fields())
|
||||
}
|
||||
|
||||
// close stores the closing. The last published time stays as evidence, and a
|
||||
// closing never moves back before it, whatever the instance clock says.
|
||||
func (publication *Publication) close(at time.Time) {
|
||||
publication.state = PublicationClosed
|
||||
publication.fields = CardFieldSet{}
|
||||
publication.closedAt = at
|
||||
if publication.closedAt.Before(publication.publishedAt) {
|
||||
publication.closedAt = publication.publishedAt
|
||||
}
|
||||
}
|
||||
|
||||
// StoredFields returns the canonical codes of the stored set for the database
|
||||
// column, whatever the effective state.
|
||||
func (publication Publication) StoredFields() []string { return publication.fields.Codes() }
|
||||
|
||||
// StoredState returns the stored state for the database column.
|
||||
func (publication Publication) StoredState() PublicationState { return publication.state }
|
||||
|
||||
// ClosedAt is the time the candidate closed the publication, and the zero
|
||||
// time while it is published or was never published.
|
||||
func (publication Publication) ClosedAt() time.Time { return publication.closedAt }
|
||||
|
||||
// LogValue logs only the account identifier, the version, and the effective
|
||||
// state.
|
||||
func (publication Publication) LogValue() slog.Value {
|
||||
return slog.GroupValue(
|
||||
slog.String("user_id", publication.userID.String()),
|
||||
slog.Int64("version", publication.version),
|
||||
slog.String("state", string(publication.State())),
|
||||
)
|
||||
}
|
||||
|
||||
// SearchStatusValue is what a candidate says about searching for work. It is
|
||||
// a statement, never a consent: it publishes nothing and hides nothing.
|
||||
type SearchStatusValue string
|
||||
|
||||
const (
|
||||
SearchStatusLooking SearchStatusValue = "looking"
|
||||
SearchStatusNotLooking SearchStatusValue = "not_looking"
|
||||
)
|
||||
|
||||
// SearchStatusConfirmation is the policy a confirmation of looking is made
|
||||
// under: the version of the product policy and its confirmation interval.
|
||||
type SearchStatusConfirmation struct {
|
||||
policyVersionID PolicyVersionID
|
||||
interval CalendarDays
|
||||
}
|
||||
|
||||
// NewSearchStatusConfirmation takes the interval from the search_status
|
||||
// section of one stored policy version. The interval comes from the versioned
|
||||
// policy, never from a constant in the code, so the owner changes it by
|
||||
// publishing a new policy version.
|
||||
func NewSearchStatusConfirmation(policyVersionID PolicyVersionID, policy SearchStatusPolicy) (SearchStatusConfirmation, error) {
|
||||
const location = "domain.NewSearchStatusConfirmation"
|
||||
if policyVersionID.IsZero() {
|
||||
return SearchStatusConfirmation{}, fmt.Errorf("%s - %w: policy version is empty", location, ErrInvalidVisibility)
|
||||
}
|
||||
if err := policy.Validate(); err != nil {
|
||||
return SearchStatusConfirmation{}, fmt.Errorf("%s - %w: %w", location, ErrInvalidVisibility, err)
|
||||
}
|
||||
return SearchStatusConfirmation{policyVersionID: policyVersionID, interval: policy.SearchingConfirmationInterval}, nil
|
||||
}
|
||||
|
||||
// StoredSearchStatus is a candidate_search_statuses row.
|
||||
type StoredSearchStatus struct {
|
||||
UserID uuid.UUID
|
||||
Status string
|
||||
ConfirmedAt time.Time
|
||||
LapsesAt time.Time
|
||||
PolicyVersionID PolicyVersionID
|
||||
Version int64
|
||||
}
|
||||
|
||||
// SearchStatus is the search status of one candidate. A candidate who never
|
||||
// set it is not looking at version 0. The stored status is what the candidate
|
||||
// last said; the status that holds now is computed against the clock, so a
|
||||
// lapse is never written and cannot make anyone more visible.
|
||||
type SearchStatus struct {
|
||||
userID uuid.UUID
|
||||
stored SearchStatusValue
|
||||
confirmedAt time.Time
|
||||
lapsesAt time.Time
|
||||
policyVersionID PolicyVersionID
|
||||
version int64
|
||||
}
|
||||
|
||||
// NewSearchStatus returns the status of a candidate who never set it.
|
||||
func NewSearchStatus(userID uuid.UUID) (SearchStatus, error) {
|
||||
if userID == uuid.Nil {
|
||||
return SearchStatus{}, fmt.Errorf("domain.NewSearchStatus - %w: user ID is empty", ErrInvalidVisibility)
|
||||
}
|
||||
return SearchStatus{userID: userID, stored: SearchStatusNotLooking}, nil
|
||||
}
|
||||
|
||||
// RestoreSearchStatus rebuilds a status from a stored row and rejects a row
|
||||
// that breaks the invariants the database also enforces.
|
||||
func RestoreSearchStatus(stored StoredSearchStatus) (SearchStatus, error) {
|
||||
const location = "domain.RestoreSearchStatus"
|
||||
if stored.UserID == uuid.Nil || stored.Version < firstStoredVersion {
|
||||
return SearchStatus{}, fmt.Errorf("%s - %w: identifier or version is invalid", location, ErrInvalidVisibility)
|
||||
}
|
||||
status := SearchStatusValue(stored.Status)
|
||||
switch {
|
||||
case status == SearchStatusLooking && !stored.ConfirmedAt.IsZero() && stored.LapsesAt.After(stored.ConfirmedAt) && !stored.PolicyVersionID.IsZero():
|
||||
case status == SearchStatusNotLooking && stored.ConfirmedAt.IsZero() && stored.LapsesAt.IsZero() && stored.PolicyVersionID.IsZero():
|
||||
default:
|
||||
return SearchStatus{}, fmt.Errorf("%s - %w: status, confirmation, and policy version disagree", location, ErrInvalidVisibility)
|
||||
}
|
||||
return SearchStatus{
|
||||
userID: stored.UserID, stored: status, confirmedAt: stored.ConfirmedAt, lapsesAt: stored.LapsesAt,
|
||||
policyVersionID: stored.PolicyVersionID, version: stored.Version,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (status SearchStatus) UserID() uuid.UUID { return status.userID }
|
||||
|
||||
// Version is 0 for a candidate who never set the status.
|
||||
func (status SearchStatus) Version() int64 { return status.version }
|
||||
|
||||
// StoredValue is the status the candidate last set.
|
||||
func (status SearchStatus) StoredValue() SearchStatusValue { return status.stored }
|
||||
|
||||
// ConfirmedAt is the latest confirmation of looking, or the zero time.
|
||||
func (status SearchStatus) ConfirmedAt() time.Time { return status.confirmedAt }
|
||||
|
||||
// LapsesAt is when the confirmed status lapses, or the zero time. It was fixed
|
||||
// at the confirmation and no later policy change moves it.
|
||||
func (status SearchStatus) LapsesAt() time.Time { return status.lapsesAt }
|
||||
|
||||
// PolicyVersionID is the policy version the lapse time was computed under, or
|
||||
// the zero value when the candidate is not looking.
|
||||
func (status SearchStatus) PolicyVersionID() PolicyVersionID { return status.policyVersionID }
|
||||
|
||||
// Effective is the status that holds at now: looking only while the
|
||||
// confirmation has not lapsed. A lapse falls to the non-public status.
|
||||
func (status SearchStatus) Effective(now time.Time) SearchStatusValue {
|
||||
if status.stored == SearchStatusLooking && now.Before(status.lapsesAt) {
|
||||
return SearchStatusLooking
|
||||
}
|
||||
return SearchStatusNotLooking
|
||||
}
|
||||
|
||||
// Lapsed reports a status the candidate set to looking and did not confirm in
|
||||
// time.
|
||||
func (status SearchStatus) Lapsed(now time.Time) bool {
|
||||
return status.stored == SearchStatusLooking && !now.Before(status.lapsesAt)
|
||||
}
|
||||
|
||||
// SearchStatusChange is the outcome of applying a status request.
|
||||
type SearchStatusChange struct {
|
||||
Status SearchStatus
|
||||
// Changed is false when the request left the stored status as it was.
|
||||
Changed bool
|
||||
// Event is the history record the change needs; empty when unchanged.
|
||||
Event PrivacyEventKind
|
||||
}
|
||||
|
||||
// Apply sets or confirms the status over the version the client read. The
|
||||
// confirmation is only used for looking and fixes the lapse time from the
|
||||
// policy at the moment of the confirmation. The request never touches the
|
||||
// publication or the hidden organizations: this type knows neither.
|
||||
//
|
||||
// Looking always changes the stored confirmation, so a stale version is a
|
||||
// conflict even for a repeat. Not looking over a stored not looking is not a
|
||||
// change.
|
||||
func (status SearchStatus) Apply(value SearchStatusValue, expectedVersion int64, confirmation SearchStatusConfirmation, at time.Time) (SearchStatusChange, error) {
|
||||
const location = "domain.SearchStatus.Apply"
|
||||
if status.userID == uuid.Nil {
|
||||
return SearchStatusChange{}, fmt.Errorf("%s - %w: status is not initialized", location, ErrInvalidVisibility)
|
||||
}
|
||||
if value != SearchStatusLooking && value != SearchStatusNotLooking {
|
||||
return SearchStatusChange{}, invalidVisibilityField(location, "/value", "is not a search status")
|
||||
}
|
||||
if expectedVersion > status.version {
|
||||
return SearchStatusChange{}, fmt.Errorf("%s - version %d does not exist: %w", location, expectedVersion, ErrVisibilityVersionConflict)
|
||||
}
|
||||
if value == SearchStatusNotLooking && status.stored == SearchStatusNotLooking {
|
||||
return SearchStatusChange{Status: status}, nil
|
||||
}
|
||||
if expectedVersion < status.version {
|
||||
return SearchStatusChange{}, fmt.Errorf("%s - expected version is not current: %w", location, ErrVisibilityVersionConflict)
|
||||
}
|
||||
|
||||
next := SearchStatus{userID: status.userID, stored: value, version: status.version + 1}
|
||||
event := PrivacyEventSearchStatusCleared
|
||||
if value == SearchStatusLooking {
|
||||
if confirmation.policyVersionID.IsZero() || confirmation.interval <= 0 {
|
||||
return SearchStatusChange{}, fmt.Errorf("%s - %w: confirmation policy is missing", location, ErrInvalidVisibility)
|
||||
}
|
||||
next.confirmedAt = at
|
||||
next.lapsesAt = at.Add(confirmation.interval.Duration())
|
||||
next.policyVersionID = confirmation.policyVersionID
|
||||
event = PrivacyEventSearchStatusConfirmed
|
||||
}
|
||||
return SearchStatusChange{Status: next, Changed: true, Event: event}, nil
|
||||
}
|
||||
|
||||
// LogValue logs only the account identifier, the version, and the stored
|
||||
// value.
|
||||
func (status SearchStatus) LogValue() slog.Value {
|
||||
return slog.GroupValue(
|
||||
slog.String("user_id", status.userID.String()),
|
||||
slog.Int64("version", status.version),
|
||||
slog.String("stored", string(status.stored)),
|
||||
)
|
||||
}
|
||||
|
||||
// HiddenOrganization is the record of a candidate hiding the profile from one
|
||||
// organization. It belongs to the candidate: no organization reads it.
|
||||
type HiddenOrganization struct {
|
||||
userID uuid.UUID
|
||||
organizationID uuid.UUID
|
||||
hiddenAt time.Time
|
||||
}
|
||||
|
||||
// NewHiddenOrganization builds the record of a hiding. The pair is unique in
|
||||
// the database, so hiding twice is the same record.
|
||||
func NewHiddenOrganization(userID, organizationID uuid.UUID, at time.Time) (HiddenOrganization, error) {
|
||||
if userID == uuid.Nil || organizationID == uuid.Nil || at.IsZero() {
|
||||
return HiddenOrganization{}, fmt.Errorf("domain.NewHiddenOrganization - %w: identifiers or time are missing", ErrInvalidVisibility)
|
||||
}
|
||||
return HiddenOrganization{userID: userID, organizationID: organizationID, hiddenAt: at}, nil
|
||||
}
|
||||
|
||||
func (hidden HiddenOrganization) UserID() uuid.UUID { return hidden.userID }
|
||||
func (hidden HiddenOrganization) OrganizationID() uuid.UUID { return hidden.organizationID }
|
||||
func (hidden HiddenOrganization) HiddenAt() time.Time { return hidden.hiddenAt }
|
||||
|
||||
// LogValue logs only the identifiers.
|
||||
func (hidden HiddenOrganization) LogValue() slog.Value {
|
||||
return slog.GroupValue(
|
||||
slog.String("user_id", hidden.userID.String()),
|
||||
slog.String("organization_id", hidden.organizationID.String()),
|
||||
)
|
||||
}
|
||||
|
||||
// PrivacyEventKind is a kind of change that the settings history records.
|
||||
type PrivacyEventKind string
|
||||
|
||||
const (
|
||||
PrivacyEventPublicationOpened PrivacyEventKind = "publication_opened"
|
||||
PrivacyEventPublicationChanged PrivacyEventKind = "publication_changed"
|
||||
PrivacyEventPublicationClosed PrivacyEventKind = "publication_closed"
|
||||
PrivacyEventSearchStatusConfirmed PrivacyEventKind = "search_status_confirmed"
|
||||
PrivacyEventSearchStatusCleared PrivacyEventKind = "search_status_cleared"
|
||||
PrivacyEventOrganizationHidden PrivacyEventKind = "organization_hidden"
|
||||
PrivacyEventOrganizationUnhidden PrivacyEventKind = "organization_unhidden"
|
||||
)
|
||||
|
||||
// Valid reports whether the kind is one the history stores.
|
||||
func (kind PrivacyEventKind) Valid() bool {
|
||||
switch kind {
|
||||
case PrivacyEventPublicationOpened, PrivacyEventPublicationChanged, PrivacyEventPublicationClosed,
|
||||
PrivacyEventSearchStatusConfirmed, PrivacyEventSearchStatusCleared,
|
||||
PrivacyEventOrganizationHidden, PrivacyEventOrganizationUnhidden:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// PrivacyEvent is one record of the settings history, in the shape the
|
||||
// candidate_privacy_events table accepts.
|
||||
type PrivacyEvent struct {
|
||||
id uuid.UUID
|
||||
userID uuid.UUID
|
||||
kind PrivacyEventKind
|
||||
occurredAt time.Time
|
||||
fields CardFieldSet
|
||||
consentRecordID uuid.UUID
|
||||
organizationID uuid.UUID
|
||||
}
|
||||
|
||||
// NewPublicationEvent records a publication change. A publication carries the
|
||||
// published fields and the C2 record behind them; a closing carries neither.
|
||||
func NewPublicationEvent(change PublicationChange, at time.Time) (PrivacyEvent, error) {
|
||||
const location = "domain.NewPublicationEvent"
|
||||
if !change.Changed {
|
||||
return PrivacyEvent{}, fmt.Errorf("%s - %w: the change is empty", location, ErrInvalidVisibility)
|
||||
}
|
||||
event := PrivacyEvent{userID: change.Publication.userID, kind: change.Event, occurredAt: at}
|
||||
switch change.Event {
|
||||
case PrivacyEventPublicationOpened, PrivacyEventPublicationChanged:
|
||||
event.fields = change.Publication.fields
|
||||
event.consentRecordID = change.Publication.consentRecordID
|
||||
case PrivacyEventPublicationClosed:
|
||||
case PrivacyEventSearchStatusConfirmed, PrivacyEventSearchStatusCleared, PrivacyEventOrganizationHidden, PrivacyEventOrganizationUnhidden:
|
||||
return PrivacyEvent{}, fmt.Errorf("%s - %w: kind %q is not a publication event", location, ErrInvalidVisibility, change.Event)
|
||||
default:
|
||||
return PrivacyEvent{}, fmt.Errorf("%s - %w: kind %q is not a publication event", location, ErrInvalidVisibility, change.Event)
|
||||
}
|
||||
return completeEvent(location, event)
|
||||
}
|
||||
|
||||
// NewSearchStatusEvent records a change of the search status.
|
||||
func NewSearchStatusEvent(change SearchStatusChange, at time.Time) (PrivacyEvent, error) {
|
||||
const location = "domain.NewSearchStatusEvent"
|
||||
if !change.Changed || (change.Event != PrivacyEventSearchStatusConfirmed && change.Event != PrivacyEventSearchStatusCleared) {
|
||||
return PrivacyEvent{}, fmt.Errorf("%s - %w: the change is not a status change", location, ErrInvalidVisibility)
|
||||
}
|
||||
return completeEvent(location, PrivacyEvent{userID: change.Status.userID, kind: change.Event, occurredAt: at})
|
||||
}
|
||||
|
||||
// NewOrganizationEvent records a hiding or the lifting of one. Only the
|
||||
// identifier is kept; the candidate's read resolves the current name.
|
||||
func NewOrganizationEvent(kind PrivacyEventKind, userID, organizationID uuid.UUID, at time.Time) (PrivacyEvent, error) {
|
||||
const location = "domain.NewOrganizationEvent"
|
||||
if kind != PrivacyEventOrganizationHidden && kind != PrivacyEventOrganizationUnhidden {
|
||||
return PrivacyEvent{}, fmt.Errorf("%s - %w: kind %q is not an organization event", location, ErrInvalidVisibility, kind)
|
||||
}
|
||||
if organizationID == uuid.Nil {
|
||||
return PrivacyEvent{}, fmt.Errorf("%s - %w: organization is missing", location, ErrInvalidVisibility)
|
||||
}
|
||||
return completeEvent(location, PrivacyEvent{
|
||||
userID: userID, kind: kind, occurredAt: at, organizationID: organizationID,
|
||||
})
|
||||
}
|
||||
|
||||
func completeEvent(location string, event PrivacyEvent) (PrivacyEvent, error) {
|
||||
if event.userID == uuid.Nil || event.occurredAt.IsZero() {
|
||||
return PrivacyEvent{}, fmt.Errorf("%s - %w: account or time is missing", location, ErrInvalidVisibility)
|
||||
}
|
||||
id, err := uuid.NewV7()
|
||||
if err != nil {
|
||||
return PrivacyEvent{}, fmt.Errorf("%s - generate ID: %w", location, err)
|
||||
}
|
||||
event.id = id
|
||||
return event, nil
|
||||
}
|
||||
|
||||
func (event PrivacyEvent) ID() uuid.UUID { return event.id }
|
||||
func (event PrivacyEvent) UserID() uuid.UUID { return event.userID }
|
||||
func (event PrivacyEvent) Kind() PrivacyEventKind { return event.kind }
|
||||
func (event PrivacyEvent) OccurredAt() time.Time { return event.occurredAt }
|
||||
func (event PrivacyEvent) Fields() CardFieldSet { return event.fields }
|
||||
func (event PrivacyEvent) ConsentRecordID() uuid.UUID { return event.consentRecordID }
|
||||
func (event PrivacyEvent) OrganizationID() uuid.UUID { return event.organizationID }
|
||||
|
||||
// HasFieldSet reports whether the event stores a field set: every publication
|
||||
// event does, an empty one for a closing, and no other kind does.
|
||||
func (event PrivacyEvent) HasFieldSet() bool {
|
||||
switch event.kind {
|
||||
case PrivacyEventPublicationOpened, PrivacyEventPublicationChanged, PrivacyEventPublicationClosed:
|
||||
return true
|
||||
case PrivacyEventSearchStatusConfirmed, PrivacyEventSearchStatusCleared, PrivacyEventOrganizationHidden, PrivacyEventOrganizationUnhidden:
|
||||
return false
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// LogValue logs only identifiers and the kind.
|
||||
func (event PrivacyEvent) LogValue() slog.Value {
|
||||
return slog.GroupValue(
|
||||
slog.String("id", event.id.String()),
|
||||
slog.String("kind", string(event.kind)),
|
||||
)
|
||||
}
|
||||
|
||||
// Rules for the content of an anonymous card (TASK-089 builds it; these are
|
||||
// the hard requirements of this task):
|
||||
// - Only confirmed profile values ever reach the card. A suggestion that
|
||||
// the candidate did not confirm (status extracted) and an unknown value
|
||||
// never do.
|
||||
// - A free text value (a stack tag, a soft skill, a location) is dropped
|
||||
// when it looks like a contact, because the card must never carry a
|
||||
// contact outside the contact grant (C4). CardTextLooksLikeContact is the
|
||||
// check the builder must apply to every free text before it enters the
|
||||
// card; it errs on the side of dropping.
|
||||
// - Quasi-identifiers (a rare combination of location, stack, and
|
||||
// experience) and the generalization of rare features are an acceptance
|
||||
// criterion of TASK-089, not decided here.
|
||||
|
||||
const (
|
||||
// cardWordStart and cardWordEnd are Unicode word boundaries. Go's \b is
|
||||
// ASCII-only, so it cannot see the edge of a Cyrillic or other non-ASCII
|
||||
// label.
|
||||
cardWordStart = `(?:^|[^\p{L}\p{N}_])`
|
||||
cardWordEnd = `(?:$|[^\p{L}\p{N}_])`
|
||||
// cardDomainEnd also treats a hyphen as part of the label, so pro.company
|
||||
// does not match the ending pro.
|
||||
cardDomainEnd = `(?:$|[^\p{L}\p{N}-])`
|
||||
// cardContactTLDs are the domain endings that make a dotted token a
|
||||
// domain. The list is deliberately wide and errs on the side of dropping:
|
||||
// Socket.io is dropped with it. "net" is not in it so that ASP.NET stays a
|
||||
// stack tag; a lowercase name.net is caught separately.
|
||||
cardContactTLDs = `com|ru|org|io|me|dev|app|xyz|info|su|рф|ua|by|kz|co|ai|de|uk|tv|ly|gl|dog|site|online|tech|fm|cc|gg|link|page|store|shop|blog|cloud|top|pro|biz|us|eu|fr|nl|pl|cz|moscow|бел|укр|рус|онлайн|сайт`
|
||||
// cardContactWords are words that introduce or disguise a contact, with
|
||||
// or without an @: messengers, contact nouns, and the spelled-out parts of
|
||||
// an address. They match as whole words only.
|
||||
cardContactWords = `at|dot|собака|точка|telegram|tg|whatsapp|viber|skype|телеграм|телега|вотсап|ватсап|вайбер|скайп|email|mail|e-mail|phone|tel|почта|телефон|контакт|contact`
|
||||
// minCardPhoneDigits is the number of digits in one group from which a
|
||||
// text is treated as a phone number. Seven is the shortest local number.
|
||||
minCardPhoneDigits = 7
|
||||
)
|
||||
|
||||
var (
|
||||
cardContactEmail = regexp.MustCompile(`[^\s@]+@[^\s@]+`)
|
||||
cardContactHandle = regexp.MustCompile(`@\s*[\p{L}\p{N}_]{3,}`)
|
||||
cardContactURL = regexp.MustCompile(`(?:https?://|tg://|www\.|\bt\.me/)|[\p{L}\p{N}-]+\.(?:` + cardContactTLDs + `)` + cardDomainEnd)
|
||||
cardContactNet = regexp.MustCompile(`[\p{Ll}\p{N}-]+\.net` + cardDomainEnd)
|
||||
cardContactWord = regexp.MustCompile(cardWordStart + `(?:` + cardContactWords + `)` + cardWordEnd)
|
||||
// cardPhoneGroup is a run of digits separated only by spaces, dashes,
|
||||
// dots, and parentheses, so "Python 3.12, Django 4.2" are separate groups.
|
||||
cardPhoneGroup = regexp.MustCompile(`[\p{Nd}+(][\p{Nd}\s().\-]*`)
|
||||
)
|
||||
|
||||
// CardTextLooksLikeContact reports whether a free text value of the profile
|
||||
// looks like a contact: an email address, a phone number, a URL or domain
|
||||
// (including an internationalized one), a Telegram link or an @handle (also
|
||||
// spelled "@ name"), an obfuscated address ("a [at] b dot com"), or a
|
||||
// messenger or contact word ("tg: name", "почта"). The text is normalized
|
||||
// with NFKC first, so fullwidth and compatibility forms of @, +, and digits
|
||||
// count, and every Unicode decimal digit counts toward a phone number. A card
|
||||
// builder drops such a value instead of publishing it. The check errs on the
|
||||
// side of dropping; it is the barrier for free text until TASK-089 replaces
|
||||
// free text by a closed taxonomy, which closes the residual risk.
|
||||
func CardTextLooksLikeContact(text string) bool {
|
||||
normalized := norm.NFKC.String(text)
|
||||
lowered := strings.ToLower(normalized)
|
||||
if cardContactEmail.MatchString(lowered) || cardContactHandle.MatchString(lowered) ||
|
||||
cardContactURL.MatchString(lowered) || cardContactNet.MatchString(normalized) || cardContactWord.MatchString(lowered) {
|
||||
return true
|
||||
}
|
||||
for _, group := range cardPhoneGroup.FindAllString(lowered, -1) {
|
||||
digits := 0
|
||||
for _, character := range group {
|
||||
if unicode.IsDigit(character) {
|
||||
digits++
|
||||
}
|
||||
}
|
||||
if digits >= minCardPhoneDigits {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,475 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
var visibilityNow = time.Date(2026, 10, 6, 9, 0, 0, 0, time.UTC)
|
||||
|
||||
func mustCardFields(t *testing.T, fields ...CardField) CardFieldSet {
|
||||
t.Helper()
|
||||
set, err := NewCardFieldSet(fields)
|
||||
if err != nil {
|
||||
t.Fatalf("NewCardFieldSet(%v) error = %v", fields, err)
|
||||
}
|
||||
return set
|
||||
}
|
||||
|
||||
func mustPublicationRequest(t *testing.T, state PublicationState, fields ...CardField) PublicationRequest {
|
||||
t.Helper()
|
||||
request, err := NewPublicationRequest(state, fields)
|
||||
if err != nil {
|
||||
t.Fatalf("NewPublicationRequest(%s, %v) error = %v", state, fields, err)
|
||||
}
|
||||
return request
|
||||
}
|
||||
|
||||
func newClosedPublication(t *testing.T) Publication {
|
||||
t.Helper()
|
||||
publication, err := NewPublication(uuid.New())
|
||||
if err != nil {
|
||||
t.Fatalf("NewPublication() error = %v", err)
|
||||
}
|
||||
return publication
|
||||
}
|
||||
|
||||
func publish(t *testing.T, publication Publication, expectedVersion int64, consent uuid.UUID, at time.Time, fields ...CardField) Publication {
|
||||
t.Helper()
|
||||
change, err := publication.Apply(mustPublicationRequest(t, PublicationPublished, fields...), expectedVersion, consent, at)
|
||||
if err != nil || !change.Changed {
|
||||
t.Fatalf("Apply(publish) = %+v, %v, want a change", change, err)
|
||||
}
|
||||
return change.Publication
|
||||
}
|
||||
|
||||
func TestNewCardFieldSetIsCanonicalAndClosed(t *testing.T) {
|
||||
set := mustCardFields(t, CardFieldStack, CardFieldCategories)
|
||||
if got := strings.Join(set.Codes(), ","); got != "categories,stack" {
|
||||
t.Fatalf("Codes() = %q, want ascending order whatever the input order", got)
|
||||
}
|
||||
if empty := mustCardFields(t); !empty.IsEmpty() || empty.Codes() == nil {
|
||||
t.Fatal("an empty set must be empty and encode as an empty, non-nil array")
|
||||
}
|
||||
for _, code := range []string{"full_name", "email", "phone", "telegram", "salary_minimum", "contacts", ""} {
|
||||
if _, err := NewCardFieldSet([]CardField{CardField(code)}); !errors.Is(err, ErrInvalidVisibility) {
|
||||
t.Errorf("NewCardFieldSet(%q) error = %v, want a refusal: the card never carries it", code, err)
|
||||
}
|
||||
}
|
||||
if _, err := NewCardFieldSet([]CardField{CardFieldStack, CardFieldStack}); !errors.Is(err, ErrInvalidVisibility) {
|
||||
t.Errorf("NewCardFieldSet(repeated) error = %v, want a refusal", err)
|
||||
}
|
||||
var fieldError *VisibilityFieldError
|
||||
if _, err := NewCardFieldSet([]CardField{CardFieldStack, "contacts"}); !errors.As(err, &fieldError) || fieldError.Pointer != "/fields/1" || strings.Contains(err.Error(), "contacts") {
|
||||
t.Errorf("an unknown field error = %v, want the pointer without the submitted value", err)
|
||||
}
|
||||
for _, field := range CardFields() {
|
||||
if !field.Valid() {
|
||||
t.Errorf("CardFields() lists %q, which is not valid", field)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewPublicationRequestChecksTheBodyAlone(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
state PublicationState
|
||||
fields []CardField
|
||||
ok bool
|
||||
}{
|
||||
{"published with a field", PublicationPublished, []CardField{CardFieldStack}, true},
|
||||
{"closed with no field", PublicationClosed, nil, true},
|
||||
{"published with no field", PublicationPublished, nil, false},
|
||||
{"closed with a field", PublicationClosed, []CardField{CardFieldStack}, false},
|
||||
{"unknown state", "hidden", nil, false},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
_, err := NewPublicationRequest(test.state, test.fields)
|
||||
if (err == nil) != test.ok {
|
||||
t.Fatalf("NewPublicationRequest() error = %v, want ok %v", err, test.ok)
|
||||
}
|
||||
if err != nil && !errors.Is(err, ErrInvalidVisibility) {
|
||||
t.Fatalf("error = %v, want ErrInvalidVisibility", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAProfileIsClosedByDefault(t *testing.T) {
|
||||
publication := newClosedPublication(t)
|
||||
if publication.State() != PublicationClosed || publication.ClosedReason() != ClosedNeverPublished ||
|
||||
publication.Version() != 0 || !publication.Fields().IsEmpty() || publication.ConsentRecordID() != uuid.Nil {
|
||||
t.Fatalf("a new publication = %v %v v%d, want closed, never published, version 0, no consent", publication.State(), publication.ClosedReason(), publication.Version())
|
||||
}
|
||||
// Closing a profile that never opened changes nothing and stores no row.
|
||||
change, err := publication.Apply(mustPublicationRequest(t, PublicationClosed), 0, uuid.Nil, visibilityNow)
|
||||
if err != nil || change.Changed || change.Publication.Version() != 0 {
|
||||
t.Fatalf("Apply(close of a never published profile) = %+v, %v, want no change", change, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublishingNeedsAnActiveC2AndNamesNoConsent(t *testing.T) {
|
||||
publication := newClosedPublication(t)
|
||||
request := mustPublicationRequest(t, PublicationPublished, CardFieldCategories)
|
||||
if _, err := publication.Apply(request, 0, uuid.Nil, visibilityNow); !errors.Is(err, ErrPublicationConsentRequired) {
|
||||
t.Fatalf("Apply(without C2) error = %v, want ErrPublicationConsentRequired", err)
|
||||
}
|
||||
consent := uuid.New()
|
||||
change, err := publication.Apply(request, 0, consent, visibilityNow)
|
||||
if err != nil || !change.Changed || change.Event != PrivacyEventPublicationOpened {
|
||||
t.Fatalf("Apply(publish) = %+v, %v, want an opened publication", change, err)
|
||||
}
|
||||
published := change.Publication
|
||||
if published.State() != PublicationPublished || published.ClosedReason() != "" || published.Version() != 1 ||
|
||||
published.ConsentRecordID() != consent || !published.PublishedAt().Equal(visibilityNow) ||
|
||||
!published.Fields().Equal(mustCardFields(t, CardFieldCategories)) {
|
||||
t.Fatalf("published = %v v%d, want the new record bound to the C2 record", published.State(), published.Version())
|
||||
}
|
||||
// The input did not change.
|
||||
if publication.State() != PublicationClosed || publication.Version() != 0 {
|
||||
t.Fatal("Apply changed its receiver")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublicationOrderOfChecks(t *testing.T) {
|
||||
consent := uuid.New()
|
||||
published := publish(t, newClosedPublication(t), 0, consent, visibilityNow, CardFieldStack, CardFieldCategories)
|
||||
same := mustPublicationRequest(t, PublicationPublished, CardFieldCategories, CardFieldStack)
|
||||
other := mustPublicationRequest(t, PublicationPublished, CardFieldCategories)
|
||||
|
||||
// A version above the current one never existed, even for an unchanged body.
|
||||
if _, err := published.Apply(same, 5, consent, visibilityNow); !errors.Is(err, ErrVisibilityVersionConflict) {
|
||||
t.Fatalf("Apply(future version) error = %v, want a version conflict", err)
|
||||
}
|
||||
// An unchanged body is a success over a stale version, so a lost response can be retried.
|
||||
published = publish(t, published, 1, consent, visibilityNow.Add(time.Hour), CardFieldCategories)
|
||||
if change, err := published.Apply(other, 1, uuid.Nil, visibilityNow); err != nil || change.Changed || change.Publication.Version() != 2 {
|
||||
t.Fatalf("Apply(unchanged, stale) = %+v, %v, want no change at version 2", change, err)
|
||||
}
|
||||
// Any other change over a stale version is a conflict, also a closing.
|
||||
if _, err := published.Apply(same, 1, consent, visibilityNow); !errors.Is(err, ErrVisibilityVersionConflict) {
|
||||
t.Fatalf("Apply(change, stale) error = %v, want a version conflict", err)
|
||||
}
|
||||
// A stale version is a conflict before the missing consent is reported.
|
||||
if _, err := published.Apply(same, 1, uuid.Nil, visibilityNow); !errors.Is(err, ErrVisibilityVersionConflict) {
|
||||
t.Fatalf("Apply(change, stale, no consent) error = %v, want the version conflict first", err)
|
||||
}
|
||||
change, err := published.Apply(mustPublicationRequest(t, PublicationClosed), 2, uuid.Nil, visibilityNow.Add(2*time.Hour))
|
||||
if err != nil || !change.Changed || change.Event != PrivacyEventPublicationClosed {
|
||||
t.Fatalf("Apply(close) = %+v, %v, want a closing that needs no consent", change, err)
|
||||
}
|
||||
closed := change.Publication
|
||||
if closed.State() != PublicationClosed || closed.ClosedReason() != ClosedByCandidate || !closed.Fields().IsEmpty() || closed.Version() != 3 ||
|
||||
!closed.PublishedAt().Equal(visibilityNow.Add(time.Hour)) || !closed.ClosedAt().Equal(visibilityNow.Add(2*time.Hour)) {
|
||||
t.Fatalf("closed = %v %v v%d, want closed by the candidate with the last published time kept", closed.State(), closed.ClosedReason(), closed.Version())
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublishedFieldsChangeWithTheirOwnEvent(t *testing.T) {
|
||||
consent := uuid.New()
|
||||
published := publish(t, newClosedPublication(t), 0, consent, visibilityNow, CardFieldStack)
|
||||
change, err := published.Apply(mustPublicationRequest(t, PublicationPublished, CardFieldStack, CardFieldLocation), 1, consent, visibilityNow.Add(time.Minute))
|
||||
if err != nil || !change.Changed || change.Event != PrivacyEventPublicationChanged || change.Publication.Version() != 2 {
|
||||
t.Fatalf("Apply(more fields) = %+v, %v, want a changed publication at version 2", change, err)
|
||||
}
|
||||
event, err := NewPublicationEvent(change, visibilityNow.Add(time.Minute))
|
||||
if err != nil || event.Kind() != PrivacyEventPublicationChanged || !event.HasFieldSet() || event.ConsentRecordID() != consent ||
|
||||
!event.Fields().Equal(mustCardFields(t, CardFieldLocation, CardFieldStack)) {
|
||||
t.Fatalf("NewPublicationEvent() = %v, %v, want the fields and the C2 record behind them", event, err)
|
||||
}
|
||||
}
|
||||
|
||||
// A revoked C2 closes the card without any write, and a later C2 grant never
|
||||
// reopens it: only an explicit publication under the new record does.
|
||||
func TestARevokedConsentClosesAndNeverReopensByItself(t *testing.T) {
|
||||
consent := uuid.New()
|
||||
published := publish(t, newClosedPublication(t), 0, consent, visibilityNow, CardFieldStack)
|
||||
stored := StoredPublication{
|
||||
UserID: published.UserID(), State: string(PublicationPublished), Fields: published.StoredFields(), ConsentRecordID: consent,
|
||||
PublishedAt: visibilityNow, Version: 1, ConsentRevoked: true,
|
||||
}
|
||||
revoked, err := RestorePublication(stored)
|
||||
if err != nil {
|
||||
t.Fatalf("RestorePublication() error = %v", err)
|
||||
}
|
||||
if revoked.State() != PublicationClosed || revoked.ClosedReason() != ClosedConsentRevoked || !revoked.Fields().IsEmpty() {
|
||||
t.Fatalf("a revoked C2 left the card %v (%v) with fields %v, want closed", revoked.State(), revoked.ClosedReason(), revoked.Fields().Codes())
|
||||
}
|
||||
// The same body is not "unchanged": the card is closed now, so it is a new publication.
|
||||
newConsent := uuid.New()
|
||||
change, err := revoked.Apply(mustPublicationRequest(t, PublicationPublished, CardFieldStack), 1, newConsent, visibilityNow.Add(time.Hour))
|
||||
if err != nil || !change.Changed || change.Event != PrivacyEventPublicationOpened || change.Publication.ConsentRecordID() != newConsent ||
|
||||
change.Publication.State() != PublicationPublished {
|
||||
t.Fatalf("Apply(publish again) = %+v, %v, want an opened publication under the new record", change, err)
|
||||
}
|
||||
// Closing a card that the revocation closed in effect is a real change:
|
||||
// the stored row is normalized to closed and the closing is recorded.
|
||||
closing, err := revoked.Apply(mustPublicationRequest(t, PublicationClosed), 1, uuid.Nil, visibilityNow.Add(2*time.Hour))
|
||||
if err != nil || !closing.Changed || closing.Event != PrivacyEventPublicationClosed || closing.Publication.StoredState() != PublicationClosed ||
|
||||
closing.Publication.ClosedReason() != ClosedByCandidate || closing.Publication.Version() != 2 {
|
||||
t.Fatalf("Apply(close over a revoked C2) = %+v, %v, want a recorded closing at version 2", closing, err)
|
||||
}
|
||||
// A second closing is the repeat of the stored closing.
|
||||
if again, err := closing.Publication.Apply(mustPublicationRequest(t, PublicationClosed), 1, uuid.Nil, visibilityNow); err != nil || again.Changed {
|
||||
t.Fatalf("Apply(close again) = %+v, %v, want no change", again, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRestorePublicationRejectsRowsThatBreakTheInvariants(t *testing.T) {
|
||||
user, consent := uuid.New(), uuid.New()
|
||||
valid := StoredPublication{UserID: user, State: "published", Fields: []string{"categories", "stack"}, ConsentRecordID: consent, PublishedAt: visibilityNow, Version: 1}
|
||||
if _, err := RestorePublication(valid); err != nil {
|
||||
t.Fatalf("RestorePublication(valid) error = %v", err)
|
||||
}
|
||||
for name, mutate := range map[string]func(*StoredPublication){
|
||||
"published without fields": func(s *StoredPublication) { s.Fields = nil },
|
||||
"closed with fields": func(s *StoredPublication) { s.State = "closed"; s.ClosedAt = visibilityNow },
|
||||
"closed without a close time": func(s *StoredPublication) { s.State = "closed"; s.Fields = nil },
|
||||
"published with a close time": func(s *StoredPublication) { s.ClosedAt = visibilityNow },
|
||||
"fields out of order": func(s *StoredPublication) { s.Fields = []string{"stack", "categories"} },
|
||||
"a contact as a field": func(s *StoredPublication) { s.Fields = []string{"phone"} },
|
||||
"unknown state": func(s *StoredPublication) { s.State = "draft" },
|
||||
"no consent record": func(s *StoredPublication) { s.ConsentRecordID = uuid.Nil },
|
||||
"version zero": func(s *StoredPublication) { s.Version = 0 },
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
stored := valid
|
||||
mutate(&stored)
|
||||
if _, err := RestorePublication(stored); !errors.Is(err, ErrInvalidVisibility) {
|
||||
t.Fatalf("RestorePublication() error = %v, want ErrInvalidVisibility", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func demoSearchConfirmation(t *testing.T) SearchStatusConfirmation {
|
||||
t.Helper()
|
||||
id, err := NewPolicyVersionID()
|
||||
if err != nil {
|
||||
t.Fatalf("NewPolicyVersionID() error = %v", err)
|
||||
}
|
||||
confirmation, err := NewSearchStatusConfirmation(id, DemoProductPolicyV1().SearchStatus)
|
||||
if err != nil {
|
||||
t.Fatalf("NewSearchStatusConfirmation() error = %v", err)
|
||||
}
|
||||
return confirmation
|
||||
}
|
||||
|
||||
func newSearchStatus(t *testing.T) SearchStatus {
|
||||
t.Helper()
|
||||
status, err := NewSearchStatus(uuid.New())
|
||||
if err != nil {
|
||||
t.Fatalf("NewSearchStatus() error = %v", err)
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
||||
func TestSearchStatusLapsesAfterThePolicyIntervalToTheNonPublicState(t *testing.T) {
|
||||
confirmation := demoSearchConfirmation(t)
|
||||
initial := newSearchStatus(t)
|
||||
if initial.Effective(visibilityNow) != SearchStatusNotLooking || initial.Version() != 0 || initial.Lapsed(visibilityNow) {
|
||||
t.Fatal("a new account must not be looking at version 0")
|
||||
}
|
||||
change, err := initial.Apply(SearchStatusLooking, 0, confirmation, visibilityNow)
|
||||
if err != nil || !change.Changed || change.Event != PrivacyEventSearchStatusConfirmed {
|
||||
t.Fatalf("Apply(looking) = %+v, %v, want a confirmation", change, err)
|
||||
}
|
||||
looking := change.Status
|
||||
// The interval is the 30 days of the demo policy, read from the versioned document.
|
||||
if want := visibilityNow.Add(30 * 24 * time.Hour); !looking.LapsesAt().Equal(want) || !looking.ConfirmedAt().Equal(visibilityNow) ||
|
||||
looking.PolicyVersionID() != confirmation.policyVersionID || looking.Version() != 1 {
|
||||
t.Fatalf("looking = confirmed %v lapses %v v%d, want 30 days under the policy version", looking.ConfirmedAt(), looking.LapsesAt(), looking.Version())
|
||||
}
|
||||
last := looking.LapsesAt().Add(-time.Nanosecond)
|
||||
if looking.Effective(last) != SearchStatusLooking || looking.Lapsed(last) {
|
||||
t.Fatal("the status must hold until the lapse time")
|
||||
}
|
||||
for _, at := range []time.Time{looking.LapsesAt(), looking.LapsesAt().Add(365 * 24 * time.Hour)} {
|
||||
if looking.Effective(at) != SearchStatusNotLooking || !looking.Lapsed(at) {
|
||||
t.Fatalf("at %v the status = %v lapsed %v, want not_looking and lapsed: a lapse only narrows", at, looking.Effective(at), looking.Lapsed(at))
|
||||
}
|
||||
}
|
||||
// A lapse is not a stored change: the stored status is still what the candidate said.
|
||||
if looking.StoredValue() != SearchStatusLooking {
|
||||
t.Fatal("the lapse rewrote the stored status")
|
||||
}
|
||||
// The candidate confirms again after the lapse with the current version.
|
||||
later := looking.LapsesAt().Add(time.Hour)
|
||||
again, err := looking.Apply(SearchStatusLooking, 1, confirmation, later)
|
||||
if err != nil || !again.Changed || again.Status.Version() != 2 || again.Status.Effective(later) != SearchStatusLooking || !again.Status.ConfirmedAt().Equal(later) {
|
||||
t.Fatalf("Apply(confirm after the lapse) = %+v, %v, want a new confirmation at version 2", again, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearchStatusVersionRules(t *testing.T) {
|
||||
confirmation := demoSearchConfirmation(t)
|
||||
initial := newSearchStatus(t)
|
||||
// Not looking over a status that was never set stores nothing.
|
||||
if change, err := initial.Apply(SearchStatusNotLooking, 0, SearchStatusConfirmation{}, visibilityNow); err != nil || change.Changed {
|
||||
t.Fatalf("Apply(not_looking, never set) = %+v, %v, want no change", change, err)
|
||||
}
|
||||
if _, err := initial.Apply(SearchStatusLooking, 4, confirmation, visibilityNow); !errors.Is(err, ErrVisibilityVersionConflict) {
|
||||
t.Fatalf("Apply(future version) error = %v, want a version conflict", err)
|
||||
}
|
||||
if _, err := initial.Apply("searching", 0, confirmation, visibilityNow); !errors.Is(err, ErrInvalidVisibility) {
|
||||
t.Fatalf("Apply(unknown value) error = %v, want ErrInvalidVisibility", err)
|
||||
}
|
||||
if _, err := initial.Apply(SearchStatusLooking, 0, SearchStatusConfirmation{}, visibilityNow); !errors.Is(err, ErrInvalidVisibility) {
|
||||
t.Fatalf("Apply(looking without a policy) error = %v, want ErrInvalidVisibility", err)
|
||||
}
|
||||
looking := mustApplySearch(t, initial, SearchStatusLooking, 0, confirmation, visibilityNow)
|
||||
// Looking again over a stale version is a conflict: a repeat of a confirmation changes the stored time.
|
||||
if _, err := looking.Apply(SearchStatusLooking, 0, confirmation, visibilityNow); !errors.Is(err, ErrVisibilityVersionConflict) {
|
||||
t.Fatalf("Apply(looking, stale) error = %v, want a version conflict", err)
|
||||
}
|
||||
cleared := mustApplySearch(t, looking, SearchStatusNotLooking, 1, SearchStatusConfirmation{}, visibilityNow.Add(time.Hour))
|
||||
if cleared.StoredValue() != SearchStatusNotLooking || !cleared.ConfirmedAt().IsZero() || !cleared.LapsesAt().IsZero() || !cleared.PolicyVersionID().IsZero() || cleared.Lapsed(visibilityNow.Add(100*24*time.Hour)) {
|
||||
t.Fatal("not_looking must carry no confirmation, and a cleared status is never lapsed")
|
||||
}
|
||||
// Clearing twice is not a change, even with a stale version.
|
||||
if change, err := cleared.Apply(SearchStatusNotLooking, 1, SearchStatusConfirmation{}, visibilityNow); err != nil || change.Changed {
|
||||
t.Fatalf("Apply(not_looking, stale, unchanged) = %+v, %v, want no change", change, err)
|
||||
}
|
||||
}
|
||||
|
||||
func mustApplySearch(t *testing.T, status SearchStatus, value SearchStatusValue, expected int64, confirmation SearchStatusConfirmation, at time.Time) SearchStatus {
|
||||
t.Helper()
|
||||
change, err := status.Apply(value, expected, confirmation, at)
|
||||
if err != nil || !change.Changed {
|
||||
t.Fatalf("Apply(%s) = %+v, %v, want a change", value, change, err)
|
||||
}
|
||||
return change.Status
|
||||
}
|
||||
|
||||
func TestSearchStatusConfirmationComesFromAValidVersionedPolicy(t *testing.T) {
|
||||
id, err := NewPolicyVersionID()
|
||||
if err != nil {
|
||||
t.Fatalf("NewPolicyVersionID() error = %v", err)
|
||||
}
|
||||
if _, err := NewSearchStatusConfirmation(PolicyVersionID{}, SearchStatusPolicy{SearchingConfirmationInterval: 30}); !errors.Is(err, ErrInvalidVisibility) {
|
||||
t.Errorf("a confirmation without a policy version error = %v, want ErrInvalidVisibility", err)
|
||||
}
|
||||
for _, days := range []CalendarDays{0, -1, maxSearchingConfirmationInterval + 1} {
|
||||
if _, err := NewSearchStatusConfirmation(id, SearchStatusPolicy{SearchingConfirmationInterval: days}); !errors.Is(err, ErrInvalidVisibility) {
|
||||
t.Errorf("a confirmation of %d days error = %v, want a refusal", days, err)
|
||||
}
|
||||
}
|
||||
// An owner-published interval is used as is.
|
||||
confirmation, err := NewSearchStatusConfirmation(id, SearchStatusPolicy{SearchingConfirmationInterval: 14})
|
||||
if err != nil {
|
||||
t.Fatalf("NewSearchStatusConfirmation(14) error = %v", err)
|
||||
}
|
||||
looking := mustApplySearch(t, newSearchStatus(t), SearchStatusLooking, 0, confirmation, visibilityNow)
|
||||
if want := visibilityNow.Add(14 * 24 * time.Hour); !looking.LapsesAt().Equal(want) {
|
||||
t.Fatalf("lapses at %v, want %v", looking.LapsesAt(), want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRestoreSearchStatusRejectsRowsThatBreakTheInvariants(t *testing.T) {
|
||||
policy, err := NewPolicyVersionID()
|
||||
if err != nil {
|
||||
t.Fatalf("NewPolicyVersionID() error = %v", err)
|
||||
}
|
||||
user := uuid.New()
|
||||
valid := StoredSearchStatus{UserID: user, Status: "looking", ConfirmedAt: visibilityNow, LapsesAt: visibilityNow.Add(time.Hour), PolicyVersionID: policy, Version: 1}
|
||||
if _, err := RestoreSearchStatus(valid); err != nil {
|
||||
t.Fatalf("RestoreSearchStatus(valid) error = %v", err)
|
||||
}
|
||||
if _, err := RestoreSearchStatus(StoredSearchStatus{UserID: user, Status: "not_looking", Version: 2}); err != nil {
|
||||
t.Fatalf("RestoreSearchStatus(not_looking) error = %v", err)
|
||||
}
|
||||
for name, mutate := range map[string]func(*StoredSearchStatus){
|
||||
"looking without a confirmation": func(s *StoredSearchStatus) { s.ConfirmedAt = time.Time{} },
|
||||
"lapse not after the confirm": func(s *StoredSearchStatus) { s.LapsesAt = s.ConfirmedAt },
|
||||
"looking without a policy": func(s *StoredSearchStatus) { s.PolicyVersionID = PolicyVersionID{} },
|
||||
"not looking with a confirmation": func(s *StoredSearchStatus) { s.Status = "not_looking" },
|
||||
"unknown status": func(s *StoredSearchStatus) { s.Status = "open" },
|
||||
"version zero": func(s *StoredSearchStatus) { s.Version = 0 },
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
stored := valid
|
||||
mutate(&stored)
|
||||
if _, err := RestoreSearchStatus(stored); !errors.Is(err, ErrInvalidVisibility) {
|
||||
t.Fatalf("RestoreSearchStatus() error = %v, want ErrInvalidVisibility", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHiddenOrganizationAndEventsNeedTheirIdentifiers(t *testing.T) {
|
||||
user, organization := uuid.New(), uuid.New()
|
||||
hidden, err := NewHiddenOrganization(user, organization, visibilityNow)
|
||||
if err != nil || hidden.UserID() != user || hidden.OrganizationID() != organization || !hidden.HiddenAt().Equal(visibilityNow) {
|
||||
t.Fatalf("NewHiddenOrganization() = %v, %v, want the record", hidden, err)
|
||||
}
|
||||
for _, args := range [][2]uuid.UUID{{uuid.Nil, organization}, {user, uuid.Nil}} {
|
||||
if _, err := NewHiddenOrganization(args[0], args[1], visibilityNow); !errors.Is(err, ErrInvalidVisibility) {
|
||||
t.Errorf("NewHiddenOrganization(%v) error = %v, want a refusal", args, err)
|
||||
}
|
||||
}
|
||||
if _, err := NewHiddenOrganization(user, organization, time.Time{}); !errors.Is(err, ErrInvalidVisibility) {
|
||||
t.Errorf("NewHiddenOrganization(no time) error = %v, want a refusal", err)
|
||||
}
|
||||
event, err := NewOrganizationEvent(PrivacyEventOrganizationHidden, user, organization, visibilityNow)
|
||||
if err != nil || event.ID() == uuid.Nil || event.HasFieldSet() || event.OrganizationID() != organization {
|
||||
t.Fatalf("NewOrganizationEvent() = %v, %v, want an event without a field set", event, err)
|
||||
}
|
||||
if _, err := NewOrganizationEvent(PrivacyEventPublicationClosed, user, organization, visibilityNow); !errors.Is(err, ErrInvalidVisibility) {
|
||||
t.Errorf("NewOrganizationEvent(publication kind) error = %v, want a refusal", err)
|
||||
}
|
||||
if _, err := NewPublicationEvent(PublicationChange{}, visibilityNow); !errors.Is(err, ErrInvalidVisibility) {
|
||||
t.Errorf("NewPublicationEvent(no change) error = %v, want a refusal", err)
|
||||
}
|
||||
if _, err := NewSearchStatusEvent(SearchStatusChange{}, visibilityNow); !errors.Is(err, ErrInvalidVisibility) {
|
||||
t.Errorf("NewSearchStatusEvent(no change) error = %v, want a refusal", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVisibilityTypesLogOnlyIdentifiers(t *testing.T) {
|
||||
publication := publish(t, newClosedPublication(t), 0, uuid.New(), visibilityNow, CardFieldStack, CardFieldLocation)
|
||||
event, err := NewOrganizationEvent(PrivacyEventOrganizationHidden, uuid.New(), uuid.New(), visibilityNow)
|
||||
if err != nil {
|
||||
t.Fatalf("NewOrganizationEvent() error = %v", err)
|
||||
}
|
||||
var out strings.Builder
|
||||
logger := slog.New(slog.NewTextHandler(&out, nil))
|
||||
logger.Info("settings", "publication", publication, "event", event)
|
||||
for _, secret := range []string{"location", "stack"} {
|
||||
if strings.Contains(out.String(), secret) {
|
||||
t.Errorf("log output %q contains %q", out.String(), secret)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCardTextLooksLikeContact(t *testing.T) {
|
||||
for _, text := range []string{
|
||||
"anna@example.com", "write to anna@mail.ru", "@anna_dev", "tg: @anna_dev", "t.me/anna", "https://github.com/anna",
|
||||
"www.example.org", "anna.dev", "+7 (900) 000-00-00", "89000000000", "8 900 000 00 00", "example.com",
|
||||
// Internationalized domains and wider endings.
|
||||
"вася.com", "site.рф", "вася.рф", "anna.ua", "anna.by", "anna.kz", "anna.co", "anna.ai", "anna.de", "anna.tv", "anna.site",
|
||||
"anna.online", "anna.tech", "bit.ly/x", "telegram.dog/anna", "tg://resolve?domain=anna", "wa.me/79000000000", "asp.net",
|
||||
// Other digit scripts and compatibility forms.
|
||||
"٧٩٠٠٠٠٠٠٠٠٠", "89000000000", "+7 900 000 00 00", "anna@example.com", "@anna_dev",
|
||||
// Obfuscation.
|
||||
"anna [at] example dot com", "vasya at gmail", "vasya собака gmail точка com", "@ vasya", "anna (dot) dev",
|
||||
// Messenger and contact words without an @.
|
||||
"tg: vasya_ivanov", "telegram vasya_ivanov", "whatsapp 1", "viber", "skype: vasya", "почта", "телефон", "email me",
|
||||
} {
|
||||
if !CardTextLooksLikeContact(text) {
|
||||
t.Errorf("CardTextLooksLikeContact(%q) = false, want true", text)
|
||||
}
|
||||
}
|
||||
for _, text := range []string{
|
||||
"PostgreSQL", "Node.js", "Vue.js", "Next.js", "Python 3.12", "ASP.NET", "C++", "C#", "Kubernetes", "Казань", "Mentoring",
|
||||
"Go 1.22", "Java 17", "Санкт-Петербург", "Python 3.12, Django 4.2, PostgreSQL 16", "pro.company", "Team leadership",
|
||||
} {
|
||||
if CardTextLooksLikeContact(text) {
|
||||
t.Errorf("CardTextLooksLikeContact(%q) = true, want false", text)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user