feat: per-type settings tabs and the SEO tab permission
This commit is contained in:
@@ -43,6 +43,7 @@ const (
|
||||
pagesPermission = "acme.pages.access"
|
||||
pagesTypeKey = "acme-page"
|
||||
pagesModel = "acme_pages_pages"
|
||||
tagsTypeKey = "acme-tag"
|
||||
adminJWTSecret = "seo-admin-test-only-hs256-secret-key"
|
||||
siteURL = "https://www.example.test"
|
||||
)
|
||||
@@ -153,7 +154,39 @@ func (p *pagesPlugin) describe(row page) pact.ContentRecord {
|
||||
}
|
||||
|
||||
func (p *pagesPlugin) MenuItemTypes() []pact.MenuItemType {
|
||||
return []pact.MenuItemType{{
|
||||
return []pact.MenuItemType{p.pageType(), p.tagType()}
|
||||
}
|
||||
|
||||
// tagType is acme-tag (/pages/tag/:slug): a content type without an admin
|
||||
// controller, so it gets per-type settings but no SEO tab.
|
||||
func (p *pagesPlugin) tagType() pact.MenuItemType {
|
||||
return pact.MenuItemType{
|
||||
Key: tagsTypeKey,
|
||||
Label: "Tags",
|
||||
DefaultPattern: "/pages/tag/:slug",
|
||||
Placeholders: []string{"slug"},
|
||||
Resolve: func(context.Context, pact.MenuItemResolve) (*pact.ResolvedMenuItem, error) {
|
||||
return nil, nil
|
||||
},
|
||||
Content: &pact.ContentDescriptor{
|
||||
Model: "acme_pages_tags",
|
||||
Describe: func(_ context.Context, in pact.ContentDescribe) (*pact.ContentRecord, error) {
|
||||
return &pact.ContentRecord{ID: in.ID, Published: true, Locales: []pact.ContentLocale{{Locale: "en", URL: "/pages/tag/" + in.ID, Title: "Tag " + in.ID}}}, nil
|
||||
},
|
||||
Match: func(_ context.Context, in pact.ContentMatch) (*pact.ContentMatchResult, error) {
|
||||
values, ok := signpost.MatchPattern(in.Pattern, in.Path)
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
return &pact.ContentMatchResult{ID: values["slug"], Locale: "en", Exact: true}, nil
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// pageType is acme-page (/pages/:slug, /pl/pages/:slug).
|
||||
func (p *pagesPlugin) pageType() pact.MenuItemType {
|
||||
return pact.MenuItemType{
|
||||
Key: pagesTypeKey,
|
||||
Label: "Page",
|
||||
DefaultPattern: "/pages/:slug",
|
||||
@@ -203,7 +236,7 @@ func (p *pagesPlugin) MenuItemTypes() []pact.MenuItemType {
|
||||
return &pact.ContentMatchResult{ID: strconv.FormatUint(uint64(rows[0].ID), 10), Locale: locale, Exact: true}, nil
|
||||
},
|
||||
},
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -233,6 +266,12 @@ func adminAPI(rel string) string { return cabana.DefaultAdminPrefix + "/api/v1"
|
||||
|
||||
// bootEnv boots acme.pages and golem15.seo on a fresh database.
|
||||
func bootEnv(t *testing.T, extraEnv ...string) *testEnv {
|
||||
t.Helper()
|
||||
return bootPlugins(t, []string{"acme.pages", "golem15.seo"}, extraEnv...)
|
||||
}
|
||||
|
||||
// bootPlugins boots the plugins ids on a fresh database.
|
||||
func bootPlugins(t *testing.T, ids []string, extraEnv ...string) *testEnv {
|
||||
t.Helper()
|
||||
sqlDB := freshDB(t)
|
||||
gdb, err := lagoon.Use(t.Context(), sqlDB)
|
||||
@@ -268,7 +307,7 @@ func bootEnv(t *testing.T, extraEnv ...string) *testEnv {
|
||||
if err := lagoon.Publish(app, sqlDB, gdb); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
plugins, err := party.Activate(app, []string{"acme.pages", "golem15.seo"})
|
||||
plugins, err := party.Activate(app, ids)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user