feat: redirects screen
- golem15.seo.redirects list and form (UI-SPEC C8): chain rows marked, status, match, origin and chain filters, the navigation item lands here - a field-less extension on the controller refuses a loop with redirects.loop on target, answers the chain notice and records history - the status dropdown posts text, read through RedirectStatus
This commit is contained in:
@@ -38,9 +38,52 @@ func (p *Plugin) AdminActionExtensions() []pact.AdminActionExtension {
|
||||
out = append(out, pact.AdminActionExtension{Controller: controllers.SettingsControllerID, Form: form})
|
||||
}
|
||||
out = append(out, pact.AdminActionExtension{Controller: controllers.RulesControllerID, Form: p.ruleHistory()})
|
||||
out = append(out, pact.AdminActionExtension{Controller: controllers.RedirectsControllerID, Form: p.redirectChecks()})
|
||||
return out
|
||||
}
|
||||
|
||||
// redirectChecks is a field-less extension on the plugin's own redirects
|
||||
// controller (P-18). Its Save runs inside the save transaction with the
|
||||
// row written: it simulates the rule in place, refuses a loop with
|
||||
// redirects.loop on target (D-19, the save rolls back), answers a chain
|
||||
// with redirects.chain_notice on target, and records the save in history.
|
||||
func (p *Plugin) redirectChecks() *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
|
||||
}
|
||||
r, ok := in.Record.(*models.Redirect)
|
||||
if !ok || r == nil {
|
||||
return pact.AdminFormSaveResult{}, nil
|
||||
}
|
||||
check, err := svc.CheckRedirect(ctx, in.DB, *r)
|
||||
if err != nil {
|
||||
return pact.AdminFormSaveResult{}, err
|
||||
}
|
||||
if check.Loop {
|
||||
return pact.AdminFormSaveResult{}, pact.AdminFormErrors{"target": {svc.LoopMessage(ctx, check)}}
|
||||
}
|
||||
before, after := classes.ChangesValues(in.Changes, in.Created)
|
||||
if err := svc.Record(ctx, in.DB, classes.Change{
|
||||
Kind: models.SubjectRedirect,
|
||||
SubjectID: in.ID,
|
||||
What: svc.Phrase("golem15.seo::lang.history.what_redirect", map[string]string{"url": r.Source}),
|
||||
Before: before,
|
||||
After: after,
|
||||
}); err != nil {
|
||||
return pact.AdminFormSaveResult{}, err
|
||||
}
|
||||
if notices := classes.ChainNotice(check); len(notices) > 0 {
|
||||
return pact.AdminFormSaveResult{Notices: map[string][]pact.FormFieldNotice{"target": notices}}, nil
|
||||
}
|
||||
return pact.AdminFormSaveResult{}, nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// 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).
|
||||
|
||||
Reference in New Issue
Block a user