V3 S6 : confiance (révocation, quota, appareils, conflits) + import + onboarding
Backend : token_version (000022, claim tv, 401 si révoqué, bump au password — fin limite V1), quota (000023 idempotente, colonne héritée de 000001, 413 QUOTA_EXCEEDED, GET /users/me/usage), devices (GET + DELETE révocation, EnforceDeviceExists en prod), renames concurrents transparents (baseUpdatedAt + conflicts[] non-fataux, tolérance 2 s). Tests service + handlers + migrations + auth. Mobile : pipeline conflits (DTO + SyncConflictStore + worker + dialogue), baseUpdatedAt prêt, liens 7j par défaut, écran Appareils (+ quota), import classeur unifié (scan/note/dossier), onboarding cercle Famille. Contrat docs/api-v1.md, V3.md (S6 livré).
This commit is contained in:
@@ -52,3 +52,61 @@ func (d *Devices) MarkUser(deviceID, userID string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeviceRow is one registered device of an account (A1 — voir / révoquer).
|
||||
type DeviceRow struct {
|
||||
DeviceID string
|
||||
LastSeenAt *int64 // ms epoch, NULL si jamais vu depuis l'enregistrement
|
||||
}
|
||||
|
||||
// ListByUser returns the devices whose last login was this account
|
||||
// (devices.user_id informatif, jamais autorisant).
|
||||
func (d *Devices) ListByUser(userID string) ([]DeviceRow, error) {
|
||||
rows, err := d.DB.Query(
|
||||
`SELECT device_id, (EXTRACT(EPOCH FROM last_seen_at) * 1000)::bigint
|
||||
FROM devices WHERE user_id = $1 ORDER BY last_seen_at DESC NULLS LAST`,
|
||||
userID,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
out := []DeviceRow{}
|
||||
for rows.Next() {
|
||||
var row DeviceRow
|
||||
if err := rows.Scan(&row.DeviceID, &row.LastSeenAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, row)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// Revoke deletes a device registration of this account (A1 — téléphone
|
||||
// perdu). Avec EnforceDeviceExists, les tokens du device deviennent 401 et
|
||||
// le login refuse le device (ré-enregistrement explicite requis).
|
||||
// Ligne absente ou d'un autre compte → ErrNotFound (pas d'énumération).
|
||||
// Les hints de présence (`storage_locations`) suivent.
|
||||
func (d *Devices) Revoke(userID, deviceID string) error {
|
||||
result, err := d.DB.Exec(
|
||||
`DELETE FROM devices WHERE device_id = $1 AND user_id = $2`,
|
||||
deviceID, userID,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
affected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if affected == 0 {
|
||||
return ErrNotFound
|
||||
}
|
||||
if _, err := d.DB.Exec(
|
||||
`DELETE FROM storage_locations WHERE device_id = $1 AND user_id = $2`,
|
||||
deviceID, userID,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user