Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go lint fixed for routers/admin #202

Merged
merged 1 commit into from
Nov 21, 2016
Merged
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
50 changes: 27 additions & 23 deletions routers/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand All @@ -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()
}
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
24 changes: 15 additions & 9 deletions routers/admin/auths.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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)
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions routers/admin/notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions routers/admin/orgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,6 +28,6 @@ func Organizations(ctx *context.Context) {
Ranger: models.Organizations,
PageSize: setting.UI.Admin.OrgPagingNum,
OrderBy: "id ASC",
TplName: ORGS,
TplName: tplOrgs,
})
}
6 changes: 4 additions & 2 deletions routers/admin/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Loading