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.9KB

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