feat: per-type settings tabs and the SEO tab permission
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"git.golem15.com/golem15/sm-seo-plugin/classes"
|
||||
"git.golem15.com/golem15/sm-seo-plugin/controllers"
|
||||
"git.golem15.com/golem15/summercms/modules/pact"
|
||||
"git.golem15.com/golem15/summercms/modules/signpost"
|
||||
)
|
||||
@@ -22,7 +23,8 @@ func (p *Plugin) AdminActionExtensions() []pact.AdminActionExtension {
|
||||
return nil
|
||||
}
|
||||
var out []pact.AdminActionExtension
|
||||
for _, typ := range reg.ContentTypes() {
|
||||
types := reg.ContentTypes()
|
||||
for _, typ := range types {
|
||||
if typ.Content == nil || strings.TrimSpace(typ.Content.Controller) == "" {
|
||||
continue
|
||||
}
|
||||
@@ -31,6 +33,9 @@ func (p *Plugin) AdminActionExtensions() []pact.AdminActionExtension {
|
||||
Form: p.seoTab(typ.Key),
|
||||
})
|
||||
}
|
||||
if form := p.typeSettingsTabs(types); form != nil {
|
||||
out = append(out, pact.AdminActionExtension{Controller: controllers.SettingsControllerID, Form: form})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -56,7 +61,11 @@ fields:
|
||||
// seoTab is the form extension of content type key.
|
||||
func (p *Plugin) seoTab(key string) *pact.AdminFormExtension {
|
||||
return &pact.AdminFormExtension{
|
||||
FieldsYAML: []byte(seoTabYAML),
|
||||
FieldsYAML: []byte(seoTabYAML),
|
||||
Permissions: []string{controllers.PermissionManage},
|
||||
Visible: func(ctx context.Context) bool {
|
||||
return p.injected(ctx, key)
|
||||
},
|
||||
Load: func(ctx context.Context, in pact.AdminFormLoad) (map[string]any, error) {
|
||||
return p.loadSEOTab(ctx, key, in)
|
||||
},
|
||||
@@ -145,3 +154,22 @@ func localeMap(raw any) map[string]string {
|
||||
}
|
||||
return map[string]string{}
|
||||
}
|
||||
|
||||
// injected reports whether the SEO tab of content type key is shown: false
|
||||
// only when its settings row turns it off. It answers true when it cannot
|
||||
// decide, so a database error never hides stored values.
|
||||
func (p *Plugin) injected(ctx context.Context, key string) bool {
|
||||
svc := p.Service()
|
||||
if svc == nil {
|
||||
return true
|
||||
}
|
||||
db, err := svc.DB(ctx)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
row, err := classes.LoadTypeSetting(db, key)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
return row.Inject
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user