mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	#2052 Ability to batch delete system notices
This commit is contained in:
		@@ -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
											
										
									
								
							@@ -47,7 +47,18 @@ func DeleteNotice(ctx *middleware.Context) {
 | 
				
			|||||||
		ctx.Handle(500, "DeleteNotice", err)
 | 
							ctx.Handle(500, "DeleteNotice", err)
 | 
				
			||||||
		return
 | 
							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.Flash.Success(ctx.Tr("admin.notices.delete_success"))
 | 
				
			||||||
	ctx.Redirect(setting.AppSubUrl + "/admin/notices")
 | 
						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">
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user