diff --git a/js/docs/src/content/docs/lex-reference/moderation/place-stream-moderation-defs.md b/js/docs/src/content/docs/lex-reference/moderation/place-stream-moderation-defs.md index 66910beb..58d54f30 100644 --- a/js/docs/src/content/docs/lex-reference/moderation/place-stream-moderation-defs.md +++ b/js/docs/src/content/docs/lex-reference/moderation/place-stream-moderation-defs.md @@ -2,27 +2,30 @@ title: place.stream.moderation.defs description: Reference for the place.stream.moderation.defs lexicon --- + **Lexicon Version:** 1 ## Definitions + ### `permissionView` **Type:** `object` **Properties:** -| Name | Type | Req'd | Description | Constraints | -|------|------|----------|-------------|-------------| -| `uri` | `string` | ✅ | AT-URI of the permission record | Format: `at-uri` | -| `cid` | `string` | ✅ | Content identifier of the permission record | Format: `cid` | -| `author` | [`app.bsky.actor.defs#profileViewBasic`](https://github.com/bluesky-social/atproto/tree/main/lexicons/app/bsky/actor/defs.json#profileViewBasic) | ✅ | The streamer who granted these permissions | | -| `record` | `unknown` | ✅ | The permission record itself | | +| Name | Type | Req'd | Description | Constraints | +| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ----- | ------------------------------------------- | ---------------- | +| `uri` | `string` | ✅ | AT-URI of the permission record | Format: `at-uri` | +| `cid` | `string` | ✅ | Content identifier of the permission record | Format: `cid` | +| `author` | [`app.bsky.actor.defs#profileViewBasic`](https://github.com/bluesky-social/atproto/tree/main/lexicons/app/bsky/actor/defs.json#profileViewBasic) | ✅ | The streamer who granted these permissions | | +| `record` | `unknown` | ✅ | The permission record itself | | --- ## Lexicon Source + ```json { "lexicon": 1, @@ -30,12 +33,7 @@ description: Reference for the place.stream.moderation.defs lexicon "defs": { "permissionView": { "type": "object", - "required": [ - "uri", - "cid", - "author", - "record" - ], + "required": ["uri", "cid", "author", "record"], "properties": { "uri": { "type": "string", diff --git a/pkg/model/model.go b/pkg/model/model.go index 4dfd831f..005d37c8 100644 --- a/pkg/model/model.go +++ b/pkg/model/model.go @@ -114,10 +114,6 @@ type Model interface { GetModerationDelegations(ctx context.Context, streamerDID, moderatorDID string) ([]*streamplace.ModerationDefs_PermissionView, error) GetModeratorDelegations(ctx context.Context, moderatorDID string) ([]*streamplace.ModerationDefs_PermissionView, error) GetStreamerModerators(ctx context.Context, streamerDID string) ([]*streamplace.ModerationDefs_PermissionView, error) - - CreateAuditLog(ctx context.Context, log *ModerationAuditLog) error - GetAuditLogs(ctx context.Context, streamerDID string, limit int, before *time.Time) ([]*ModerationAuditLog, error) - GetModeratorAuditLogs(ctx context.Context, moderatorDID string, limit int, before *time.Time) ([]*ModerationAuditLog, error) } var DBRevision = 2 @@ -187,7 +183,6 @@ func MakeDB(dbURL string) (Model, error) { BroadcastOrigin{}, MetadataConfiguration{}, ModerationDelegation{}, - ModerationAuditLog{}, } { err = db.AutoMigrate(model) if err != nil { diff --git a/pkg/spxrpc/place_stream_moderation.go b/pkg/spxrpc/place_stream_moderation.go index 66691b36..c6bb21a8 100644 --- a/pkg/spxrpc/place_stream_moderation.go +++ b/pkg/spxrpc/place_stream_moderation.go @@ -15,7 +15,7 @@ import ( "github.com/labstack/echo/v4" "stream.place/streamplace/pkg/constants" "stream.place/streamplace/pkg/log" - "stream.place/streamplace/pkg/model" + "stream.place/streamplace/pkg/statedb" "stream.place/streamplace/pkg/streamplace" ) @@ -346,7 +346,7 @@ func validateATURI(uri string) error { // logAudit logs a moderation action to the audit log func (s *Server) logAudit(ctx context.Context, streamerDID, moderatorDID, action, targetURI, targetDID, resultURI string, success bool, errorMsg string) error { - auditLog := &model.ModerationAuditLog{ + auditLog := &statedb.ModerationAuditLog{ StreamerDID: streamerDID, ModeratorDID: moderatorDID, Action: action, @@ -358,5 +358,5 @@ func (s *Server) logAudit(ctx context.Context, streamerDID, moderatorDID, action CreatedAt: time.Now(), } - return s.model.CreateAuditLog(ctx, auditLog) + return s.statefulDB.CreateAuditLog(ctx, auditLog) } diff --git a/pkg/model/moderation_audit_log.go b/pkg/statedb/moderation_audit_log.go similarity index 65% rename from pkg/model/moderation_audit_log.go rename to pkg/statedb/moderation_audit_log.go index 1cb26a60..afcb2262 100644 --- a/pkg/model/moderation_audit_log.go +++ b/pkg/statedb/moderation_audit_log.go @@ -1,4 +1,4 @@ -package model +package statedb import ( "context" @@ -18,13 +18,17 @@ type ModerationAuditLog struct { CreatedAt time.Time `gorm:"column:created_at;index:idx_streamer_time,priority:2"` } -func (m *DBModel) CreateAuditLog(ctx context.Context, log *ModerationAuditLog) error { - return m.DB.WithContext(ctx).Create(log).Error +func (ModerationAuditLog) TableName() string { + return "moderation_audit_logs" } -func (m *DBModel) GetAuditLogs(ctx context.Context, streamerDID string, limit int, before *time.Time) ([]*ModerationAuditLog, error) { +func (state *StatefulDB) CreateAuditLog(ctx context.Context, log *ModerationAuditLog) error { + return state.DB.WithContext(ctx).Create(log).Error +} + +func (state *StatefulDB) GetAuditLogs(ctx context.Context, streamerDID string, limit int, before *time.Time) ([]*ModerationAuditLog, error) { var logs []*ModerationAuditLog - query := m.DB.WithContext(ctx).Where("streamer_did = ?", streamerDID). + query := state.DB.WithContext(ctx).Where("streamer_did = ?", streamerDID). Order("created_at DESC"). Limit(limit) @@ -39,9 +43,9 @@ func (m *DBModel) GetAuditLogs(ctx context.Context, streamerDID string, limit in return logs, nil } -func (m *DBModel) GetModeratorAuditLogs(ctx context.Context, moderatorDID string, limit int, before *time.Time) ([]*ModerationAuditLog, error) { +func (state *StatefulDB) GetModeratorAuditLogs(ctx context.Context, moderatorDID string, limit int, before *time.Time) ([]*ModerationAuditLog, error) { var logs []*ModerationAuditLog - query := m.DB.WithContext(ctx).Where("moderator_did = ?", moderatorDID). + query := state.DB.WithContext(ctx).Where("moderator_did = ?", moderatorDID). Order("created_at DESC"). Limit(limit) diff --git a/pkg/statedb/statedb.go b/pkg/statedb/statedb.go index e319deac..f0c71c24 100644 --- a/pkg/statedb/statedb.go +++ b/pkg/statedb/statedb.go @@ -49,6 +49,7 @@ var StatefulDBModels = []any{ AppTask{}, Repo{}, Webhook{}, + ModerationAuditLog{}, } var NoPostgresDatabaseCode = "3D000"