Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

notice.go 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package admin
  5. import (
  6. "github.com/Unknwon/com"
  7. "github.com/Unknwon/paginater"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/modules/base"
  10. "code.gitea.io/gitea/modules/context"
  11. "code.gitea.io/gitea/modules/log"
  12. "code.gitea.io/gitea/modules/setting"
  13. )
  14. const (
  15. tplNotices base.TplName = "admin/notice"
  16. )
  17. // Notices show notices for admin
  18. func Notices(ctx *context.Context) {
  19. ctx.Data["Title"] = ctx.Tr("admin.notices")
  20. ctx.Data["PageIsAdmin"] = true
  21. ctx.Data["PageIsAdminNotices"] = true
  22. total := models.CountNotices()
  23. page := ctx.QueryInt("page")
  24. if page <= 1 {
  25. page = 1
  26. }
  27. ctx.Data["Page"] = paginater.New(int(total), setting.UI.Admin.NoticePagingNum, page, 5)
  28. notices, err := models.Notices(page, setting.UI.Admin.NoticePagingNum)
  29. if err != nil {
  30. ctx.Handle(500, "Notices", err)
  31. return
  32. }
  33. ctx.Data["Notices"] = notices
  34. ctx.Data["Total"] = total
  35. ctx.HTML(200, tplNotices)
  36. }
  37. // DeleteNotices delete the specific notices
  38. func DeleteNotices(ctx *context.Context) {
  39. strs := ctx.QueryStrings("ids[]")
  40. ids := make([]int64, 0, len(strs))
  41. for i := range strs {
  42. id := com.StrTo(strs[i]).MustInt64()
  43. if id > 0 {
  44. ids = append(ids, id)
  45. }
  46. }
  47. if err := models.DeleteNoticesByIDs(ids); err != nil {
  48. ctx.Flash.Error("DeleteNoticesByIDs: " + err.Error())
  49. ctx.Status(500)
  50. } else {
  51. ctx.Flash.Success(ctx.Tr("admin.notices.delete_success"))
  52. ctx.Status(200)
  53. }
  54. }
  55. // EmptyNotices delete all the notices
  56. func EmptyNotices(ctx *context.Context) {
  57. if err := models.DeleteNotices(0, 0); err != nil {
  58. ctx.Handle(500, "DeleteNotices", err)
  59. return
  60. }
  61. log.Trace("System notices deleted by admin (%s): [start: %d]", ctx.User.Name, 0)
  62. ctx.Flash.Success(ctx.Tr("admin.notices.delete_success"))
  63. ctx.Redirect(setting.AppSubURL + "/admin/notices")
  64. }