feat: SEO change history
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"git.golem15.com/golem15/sm-seo-plugin/classes"
|
||||
"git.golem15.com/golem15/sm-seo-plugin/controllers"
|
||||
"git.golem15.com/golem15/sm-seo-plugin/models"
|
||||
"git.golem15.com/golem15/summercms/modules/pact"
|
||||
"git.golem15.com/golem15/summercms/modules/signpost"
|
||||
)
|
||||
@@ -36,9 +37,37 @@ func (p *Plugin) AdminActionExtensions() []pact.AdminActionExtension {
|
||||
if form := p.typeSettingsTabs(types); form != nil {
|
||||
out = append(out, pact.AdminActionExtension{Controller: controllers.SettingsControllerID, Form: form})
|
||||
}
|
||||
out = append(out, pact.AdminActionExtension{Controller: controllers.RulesControllerID, Form: p.ruleHistory()})
|
||||
return out
|
||||
}
|
||||
|
||||
// ruleHistory is a field-less extension on the plugin's own rules
|
||||
// controller: its Save sees the save's changes inside the save transaction
|
||||
// and records them in history (deletes are recorded by the controller).
|
||||
func (p *Plugin) ruleHistory() *pact.AdminFormExtension {
|
||||
return &pact.AdminFormExtension{
|
||||
Permissions: []string{controllers.PermissionManage},
|
||||
Save: func(ctx context.Context, in pact.AdminFormSave) (pact.AdminFormSaveResult, error) {
|
||||
svc := p.Service()
|
||||
if svc == nil {
|
||||
return pact.AdminFormSaveResult{}, classes.ErrNotBooted
|
||||
}
|
||||
before, after := classes.ChangesValues(in.Changes, in.Created)
|
||||
url := ""
|
||||
if r, ok := in.Record.(*models.Rule); ok && r != nil {
|
||||
url = r.URL
|
||||
}
|
||||
return pact.AdminFormSaveResult{}, svc.Record(ctx, in.DB, classes.Change{
|
||||
Kind: models.SubjectRule,
|
||||
SubjectID: in.ID,
|
||||
What: svc.Phrase("golem15.seo::lang.history.what_rule", map[string]string{"url": url}),
|
||||
Before: before,
|
||||
After: after,
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Plugin) registry() *signpost.Registry {
|
||||
if p == nil || p.app == nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user