Skip to content

golint fixed for parts of routers root, dev, user and org dirs #167

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

Merged
merged 4 commits into from
Nov 18, 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
1 change: 1 addition & 0 deletions routers/dev/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/modules/setting"
)

// TemplatePreview render for previewing the indicated template
func TemplatePreview(ctx *context.Context) {
ctx.Data["User"] = models.User{Name: "Unknown"}
ctx.Data["AppName"] = setting.AppName
Expand Down
31 changes: 22 additions & 9 deletions routers/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ import (
)

const (
HOME base.TplName = "home"
EXPLORE_REPOS base.TplName = "explore/repos"
EXPLORE_USERS base.TplName = "explore/users"
EXPLORE_ORGANIZATIONS base.TplName = "explore/organizations"
// tplHome home page template
tplHome base.TplName = "home"
// tplExploreRepos explore repositories page template
tplExploreRepos base.TplName = "explore/repos"
// tplExploreUsers explore users page template
tplExploreUsers base.TplName = "explore/users"
// tplExploreOrganizations explore organizations page template
tplExploreOrganizations base.TplName = "explore/organizations"
)

// Home render home page
func Home(ctx *context.Context) {
if ctx.IsSigned {
if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
ctx.HTML(200, user.ACTIVATE)
ctx.HTML(200, user.TplActivate)
} else {
user.Dashboard(ctx)
}
Expand All @@ -42,9 +47,10 @@ func Home(ctx *context.Context) {
}

ctx.Data["PageIsHome"] = true
ctx.HTML(200, HOME)
ctx.HTML(200, tplHome)
}

// RepoSearchOptions when calling search repositories
type RepoSearchOptions struct {
Counter func(bool) int64
Ranger func(int, int) ([]*models.Repository, error)
Expand All @@ -54,6 +60,7 @@ type RepoSearchOptions struct {
TplName base.TplName
}

// RenderRepoSearch render repositories search page
func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
page := ctx.QueryInt("page")
if page <= 0 {
Expand Down Expand Up @@ -102,6 +109,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
ctx.HTML(200, opts.TplName)
}

// ExploreRepos render explore repositories page
func ExploreRepos(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("explore")
ctx.Data["PageIsExplore"] = true
Expand All @@ -112,10 +120,11 @@ func ExploreRepos(ctx *context.Context) {
Ranger: models.GetRecentUpdatedRepositories,
PageSize: setting.UI.ExplorePagingNum,
OrderBy: "updated_unix DESC",
TplName: EXPLORE_REPOS,
TplName: tplExploreRepos,
})
}

// UserSearchOptions options when render search user page
type UserSearchOptions struct {
Type models.UserType
Counter func() int64
Expand All @@ -125,6 +134,7 @@ type UserSearchOptions struct {
TplName base.TplName
}

// RenderUserSearch render user search page
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could just be RenderUserSearch page :)

func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
page := ctx.QueryInt("page")
if page <= 1 {
Expand Down Expand Up @@ -166,6 +176,7 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) {
ctx.HTML(200, opts.TplName)
}

// ExploreUsers render explore users page
func ExploreUsers(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("explore")
ctx.Data["PageIsExplore"] = true
Expand All @@ -177,10 +188,11 @@ func ExploreUsers(ctx *context.Context) {
Ranger: models.Users,
PageSize: setting.UI.ExplorePagingNum,
OrderBy: "name ASC",
TplName: EXPLORE_USERS,
TplName: tplExploreUsers,
})
}

// ExploreOrganizations render explore organizations page
func ExploreOrganizations(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("explore")
ctx.Data["PageIsExplore"] = true
Expand All @@ -192,10 +204,11 @@ func ExploreOrganizations(ctx *context.Context) {
Ranger: models.Organizations,
PageSize: setting.UI.ExplorePagingNum,
OrderBy: "name ASC",
TplName: EXPLORE_ORGANIZATIONS,
TplName: tplExploreOrganizations,
})
}

