Browse Source

Реализована точка доступа по обновлению компетенций проекта #128

pull/150/head
Artur Galyamov 2 years ago
parent
commit
c02f7bd41a
  1. 40
      routers/web/repo/competence.go
  2. 1
      routers/web/web.go

40
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,
)
}

1
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)

Loading…
Cancel
Save