mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2026-01-13 09:41:22 +01:00
feat: add reactions (#1074)
This commit is contained in:
@@ -11,15 +11,15 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
TimelineCollectionName = "timeline"
|
||||
CommentCollectionName = "comments"
|
||||
fileCollectionName = "files"
|
||||
FeatureCollectionName = "features"
|
||||
LinkCollectionName = "links"
|
||||
TaskCollectionName = "tasks"
|
||||
TicketCollectionName = "tickets"
|
||||
TimelineCollectionName = "timeline"
|
||||
TypeCollectionName = "types"
|
||||
WebhookCollectionName = "webhooks"
|
||||
FeatureCollectionName = "features"
|
||||
fileCollectionName = "files"
|
||||
|
||||
UserCollectionName = "_pb_users_auth_"
|
||||
)
|
||||
@@ -138,14 +138,14 @@ func internalCollection(c *models.Collection) *models.Collection {
|
||||
|
||||
func collectionsDown(db dbx.Builder) error {
|
||||
collections := []string{
|
||||
TicketCollectionName,
|
||||
TypeCollectionName,
|
||||
fileCollectionName,
|
||||
LinkCollectionName,
|
||||
TaskCollectionName,
|
||||
CommentCollectionName,
|
||||
TimelineCollectionName,
|
||||
FeatureCollectionName,
|
||||
TicketCollectionName,
|
||||
TypeCollectionName,
|
||||
}
|
||||
|
||||
dao := daos.New(db)
|
||||
|
||||
40
migrations/5_reactions.go
Normal file
40
migrations/5_reactions.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase/daos"
|
||||
"github.com/pocketbase/pocketbase/models"
|
||||
"github.com/pocketbase/pocketbase/models/schema"
|
||||
)
|
||||
|
||||
const ReactionCollectionName = "reactions"
|
||||
|
||||
func reactionsUp(db dbx.Builder) error {
|
||||
triggers := []string{"webhook", "hook"}
|
||||
reactions := []string{"python", "webhook"}
|
||||
|
||||
return daos.New(db).SaveCollection(internalCollection(&models.Collection{
|
||||
Name: ReactionCollectionName,
|
||||
Type: models.CollectionTypeBase,
|
||||
Schema: schema.NewSchema(
|
||||
&schema.SchemaField{Name: "name", Type: schema.FieldTypeText, Required: true},
|
||||
&schema.SchemaField{Name: "trigger", Type: schema.FieldTypeSelect, Required: true, Options: &schema.SelectOptions{MaxSelect: 1, Values: triggers}},
|
||||
&schema.SchemaField{Name: "triggerdata", Type: schema.FieldTypeJson, Required: true},
|
||||
&schema.SchemaField{Name: "action", Type: schema.FieldTypeSelect, Required: true, Options: &schema.SelectOptions{MaxSelect: 1, Values: reactions}},
|
||||
&schema.SchemaField{Name: "actiondata", Type: schema.FieldTypeJson, Required: true},
|
||||
),
|
||||
}))
|
||||
}
|
||||
|
||||
func reactionsDown(db dbx.Builder) error {
|
||||
dao := daos.New(db)
|
||||
|
||||
id, err := dao.FindCollectionByNameOrId(ReactionCollectionName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find collection %s: %w", ReactionCollectionName, err)
|
||||
}
|
||||
|
||||
return dao.DeleteCollection(id)
|
||||
}
|
||||
@@ -9,4 +9,5 @@ func Register() {
|
||||
migrations.Register(collectionsUp, collectionsDown, "1700000001_collections.go")
|
||||
migrations.Register(defaultDataUp, nil, "1700000003_defaultdata.go")
|
||||
migrations.Register(viewsUp, viewsDown, "1700000004_views.go")
|
||||
migrations.Register(reactionsUp, reactionsDown, "1700000005_reactions.go")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user