From 168b210c5bf8f39daeb002f7450e4f1038835257 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Sat, 10 Sep 2022 12:54:26 -0500 Subject: [PATCH] Restore the library since we're not actually rolling out education yet --- src/hmnurl/urls.go | 7 +++++++ src/templates/src/include/header.html | 5 ++++- src/templates/types.go | 1 + src/website/base_data.go | 1 + src/website/library.go | 9 +++++++++ src/website/middlewares.go | 10 ++++++++++ src/website/routes.go | 28 +++++++++++++++------------ 7 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 src/website/library.go diff --git a/src/hmnurl/urls.go b/src/hmnurl/urls.go index 2789fff..8b6b537 100644 --- a/src/hmnurl/urls.go +++ b/src/hmnurl/urls.go @@ -700,6 +700,13 @@ func (c *UrlContext) BuildBlogPostReply(threadId int, postId int) string { var RegexLibraryAny = regexp.MustCompile(`^/library`) +var RegexLibrary = regexp.MustCompile(`^/library$`) + +func BuildLibrary() string { + defer CatchPanic() + return Url("/library", nil) +} + /* * Episode Guide */ diff --git a/src/templates/src/include/header.html b/src/templates/src/include/header.html index 8346ec0..1bc8687 100644 --- a/src/templates/src/include/header.html +++ b/src/templates/src/include/header.html @@ -84,7 +84,10 @@
Resources
{{ svg "chevron-down-thick" }}
diff --git a/src/templates/types.go b/src/templates/types.go index 0173c88..e1e7022 100644 --- a/src/templates/types.go +++ b/src/templates/types.go @@ -52,6 +52,7 @@ type Header struct { FishbowlUrl string ForumsUrl string ConferencesUrl string + LibraryUrl string EducationUrl string Project *ProjectHeader diff --git a/src/website/base_data.go b/src/website/base_data.go index a813c74..c9ec89d 100644 --- a/src/website/base_data.go +++ b/src/website/base_data.go @@ -75,6 +75,7 @@ func getBaseData(c *RequestContext, title string, breadcrumbs []templates.Breadc FishbowlUrl: hmnurl.BuildFishbowlIndex(), ForumsUrl: hmnurl.HMNProjectContext.BuildForum(nil, 1), ConferencesUrl: hmnurl.BuildConferences(), + LibraryUrl: hmnurl.BuildLibrary(), EducationUrl: hmnurl.BuildEducationIndex(), }, Footer: templates.Footer{ diff --git a/src/website/library.go b/src/website/library.go new file mode 100644 index 0000000..17d58c8 --- /dev/null +++ b/src/website/library.go @@ -0,0 +1,9 @@ +package website + +func LibraryNotPortedYet(c *RequestContext) ResponseData { + baseData := getBaseData(c, "Library", nil) + + var res ResponseData + res.MustWriteTemplate("library_not_ported_yet.html", baseData, c.Perf) + return res +} diff --git a/src/website/middlewares.go b/src/website/middlewares.go index d5191fc..1074d71 100644 --- a/src/website/middlewares.go +++ b/src/website/middlewares.go @@ -75,6 +75,16 @@ func adminsOnly(h Handler) Handler { } } +func educationBetaTestersOnly(h Handler) Handler { + return func(c *RequestContext) ResponseData { + if c.CurrentUser == nil || !c.CurrentUser.CanSeeUnpublishedEducationContent() { + return FourOhFour(c) + } + + return h(c) + } +} + func educationAuthorsOnly(h Handler) Handler { return func(c *RequestContext) ResponseData { if c.CurrentUser == nil || !c.CurrentUser.CanAuthorEducation() { diff --git a/src/website/routes.go b/src/website/routes.go index a9c165b..fa85404 100644 --- a/src/website/routes.go +++ b/src/website/routes.go @@ -117,21 +117,25 @@ func NewWebsiteRoutes(conn *pgxpool.Pool) http.Handler { hmnOnly.GET(hmnurl.RegexFishbowlIndex, FishbowlIndex) hmnOnly.GET(hmnurl.RegexFishbowl, Fishbowl) - hmnOnly.GET(hmnurl.RegexEducationIndex, EducationIndex) - hmnOnly.GET(hmnurl.RegexEducationGlossary, EducationGlossary) - hmnOnly.GET(hmnurl.RegexEducationArticleNew, educationAuthorsOnly(EducationArticleNew)) - hmnOnly.POST(hmnurl.RegexEducationArticleNew, educationAuthorsOnly(EducationArticleNewSubmit)) - hmnOnly.GET(hmnurl.RegexEducationArticle, EducationArticle) // Article stuff must be last so `/glossary` and others do not match as an article slug - hmnOnly.GET(hmnurl.RegexEducationArticleEdit, educationAuthorsOnly(EducationArticleEdit)) - hmnOnly.POST(hmnurl.RegexEducationArticleEdit, educationAuthorsOnly(EducationArticleEditSubmit)) - hmnOnly.GET(hmnurl.RegexEducationArticleDelete, educationAuthorsOnly(EducationArticleDelete)) - hmnOnly.POST(hmnurl.RegexEducationArticleDelete, educationAuthorsOnly(csrfMiddleware(EducationArticleDeleteSubmit))) + educationPrerelease := hmnOnly.WithMiddleware(educationBetaTestersOnly) + { + educationPrerelease.GET(hmnurl.RegexEducationIndex, EducationIndex) + educationPrerelease.GET(hmnurl.RegexEducationGlossary, EducationGlossary) + educationPrerelease.GET(hmnurl.RegexEducationArticleNew, educationAuthorsOnly(EducationArticleNew)) + educationPrerelease.POST(hmnurl.RegexEducationArticleNew, educationAuthorsOnly(EducationArticleNewSubmit)) + educationPrerelease.GET(hmnurl.RegexEducationArticle, EducationArticle) // Article stuff must be last so `/glossary` and others do not match as an article slug + educationPrerelease.GET(hmnurl.RegexEducationArticleEdit, educationAuthorsOnly(EducationArticleEdit)) + educationPrerelease.POST(hmnurl.RegexEducationArticleEdit, educationAuthorsOnly(EducationArticleEditSubmit)) + educationPrerelease.GET(hmnurl.RegexEducationArticleDelete, educationAuthorsOnly(EducationArticleDelete)) + educationPrerelease.POST(hmnurl.RegexEducationArticleDelete, educationAuthorsOnly(csrfMiddleware(EducationArticleDeleteSubmit))) + } hmnOnly.POST(hmnurl.RegexAPICheckUsername, csrfMiddleware(APICheckUsername)) - hmnOnly.GET(hmnurl.RegexLibraryAny, func(c *RequestContext) ResponseData { - return c.Redirect(hmnurl.BuildEducationIndex(), http.StatusFound) - }) + hmnOnly.GET(hmnurl.RegexLibraryAny, LibraryNotPortedYet) + // hmnOnly.GET(hmnurl.RegexLibraryAny, func(c *RequestContext) ResponseData { + // return c.Redirect(hmnurl.BuildEducationIndex(), http.StatusFound) + // }) // Project routes can appear either at the root (e.g. hero.handmade.network/edit) // or on a personal project path (e.g. handmade.network/p/123/hero/edit). So, we