diff --git a/models/unit/unit.go b/models/unit/unit.go index 3b62e5f982..d07bb67822 100644 --- a/models/unit/unit.go +++ b/models/unit/unit.go @@ -206,7 +206,7 @@ var ( UnitCode = Unit{ TypeCode, "repo.code", - "/", + "/code", "repo.code.desc", 0, perm.AccessModeOwner, diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 35f10a1a2f..eb27875db1 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -773,8 +773,8 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) { } } -// Home render repository home page -func Home(ctx *context.Context) { +// HomeWithFeedCheck render repository home page or return feed +func HomeWithFeedCheck(ctx *context.Context) { if setting.Other.EnableFeed { isFeed, _, showFeedType := feed.GetFeedType(ctx.PathParam(":reponame"), ctx.Req) if isFeed { @@ -790,6 +790,15 @@ func Home(ctx *context.Context) { } } + defaultURI := ctx.Repo.Repository.MustGetUnit(ctx, ctx.Repo.Repository.DefaultUnit).Unit().URI + if defaultURI == "/" { // support legacy code units + defaultURI = "/code" + } + ctx.Redirect(ctx.Repo.RepoLink + defaultURI) +} + +// Home render repository home page +func Home(ctx *context.Context) { checkHomeCodeViewable(ctx) if ctx.Written() { return diff --git a/routers/web/web.go b/routers/web/web.go index a6ccb7a792..1d34d32db3 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1140,7 +1140,8 @@ func registerRoutes(m *web.Router) { // end "/{username}/{reponame}/settings" // user/org home, including rss feeds - m.Get("/{username}/{reponame}", ignSignIn, context.RepoAssignment, context.RepoRef(), repo.SetEditorconfigIfExists, repo.Home) + m.Get("/{username}/{reponame}", ignSignIn, context.RepoAssignment, context.RepoRef(), repo.SetEditorconfigIfExists, repo.HomeWithFeedCheck) + m.Get("/{username}/{reponame}/code", ignSignIn, context.RepoAssignment, context.RepoRef(), repo.SetEditorconfigIfExists, repo.Home) // TODO: maybe it should relax the permission to allow "any access" m.Post("/{username}/{reponame}/markup", ignSignIn, context.RepoAssignment, context.RequireRepoReaderOr(unit.TypeCode, unit.TypeIssues, unit.TypePullRequests, unit.TypeReleases, unit.TypeWiki), web.Bind(structs.MarkupOption{}), misc.Markup)