notice.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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/gogits/gogs/models"
  8. "github.com/gogits/gogs/modules/base"
  9. "github.com/gogits/gogs/modules/log"
  10. "github.com/gogits/gogs/modules/middleware"
  11. )
  12. const (
  13. NOTICES base.TplName = "admin/notice"
  14. )
  15. func Notices(ctx *middleware.Context) {
  16. ctx.Data["Title"] = ctx.Tr("admin.notices")
  17. ctx.Data["PageIsAdmin"] = true
  18. ctx.Data["PageIsAdminNotices"] = true
  19. pageNum := 50
  20. p := pagination(ctx, models.CountNotices(), pageNum)
  21. notices, err := models.GetNotices(pageNum, (p-1)*pageNum)
  22. if err != nil {
  23. ctx.Handle(500, "GetNotices", err)
  24. return
  25. }
  26. ctx.Data["Notices"] = notices
  27. ctx.HTML(200, NOTICES)
  28. }
  29. func DeleteNotice(ctx *middleware.Context) {
  30. id := com.StrTo(ctx.Params(":id")).MustInt64()
  31. if err := models.DeleteNotice(id); err != nil {
  32. ctx.Handle(500, "DeleteNotice", err)
  33. return
  34. }
  35. log.Trace("System notice deleted by admin(%s): %d", ctx.User.Name, id)
  36. ctx.Flash.Success(ctx.Tr("admin.notices.delete_success"))
  37. ctx.Redirect("/admin/notices")
  38. }