[server][delete] return list of apps being used

This commit is contained in:
Neeraj Gupta
2024-11-22 16:17:08 +05:30
parent 8e215d783f
commit 338c2ec369
3 changed files with 25 additions and 0 deletions

View File

@@ -115,6 +115,7 @@ type DeleteChallengeResponse struct {
// AllowDelete indicates whether the user is allowed to delete their account via app // AllowDelete indicates whether the user is allowed to delete their account via app
AllowDelete bool `json:"allowDelete"` AllowDelete bool `json:"allowDelete"`
EncryptedChallenge *string `json:"encryptedChallenge,omitempty"` EncryptedChallenge *string `json:"encryptedChallenge,omitempty"`
Apps []App `json:"apps"`
} }
type DeleteAccountRequest struct { type DeleteAccountRequest struct {

View File

@@ -49,9 +49,15 @@ func (c *UserController) GetDeleteChallengeToken(ctx *gin.Context) (*ente.Delete
if err != nil { if err != nil {
return nil, stacktrace.Propagate(err, "") return nil, stacktrace.Propagate(err, "")
} }
apps, err := c.UserAuthRepo.GetAppsForUser(userID)
if err != nil {
return nil, stacktrace.Propagate(err, "")
}
return &ente.DeleteChallengeResponse{ return &ente.DeleteChallengeResponse{
EncryptedChallenge: &encryptedToken, EncryptedChallenge: &encryptedToken,
AllowDelete: true, AllowDelete: true,
Apps: apps,
}, nil }, nil
} }

View File

@@ -66,6 +66,24 @@ func (repo *UserAuthRepository) GetUserTokenInfo(userID int64) ([]ente.TokenInfo
return tokenInfos, nil return tokenInfos, nil
} }
func (repo *UserAuthRepository) GetAppsForUser(userID int64) ([]ente.App, error) {
rows, err := repo.DB.Query(`SELECT DISTINCT app FROM tokens WHERE user_id = $1`, userID)
if err != nil {
return nil, stacktrace.Propagate(err, "")
}
defer rows.Close()
apps := make([]ente.App, 0)
for rows.Next() {
var app ente.App
err := rows.Scan(&app)
if err != nil {
return nil, stacktrace.Propagate(err, "")
}
apps = append(apps, app)
}
return apps, nil
}
// GetValidOTTs returns the list of OTTs that haven't expired for a given user // GetValidOTTs returns the list of OTTs that haven't expired for a given user
func (repo *UserAuthRepository) GetValidOTTs(emailHash string, app ente.App) ([]string, error) { func (repo *UserAuthRepository) GetValidOTTs(emailHash string, app ente.App) ([]string, error) {
rows, err := repo.DB.Query(`SELECT ott FROM otts WHERE email_hash = $1 AND app = $2 AND expiration_time > $3`, rows, err := repo.DB.Query(`SELECT ott FROM otts WHERE email_hash = $1 AND app = $2 AND expiration_time > $3`,