feat(invitations): check contact grants on every read, cap pending invitations, and expire them at the deadline
This commit is contained in:
1 parent
676b3c6e24
commit
12a7213d4a
67 files changed
+4255
-149
No files matched your search
@@ -0,0 +1,30 @@
|
||||
-- Takes the row lock of one invitation by its identifier alone. Only the
|
||||
-- response deadline job reads an invitation without an organization or a
|
||||
-- candidate of the request; it reads the organization from this row and then
|
||||
-- reads the locked invitation with its scope.
|
||||
-- name: LockInvitationByID :one
|
||||
SELECT organization_id
|
||||
FROM invitations
|
||||
WHERE id = sqlc.arg(invitation_id)
|
||||
FOR UPDATE;
|
||||
|
||||
-- The compare-and-swap of the expiry: it applies only to a delivered or viewed
|
||||
-- invitation at the version the caller read, whose deadline has passed at the
|
||||
-- expiry time. It keeps the deadline, the terms, and every answer field, and it
|
||||
-- sets the timeout reason. No row is returned when it lost a race or the
|
||||
-- deadline has not passed.
|
||||
-- name: ExpireInvitation :one
|
||||
UPDATE invitations
|
||||
SET
|
||||
state = 'expired',
|
||||
expiry_reason = 'invitation_timeout',
|
||||
version = sqlc.arg(next_version),
|
||||
updated_at = sqlc.arg(expired_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 response_deadline_at <= sqlc.arg(expired_at)
|
||||
AND sqlc.arg(next_version)::bigint = sqlc.arg(expected_version)::bigint + 1
|
||||
RETURNING id;
|
||||
Reference in new issue
Block a user