notice.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. log "unknwon.dev/clog/v2"
  9. "gogs.io/gogs/internal/context"
  10. "gogs.io/gogs/internal/db"
  11. "gogs.io/gogs/internal/setting"
  12. )
  13. const (
  14. NOTICES = "admin/notice"
  15. )
  16. func Notices(c *context.Context) {
  17. c.Data["Title"] = c.Tr("admin.notices")
  18. c.Data["PageIsAdmin"] = true
  19. c.Data["PageIsAdminNotices"] = true
  20. total := db.CountNotices()
  21. page := c.QueryInt("page")
  22. if page <= 1 {
  23. page = 1
  24. }
  25. c.Data["Page"] = paginater.New(int(total), setting.UI.Admin.NoticePagingNum, page, 5)
  26. notices, err := db.Notices(page, setting.UI.Admin.NoticePagingNum)
  27. if err != nil {
  28. c.Handle(500, "Notices", err)
  29. return
  30. }
  31. c.Data["Notices"] = notices
  32. c.Data["Total"] = total
  33. c.HTML(200, NOTICES)
  34. }
  35. func DeleteNotices(c *context.Context) {
  36. strs := c.QueryStrings("ids[]")
  37. ids := make([]int64, 0, len(strs))
  38. for i := range strs {
  39. id := com.StrTo(strs[i]).MustInt64()
  40. if id > 0 {
  41. ids = append(ids, id)
  42. }
  43. }
  44. if err := db.DeleteNoticesByIDs(ids); err != nil {
  45. c.Flash.Error("DeleteNoticesByIDs: " + err.Error())
  46. c.Status(500)
  47. } else {
  48. c.Flash.Success(c.Tr("admin.notices.delete_success"))
  49. c.Status(200)
  50. }
  51. }
  52. func EmptyNotices(c *context.Context) {
  53. if err := db.DeleteNotices(0, 0); err != nil {
  54. c.Handle(500, "DeleteNotices", err)
  55. return
  56. }
  57. log.Trace("System notices deleted by admin (%s): [start: %d]", c.User.Name, 0)
  58. c.Flash.Success(c.Tr("admin.notices.delete_success"))
  59. c.Redirect(setting.AppSubURL + "/admin/notices")
  60. }