Переглянути джерело

Rename account_recovery -> two_factor_recovery

Neeraj Gupta 1 рік тому
батько
коміт
f766484b2e

+ 3 - 3
server/cmd/museum/main.go

@@ -5,7 +5,7 @@ import (
 	"database/sql"
 	b64 "encoding/base64"
 	"fmt"
-	"github.com/ente-io/museum/pkg/repo/accountrecovery"
+	"github.com/ente-io/museum/pkg/repo/two_factor_recovery"
 	"net/http"
 	"os"
 	"os/signal"
@@ -138,7 +138,7 @@ func main() {
 
 	twoFactorRepo := &repo.TwoFactorRepository{DB: db, SecretEncryptionKey: secretEncryptionKeyBytes}
 	userAuthRepo := &repo.UserAuthRepository{DB: db}
-	accountRecoveryRepo := &accountrecovery.Repository{Db: db}
+	twoFactorRecoveryRepo := &two_factor_recovery.Repository{Db: db}
 	billingRepo := &repo.BillingRepository{DB: db}
 	userEntityRepo := &userEntityRepo.Repository{DB: db}
 	locationTagRepository := &locationtagRepo.Repository{DB: db}
@@ -306,7 +306,7 @@ func main() {
 		usageRepo,
 		userAuthRepo,
 		twoFactorRepo,
-		accountRecoveryRepo,
+		twoFactorRecoveryRepo,
 		passkeysRepo,
 		storagBonusRepo,
 		fileRepo,

+ 1 - 1
server/ente/passkey.go

@@ -18,7 +18,7 @@ type ConfigurePassKeySkipRequest struct {
 	EncPassKeySkipSecret EncData `json:"encPassKeySkipSecret" binding:"required"`
 }
 
-type AccountRecoveryStatus struct {
+type TwoFactorRecoveryStatus struct {
 	// AllowAdminReset is a boolean that determines if the admin can reset the user's MFA.
 	// If true, in the event that the user loses their MFA device, the admin can reset the user's MFA.
 	AllowAdminReset      bool `json:"allowAdminReset" binding:"required"`

+ 0 - 2
server/migrations/80_account_recovery.down.sql

@@ -1,2 +0,0 @@
-DROP TABLE IF NOT EXISTS account_recovery;
-DROP TRIGGER IF EXISTS update_account_recovery_updated_at ON account_recovery;

+ 2 - 0
server/migrations/80_two_factor_recovery.down.sql

@@ -0,0 +1,2 @@
+DROP TABLE IF NOT EXISTS two_factor_recovery;
+DROP TRIGGER IF EXISTS update_two_factor_recovery_updated_at ON two_factor_recovery;

+ 3 - 3
server/migrations/80_account_recovery.up.sql → server/migrations/80_two_factor_recovery.up.sql

@@ -1,4 +1,4 @@
-CREATE TABLE IF NOT EXISTS account_recovery (
+CREATE TABLE IF NOT EXISTS two_factor_recovery (
     user_id bigint NOT NULL,
     -- if false, the support team team will not be able to reset the MFA for the user
     enable_admin_mfa_reset boolean NOT NULL DEFAULT true,
@@ -10,9 +10,9 @@ CREATE TABLE IF NOT EXISTS account_recovery (
     updated_at    bigint NOT NULL DEFAULT now_utc_micro_seconds()
 );
 
-CREATE TRIGGER update_account_recovery_updated_at
+CREATE TRIGGER update_two_factor_recovery_updated_at
     BEFORE UPDATE
-    ON account_recovery
+    ON two_factor_recovery
     FOR EACH ROW
     EXECUTE PROCEDURE
         trigger_updated_at_microseconds_column();

+ 6 - 6
server/pkg/controller/user/passkey.go

@@ -8,14 +8,14 @@ import (
 )
 
 // GetAccountRecoveryStatus returns a user's passkey reset status
-func (c *UserController) GetAccountRecoveryStatus(ctx *gin.Context) (*ente.AccountRecoveryStatus, error) {
+func (c *UserController) GetAccountRecoveryStatus(ctx *gin.Context) (*ente.TwoFactorRecoveryStatus, error) {
 	userID := auth.GetUserID(ctx.Request.Header)
-	return c.AccountRecoveryRepo.GetAccountRecoveryStatus(userID)
+	return c.TwoFactorRecoveryRepo.GetStatus(userID)
 }
 
 func (c *UserController) ConfigurePassKeySkip(ctx *gin.Context, req *ente.ConfigurePassKeySkipRequest) error {
 	userID := auth.GetUserID(ctx.Request.Header)
-	return c.AccountRecoveryRepo.ConfigurePassKeyRecovery(ctx, userID, req)
+	return c.TwoFactorRecoveryRepo.ConfigurePassKeyRecovery(ctx, userID, req)
 }
 
 func (c *UserController) GetPasskeySkipChallenge(ctx *gin.Context, passKeySessionID string) (*ente.EncData, error) {
@@ -23,7 +23,7 @@ func (c *UserController) GetPasskeySkipChallenge(ctx *gin.Context, passKeySessio
 	if err != nil {
 		return nil, err
 	}
-	recoveryStatus, err := c.AccountRecoveryRepo.GetAccountRecoveryStatus(userID)
+	recoveryStatus, err := c.TwoFactorRecoveryRepo.GetStatus(userID)
 	if err != nil {
 		return nil, err
 	}
@@ -31,7 +31,7 @@ func (c *UserController) GetPasskeySkipChallenge(ctx *gin.Context, passKeySessio
 		return nil, ente.NewBadRequestWithMessage("Passkey reset is not configured")
 	}
 
-	result, err := c.AccountRecoveryRepo.GetPasskeyResetChallenge(ctx, userID)
+	result, err := c.TwoFactorRecoveryRepo.GetPasskeyResetChallenge(ctx, userID)
 	if err != nil {
 		return nil, err
 	}
@@ -46,7 +46,7 @@ func (c *UserController) SkipPassKey(context *gin.Context, req *ente.SkipPassKey
 	if err != nil {
 		return nil, stacktrace.Propagate(err, "")
 	}
-	exists, err := c.AccountRecoveryRepo.VerifyRecoveryKeyForPassKey(userID, req.PassKeySkipSecret)
+	exists, err := c.TwoFactorRecoveryRepo.VerifyRecoveryKeyForPassKey(userID, req.PassKeySkipSecret)
 	if err != nil {
 		return nil, stacktrace.Propagate(err, "")
 	}

+ 4 - 4
server/pkg/controller/user/user.go

@@ -3,7 +3,7 @@ package user
 import (
 	"errors"
 	"fmt"
-	"github.com/ente-io/museum/pkg/repo/accountrecovery"
+	"github.com/ente-io/museum/pkg/repo/two_factor_recovery"
 	"strings"
 
 	cache2 "github.com/ente-io/museum/ente/cache"
@@ -31,7 +31,7 @@ import (
 // UserController exposes request handlers for all user related requests
 type UserController struct {
 	UserRepo               *repo.UserRepository
-	AccountRecoveryRepo    *accountrecovery.Repository
+	TwoFactorRecoveryRepo  *two_factor_recovery.Repository
 	UsageRepo              *repo.UsageRepository
 	UserAuthRepo           *repo.UserAuthRepository
 	TwoFactorRepo          *repo.TwoFactorRepository
@@ -101,7 +101,7 @@ func NewUserController(
 	usageRepo *repo.UsageRepository,
 	userAuthRepo *repo.UserAuthRepository,
 	twoFactorRepo *repo.TwoFactorRepository,
-	accountRecoveryRepo *accountrecovery.Repository,
+	twoFactorRecoveryRepo *two_factor_recovery.Repository,
 	passkeyRepo *passkey.Repository,
 	storageBonusRepo *storageBonusRepo.Repository,
 	fileRepo *repo.FileRepository,
@@ -124,7 +124,7 @@ func NewUserController(
 	return &UserController{
 		UserRepo:               userRepo,
 		UsageRepo:              usageRepo,
-		AccountRecoveryRepo:    accountRecoveryRepo,
+		TwoFactorRecoveryRepo:  twoFactorRecoveryRepo,
 		UserAuthRepo:           userAuthRepo,
 		StorageBonusRepo:       storageBonusRepo,
 		TwoFactorRepo:          twoFactorRepo,

+ 11 - 10
server/pkg/repo/accountrecovery/repository.go → server/pkg/repo/two_factor_recovery/repository.go

@@ -1,4 +1,4 @@
-package accountrecovery
+package two_factor_recovery
 
 import (
 	"context"
@@ -11,35 +11,36 @@ type Repository struct {
 	Db *sql.DB
 }
 
-// GetAccountRecoveryStatus returns `ente.AccountRecoveryStatus` for a user
-func (r *Repository) GetAccountRecoveryStatus(userID int64) (*ente.AccountRecoveryStatus, error) {
+// GetStatus returns `ente.TwoFactorRecoveryStatus` for a user
+func (r *Repository) GetStatus(userID int64) (*ente.TwoFactorRecoveryStatus, error) {
 	var isAdminResetEnabled bool
 	var resetKey sql.NullString
-	row := r.Db.QueryRow("SELECT enable_admin_mfa_reset, pass_key_reset_key FROM account_recovery WHERE user_id = $1", userID)
+	row := r.Db.QueryRow("SELECT enable_admin_mfa_reset, pass_key_reset_key FROM two_factor_recovery WHERE user_id = $1", userID)
 	err := row.Scan(&isAdminResetEnabled, &resetKey)
 	if err != nil {
 		if err == sql.ErrNoRows {
 			// by default, admin
-			return &ente.AccountRecoveryStatus{
+			return &ente.TwoFactorRecoveryStatus{
 				AllowAdminReset:      true,
 				IsPassKeySkipEnabled: false,
 			}, nil
 		}
 		return nil, err
 	}
-	return &ente.AccountRecoveryStatus{AllowAdminReset: isAdminResetEnabled, IsPassKeySkipEnabled: resetKey.Valid}, nil
+	return &ente.TwoFactorRecoveryStatus{AllowAdminReset: isAdminResetEnabled, IsPassKeySkipEnabled: resetKey.Valid}, nil
 }
 
 func (r *Repository) ConfigurePassKeyRecovery(ctx context.Context, userID int64, req *ente.ConfigurePassKeySkipRequest) error {
-	_, err := r.Db.ExecContext(ctx, `INSERT INTO account_recovery (user_id, pass_key_reset_key, pass_key_reset_enc_data) 
+	_, err := r.Db.ExecContext(ctx, `INSERT INTO two_factor_recovery (user_id, pass_key_reset_key, pass_key_reset_enc_data) 
 											VALUES ($1, $2,$3) ON CONFLICT (user_id) 
-											DO UPDATE SET pass_key_reset_key = $2, pass_key_reset_enc_data = $3`, userID, req.PassKeySkipKey, req.EncPassKeySkipSecret)
+											DO UPDATE SET pass_key_reset_key = $2, pass_key_reset_enc_data = $3`, userID, req.PassKeySkipSecret,
+		req.EncPassKeySkipSecret)
 	return err
 }
 
 func (r *Repository) GetPasskeyResetChallenge(ctx context.Context, userID int64) (*ente.EncData, error) {
 	var encData *ente.EncData
-	err := r.Db.QueryRowContext(ctx, "SELECT pass_key_reset_enc_data FROM account_recovery WHERE  user_id= $1", userID).Scan(encData)
+	err := r.Db.QueryRowContext(ctx, "SELECT pass_key_reset_enc_data FROM two_factor_recovery WHERE  user_id= $1", userID).Scan(encData)
 	if err != nil {
 		return nil, err
 	}
@@ -49,7 +50,7 @@ func (r *Repository) GetPasskeyResetChallenge(ctx context.Context, userID int64)
 // VerifyRecoveryKeyForPassKey checks if the passkey reset key is valid for a user
 func (r *Repository) VerifyRecoveryKeyForPassKey(userID int64, passKeyResetKey string) (bool, error) {
 	var exists bool
-	row := r.Db.QueryRow(`SELECT EXISTS( SELECT 1 FROM account_recovery WHERE user_id = $1 AND pass_key_reset_key = $2)`, userID, passKeyResetKey)
+	row := r.Db.QueryRow(`SELECT EXISTS( SELECT 1 FROM two_factor_recovery WHERE user_id = $1 AND pass_key_reset_key = $2)`, userID, passKeyResetKey)
 	err := row.Scan(&exists)
 	if err != nil {
 		return false, stacktrace.Propagate(err, "")