feat(invitations): accept invitations with C4 consent and contact grants; share the E0 quota across holdings

This commit is contained in:
shira committed 2026-10-09 18:03:35 +03:00
1 parent a5990d3fc6
commit 676b3c6e24
59 files changed
+4926 -194

No files matched your search

+39
View File
@@ -127,3 +127,42 @@ SELECT
outcome
FROM invitation_decline_results
WHERE scope_hash = sqlc.arg(scope_hash);
-- The compare-and-swap of an acceptance: it applies only to a delivered or
-- viewed invitation at the version and the terms version that the candidate
-- read, and before its deadline. The answer is the acceptance time, and the
-- deadline is kept.
-- name: AcceptInvitation :one
UPDATE invitations
SET
state = 'accepted',
version = sqlc.arg(next_version),
responded_at = sqlc.arg(accepted_at),
updated_at = sqlc.arg(accepted_at)
WHERE
organization_id = sqlc.arg(organization_id)
AND id = sqlc.arg(invitation_id)
AND state IN ('delivered', 'viewed')
AND version = sqlc.arg(expected_version)
AND terms_version = sqlc.arg(terms_version)
AND response_deadline_at > sqlc.arg(accepted_at)
AND sqlc.arg(next_version)::bigint = sqlc.arg(expected_version)::bigint + 1
RETURNING id;
-- name: InsertInvitationAcceptResult :exec
INSERT INTO invitation_accept_results (
scope_hash,
invitation_id,
outcome
) VALUES (
sqlc.arg(scope_hash),
sqlc.arg(invitation_id),
sqlc.arg(outcome)
);
-- name: GetInvitationAcceptResult :one
SELECT
invitation_id,
outcome
FROM invitation_accept_results
WHERE scope_hash = sqlc.arg(scope_hash);