feat: change email, export my data, delete account (with data anonymization)
This commit is contained in:
1 parent
bb191c389a
commit
10a66cd979
123 files changed
+10789
-76
No files matched your search
@@ -5,6 +5,7 @@ import (
|
||||
"RenewCMS/internal/infrastructure/persistence/mappers"
|
||||
entity "RenewCMS/internal/infrastructure/persistence/models"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -233,3 +234,38 @@ func (a *AuditEventRepository) DeleteOldest(limit int, before time.Time) (int, e
|
||||
}
|
||||
return removed, nil
|
||||
}
|
||||
|
||||
const (
|
||||
erasedParams = "{}"
|
||||
erasedChanges = "[]"
|
||||
authorActions = "author.%"
|
||||
)
|
||||
|
||||
func (a *AuditEventRepository) AnonymiseUser(userID uint32, ownAuthorID *uint32, name string) error {
|
||||
userTargetID := strconv.FormatUint(uint64(userID), 10)
|
||||
involved := "(actor_type = ? AND actor_id = ?) OR (target_type = ? AND target_id = ?)"
|
||||
asActor := a.db.Model(&entity.AuditEvent{}).
|
||||
Where("actor_type = ? AND actor_id = ?", string(audit.ActorUser), userID).
|
||||
Updates(map[string]any{"actor_name": name, "ip": nil, "user_agent": nil})
|
||||
if asActor.Error != nil {
|
||||
return asActor.Error
|
||||
}
|
||||
asTarget := a.db.Model(&entity.AuditEvent{}).
|
||||
Where("target_type = ? AND target_id = ?", audit.TargetUser, userTargetID).
|
||||
Update("target_name", name)
|
||||
if asTarget.Error != nil {
|
||||
return asTarget.Error
|
||||
}
|
||||
if ownAuthorID != nil {
|
||||
ownProfile := a.db.Model(&entity.AuditEvent{}).
|
||||
Where("actor_type = ? AND actor_id = ? AND action LIKE ? AND target_type = ? AND target_id = ?",
|
||||
string(audit.ActorUser), userID, authorActions, audit.TargetAuthor, strconv.FormatUint(uint64(*ownAuthorID), 10)).
|
||||
Update("target_name", name)
|
||||
if ownProfile.Error != nil {
|
||||
return ownProfile.Error
|
||||
}
|
||||
}
|
||||
return a.db.Model(&entity.AuditEvent{}).
|
||||
Where(involved, string(audit.ActorUser), userID, audit.TargetUser, userTargetID).
|
||||
Updates(map[string]any{"params": erasedParams, "changes": erasedChanges}).Error
|
||||
}
|
||||
Reference in new issue
Block a user