Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions routers/web/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ import (
)

const (
tplDashboard templates.TplName = "admin/dashboard"
tplSystemStatus templates.TplName = "admin/system_status"
tplSelfCheck templates.TplName = "admin/self_check"
tplCron templates.TplName = "admin/cron"
tplQueue templates.TplName = "admin/queue"
tplPerfTrace templates.TplName = "admin/perftrace"
tplStacktrace templates.TplName = "admin/stacktrace"
tplQueueManage templates.TplName = "admin/queue_manage"
tplStats templates.TplName = "admin/stats"
tplDashboard templates.TplName = "admin/dashboard"
tplSystemStatus templates.TplName = "admin/system_status"
tplMaintenanceOperations templates.TplName = "admin/maintenance_operations"
tplSelfCheck templates.TplName = "admin/self_check"
tplCron templates.TplName = "admin/cron"
tplQueue templates.TplName = "admin/queue"
tplPerfTrace templates.TplName = "admin/perftrace"
tplStacktrace templates.TplName = "admin/stacktrace"
tplQueueManage templates.TplName = "admin/queue_manage"
tplStats templates.TplName = "admin/stats"
)

var sysStatus struct {
Expand Down Expand Up @@ -151,13 +152,18 @@ func SystemStatus(ctx *context.Context) {
ctx.HTML(http.StatusOK, tplSystemStatus)
}

// DashboardPost run an admin operation
func DashboardPost(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.AdminDashboardForm)
ctx.Data["Title"] = ctx.Tr("admin.dashboard")
ctx.Data["PageIsAdminDashboard"] = true
updateSystemStatus()
ctx.Data["SysStatus"] = sysStatus
// MaintenanceOperations show admin panel maintenance operations
func MaintenanceOperations(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("admin.dashboard.maintenance_operations")
ctx.Data["PageIsAdminMaintenanceOperations"] = true
ctx.HTML(http.StatusOK, tplMaintenanceOperations)
}

// MaintenanceOperationsPost run an admin maintenance operations
func MaintenanceOperationsPost(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.AdminMaintenanceOperationsForm)
ctx.Data["Title"] = ctx.Tr("admin.dashboard.maintenance_operations")
ctx.Data["PageIsAdminMaintenanceOperations"] = true

// Run operation.
if form.Op != "" {
Expand Down Expand Up @@ -189,7 +195,7 @@ func DashboardPost(ctx *context.Context) {
if form.From == "monitor" {
ctx.Redirect(setting.AppSubURL + "/-/admin/monitor/cron")
} else {
ctx.Redirect(setting.AppSubURL + "/-/admin")
ctx.Redirect(setting.AppSubURL + "/-/admin/maintenance-operations")
}
}

Expand Down
5 changes: 4 additions & 1 deletion routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,11 @@ func registerWebRoutes(m *web.Router) {
// ***** START: Admin *****
m.Group("/-/admin", func() {
m.Get("", admin.Dashboard)

m.Get("/system_status", admin.SystemStatus)
m.Post("", web.Bind(forms.AdminDashboardForm{}), admin.DashboardPost)

m.Get("/maintenance-operations", admin.MaintenanceOperations)
m.Post("/maintenance-operations", web.Bind(forms.AdminMaintenanceOperationsForm{}), admin.MaintenanceOperationsPost)

m.Get("/self_check", admin.SelfCheck)
m.Post("/self_check", admin.SelfCheckPost)
Expand Down
6 changes: 3 additions & 3 deletions services/forms/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ func (f *AdminEditUserForm) Validate(req *http.Request, errs binding.Errors) bin
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
}

// AdminDashboardForm form for admin dashboard operations
type AdminDashboardForm struct {
// AdminMaintenanceOperationsForm form for admin maintenance operations
type AdminMaintenanceOperationsForm struct {
Op string `binding:"required"`
From string
}

// Validate validates form fields
func (f *AdminDashboardForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
func (f *AdminMaintenanceOperationsForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
ctx := context.GetValidateContext(req)
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
}
67 changes: 0 additions & 67 deletions templates/admin/dashboard.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,6 @@
<p>{{ctx.Locale.Tr "admin.dashboard.new_version_hint" .RemoteVersion AppVer "https://blog.gitea.com"}}</p>
</div>
{{end}}
<h4 class="ui top attached header">
{{ctx.Locale.Tr "admin.dashboard.maintenance_operations"}}
</h4>
<div class="ui attached table segment">
<form method="post" action="{{AppSubUrl}}/-/admin">
{{.CsrfTokenHtml}}
<table class="ui very basic table tw-mt-0 tw-px-4">
<tbody>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.delete_inactive_accounts"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="delete_inactive_accounts">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.delete_repo_archives"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="delete_repo_archives">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.delete_missing_repos"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="delete_missing_repos">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.git_gc_repos"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="git_gc_repos">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
{{if and (not .SSH.Disabled) (not .SSH.StartBuiltinServer)}}
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.resync_all_sshkeys"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="resync_all_sshkeys">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.resync_all_sshprincipals"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="resync_all_sshprincipals">{{svg "octicon-play" 16}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
{{end}}
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.resync_all_hooks"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="resync_all_hooks">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.reinit_missing_repos"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="reinit_missing_repos">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.sync_external_users"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="sync_external_users">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.repo_health_check"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="repo_health_check">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.delete_generated_repository_avatars"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="delete_generated_repository_avatars">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.sync_repo_branches"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="sync_repo_branches">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.sync_repo_tags"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="sync_repo_tags">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
</tbody>
</table>
</form>
</div>

<h4 class="ui top attached header">
{{ctx.Locale.Tr "admin.dashboard.system_status"}}
</h4>
Expand Down
70 changes: 70 additions & 0 deletions templates/admin/maintenance_operations.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{{template "admin/layout_head" (dict "ctxData" . "pageClass" "admin maintenance operations")}}
<div class="admin-setting-content">
<h4 class="ui top attached header">
{{ctx.Locale.Tr "admin.dashboard.maintenance_operations"}}
</h4>
<div class="ui attached table segment">
<form method="post" action="{{AppSubUrl}}/-/admin/maintenance-operations">
{{.CsrfTokenHtml}}
<table class="ui very basic table tw-mt-0 tw-px-4">
<tbody>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.delete_inactive_accounts"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="delete_inactive_accounts">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.delete_repo_archives"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="delete_repo_archives">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.delete_missing_repos"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="delete_missing_repos">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.git_gc_repos"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="git_gc_repos">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
{{if and (not .SSH.Disabled) (not .SSH.StartBuiltinServer)}}
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.resync_all_sshkeys"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="resync_all_sshkeys">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.resync_all_sshprincipals"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="resync_all_sshprincipals">{{svg "octicon-play" 16}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
{{end}}
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.resync_all_hooks"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="resync_all_hooks">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.reinit_missing_repos"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="reinit_missing_repos">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.sync_external_users"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="sync_external_users">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.repo_health_check"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="repo_health_check">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.delete_generated_repository_avatars"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="delete_generated_repository_avatars">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.sync_repo_branches"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="sync_repo_branches">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
<tr>
<td>{{ctx.Locale.Tr "admin.dashboard.sync_repo_tags"}}</td>
<td class="tw-text-right"><button type="submit" class="ui primary button" name="op" value="sync_repo_tags">{{svg "octicon-play"}} {{ctx.Locale.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
{{template "admin/layout_footer" .}}
5 changes: 4 additions & 1 deletion templates/admin/navbar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
<div class="ui fluid vertical menu">
<div class="header item">{{ctx.Locale.Tr "admin.settings"}}</div>

<details class="item toggleable-item" {{if or .PageIsAdminDashboard .PageIsAdminSelfCheck}}open{{end}}>
<details class="item toggleable-item" {{if or .PageIsAdminDashboard .PageIsAdminMaintenanceOperations .PageIsAdminSelfCheck}}open{{end}}>
<summary>{{ctx.Locale.Tr "admin.maintenance"}}</summary>
<div class="menu">
<a class="{{if .PageIsAdminDashboard}}active {{end}}item" href="{{AppSubUrl}}/-/admin">
{{ctx.Locale.Tr "admin.dashboard"}}
</a>
<a class="{{if .PageIsAdminMaintenanceOperations}}active {{end}}item" href="{{AppSubUrl}}/-/admin/maintenance-operations">
{{ctx.Locale.Tr "admin.dashboard.maintenance_operations"}}
</a>
<a class="{{if .PageIsAdminSelfCheck}}active {{end}}item" href="{{AppSubUrl}}/-/admin/self_check">
{{ctx.Locale.Tr "admin.self_check"}}
</a>
Expand Down