1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-11-04 08:17:24 -05:00

Change admin dashboard to POST (#10465)

* Add form and convert to POST

* Redirect for flash

Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
John Olheiser 2020-02-25 16:54:13 -06:00 committed by GitHub
parent c161bb013e
commit e5944a9521
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 81 additions and 55 deletions

View File

@ -48,3 +48,13 @@ type AdminEditUserForm struct {
func (f *AdminEditUserForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { func (f *AdminEditUserForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
return validate(errs, ctx.Data, f, ctx.Locale) return validate(errs, ctx.Data, f, ctx.Locale)
} }
// AdminDashboardForm form for admin dashboard operations
type AdminDashboardForm struct {
Op int `binding:"required"`
}
// Validate validates form fields
func (f *AdminDashboardForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
return validate(errs, ctx.Data, f, ctx.Locale)
}

View File

@ -16,6 +16,7 @@ import (
"time" "time"
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/cron" "code.gitea.io/gitea/modules/cron"
@ -31,7 +32,6 @@ import (
"gitea.com/macaron/macaron" "gitea.com/macaron/macaron"
"gitea.com/macaron/session" "gitea.com/macaron/session"
"github.com/unknwon/com"
) )
const ( const (
@ -145,15 +145,29 @@ func Dashboard(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.dashboard") ctx.Data["Title"] = ctx.Tr("admin.dashboard")
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminDashboard"] = true ctx.Data["PageIsAdminDashboard"] = true
ctx.Data["Stats"] = models.GetStatistic()
// FIXME: update periodically
updateSystemStatus()
ctx.Data["SysStatus"] = sysStatus
ctx.HTML(200, tplDashboard)
}
// DashboardPost run an admin operation
func DashboardPost(ctx *context.Context, form auth.AdminDashboardForm) {
ctx.Data["Title"] = ctx.Tr("admin.dashboard")
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminDashboard"] = true
ctx.Data["Stats"] = models.GetStatistic()
updateSystemStatus()
ctx.Data["SysStatus"] = sysStatus
// Run operation. // Run operation.
op, _ := com.StrTo(ctx.Query("op")).Int() if form.Op > 0 {
if op > 0 {
var err error var err error
var success string var success string
shutdownCtx := graceful.GetManager().ShutdownContext() shutdownCtx := graceful.GetManager().ShutdownContext()
switch Operation(op) { switch Operation(form.Op) {
case cleanInactivateUser: case cleanInactivateUser:
success = ctx.Tr("admin.dashboard.delete_inactivate_accounts_success") success = ctx.Tr("admin.dashboard.delete_inactivate_accounts_success")
err = models.DeleteInactivateUsers() err = models.DeleteInactivateUsers()
@ -191,15 +205,9 @@ func Dashboard(ctx *context.Context) {
} else { } else {
ctx.Flash.Success(success) ctx.Flash.Success(success)
} }
ctx.Redirect(setting.AppSubURL + "/admin")
return
} }
ctx.Data["Stats"] = models.GetStatistic() ctx.Redirect(setting.AppSubURL + "/admin")
// FIXME: update periodically
updateSystemStatus()
ctx.Data["SysStatus"] = sysStatus
ctx.HTML(200, tplDashboard)
} }
// SendTestMail send test mail to confirm mail service is OK // SendTestMail send test mail to confirm mail service is OK

View File

@ -422,6 +422,7 @@ func RegisterRoutes(m *macaron.Macaron) {
// ***** START: Admin ***** // ***** START: Admin *****
m.Group("/admin", func() { m.Group("/admin", func() {
m.Get("", adminReq, admin.Dashboard) m.Get("", adminReq, admin.Dashboard)
m.Post("", adminReq, bindIgnErr(auth.AdminDashboardForm{}), admin.DashboardPost)
m.Get("/config", admin.Config) m.Get("/config", admin.Config)
m.Post("/config/test_mail", admin.SendTestMail) m.Post("/config/test_mail", admin.SendTestMail)
m.Group("/monitor", func() { m.Group("/monitor", func() {

View File

@ -15,50 +15,53 @@
{{.i18n.Tr "admin.dashboard.operations"}} {{.i18n.Tr "admin.dashboard.operations"}}
</h4> </h4>
<div class="ui attached table segment"> <div class="ui attached table segment">
<form method="post" action="{{AppSubUrl}}/admin">
{{.CsrfTokenHtml}}
<table class="ui very basic table"> <table class="ui very basic table">
<tbody> <tbody>
<tr> <tr>
<td>{{.i18n.Tr "admin.dashboard.delete_inactivate_accounts"}}</td> <td>{{.i18n.Tr "admin.dashboard.delete_inactivate_accounts"}}</td>
<td><i class="fa fa-caret-square-o-right"></i> <a href="{{AppSubUrl}}/admin?op=1">{{.i18n.Tr "admin.dashboard.operation_run"}}</a></td> <td><button type="submit" class="ui green button" name="op" value="1">{{svg "octicon-triangle-right" 16}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>
</tr> </tr>
<tr> <tr>
<td>{{.i18n.Tr "admin.dashboard.delete_repo_archives"}}</td> <td>{{.i18n.Tr "admin.dashboard.delete_repo_archives"}}</td>
<td><i class="fa fa-caret-square-o-right"></i> <a href="{{AppSubUrl}}/admin?op=2">{{.i18n.Tr "admin.dashboard.operation_run"}}</a></td> <td><button type="submit" class="ui green button" name="op" value="2">{{svg "octicon-triangle-right" 16}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>
</tr> </tr>
<tr> <tr>
<td>{{.i18n.Tr "admin.dashboard.delete_missing_repos"}}</td> <td>{{.i18n.Tr "admin.dashboard.delete_missing_repos"}}</td>
<td><i class="fa fa-caret-square-o-right"></i> <a href="{{AppSubUrl}}/admin?op=3">{{.i18n.Tr "admin.dashboard.operation_run"}}</a></td> <td><button type="submit" class="ui green button" name="op" value="3">{{svg "octicon-triangle-right" 16}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>
</tr> </tr>
<tr> <tr>
<td>{{.i18n.Tr "admin.dashboard.git_gc_repos"}}</td> <td>{{.i18n.Tr "admin.dashboard.git_gc_repos"}}</td>
<td><i class="fa fa-caret-square-o-right"></i> <a href="{{AppSubUrl}}/admin?op=4">{{.i18n.Tr "admin.dashboard.operation_run"}}</a></td> <td><button type="submit" class="ui green button" name="op" value="4">{{svg "octicon-triangle-right" 16}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>
</tr> </tr>
<tr> <tr>
<td>{{.i18n.Tr "admin.dashboard.resync_all_sshkeys"}}</td> <td>{{.i18n.Tr "admin.dashboard.resync_all_sshkeys"}}</td>
<td><i class="fa fa-caret-square-o-right"></i> <a href="{{AppSubUrl}}/admin?op=5">{{.i18n.Tr "admin.dashboard.operation_run"}}</a></td> <td><button type="submit" class="ui green button" name="op" value="5">{{svg "octicon-triangle-right" 16}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>
</tr> </tr>
<tr> <tr>
<td>{{.i18n.Tr "admin.dashboard.resync_all_hooks"}}</td> <td>{{.i18n.Tr "admin.dashboard.resync_all_hooks"}}</td>
<td><i class="fa fa-caret-square-o-right"></i> <a href="{{AppSubUrl}}/admin?op=6">{{.i18n.Tr "admin.dashboard.operation_run"}}</a></td> <td><button type="submit" class="ui green button" name="op" value="6">{{svg "octicon-triangle-right" 16}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>
</tr> </tr>
<tr> <tr>
<td>{{.i18n.Tr "admin.dashboard.reinit_missing_repos"}}</td> <td>{{.i18n.Tr "admin.dashboard.reinit_missing_repos"}}</td>
<td><i class="fa fa-caret-square-o-right"></i> <a href="{{AppSubUrl}}/admin?op=7">{{.i18n.Tr "admin.dashboard.operation_run"}}</a></td> <td><button type="submit" class="ui green button" name="op" value="7">{{svg "octicon-triangle-right" 16}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>
</tr> </tr>
<tr> <tr>
<td>{{.i18n.Tr "admin.dashboard.sync_external_users"}}</td> <td>{{.i18n.Tr "admin.dashboard.sync_external_users"}}</td>
<td><i class="fa fa-caret-square-o-right"></i> <a href="{{AppSubUrl}}/admin?op=8">{{.i18n.Tr "admin.dashboard.operation_run"}}</a></td> <td><button type="submit" class="ui green button" name="op" value="8">{{svg "octicon-triangle-right" 16}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>
</tr> </tr>
<tr> <tr>
<td>{{.i18n.Tr "admin.dashboard.git_fsck"}}</td> <td>{{.i18n.Tr "admin.dashboard.git_fsck"}}</td>
<td><i class="fa fa-caret-square-o-right"></i> <a href="{{AppSubUrl}}/admin?op=9">{{.i18n.Tr "admin.dashboard.operation_run"}}</a></td> <td><button type="submit" class="ui green button" name="op" value="9">{{svg "octicon-triangle-right" 16}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>
</tr> </tr>
<tr> <tr>
<td>{{.i18n.Tr "admin.dashboard.delete_generated_repository_avatars"}}</td> <td>{{.i18n.Tr "admin.dashboard.delete_generated_repository_avatars"}}</td>
<td><i class="fa fa-caret-square-o-right"></i> <a href="{{AppSubUrl}}/admin?op=10">{{.i18n.Tr "admin.dashboard.operation_run"}}</a></td> <td><button type="submit" class="ui green button" name="op" value="10">{{svg "octicon-triangle-right" 16}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</form>
</div> </div>
<h4 class="ui top attached header"> <h4 class="ui top attached header">

View File

@ -28,6 +28,10 @@
} }
} }
} }
form button[type='submit'] {
padding: 5px 8px;
}
} }
.ui.header, .ui.header,