code.gitea.io/gitea@v1.21.7/routers/web/admin/notice.go (about) 1 // Copyright 2014 The Gogs Authors. All rights reserved. 2 // Copyright 2019 The Gitea Authors. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 5 package admin 6 7 import ( 8 "net/http" 9 "strconv" 10 11 system_model "code.gitea.io/gitea/models/system" 12 "code.gitea.io/gitea/modules/base" 13 "code.gitea.io/gitea/modules/context" 14 "code.gitea.io/gitea/modules/log" 15 "code.gitea.io/gitea/modules/setting" 16 ) 17 18 const ( 19 tplNotices base.TplName = "admin/notice" 20 ) 21 22 // Notices show notices for admin 23 func Notices(ctx *context.Context) { 24 ctx.Data["Title"] = ctx.Tr("admin.notices") 25 ctx.Data["PageIsAdminNotices"] = true 26 27 total := system_model.CountNotices() 28 page := ctx.FormInt("page") 29 if page <= 1 { 30 page = 1 31 } 32 33 notices, err := system_model.Notices(ctx, page, setting.UI.Admin.NoticePagingNum) 34 if err != nil { 35 ctx.ServerError("Notices", err) 36 return 37 } 38 ctx.Data["Notices"] = notices 39 40 ctx.Data["Total"] = total 41 42 ctx.Data["Page"] = context.NewPagination(int(total), setting.UI.Admin.NoticePagingNum, page, 5) 43 44 ctx.HTML(http.StatusOK, tplNotices) 45 } 46 47 // DeleteNotices delete the specific notices 48 func DeleteNotices(ctx *context.Context) { 49 strs := ctx.FormStrings("ids[]") 50 ids := make([]int64, 0, len(strs)) 51 for i := range strs { 52 id, _ := strconv.ParseInt(strs[i], 10, 64) 53 if id > 0 { 54 ids = append(ids, id) 55 } 56 } 57 58 if err := system_model.DeleteNoticesByIDs(ctx, ids); err != nil { 59 ctx.Flash.Error("DeleteNoticesByIDs: " + err.Error()) 60 ctx.Status(http.StatusInternalServerError) 61 } else { 62 ctx.Flash.Success(ctx.Tr("admin.notices.delete_success")) 63 ctx.Status(http.StatusOK) 64 } 65 } 66 67 // EmptyNotices delete all the notices 68 func EmptyNotices(ctx *context.Context) { 69 if err := system_model.DeleteNotices(ctx, 0, 0); err != nil { 70 ctx.ServerError("DeleteNotices", err) 71 return 72 } 73 74 log.Trace("System notices deleted by admin (%s): [start: %d]", ctx.Doer.Name, 0) 75 ctx.Flash.Success(ctx.Tr("admin.notices.delete_success")) 76 ctx.Redirect(setting.AppSubURL + "/admin/notices") 77 }