Skip to content

Commit

Permalink
Add db queries related to the user_invites table (#3662)
Browse files Browse the repository at this point in the history
Signed-off-by: Radoslav Dimitrov <[email protected]>
  • Loading branch information
rdimitrov authored Jun 19, 2024
1 parent ef1ea3d commit 95a340b
Show file tree
Hide file tree
Showing 4 changed files with 291 additions and 24 deletions.
89 changes: 82 additions & 7 deletions database/mock/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 40 additions & 3 deletions database/query/invitations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,48 @@ FROM user_invites
JOIN users ON user_invites.sponsor = users.id
WHERE project = $1;

-- GetInvitationByEmail retrieves all invitations for a given email address.
-- GetInvitationsByEmail retrieves all invitations for a given email address.
-- This is intended to be called by a logged in user with their own email address,
-- to allow them to accept invitations even if email delivery was not working.
-- Note that this requires that the destination email address matches the email
-- address of the logged in user in the external identity service / auth token.

-- name: GetInvitationByEmail :many
SELECT code, role, project, updated_at FROM user_invites WHERE email = $1;
-- name: GetInvitationsByEmail :many
SELECT * FROM user_invites WHERE email = $1;

-- GetInvitationByEmailAndProjectAndRole retrieves an invitation by email, project,
-- and role.

-- name: GetInvitationByEmailAndProjectAndRole :one
SELECT * FROM user_invites WHERE email = $1 AND project = $2 AND role = $3;

-- GetInvitationByCode retrieves an invitation by its code. This is intended to
-- be called by a user who has received an invitation email and is following the
-- link to accept the invitation or when querying for additional info about the
-- invitation.

-- name: GetInvitationByCode :one
SELECT * FROM user_invites WHERE code = $1;

-- CreateInvitation creates a new invitation. The code is a secret that is sent
-- to the invitee, and the email is the address to which the invitation will be
-- sent. The role is the role that the invitee will have when they accept the
-- invitation. The project is the project to which the invitee will be invited.
-- The sponsor is the user who is inviting the invitee.

-- name: CreateInvitation :one
INSERT INTO user_invites (code, email, role, project, sponsor) VALUES ($1, $2, $3, $4, $5) RETURNING *;

-- DeleteInvitation deletes an invitation by its code. This is intended to be
-- called by a user who has issued an invitation and then accepted it, declined
-- it or the sponsor has decided to revoke it.

-- name: DeleteInvitation :one
DELETE FROM user_invites WHERE code = $1 RETURNING *;

-- UpdateInvitation updates an invitation by its code. This is intended to be
-- called by a user who has issued an invitation and then decided to bump its
-- expiration.

-- name: UpdateInvitation :one
UPDATE user_invites SET updated_at = NOW() WHERE code = $1 RETURNING *;
157 changes: 145 additions & 12 deletions internal/db/invitations.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 95a340b

Please sign in to comment.