本站源代码
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

79 lines
1.9KB

  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. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/base"
  9. "code.gitea.io/gitea/modules/context"
  10. "code.gitea.io/gitea/modules/log"
  11. "code.gitea.io/gitea/modules/setting"
  12. "github.com/unknwon/com"
  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. notices, err := models.Notices(page, setting.UI.Admin.NoticePagingNum)
  28. if err != nil {
  29. ctx.ServerError("Notices", err)
  30. return
  31. }
  32. ctx.Data["Notices"] = notices
  33. ctx.Data["Total"] = total
  34. ctx.Data["Page"] = context.NewPagination(int(total), setting.UI.Admin.NoticePagingNum, page, 5)
  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.ServerError("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. }
上海开阖软件有限公司 沪ICP备12045867号-1