tenseleyflow/shithub / b0a0cc3

Browse files

users/sqlc: GetUserGPGKey excludes revoked rows

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
b0a0cc3e29f85dc7038f55294dd7a1ebae267ed2
Parents
3168964
Tree
977aac2

3 changed files

StatusFile+-
M internal/users/queries/user_gpg_keys.sql 5 2
M internal/users/sqlc/querier.go 4 1
M internal/users/sqlc/user_gpg_keys.sql.go 5 2
internal/users/queries/user_gpg_keys.sqlmodified
@@ -39,13 +39,16 @@ SELECT count(*) FROM user_gpg_keys WHERE user_id = $1 AND revoked_at IS NULL;
3939
 -- name: GetUserGPGKey :one
4040
 -- Scoped single-key lookup for REST GET-by-id. user_id filter prevents
4141
 -- cross-user reads (existence-leak-safe: returns no row if the id
42
--- belongs to another user).
42
+-- belongs to another user). Excludes soft-deleted rows so the public
43
+-- surface mirrors a hard delete from the consumer's perspective;
44
+-- verification (which needs historical attribution) uses
45
+-- GetUserGPGKeyForVerification which has no revoked filter.
4346
 SELECT id, user_id, name, fingerprint, key_id, armored,
4447
        can_sign, can_encrypt_comms, can_encrypt_storage, can_certify, can_authenticate,
4548
        uids, subkeys, primary_algo,
4649
        created_at, last_used_at, revoked_at, expires_at
4750
 FROM user_gpg_keys
48
-WHERE id = $1 AND user_id = $2;
51
+WHERE id = $1 AND user_id = $2 AND revoked_at IS NULL;
4952
 
5053
 -- name: GetUserGPGKeyForVerification :one
5154
 -- Non-user-scoped lookup used by the verification path. Unlike
internal/users/sqlc/querier.gomodified
@@ -85,7 +85,10 @@ type Querier interface {
8585
 	GetUserEmailByVerificationHash(ctx context.Context, db DBTX, verificationTokenHash []byte) (UserEmail, error)
8686
 	// Scoped single-key lookup for REST GET-by-id. user_id filter prevents
8787
 	// cross-user reads (existence-leak-safe: returns no row if the id
88
-	// belongs to another user).
88
+	// belongs to another user). Excludes soft-deleted rows so the public
89
+	// surface mirrors a hard delete from the consumer's perspective;
90
+	// verification (which needs historical attribution) uses
91
+	// GetUserGPGKeyForVerification which has no revoked filter.
8992
 	GetUserGPGKey(ctx context.Context, db DBTX, arg GetUserGPGKeyParams) (UserGpgKey, error)
9093
 	// Uniqueness probe used by the add path to surface a friendly
9194
 	// "this key is already registered" error before the unique index
internal/users/sqlc/user_gpg_keys.sql.gomodified
@@ -29,7 +29,7 @@ SELECT id, user_id, name, fingerprint, key_id, armored,
2929
        uids, subkeys, primary_algo,
3030
        created_at, last_used_at, revoked_at, expires_at
3131
 FROM user_gpg_keys
32
-WHERE id = $1 AND user_id = $2
32
+WHERE id = $1 AND user_id = $2 AND revoked_at IS NULL
3333
 `
3434
 
3535
 type GetUserGPGKeyParams struct {
@@ -39,7 +39,10 @@ type GetUserGPGKeyParams struct {
3939
 
4040
 // Scoped single-key lookup for REST GET-by-id. user_id filter prevents
4141
 // cross-user reads (existence-leak-safe: returns no row if the id
42
-// belongs to another user).
42
+// belongs to another user). Excludes soft-deleted rows so the public
43
+// surface mirrors a hard delete from the consumer's perspective;
44
+// verification (which needs historical attribution) uses
45
+// GetUserGPGKeyForVerification which has no revoked filter.
4346
 func (q *Queries) GetUserGPGKey(ctx context.Context, db DBTX, arg GetUserGPGKeyParams) (UserGpgKey, error) {
4447
 	row := db.QueryRow(ctx, getUserGPGKey, arg.ID, arg.UserID)
4548
 	var i UserGpgKey