You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

notice.go 1.8KB

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