diff --git a/src/main/scala/ScalatraBootstrap.scala b/src/main/scala/ScalatraBootstrap.scala index 5947977..554bb32 100644 --- a/src/main/scala/ScalatraBootstrap.scala +++ b/src/main/scala/ScalatraBootstrap.scala @@ -27,12 +27,10 @@ } context.mount(new IndexController, "/") - context.mount(new SearchController, "/") context.mount(new FileUploadController, "/upload") context.mount(new DashboardController, "/*") context.mount(new UserManagementController, "/*") context.mount(new SystemSettingsController, "/*") - context.mount(new PluginsController, "/*") context.mount(new AccountController, "/*") context.mount(new RepositoryViewerController, "/*") context.mount(new WikiController, "/*") diff --git a/src/main/scala/gitbucket/core/controller/IndexController.scala b/src/main/scala/gitbucket/core/controller/IndexController.scala index 6a804f8..5c83cbb 100644 --- a/src/main/scala/gitbucket/core/controller/IndexController.scala +++ b/src/main/scala/gitbucket/core/controller/IndexController.scala @@ -2,33 +2,44 @@ import gitbucket.core.api._ import gitbucket.core.helper.xml -import gitbucket.core.html import gitbucket.core.model.Account -import gitbucket.core.service.{RepositoryService, ActivityService, AccountService} +import gitbucket.core.service.{RepositoryService, ActivityService, AccountService, RepositorySearchService, IssuesService} import gitbucket.core.util.Implicits._ -import gitbucket.core.util.{LDAPUtil, Keys, UsersAuthenticator} +import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.{LDAPUtil, Keys, UsersAuthenticator, ReferrerAuthenticator, StringUtil} import io.github.gitbucket.scalatra.forms._ class IndexController extends IndexControllerBase - with RepositoryService with ActivityService with AccountService with UsersAuthenticator + with RepositoryService with ActivityService with AccountService with RepositorySearchService with IssuesService + with UsersAuthenticator with ReferrerAuthenticator trait IndexControllerBase extends ControllerBase { - self: RepositoryService with ActivityService with AccountService with UsersAuthenticator => + self: RepositoryService with ActivityService with AccountService with RepositorySearchService + with UsersAuthenticator with ReferrerAuthenticator => case class SignInForm(userName: String, password: String) - val form = mapping( + val signinForm = mapping( "userName" -> trim(label("Username", text(required))), "password" -> trim(label("Password", text(required))) )(SignInForm.apply) + val searchForm = mapping( + "query" -> trim(text(required)), + "owner" -> trim(text(required)), + "repository" -> trim(text(required)) + )(SearchForm.apply) + + case class SearchForm(query: String, owner: String, repository: String) + + get("/"){ val loginAccount = context.loginAccount if(loginAccount.isEmpty) { - html.index(getRecentActivities(), + gitbucket.core.html.index(getRecentActivities(), getVisibleRepositories(loginAccount, withoutPhysicalInfo = true), loginAccount.map{ account => getUserRepositories(account.userName, withoutPhysicalInfo = true) }.getOrElse(Nil) ) @@ -39,7 +50,7 @@ visibleOwnerSet ++= loginUserGroups - html.index(getRecentActivitiesByOwners(visibleOwnerSet), + gitbucket.core.html.index(getRecentActivitiesByOwners(visibleOwnerSet), getVisibleRepositories(loginAccount, withoutPhysicalInfo = true), loginAccount.map{ account => getUserRepositories(account.userName, withoutPhysicalInfo = true) }.getOrElse(Nil) ) @@ -51,10 +62,10 @@ if(redirect.isDefined && redirect.get.startsWith("/")){ flash += Keys.Flash.Redirect -> redirect.get } - html.signin() + gitbucket.core.html.signin() } - post("/signin", form){ form => + post("/signin", signinForm){ form => authenticate(context.settings, form.userName, form.password) match { case Some(account) => signin(account) case None => redirect("/signin") @@ -119,4 +130,33 @@ // this message is same as github enterprise... org.scalatra.NotFound(ApiError("Rate limiting is not enabled.")) } + + // TODO Move to RepositoryViwerController? + post("/search", searchForm){ form => + redirect(s"/${form.owner}/${form.repository}/search?q=${StringUtil.urlEncode(form.query)}") + } + + // TODO Move to RepositoryViwerController? + get("/:owner/:repository/search")(referrersOnly { repository => + defining(params("q").trim, params.getOrElse("type", "code")){ case (query, target) => + val page = try { + val i = params.getOrElse("page", "1").toInt + if(i <= 0) 1 else i + } catch { + case e: NumberFormatException => 1 + } + + target.toLowerCase match { + case "issue" => gitbucket.core.search.html.issues( + searchIssues(repository.owner, repository.name, query), + countFiles(repository.owner, repository.name, query), + query, page, repository) + + case _ => gitbucket.core.search.html.code( + searchFiles(repository.owner, repository.name, query), + countIssues(repository.owner, repository.name, query), + query, page, repository) + } + } + }) } diff --git a/src/main/scala/gitbucket/core/controller/PluginsController.scala b/src/main/scala/gitbucket/core/controller/PluginsController.scala deleted file mode 100644 index 942e169..0000000 --- a/src/main/scala/gitbucket/core/controller/PluginsController.scala +++ /dev/null @@ -1,11 +0,0 @@ -package gitbucket.core.controller - -import gitbucket.core.admin.plugins.html -import gitbucket.core.plugin.PluginRegistry -import gitbucket.core.util.AdminAuthenticator - -class PluginsController extends ControllerBase with AdminAuthenticator { - get("/admin/plugins")(adminOnly { - html.plugins(PluginRegistry().getPlugins()) - }) -} diff --git a/src/main/scala/gitbucket/core/controller/SearchController.scala b/src/main/scala/gitbucket/core/controller/SearchController.scala deleted file mode 100644 index 42b266b..0000000 --- a/src/main/scala/gitbucket/core/controller/SearchController.scala +++ /dev/null @@ -1,51 +0,0 @@ -package gitbucket.core.controller - -import gitbucket.core.search.html -import gitbucket.core.service._ -import gitbucket.core.util.{StringUtil, ControlUtil, ReferrerAuthenticator, Implicits} -import ControlUtil._ -import Implicits._ -import io.github.gitbucket.scalatra.forms._ - -class SearchController extends SearchControllerBase - with RepositoryService with AccountService with ActivityService with RepositorySearchService with IssuesService with ReferrerAuthenticator - -trait SearchControllerBase extends ControllerBase { self: RepositoryService - with ActivityService with RepositorySearchService with ReferrerAuthenticator => - - val searchForm = mapping( - "query" -> trim(text(required)), - "owner" -> trim(text(required)), - "repository" -> trim(text(required)) - )(SearchForm.apply) - - case class SearchForm(query: String, owner: String, repository: String) - - post("/search", searchForm){ form => - redirect(s"/${form.owner}/${form.repository}/search?q=${StringUtil.urlEncode(form.query)}") - } - - get("/:owner/:repository/search")(referrersOnly { repository => - defining(params("q").trim, params.getOrElse("type", "code")){ case (query, target) => - val page = try { - val i = params.getOrElse("page", "1").toInt - if(i <= 0) 1 else i - } catch { - case e: NumberFormatException => 1 - } - - target.toLowerCase match { - case "issue" => html.issues( - searchIssues(repository.owner, repository.name, query), - countFiles(repository.owner, repository.name, query), - query, page, repository) - - case _ => html.code( - searchFiles(repository.owner, repository.name, query), - countIssues(repository.owner, repository.name, query), - query, page, repository) - } - } - }) - -} diff --git a/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala b/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala index bb81092..b921895 100644 --- a/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala +++ b/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala @@ -4,6 +4,7 @@ import gitbucket.core.service.{AccountService, SystemSettingsService} import gitbucket.core.util.AdminAuthenticator import gitbucket.core.ssh.SshServer +import gitbucket.core.plugin.PluginRegistry import SystemSettingsService._ import io.github.gitbucket.scalatra.forms._ @@ -87,4 +88,8 @@ redirect("/admin/system") }) + get("/admin/plugins")(adminOnly { + html.plugins(PluginRegistry().getPlugins()) + }) + } diff --git a/src/main/twirl/gitbucket/core/admin/plugins.scala.html b/src/main/twirl/gitbucket/core/admin/plugins.scala.html new file mode 100644 index 0000000..ed50e45 --- /dev/null +++ b/src/main/twirl/gitbucket/core/admin/plugins.scala.html @@ -0,0 +1,42 @@ +@(plugins: List[gitbucket.core.plugin.PluginInfo])(implicit context: gitbucket.core.controller.Context) +@import context._ +@import gitbucket.core.view.helpers._ +@html.main("Plugins"){ + @admin.html.menu("plugins") { +
No plugin detected on your gitbucket installation.
+ } + } +} diff --git a/src/main/twirl/gitbucket/core/admin/plugins/plugins.scala.html b/src/main/twirl/gitbucket/core/admin/plugins/plugins.scala.html deleted file mode 100644 index ed50e45..0000000 --- a/src/main/twirl/gitbucket/core/admin/plugins/plugins.scala.html +++ /dev/null @@ -1,42 +0,0 @@ -@(plugins: List[gitbucket.core.plugin.PluginInfo])(implicit context: gitbucket.core.controller.Context) -@import context._ -@import gitbucket.core.view.helpers._ -@html.main("Plugins"){ - @admin.html.menu("plugins") { -No plugin detected on your gitbucket installation.
- } - } -}