From 55bcd99d3d64c36ca947f5be4e81cb5a3d8de6ce Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 31 Jan 2023 17:05:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BD=AE=E9=A1=B6=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/issue.go | 28 ++++++++++++++++++++++++++-- routers/repo/issue.go | 24 ++++++++++++++++++++++++ routers/routes/routes.go | 1 + 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/models/issue.go b/models/issue.go index 037a33308..4f3f3987c 100755 --- a/models/issue.go +++ b/models/issue.go @@ -69,8 +69,8 @@ type Issue struct { //block_chain Amount int64 - IsTransformed bool `xorm:"INDEX NOT NULL DEFAULT false"` - StayTop int `xorm:"NOT NULL DEFAULT 0"` + IsTransformed bool `xorm:"INDEX NOT NULL DEFAULT false"` + StayTop int64 `xorm:"NOT NULL DEFAULT 0"` } var ( @@ -776,6 +776,19 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) { return sess.Commit() } +func (issue *Issue) ChangeStayTop(doer *User, stayTop int64) (err error) { + issue.StayTop = stayTop + sess := x.NewSession() + defer sess.Close() + if err = sess.Begin(); err != nil { + return err + } + if err = updateIssueCols(sess, issue, "stay_top"); err != nil { + return fmt.Errorf("UpdateIssueCols,stayTop: %v", err) + } + return sess.Commit() +} + // ChangeRef changes issue ref, as the given user. func (issue *Issue) ChangeRef(doer *User, newRef string) (err error) { oldRef := issue.Ref @@ -1968,3 +1981,14 @@ func UpdateReactionsMigrationsByType(gitServiceType structs.GitServiceType, orig }) return err } + +func GetMaxStayTop(repoId int64) int64 { + re := new(Issue) + isExist, err := x.Table(new(Issue)).Where("repo_id="+fmt.Sprint(repoId)).Desc("stay_top").Limit(1, 0).Get(re) + if err == nil { + if isExist { + return re.StayTop + 1 + } + } + return 1 +} diff --git a/routers/repo/issue.go b/routers/repo/issue.go index d28936594..e48f092de 100755 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -2079,3 +2079,27 @@ func attachmentsHTML(ctx *context.Context, attachments []*models.Attachment) str } return attachHTML } + +func SetIssueStayTop(ctx *context.Context) { + issue := GetActionIssue(ctx) + if ctx.Written() { + return + } + isStayTop := ctx.QueryBool("isStayTop") + if !ctx.IsSigned || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) { + ctx.Error(403) + return + } + var stayTop int64 + stayTop = 0 + if isStayTop { + stayTop = models.GetMaxStayTop(ctx.Repo.Repository.ID) + } + err := issue.ChangeStayTop(ctx.User, stayTop) + if err != nil { + log.Info("update stay top error," + err.Error()) + } + ctx.JSON(200, map[string]interface{}{ + "code": 0, + }) +} diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 31bba2aeb..ed0b33190 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -1006,6 +1006,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/title", repo.UpdateIssueTitle) m.Post("/content", repo.UpdateIssueContent) m.Post("/watch", repo.IssueWatch) + m.Post("/setstaytop", repo.SetIssueStayTop) m.Group("/dependency", func() { m.Post("/add", repo.AddDependency) m.Post("/delete", repo.RemoveDependency)