Переглянути джерело

#2052 Ability to batch delete system notices

Unknwon 9 роки тому
батько
коміт
0be8b1b1a1

+ 1 - 1
README.md

@@ -5,7 +5,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
 
 ![](public/img/gogs-large-resize.png)
 
-##### Current version: 0.7.24 Beta
+##### Current version: 0.7.25 Beta
 
 <table>
     <tr>

+ 1 - 0
cmd/web.go

@@ -338,6 +338,7 @@ func runWeb(ctx *cli.Context) {
 		m.Group("/notices", func() {
 			m.Get("", admin.Notices)
 			m.Get("/:id:int/delete", admin.DeleteNotice)
+			m.Get("/empty", admin.EmptyNotices)
 		})
 	}, adminReq)
 	// ***** END: Admin *****

+ 1 - 0
conf/locale/locale_en-US.ini

@@ -983,6 +983,7 @@ monitor.start = Start Time
 monitor.execute_time = Execution Time
 
 notices.system_notice_list = System Notices
+notices.empty_all = Remove All Notices
 notices.type = Type
 notices.type_1 = Repository
 notices.desc = Description

+ 1 - 1
gogs.go

@@ -17,7 +17,7 @@ import (
 	"github.com/gogits/gogs/modules/setting"
 )
 
-const APP_VER = "0.7.24.1201 Beta"
+const APP_VER = "0.7.25.1202 Beta"
 
 func init() {
 	runtime.GOMAXPROCS(runtime.NumCPU())

+ 10 - 0
models/admin.go

@@ -61,3 +61,13 @@ func DeleteNotice(id int64) error {
 	_, err := x.Id(id).Delete(new(Notice))
 	return err
 }
+
+// DeleteNotices deletes all notices with ID from start to end (inclusive).
+func DeleteNotices(start, end int64) error {
+	sess := x.Where("id >= ?", start)
+	if end > 0 {
+		sess.And("id <= ?", end)
+	}
+	_, err := sess.Delete(new(Notice))
+	return err
+}

Різницю між файлами не показано, бо вона завелика
+ 0 - 0
modules/bindata/bindata.go


+ 12 - 1
routers/admin/notice.go

@@ -47,7 +47,18 @@ func DeleteNotice(ctx *middleware.Context) {
 		ctx.Handle(500, "DeleteNotice", err)
 		return
 	}
-	log.Trace("System notice deleted by admin(%s): %d", ctx.User.Name, id)
+	log.Trace("System notice deleted by admin (%s): %d", ctx.User.Name, id)
+	ctx.Flash.Success(ctx.Tr("admin.notices.delete_success"))
+	ctx.Redirect(setting.AppSubUrl + "/admin/notices")
+}
+
+func EmptyNotices(ctx *middleware.Context) {
+	if err := models.DeleteNotices(0, 0); err != nil {
+		ctx.Handle(500, "DeleteNotices", err)
+		return
+	}
+
+	log.Trace("System notices deleted by admin (%s): [start: %d]", ctx.User.Name, 0)
 	ctx.Flash.Success(ctx.Tr("admin.notices.delete_success"))
 	ctx.Redirect(setting.AppSubUrl + "/admin/notices")
 }

+ 1 - 1
templates/.VERSION

@@ -1 +1 @@
-0.7.24.1201 Beta
+0.7.25.1202 Beta

+ 3 - 0
templates/admin/notice.tmpl

@@ -7,6 +7,9 @@
         {{template "base/alert" .}}
         <h4 class="ui top attached header">
           {{.i18n.Tr "admin.notices.system_notice_list"}} ({{.i18n.Tr "admin.total" .Total}})
+          <div class="ui right">
+            <a class="ui red tiny button" href="{{AppSubUrl}}/admin/notices/empty">{{.i18n.Tr "admin.notices.empty_all"}}</a>
+          </div>
         </h4>
         <div class="ui attached table segment">
           <table class="ui very basic striped table">

Деякі файли не було показано, через те що забагато файлів було змінено