// NotFound render 404 page
func NotFound(ctx *context.Context) {
ctx.Data["Title"] = "Page Not Found"
ctx.Handle(404, "home.NotFound", nil)
Expand Down
43 changes: 24 additions & 19 deletions routers/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import (
)

const (
INSTALL base.TplName = "install"
// tplInstall template for installation page
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for a comment here since it isn't exported 🙂

tplInstall base.TplName = "install"
)

func checkRunMode() {
Expand All @@ -49,6 +50,7 @@ func checkRunMode() {
log.Info("Run Mode: %s", strings.Title(macaron.Env))
}

// NewServices init new services
func NewServices() {
setting.NewServices()
mailer.NewContext()
Expand Down Expand Up @@ -97,6 +99,7 @@ func GlobalInit() {
}
}

// InstallInit prepare for rendering installation page
func InstallInit(ctx *context.Context) {
if setting.InstallLock {
ctx.Handle(404, "Install", errors.New("Installation is prohibited"))
Expand All @@ -116,6 +119,7 @@ func InstallInit(ctx *context.Context) {
ctx.Data["DbOptions"] = dbOpts
}

// Install render installation page
func Install(ctx *context.Context) {
form := auth.InstallForm{}

Expand Down Expand Up @@ -175,9 +179,10 @@ func Install(ctx *context.Context) {
form.RequireSignInView = setting.Service.RequireSignInView

auth.AssignForm(form, ctx.Data)
ctx.HTML(200, INSTALL)
ctx.HTML(200, tplInstall)
}

// InstallPost response for submit install items
func InstallPost(ctx *context.Context, form auth.InstallForm) {
ctx.Data["CurDbOption"] = form.DbType

Expand All @@ -191,12 +196,12 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
ctx.Data["Err_Admin"] = true
}

ctx.HTML(200, INSTALL)
ctx.HTML(200, tplInstall)
return
}

if _, err := exec.LookPath("git"); err != nil {
ctx.RenderWithErr(ctx.Tr("install.test_git_failed", err), INSTALL, &form)
ctx.RenderWithErr(ctx.Tr("install.test_git_failed", err), tplInstall, &form)
return
}

Expand All @@ -214,12 +219,12 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
if (models.DbCfg.Type == "sqlite3" || models.DbCfg.Type == "tidb") &&
len(models.DbCfg.Path) == 0 {
ctx.Data["Err_DbPath"] = true
ctx.RenderWithErr(ctx.Tr("install.err_empty_db_path"), INSTALL, &form)
ctx.RenderWithErr(ctx.Tr("install.err_empty_db_path"), tplInstall, &form)
return
} else if models.DbCfg.Type == "tidb" &&
strings.ContainsAny(path.Base(models.DbCfg.Path), ".-") {
ctx.Data["Err_DbPath"] = true
ctx.RenderWithErr(ctx.Tr("install.err_invalid_tidb_name"), INSTALL, &form)
ctx.RenderWithErr(ctx.Tr("install.err_invalid_tidb_name"), tplInstall, &form)
return
}

Expand All @@ -228,10 +233,10 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
if err := models.NewTestEngine(x); err != nil {
if strings.Contains(err.Error(), `Unknown database type: sqlite3`) {
ctx.Data["Err_DbType"] = true
ctx.RenderWithErr(ctx.Tr("install.sqlite3_not_available", "https://gogs.io/docs/installation/install_from_binary.html"), INSTALL, &form)
ctx.RenderWithErr(ctx.Tr("install.sqlite3_not_available", "https://gogs.io/docs/installation/install_from_binary.html"), tplInstall, &form)
} else {
ctx.Data["Err_DbSetting"] = true
ctx.RenderWithErr(ctx.Tr("install.invalid_db_setting", err), INSTALL, &form)
ctx.RenderWithErr(ctx.Tr("install.invalid_db_setting", err), tplInstall, &form)
}
return
}
Expand All @@ -240,44 +245,44 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
form.RepoRootPath = strings.Replace(form.RepoRootPath, "\\", "/", -1)
if err := os.MkdirAll(form.RepoRootPath, os.ModePerm); err != nil {
ctx.Data["Err_RepoRootPath"] = true
ctx.RenderWithErr(ctx.Tr("install.invalid_repo_path", err), INSTALL, &form)
ctx.RenderWithErr(ctx.Tr("install.invalid_repo_path", err), tplInstall, &form)
return
}

// Test log root path.
form.LogRootPath = strings.Replace(form.LogRootPath, "\\", "/", -1)
if err := os.MkdirAll(form.LogRootPath, os.ModePerm); err != nil {
ctx.Data["Err_LogRootPath"] = true
ctx.RenderWithErr(ctx.Tr("install.invalid_log_root_path", err), INSTALL, &form)
ctx.RenderWithErr(ctx.Tr("install.invalid_log_root_path", err), tplInstall, &form)
return
}

currentUser, match := setting.IsRunUserMatchCurrentUser(form.RunUser)
if !match {
ctx.Data["Err_RunUser"] = true
ctx.RenderWithErr(ctx.Tr("install.run_user_not_match", form.RunUser, currentUser), INSTALL, &form)
ctx.RenderWithErr(ctx.Tr("install.run_user_not_match", form.RunUser, currentUser), tplInstall, &form)
return
}

// Check logic loophole between disable self-registration and no admin account.
if form.DisableRegistration && len(form.AdminName) == 0 {
ctx.Data["Err_Services"] = true
ctx.Data["Err_Admin"] = true
ctx.RenderWithErr(ctx.Tr("install.no_admin_and_disable_registration"), INSTALL, form)
ctx.RenderWithErr(ctx.Tr("install.no_admin_and_disable_registration"), tplInstall, form)
return
}

// Check admin password.
if len(form.AdminName) > 0 && len(form.AdminPasswd) == 0 {
ctx.Data["Err_Admin"] = true
ctx.Data["Err_AdminPasswd"] = true
ctx.RenderWithErr(ctx.Tr("install.err_empty_admin_password"), INSTALL, form)
ctx.RenderWithErr(ctx.Tr("install.err_empty_admin_password"), tplInstall, form)
return
}
if form.AdminPasswd != form.AdminConfirmPasswd {
ctx.Data["Err_Admin"] = true
ctx.Data["Err_AdminPasswd"] = true
ctx.RenderWithErr(ctx.Tr("form.password_not_match"), INSTALL, form)
ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplInstall, form)
return
}

Expand Down Expand Up @@ -347,12 +352,12 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {

err := os.MkdirAll(filepath.Dir(setting.CustomConf), os.ModePerm)
if err != nil {
ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), tplInstall, &form)
return
}

if err := cfg.SaveTo(setting.CustomConf); err != nil {
ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), tplInstall, &form)
return
}

