Browse Source

提交代码。增加置顶功能。

Signed-off-by: zouap <zouap@pcl.ac.cn>
zouap
zouap 2 years ago
parent
commit
55bcd99d3d
3 changed files with 51 additions and 2 deletions
  1. +26
    -2
      models/issue.go
  2. +24
    -0
      routers/repo/issue.go
  3. +1
    -0
      routers/routes/routes.go

+ 26
- 2
models/issue.go View File

@@ -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
}

+ 24
- 0
routers/repo/issue.go View File

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

+ 1
- 0
routers/routes/routes.go View File

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


Loading…
Cancel
Save