Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Rename account_recovery -> two_factor_recovery

Neeraj Guptaf766484b2ee6
diff --git a/server/cmd/museum/main.go b/server/cmd/museum/main.go
index 34dbfbfc26..0467337195 100644
--- a/server/cmd/museum/main.go
+++ b/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,
diff --git a/server/ente/passkey.go b/server/ente/passkey.go
index 3edcf52b9a..e4ddb6e52e 100644
--- a/server/ente/passkey.go
+++ b/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"`
diff --git a/server/migrations/80_account_recovery.down.sql b/server/migrations/80_account_recovery.down.sql
deleted file mode 100644
index d5446f1c75..0000000000
--- a/server/migrations/80_account_recovery.down.sql
+++ /dev/null
@@ -1,2 +0,0 @@
-DROP TABLE IF NOT EXISTS account_recovery;
-DROP TRIGGER IF EXISTS update_account_recovery_updated_at ON account_recovery;
\ No newline at end of file
diff --git a/server/migrations/80_two_factor_recovery.down.sql b/server/migrations/80_two_factor_recovery.down.sql
new file mode 100644
index 0000000000..f89f1689f1
--- /dev/null
+++ b/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;
\ No newline at end of file
diff --git a/server/migrations/80_account_recovery.up.sql b/server/migrations/80_two_factor_recovery.up.sql
similarity index 80%
rename from server/migrations/80_account_recovery.up.sql
rename to server/migrations/80_two_factor_recovery.up.sql
index bcf8c5e8cb..670fb74d1d 100644
--- a/server/migrations/80_account_recovery.up.sql
+++ b/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();
diff --git a/server/pkg/controller/user/passkey.go b/server/pkg/controller/user/passkey.go
index 058d201926..b92baf649b 100644
--- a/server/pkg/controller/user/passkey.go
+++ b/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, "")
}
diff --git a/server/pkg/controller/user/user.go b/server/pkg/controller/user/user.go
index 0e2b6fe7e9..afba09058f 100644
--- a/server/pkg/controller/user/user.go
+++ b/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,
diff --git a/server/pkg/repo/accountrecovery/repository.go b/server/pkg/repo/two_factor_recovery/repository.go
similarity index 61%
rename from server/pkg/repo/accountrecovery/repository.go
rename to server/pkg/repo/two_factor_recovery/repository.go
index 8b81e67f52..fa2ecb0a65 100644
--- a/server/pkg/repo/accountrecovery/repository.go
+++ b/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, "")