feat(org): add organization and membership contract and storage

This commit is contained in:
shira committed 2026-10-06 15:55:29 +03:00
1 parent a0551a34b8
commit bdc5855001
90 files changed
+17545 -480

No files matched your search

@@ -273,6 +273,39 @@ func (UnimplementedHandler) CreateMySupportCase(ctx context.Context, req Support
return r, ht.ErrNotImplemented
}
// CreateOrganization implements CreateOrganization operation.
//
// Requires the session cookie of an employer account with a confirmed email, the CSRF token of that
// session in X-CSRF-Token, an allowed Origin, and an Idempotency-Key. The owner is the account of the
// session: the body has no owner, membership, role, verification, or version field, and unknown fields
// fail validation.
//
// The server creates the organization and the owner membership of the caller (role `owner`, state
// `active`) in one transaction, so an organization never exists without its owner. The organization
// starts at the verification level `e0` with the basis `confirmed_email`. The level cannot be
// requested: the creator of a company with a corporate domain, a long description, or many
// representatives still gets `e0`, and `e1`, `e2`, and `e3` come only from verification processes of
// the server that do not exist yet. Only `name` is required; the rest of the card can be completed
// with UpdateOrganization.
//
// Idempotency: a retry with the same key and body within 24 hours replays the stored 201 and creates
// nothing, so a lost response never creates a second organization. A different body with the same key
// answers 422 idempotency_key_reused. 400 is never stored, so a corrected retry is evaluated again.
// Two requests with different keys are two organizations; the product may limit the number of
// organizations per account (open question), which would answer 409 `state_conflict` without a change
// of the schema.
//
// Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400),
// account scenario (403 forbidden for a candidate account), the Idempotency-Key (422, 409
// idempotency_in_progress, replay), domain rules (400 with a pointer such as `/contacts/website` for a
// website that is not an https URL of a host name, `/name` for a name with surrounding whitespace).
// The general rate limit can answer 429 with Retry-After before any check; 429 is never stored.
//
// POST /api/v1/organizations
func (UnimplementedHandler) CreateOrganization(ctx context.Context, req *OrganizationCreate, params CreateOrganizationParams) (r CreateOrganizationRes, _ error) {
return r, ht.ErrNotImplemented
}
// CreateOrganizationInvitation implements CreateOrganizationInvitation operation.
//
// Requires the session cookie of an employer account with an active membership in `org_id`, the CSRF
@@ -670,6 +703,33 @@ func (UnimplementedHandler) GetMySupportCase(ctx context.Context, params GetMySu
return r, ht.ErrNotImplemented
}
// GetOrganization implements GetOrganization operation.
//
// Requires the session cookie of an employer account with an active membership in `org_id`. The
// organization comes from the path and is checked against the membership that the server holds for the
// session account on every request; the identifier itself grants nothing.
//
// Returns the profile with its current `version`, the verification level (`verification`), and the
// card as a candidate sees it (`candidate_card`). The verification level is always the one the server
// holds: it never rises because the profile is complete, because the organization has members, or
// because of an email domain. The role of the caller is not part of this resource; ListMyOrganizations
// returns it with the membership.
//
// In the MVP the profile is readable by any active member; every member is an owner, because the
// operations that add members are planned. The roles of PRD FR07 that read a company card without
// managing it change no field of this contract.
//
// Access: a missing, unknown, expired, or revoked session answers 401 unauthenticated; a candidate
// account answers 403 forbidden; an account without an active membership in the organization,
// including a `suspended`, `removed`, or `left` one, and an unknown organization all answer 404
// not_found, so organizations cannot be enumerated. A malformed `org_id` answers 400 validation_failed
// with the path pointer.
//
// GET /api/v1/organizations/{org_id}
func (UnimplementedHandler) GetOrganization(ctx context.Context, params GetOrganizationParams) (r GetOrganizationRes, _ error) {
return r, ht.ErrNotImplemented
}
// GetOrganizationInvitation implements GetOrganizationInvitation operation.
//
// Requires the session cookie of an employer account with an active membership in `org_id`. The
@@ -845,6 +905,38 @@ func (UnimplementedHandler) ListMyInvitations(ctx context.Context, params ListMy
return r, ht.ErrNotImplemented
}
// ListMyOrganizations implements ListMyOrganizations operation.
//
// Requires the session cookie of an employer account. The account comes from the session, never from a
// request parameter, so the response holds only the caller's own memberships and no request can name
// another account.
//
// Returns a page of the organizations in which the caller has an `active` membership, newest
// membership first with the organization identifier as the tie-breaker, with cursor pagination. Each
// item names the organization (`OrganizationSummary`) and holds the caller's role and state in it
// (`OrganizationMembership`). A membership in another state (`suspended`, `removed`, `left`) does not
// list its organization, so an organization the caller cannot enter is never named, and one that the
// caller was removed from disappears from the list at once.
//
// The list is the directory of the active organization context. The context is not stored on the
// server: every organization-scoped operation names its organization in the path `org_id`, and the
// server checks that identifier against the caller's active membership on every request, so a switch
// between organizations is a different `org_id` in the client's routes and cannot outlive a revoked
// membership. A client picks the context from this list, may remember the last choice in the browser
// as a convenience, and must read the list again after any answer 404 `not_found` from an organization
// path. An account with several memberships sees all of them here and works in one at a time; the
// rights and the data of the organizations stay separate.
//
// Access: a missing, unknown, expired, or revoked session answers 401 unauthenticated; a candidate
// account answers 403 forbidden. An employer account without an organization gets an empty page, which
// tells the client to offer CreateOrganization. A malformed `limit` or `cursor` answers 400
// validation_failed.
//
// GET /api/v1/me/organizations
func (UnimplementedHandler) ListMyOrganizations(ctx context.Context, params ListMyOrganizationsParams) (r ListMyOrganizationsRes, _ 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
@@ -1199,6 +1291,45 @@ func (UnimplementedHandler) SubmitMyAssessmentAnswer(ctx context.Context, req *A
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
// token of that session in X-CSRF-Token, and an allowed Origin. Only the owner manages the
// organization (the FR07 matrix gives this to no other role), so a member with another role answers
// 403 forbidden. The role comes from the server-side membership; the body has no organization,
// membership, role, owner, or verification field.
//
// Merge rules: the body is `application/json` with explicit field replacement, not JSON Merge Patch.
// Each field present replaces that field as a whole and an absent field stays unchanged; `contacts`
// and `representatives` are replaced entirely and never merged. `description` and `sphere` sent as
// null become unset; `name`, `contacts`, and `representatives` cannot be null.
//
// The body can change the profile only. The verification level, its basis, the card, the members, and
// every role are not fields of it, and unknown fields fail validation, so the owner can neither raise
// the trust level of the organization nor the rights of anyone by editing the profile; a longer
// description, a verified-looking website, or a new representative leaves the level unchanged. The
// level and the roles change only through processes of the server.
//
// Versions: every committed change creates version `expected_version + 1` and answers 200 with the
// organization. `expected_version` is the `version` the client read; when it is not current, the
// server answers 412 version_conflict and changes nothing, and the client reads the organization again
// and reapplies its edits. The version travels in the body rather than in If-Match because the
// generated client cannot read the ETag response header yet, as for needs. A body that changes nothing
// when applied to the current profile keeps the version and answers 200 with the current organization
// even when `expected_version` is older, so the operation needs no Idempotency-Key and a retry of a
// change that already succeeded is harmless.
//
// Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400),
// account scenario (403 forbidden for a candidate account), membership (404 not_found) and role (403
// forbidden), a body that changes nothing (200), the version (412), domain rules (400 with a pointer
// such as `/contacts/website`, `/name`, or `/representatives/0/job_title`). The general rate limit can
// answer 429 with Retry-After before any check.
//
// PATCH /api/v1/organizations/{org_id}
func (UnimplementedHandler) UpdateOrganization(ctx context.Context, req *OrganizationUpdate, params UpdateOrganizationParams) (r UpdateOrganizationRes, _ error) {
return r, ht.ErrNotImplemented
}
// UpdateOrganizationInvitation implements UpdateOrganizationInvitation operation.
//
// Requires the session cookie of an employer account with an active membership in `org_id`, the CSRF