Expand All @@ -372,7 +377,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
setting.InstallLock = false
ctx.Data["Err_AdminName"] = true
ctx.Data["Err_AdminEmail"] = true
ctx.RenderWithErr(ctx.Tr("install.invalid_admin_setting", err), INSTALL, &form)
ctx.RenderWithErr(ctx.Tr("install.invalid_admin_setting", err), tplInstall, &form)
return
}
log.Info("Admin account already exist")
Expand All @@ -381,11 +386,11 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {

// Auto-login for admin
if err := ctx.Session.Set("uid", u.ID); err != nil {
ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), tplInstall, &form)
return
}
if err := ctx.Session.Set("uname", u.Name); err != nil {
ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), tplInstall, &form)
return
}
}
Expand Down
13 changes: 9 additions & 4 deletions routers/org/members.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ import (
)

const (
MEMBERS base.TplName = "org/member/members"
MEMBER_INVITE base.TplName = "org/member/invite"
// tplMembers template for organization members page
tplMembers base.TplName = "org/member/members"
// tplMemberInvite template for orgnization invite page
tplMemberInvite base.TplName = "org/member/invite"
)

// Members render orgnization users page
func Members(ctx *context.Context) {
org := ctx.Org.Organization
ctx.Data["Title"] = org.FullName
Expand All @@ -30,9 +33,10 @@ func Members(ctx *context.Context) {
}
ctx.Data["Members"] = org.Members

ctx.HTML(200, MEMBERS)
ctx.HTML(200, tplMembers)
}

// MembersAction response for operation to a member of orgnization
func MembersAction(ctx *context.Context) {
uid := com.StrTo(ctx.Query("uid")).MustInt64()
if uid == 0 {
Expand Down Expand Up @@ -91,6 +95,7 @@ func MembersAction(ctx *context.Context) {
}
}

// Invitation render organization invitation page
func Invitation(ctx *context.Context) {
org := ctx.Org.Organization
ctx.Data["Title"] = org.FullName
Expand Down Expand Up @@ -119,5 +124,5 @@ func Invitation(ctx *context.Context) {
return
}

ctx.HTML(200, MEMBER_INVITE)
ctx.HTML(200, tplMemberInvite)
}
15 changes: 9 additions & 6 deletions routers/org/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ import (
)

const (
CREATE base.TplName = "org/create"
// tplCreateOrg template path for create organization
tplCreateOrg base.TplName = "org/create"
)

// Create render the page for create organization
func Create(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("new_org")
ctx.HTML(200, CREATE)
ctx.HTML(200, tplCreateOrg)
}

// CreatePost response for create organization
func CreatePost(ctx *context.Context, form auth.CreateOrgForm) {
ctx.Data["Title"] = ctx.Tr("new_org")

if ctx.HasError() {
ctx.HTML(200, CREATE)
ctx.HTML(200, tplCreateOrg)
return
}

Expand All @@ -40,11 +43,11 @@ func CreatePost(ctx *context.Context, form auth.CreateOrgForm) {
ctx.Data["Err_OrgName"] = true
switch {
case models.IsErrUserAlreadyExist(err):
ctx.RenderWithErr(ctx.Tr("form.org_name_been_taken"), CREATE, &form)
ctx.RenderWithErr(ctx.Tr("form.org_name_been_taken"), tplCreateOrg, &form)
case models.IsErrNameReserved(err):
ctx.RenderWithErr(ctx.Tr("org.form.name_reserved", err.(models.ErrNameReserved).Name), CREATE, &form)
ctx.RenderWithErr(ctx.Tr("org.form.name_reserved", err.(models.ErrNameReserved).Name), tplCreateOrg, &form)
case models.IsErrNamePatternNotAllowed(err):
ctx.RenderWithErr(ctx.Tr("org.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), CREATE, &form)
ctx.RenderWithErr(ctx.Tr("org.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tplCreateOrg, &form)
default:
ctx.Handle(500, "CreateOrganization", err)
}
Expand Down
Loading