mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-26 01:40:36 +00:00
go lint fixed for routers/admin
This commit is contained in:
parent
bd13c81684
commit
659bc2814c
6 changed files with 73 additions and 51 deletions
|
@ -22,9 +22,9 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
DASHBOARD base.TplName = "admin/dashboard"
|
||||
CONFIG base.TplName = "admin/config"
|
||||
MONITOR base.TplName = "admin/monitor"
|
||||
tplDashboard base.TplName = "admin/dashboard"
|
||||
tplConfig base.TplName = "admin/config"
|
||||
tplMonitor base.TplName = "admin/monitor"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -110,19 +110,20 @@ func updateSystemStatus() {
|
|||
sysStatus.NumGC = m.NumGC
|
||||
}
|
||||
|
||||
// Operation types.
|
||||
type AdminOperation int
|
||||
// Operation Operation types.
|
||||
type Operation int
|
||||
|
||||
const (
|
||||
CLEAN_INACTIVATE_USER AdminOperation = iota + 1
|
||||
CLEAN_REPO_ARCHIVES
|
||||
CLEAN_MISSING_REPOS
|
||||
GIT_GC_REPOS
|
||||
SYNC_SSH_AUTHORIZED_KEY
|
||||
SYNC_REPOSITORY_UPDATE_HOOK
|
||||
REINIT_MISSING_REPOSITORY
|
||||
cleanInactivateUser Operation = iota + 1
|
||||
cleanRepoArchives
|
||||
cleanMissingRepos
|
||||
gitGCRepos
|
||||
syncSSHAuthorizedKey
|
||||
syncRepositoryUpdateHook
|
||||
reinitMissingRepository
|
||||
)
|
||||
|
||||
// Dashboard show admin panel dashboard
|
||||
func Dashboard(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.dashboard")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
|
@ -134,26 +135,26 @@ func Dashboard(ctx *context.Context) {
|
|||
var err error
|
||||
var success string
|
||||
|
||||
switch AdminOperation(op) {
|
||||
case CLEAN_INACTIVATE_USER:
|
||||
switch Operation(op) {
|
||||
case cleanInactivateUser:
|
||||
success = ctx.Tr("admin.dashboard.delete_inactivate_accounts_success")
|
||||
err = models.DeleteInactivateUsers()
|
||||
case CLEAN_REPO_ARCHIVES:
|
||||
case cleanRepoArchives:
|
||||
success = ctx.Tr("admin.dashboard.delete_repo_archives_success")
|
||||
err = models.DeleteRepositoryArchives()
|
||||
case CLEAN_MISSING_REPOS:
|
||||
case cleanMissingRepos:
|
||||
success = ctx.Tr("admin.dashboard.delete_missing_repos_success")
|
||||
err = models.DeleteMissingRepositories()
|
||||
case GIT_GC_REPOS:
|
||||
case gitGCRepos:
|
||||
success = ctx.Tr("admin.dashboard.git_gc_repos_success")
|
||||
err = models.GitGcRepos()
|
||||
case SYNC_SSH_AUTHORIZED_KEY:
|
||||
case syncSSHAuthorizedKey:
|
||||
success = ctx.Tr("admin.dashboard.resync_all_sshkeys_success")
|
||||
err = models.RewriteAllPublicKeys()
|
||||
case SYNC_REPOSITORY_UPDATE_HOOK:
|
||||
case syncRepositoryUpdateHook:
|
||||
success = ctx.Tr("admin.dashboard.resync_all_update_hooks_success")
|
||||
err = models.RewriteRepositoryUpdateHook()
|
||||
case REINIT_MISSING_REPOSITORY:
|
||||
case reinitMissingRepository:
|
||||
success = ctx.Tr("admin.dashboard.reinit_missing_repos_success")
|
||||
err = models.ReinitMissingRepositories()
|
||||
}
|
||||
|
@ -171,9 +172,10 @@ func Dashboard(ctx *context.Context) {
|
|||
// FIXME: update periodically
|
||||
updateSystemStatus()
|
||||
ctx.Data["SysStatus"] = sysStatus
|
||||
ctx.HTML(200, DASHBOARD)
|
||||
ctx.HTML(200, tplDashboard)
|
||||
}
|
||||
|
||||
// SendTestMail send test mail to confirm mail service is OK
|
||||
func SendTestMail(ctx *context.Context) {
|
||||
email := ctx.Query("email")
|
||||
// Send a test email to the user's email address and redirect back to Config
|
||||
|
@ -186,6 +188,7 @@ func SendTestMail(ctx *context.Context) {
|
|||
ctx.Redirect(setting.AppSubUrl + "/admin/config")
|
||||
}
|
||||
|
||||
// Config show admin config page
|
||||
func Config(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.config")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
|
@ -235,14 +238,15 @@ func Config(ctx *context.Context) {
|
|||
}
|
||||
ctx.Data["Loggers"] = loggers
|
||||
|
||||
ctx.HTML(200, CONFIG)
|
||||
ctx.HTML(200, tplConfig)
|
||||
}
|
||||
|
||||
// Monitor show admin monitor page
|
||||
func Monitor(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.monitor")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
ctx.Data["PageIsAdminMonitor"] = true
|
||||
ctx.Data["Processes"] = process.Processes
|
||||
ctx.Data["Entries"] = cron.ListTasks()
|
||||
ctx.HTML(200, MONITOR)
|
||||
ctx.HTML(200, tplMonitor)
|
||||
}
|
||||
|
|
|
@ -20,11 +20,12 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
AUTHS base.TplName = "admin/auth/list"
|
||||
AUTH_NEW base.TplName = "admin/auth/new"
|
||||
AUTH_EDIT base.TplName = "admin/auth/edit"
|
||||
tplAuths base.TplName = "admin/auth/list"
|
||||
tplAuthNew base.TplName = "admin/auth/new"
|
||||
tplAuthEdit base.TplName = "admin/auth/edit"
|
||||
)
|
||||
|
||||
// Authentications show authentication config page
|
||||
func Authentications(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.authentication")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
|
@ -38,7 +39,7 @@ func Authentications(ctx *context.Context) {
|
|||
}
|
||||
|
||||
ctx.Data["Total"] = models.CountLoginSources()
|
||||
ctx.HTML(200, AUTHS)
|
||||
ctx.HTML(200, tplAuths)
|
||||
}
|
||||
|
||||
type dropdownItem struct {
|
||||
|
@ -60,6 +61,7 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
// NewAuthSource render adding a new auth source page
|
||||
func NewAuthSource(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.auths.new")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
|
@ -73,7 +75,7 @@ func NewAuthSource(ctx *context.Context) {
|
|||
ctx.Data["AuthSources"] = authSources
|
||||
ctx.Data["SecurityProtocols"] = securityProtocols
|
||||
ctx.Data["SMTPAuths"] = models.SMTPAuths
|
||||
ctx.HTML(200, AUTH_NEW)
|
||||
ctx.HTML(200, tplAuthNew)
|
||||
}
|
||||
|
||||
func parseLDAPConfig(form auth.AuthenticationForm) *models.LDAPConfig {
|
||||
|
@ -111,6 +113,7 @@ func parseSMTPConfig(form auth.AuthenticationForm) *models.SMTPConfig {
|
|||
}
|
||||
}
|
||||
|
||||
// NewAuthSourcePost response for adding an auth source
|
||||
func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.auths.new")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
|
@ -142,7 +145,7 @@ func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
|||
ctx.Data["HasTLS"] = hasTLS
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, AUTH_NEW)
|
||||
ctx.HTML(200, tplAuthNew)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -154,7 +157,7 @@ func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
|||
}); err != nil {
|
||||
if models.IsErrLoginSourceAlreadyExist(err) {
|
||||
ctx.Data["Err_Name"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_exist", err.(models.ErrLoginSourceAlreadyExist).Name), AUTH_NEW, form)
|
||||
ctx.RenderWithErr(ctx.Tr("admin.auths.login_source_exist", err.(models.ErrLoginSourceAlreadyExist).Name), tplAuthNew, form)
|
||||
} else {
|
||||
ctx.Handle(500, "CreateSource", err)
|
||||
}
|
||||
|
@ -167,6 +170,7 @@ func NewAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
|||
ctx.Redirect(setting.AppSubUrl + "/admin/auths")
|
||||
}
|
||||
|
||||
// EditAuthSource render editing auth source page
|
||||
func EditAuthSource(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.auths.edit")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
|
@ -183,9 +187,10 @@ func EditAuthSource(ctx *context.Context) {
|
|||
ctx.Data["Source"] = source
|
||||
ctx.Data["HasTLS"] = source.HasTLS()
|
||||
|
||||
ctx.HTML(200, AUTH_EDIT)
|
||||
ctx.HTML(200, tplAuthEdit)
|
||||
}
|
||||
|
||||
// EditAuthSourcePost resposne for editing auth source
|
||||
func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.auths.edit")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
|
@ -202,7 +207,7 @@ func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
|||
ctx.Data["HasTLS"] = source.HasTLS()
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, AUTH_EDIT)
|
||||
ctx.HTML(200, tplAuthEdit)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -234,6 +239,7 @@ func EditAuthSourcePost(ctx *context.Context, form auth.AuthenticationForm) {
|
|||
ctx.Redirect(setting.AppSubUrl + "/admin/auths/" + com.ToStr(form.ID))
|
||||
}
|
||||
|
||||
// DeleteAuthSource response for deleting an auth source
|
||||
func DeleteAuthSource(ctx *context.Context) {
|
||||
source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid"))
|
||||
if err != nil {
|
||||
|
|
|
@ -16,9 +16,10 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
NOTICES base.TplName = "admin/notice"
|
||||
tplNotices base.TplName = "admin/notice"
|
||||
)
|
||||
|
||||
// Notices show notices for admin
|
||||
func Notices(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.notices")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
|
@ -39,9 +40,10 @@ func Notices(ctx *context.Context) {
|
|||
ctx.Data["Notices"] = notices
|
||||
|
||||
ctx.Data["Total"] = total
|
||||
ctx.HTML(200, NOTICES)
|
||||
ctx.HTML(200, tplNotices)
|
||||
}
|
||||
|
||||
// DeleteNotices delete the specific notices
|
||||
func DeleteNotices(ctx *context.Context) {
|
||||
strs := ctx.QueryStrings("ids[]")
|
||||
ids := make([]int64, 0, len(strs))
|
||||
|
@ -61,6 +63,7 @@ func DeleteNotices(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
// EmptyNotices delete all the notices
|
||||
func EmptyNotices(ctx *context.Context) {
|
||||
if err := models.DeleteNotices(0, 0); err != nil {
|
||||
ctx.Handle(500, "DeleteNotices", err)
|
||||
|
|
|
@ -13,9 +13,10 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
ORGS base.TplName = "admin/org/list"
|
||||
tplOrgs base.TplName = "admin/org/list"
|
||||
)
|
||||
|
||||
// Organizations show all the organizations
|
||||
func Organizations(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.organizations")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
|
@ -27,6 +28,6 @@ func Organizations(ctx *context.Context) {
|
|||
Ranger: models.Organizations,
|
||||
PageSize: setting.UI.Admin.OrgPagingNum,
|
||||
OrderBy: "id ASC",
|
||||
TplName: ORGS,
|
||||
TplName: tplOrgs,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -14,9 +14,10 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
REPOS base.TplName = "admin/repo/list"
|
||||
tplRepos base.TplName = "admin/repo/list"
|
||||
)
|
||||
|
||||
// Repos show all the repositories
|
||||
func Repos(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.repositories")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
|
@ -28,10 +29,11 @@ func Repos(ctx *context.Context) {
|
|||
Private: true,
|
||||
PageSize: setting.UI.Admin.RepoPagingNum,
|
||||
OrderBy: "owner_id ASC, name ASC, id ASC",
|
||||
TplName: REPOS,
|
||||
TplName: tplRepos,
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteRepo delete one repository
|
||||
func DeleteRepo(ctx *context.Context) {
|
||||
repo, err := models.GetRepositoryByID(ctx.QueryInt64("id"))
|
||||
if err != nil {
|
||||
|
|
|
@ -19,11 +19,12 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
USERS base.TplName = "admin/user/list"
|
||||
USER_NEW base.TplName = "admin/user/new"
|
||||
USER_EDIT base.TplName = "admin/user/edit"
|
||||
tplUsers base.TplName = "admin/user/list"
|
||||
tplUserNew base.TplName = "admin/user/new"
|
||||
tplUserEdit base.TplName = "admin/user/edit"
|
||||
)
|
||||
|
||||
// Users show all the users
|
||||
func Users(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.users")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
|
@ -35,10 +36,11 @@ func Users(ctx *context.Context) {
|
|||
Ranger: models.Users,
|
||||
PageSize: setting.UI.Admin.UserPagingNum,
|
||||
OrderBy: "id ASC",
|
||||
TplName: USERS,
|
||||
TplName: tplUsers,
|
||||
})
|
||||
}
|
||||
|
||||
// NewUser render adding a new user page
|
||||
func NewUser(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.users.new_account")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
|
@ -54,9 +56,10 @@ func NewUser(ctx *context.Context) {
|
|||
ctx.Data["Sources"] = sources
|
||||
|
||||
ctx.Data["CanSendEmail"] = setting.MailService != nil
|
||||
ctx.HTML(200, USER_NEW)
|
||||
ctx.HTML(200, tplUserNew)
|
||||
}
|
||||
|
||||
// NewUserPost response for adding a new user
|
||||
func NewUserPost(ctx *context.Context, form auth.AdminCrateUserForm) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.users.new_account")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
|
@ -72,7 +75,7 @@ func NewUserPost(ctx *context.Context, form auth.AdminCrateUserForm) {
|
|||
ctx.Data["CanSendEmail"] = setting.MailService != nil
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, USER_NEW)
|
||||
ctx.HTML(200, tplUserNew)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -97,16 +100,16 @@ func NewUserPost(ctx *context.Context, form auth.AdminCrateUserForm) {
|
|||
switch {
|
||||
case models.IsErrUserAlreadyExist(err):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), USER_NEW, &form)
|
||||
ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tplUserNew, &form)
|
||||
case models.IsErrEmailAlreadyUsed(err):
|
||||
ctx.Data["Err_Email"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("form.email_been_used"), USER_NEW, &form)
|
||||
ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplUserNew, &form)
|
||||
case models.IsErrNameReserved(err):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), USER_NEW, &form)
|
||||
ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), tplUserNew, &form)
|
||||
case models.IsErrNamePatternNotAllowed(err):
|
||||
ctx.Data["Err_UserName"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), USER_NEW, &form)
|
||||
ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplUserNew, &form)
|
||||
default:
|
||||
ctx.Handle(500, "CreateUser", err)
|
||||
}
|
||||
|
@ -151,6 +154,7 @@ func prepareUserInfo(ctx *context.Context) *models.User {
|
|||
return u
|
||||
}
|
||||
|
||||
// EditUser show editting user page
|
||||
func EditUser(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.users.edit_account")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
|
@ -161,9 +165,10 @@ func EditUser(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.HTML(200, USER_EDIT)
|
||||
ctx.HTML(200, tplUserEdit)
|
||||
}
|
||||
|
||||
// EditUserPost response for editting user
|
||||
func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.users.edit_account")
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
|
@ -175,7 +180,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
|
|||
}
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, USER_EDIT)
|
||||
ctx.HTML(200, tplUserEdit)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -211,7 +216,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
|
|||
if err := models.UpdateUser(u); err != nil {
|
||||
if models.IsErrEmailAlreadyUsed(err) {
|
||||
ctx.Data["Err_Email"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("form.email_been_used"), USER_EDIT, &form)
|
||||
ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplUserEdit, &form)
|
||||
} else {
|
||||
ctx.Handle(500, "UpdateUser", err)
|
||||
}
|
||||
|
@ -223,6 +228,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
|
|||
ctx.Redirect(setting.AppSubUrl + "/admin/users/" + ctx.Params(":userid"))
|
||||
}
|
||||
|
||||
// DeleteUser response for deleting a user
|
||||
func DeleteUser(ctx *context.Context) {
|
||||
u, err := models.GetUserByID(ctx.ParamsInt64(":userid"))
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue