From c02f7bd41a270f1a5b15b6a1c4eb9855edce0f74 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Wed, 2 Nov 2022 14:18:19 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B0=20=D1=82=D0=BE=D1=87=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B4=D0=BE=D1=81=D1=82=D1=83=D0=BF=D0=B0=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8E=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BF=D0=B5=D1=82=D0=B5=D0=BD=D1=86=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0=20#128?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/web/repo/competence.go | 40 ++++++++++++++++++++++++++++++++++++++++ routers/web/web.go | 1 + 2 files changed, 41 insertions(+) diff --git a/routers/web/repo/competence.go b/routers/web/repo/competence.go index 5562482324..2002cbc41b 100644 --- a/routers/web/repo/competence.go +++ b/routers/web/repo/competence.go @@ -1,8 +1,11 @@ package repo import ( + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/markup" + "code.gitea.io/gitea/modules/markup/markdown" "net/http" ) @@ -24,3 +27,40 @@ func Competences(ctx *context.Context) { ctx.HTML(http.StatusOK, tplCompetences) } + +func ToggleCompetences(ctx *context.Context) { + if !ctx.IsSigned { + ctx.Error(http.StatusForbidden) + return + } + + repo := ctx.Repo.Repository + toggledContent := ctx.FormString("content") + + content, err := markdown.RenderString(&markup.RenderContext{ + URLPrefix: ctx.FormString("context"), // FIXME: <- IS THIS SAFE ? + Metas: ctx.Repo.Repository.ComposeMetas(), + GitRepo: ctx.Repo.GitRepo, + Ctx: ctx, + }, toggledContent) + if err != nil { + ctx.ServerError("RenderString", err) + return + } + + repo.Competences = toggledContent + err = repo_model.UpdateRepositoryCols(repo, "competences") + if err != nil { + ctx.ServerError("ToggleCompetences", err) + return + } + + responseBody := map[string]interface{}{ + "content": content, + } + + ctx.JSON( + http.StatusOK, + responseBody, + ) +} diff --git a/routers/web/web.go b/routers/web/web.go index 1e0937671e..bca09e950c 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -892,6 +892,7 @@ func RegisterRoutes(m *web.Route) { m.Get("/issues_tree", repo.IssuesTree) m.Get("/resources", repo.Resources) m.Get("/competences", repo.Competences) + m.Post("/competences", repo.ToggleCompetences) m.Get("/{type:issues|pulls}/{index}", repo.ViewIssue) m.Group("/{type:issues|pulls}/{index}/content-history", func() { m.Get("/overview", repo.GetContentHistoryOverview)