#2052 Ability to batch delete system notices
This commit is contained in:
		
							parent
							
								
									834d38a8fb
								
							
						
					
					
						commit
						0be8b1b1a1
					
				|  | @ -5,7 +5,7 @@ Gogs - Go Git Service [ |  | ||||||
| 
 | 
 | ||||||
| ##### Current version: 0.7.24 Beta | ##### Current version: 0.7.25 Beta | ||||||
| 
 | 
 | ||||||
| <table> | <table> | ||||||
|     <tr> |     <tr> | ||||||
|  |  | ||||||
|  | @ -338,6 +338,7 @@ func runWeb(ctx *cli.Context) { | ||||||
| 		m.Group("/notices", func() { | 		m.Group("/notices", func() { | ||||||
| 			m.Get("", admin.Notices) | 			m.Get("", admin.Notices) | ||||||
| 			m.Get("/:id:int/delete", admin.DeleteNotice) | 			m.Get("/:id:int/delete", admin.DeleteNotice) | ||||||
|  | 			m.Get("/empty", admin.EmptyNotices) | ||||||
| 		}) | 		}) | ||||||
| 	}, adminReq) | 	}, adminReq) | ||||||
| 	// ***** END: Admin *****
 | 	// ***** END: Admin *****
 | ||||||
|  |  | ||||||
|  | @ -983,6 +983,7 @@ monitor.start = Start Time | ||||||
| monitor.execute_time = Execution Time | monitor.execute_time = Execution Time | ||||||
| 
 | 
 | ||||||
| notices.system_notice_list = System Notices | notices.system_notice_list = System Notices | ||||||
|  | notices.empty_all = Remove All Notices | ||||||
| notices.type = Type | notices.type = Type | ||||||
| notices.type_1 = Repository | notices.type_1 = Repository | ||||||
| notices.desc = Description | notices.desc = Description | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								gogs.go
								
								
								
								
							
							
						
						
									
										2
									
								
								gogs.go
								
								
								
								
							|  | @ -17,7 +17,7 @@ import ( | ||||||
| 	"github.com/gogits/gogs/modules/setting" | 	"github.com/gogits/gogs/modules/setting" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| const APP_VER = "0.7.24.1201 Beta" | const APP_VER = "0.7.25.1202 Beta" | ||||||
| 
 | 
 | ||||||
| func init() { | func init() { | ||||||
| 	runtime.GOMAXPROCS(runtime.NumCPU()) | 	runtime.GOMAXPROCS(runtime.NumCPU()) | ||||||
|  |  | ||||||
|  | @ -61,3 +61,13 @@ func DeleteNotice(id int64) error { | ||||||
| 	_, err := x.Id(id).Delete(new(Notice)) | 	_, err := x.Id(id).Delete(new(Notice)) | ||||||
| 	return err | 	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 | ||||||
|  | } | ||||||
|  |  | ||||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							|  | @ -51,3 +51,14 @@ func DeleteNotice(ctx *middleware.Context) { | ||||||
| 	ctx.Flash.Success(ctx.Tr("admin.notices.delete_success")) | 	ctx.Flash.Success(ctx.Tr("admin.notices.delete_success")) | ||||||
| 	ctx.Redirect(setting.AppSubUrl + "/admin/notices") | 	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 @@ | ||||||
| 0.7.24.1201 Beta | 0.7.25.1202 Beta | ||||||
|  | @ -7,6 +7,9 @@ | ||||||
|         {{template "base/alert" .}} |         {{template "base/alert" .}} | ||||||
|         <h4 class="ui top attached header"> |         <h4 class="ui top attached header"> | ||||||
|           {{.i18n.Tr "admin.notices.system_notice_list"}} ({{.i18n.Tr "admin.total" .Total}}) |           {{.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> |         </h4> | ||||||
|         <div class="ui attached table segment"> |         <div class="ui attached table segment"> | ||||||
|           <table class="ui very basic striped table"> |           <table class="ui very basic striped table"> | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue