2014-10-08 18:29:18 -04:00
|
|
|
package admin
|
|
|
|
|
|
|
|
|
|
import (
|
2020-03-16 01:22:27 +08:00
|
|
|
"net/http"
|
|
|
|
|
|
2019-10-23 23:03:17 -07:00
|
|
|
"github.com/unknwon/com"
|
|
|
|
|
"github.com/unknwon/paginater"
|
2020-02-20 02:25:02 +08:00
|
|
|
log "unknwon.dev/clog/v2"
|
2014-10-08 18:29:18 -04:00
|
|
|
|
2020-02-22 09:05:26 +08:00
|
|
|
"gogs.io/gogs/internal/conf"
|
2019-10-24 01:51:46 -07:00
|
|
|
"gogs.io/gogs/internal/context"
|
2024-02-18 19:39:41 -05:00
|
|
|
"gogs.io/gogs/internal/database"
|
2014-10-08 18:29:18 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
2017-04-05 09:17:21 -04:00
|
|
|
NOTICES = "admin/notice"
|
2014-10-08 18:29:18 -04:00
|
|
|
)
|
|
|
|
|
|
2017-06-03 07:26:09 -04:00
|
|
|
func Notices(c *context.Context) {
|
2020-03-16 01:22:27 +08:00
|
|
|
c.Title("admin.notices")
|
2017-06-03 07:26:09 -04:00
|
|
|
c.Data["PageIsAdmin"] = true
|
|
|
|
|
c.Data["PageIsAdminNotices"] = true
|
2014-10-08 18:29:18 -04:00
|
|
|
|
2024-03-17 20:44:13 -04:00
|
|
|
total := database.Handle.Notices().Count(c.Req.Context())
|
2017-06-03 07:26:09 -04:00
|
|
|
page := c.QueryInt("page")
|
2015-09-25 18:13:38 +02:00
|
|
|
if page <= 1 {
|
|
|
|
|
page = 1
|
|
|
|
|
}
|
2020-02-22 09:05:26 +08:00
|
|
|
c.Data["Page"] = paginater.New(int(total), conf.UI.Admin.NoticePagingNum, page, 5)
|
2015-09-25 12:58:39 -04:00
|
|
|
|
2024-03-17 20:44:13 -04:00
|
|
|
notices, err := database.Handle.Notices().List(c.Req.Context(), page, conf.UI.Admin.NoticePagingNum)
|
2014-10-08 18:29:18 -04:00
|
|
|
if err != nil {
|
2020-03-16 01:22:27 +08:00
|
|
|
c.Error(err, "list notices")
|
2014-10-08 18:29:18 -04:00
|
|
|
return
|
|
|
|
|
}
|
2017-06-03 07:26:09 -04:00
|
|
|
c.Data["Notices"] = notices
|
2015-09-25 12:58:39 -04:00
|
|
|
|
2017-06-03 07:26:09 -04:00
|
|
|
c.Data["Total"] = total
|
2020-03-16 01:22:27 +08:00
|
|
|
c.Success(NOTICES)
|
2014-10-08 18:29:18 -04:00
|
|
|
}
|
|
|
|
|
|
2017-06-03 07:26:09 -04:00
|
|
|
func DeleteNotices(c *context.Context) {
|
|
|
|
|
strs := c.QueryStrings("ids[]")
|
2015-12-05 01:09:14 -05:00
|
|
|
ids := make([]int64, 0, len(strs))
|
|
|
|
|
for i := range strs {
|
|
|
|
|
id := com.StrTo(strs[i]).MustInt64()
|
|
|
|
|
if id > 0 {
|
|
|
|
|
ids = append(ids, id)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 20:44:13 -04:00
|
|
|
if err := database.Handle.Notices().DeleteByIDs(c.Req.Context(), ids...); err != nil {
|
2017-06-03 07:26:09 -04:00
|
|
|
c.Flash.Error("DeleteNoticesByIDs: " + err.Error())
|
2020-03-16 01:22:27 +08:00
|
|
|
c.Status(http.StatusInternalServerError)
|
2015-12-05 01:09:14 -05:00
|
|
|
} else {
|
2017-06-03 07:26:09 -04:00
|
|
|
c.Flash.Success(c.Tr("admin.notices.delete_success"))
|
2020-03-16 01:22:27 +08:00
|
|
|
c.Status(http.StatusOK)
|
2014-10-08 18:29:18 -04:00
|
|
|
}
|
2015-12-01 23:33:08 -05:00
|
|
|
}
|
|
|
|
|
|
2017-06-03 07:26:09 -04:00
|
|
|
func EmptyNotices(c *context.Context) {
|
2024-03-17 20:44:13 -04:00
|
|
|
if err := database.Handle.Notices().DeleteAll(c.Req.Context()); err != nil {
|
2021-05-19 13:38:13 +08:00
|
|
|
c.Error(err, "delete notices")
|
2015-12-01 23:33:08 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-03 07:26:09 -04:00
|
|
|
log.Trace("System notices deleted by admin (%s): [start: %d]", c.User.Name, 0)
|
|
|
|
|
c.Flash.Success(c.Tr("admin.notices.delete_success"))
|
2020-02-22 09:05:26 +08:00
|
|
|
c.Redirect(conf.Server.Subpath + "/admin/notices")
|
2014-10-08 18:29:18 -04:00
|
|
|
}
|