feat: activity log producers
This commit is contained in:
1 parent
50b1649965
commit
e37a46a027
93 files changed
+3396
-440
No files matched your search
@@ -0,0 +1,30 @@
|
||||
package audit
|
||||
|
||||
import (
|
||||
"RenewCMS/internal/domain/article"
|
||||
"strconv"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func TextChange(field string, before string, after string) Change {
|
||||
return Change{Field: field, Kind: ChangeText, Before: &before, After: &after}
|
||||
}
|
||||
|
||||
func BodyChange(before string, after string) Change {
|
||||
delta := utf8.RuneCountInString(after) - utf8.RuneCountInString(before)
|
||||
return Change{Field: FieldBody, Kind: ChangeBody, Delta: &delta}
|
||||
}
|
||||
|
||||
func ArticleChanges(before article.Article, after article.Article) []Change {
|
||||
changes := []Change{}
|
||||
if before.Title != after.Title {
|
||||
changes = append(changes, TextChange(FieldTitle, before.Title, after.Title))
|
||||
}
|
||||
if before.IsOnline != after.IsOnline {
|
||||
changes = append(changes, TextChange(FieldOnline, strconv.FormatBool(before.IsOnline), strconv.FormatBool(after.IsOnline)))
|
||||
}
|
||||
if before.Body != after.Body {
|
||||
changes = append(changes, BodyChange(before.Body, after.Body))
|
||||
}
|
||||
return changes
|
||||
}
|
||||
@@ -66,11 +66,36 @@ const (
|
||||
ActionAPIKeyRevoke = "api_key.revoke"
|
||||
ActionRetentionChanged = "system.activity_retention_changed"
|
||||
ActionCleanup = "system.activity_cleanup"
|
||||
ActionArticleCreate = "article.create"
|
||||
ActionArticleEdit = "article.edit"
|
||||
ActionArticlePublish = "article.publish"
|
||||
ActionArticleUnpublish = "article.unpublish"
|
||||
ActionArticleDelete = "article.delete"
|
||||
ActionMediaUpload = "media.upload"
|
||||
ActionMediaRename = "media.rename"
|
||||
ActionMediaDelete = "media.delete"
|
||||
ActionMediaMerge = "media.merge"
|
||||
ActionMediaPurge = "media.purge"
|
||||
ActionUserRegister = "user.register"
|
||||
ActionUserVerify = "user.verify"
|
||||
ActionUserUpdateProfile = "user.update_profile"
|
||||
ActionInviteCreate = "invite.create"
|
||||
ActionInviteCancel = "invite.cancel"
|
||||
ActionInviteRenew = "invite.renew"
|
||||
ActionInviteAccept = "invite.accept"
|
||||
ActionMediaPurgeScheduled = "system.media_purge"
|
||||
ActionUpdateChecked = "system.update_checked"
|
||||
ActionUpdateDownloaded = "system.update_downloaded"
|
||||
ActionRestartRequested = "system.restart_requested"
|
||||
)
|
||||
|
||||
const (
|
||||
TargetAPIKey = "api_key"
|
||||
TargetUser = "user"
|
||||
TargetAPIKey = "api_key"
|
||||
TargetUser = "user"
|
||||
TargetArticle = "article"
|
||||
TargetImage = "image"
|
||||
TargetInvite = "invite"
|
||||
TargetRelease = "release"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -80,6 +105,17 @@ const (
|
||||
ParamRemoved = "removed"
|
||||
ParamFrom = "from"
|
||||
ParamTo = "to"
|
||||
ParamMerged = "merged"
|
||||
ParamArticlesUpdated = "articles_updated"
|
||||
ParamFailedGroups = "failed_groups"
|
||||
ParamUpdateAvailable = "update_available"
|
||||
ParamKind = "kind"
|
||||
ParamTag = "tag"
|
||||
FieldTitle = "title"
|
||||
FieldOnline = "online"
|
||||
FieldBody = "body"
|
||||
FieldFilename = "filename"
|
||||
FieldDisplayName = "display_name"
|
||||
maxNameLength = 255
|
||||
maxActionLength = 64
|
||||
maxFailureReasonSize = 255
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package audit
|
||||
|
||||
import "strconv"
|
||||
|
||||
func NewTarget(targetType string, id uint32, name string) Target {
|
||||
return Target{Type: targetType, ID: strconv.FormatUint(uint64(id), 10), Name: name}
|
||||
}
|
||||
|
||||
func ReleaseTarget(tag string) Target {
|
||||
return Target{Type: TargetRelease, ID: tag, Name: tag}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ var ErrInvalidPasswordResetCode = errors.New("invalid password reset code")
|
||||
var ErrPasswordResetCodeExpired = errors.New("password reset code expired")
|
||||
var ErrInvalidDisplayName = errors.New("invalid display name")
|
||||
var ErrUsernameTaken = errors.New("username taken")
|
||||
var ErrVerificationEmailNotSent = errors.New("verification email not sent")
|
||||
|
||||
type Role string
|
||||
|
||||
|
||||
Reference in new issue
Block a user