diff --git a/src/main/scala/gitbucket/core/plugin/Plugin.scala b/src/main/scala/gitbucket/core/plugin/Plugin.scala index ceb9b10..8d4a046 100644 --- a/src/main/scala/gitbucket/core/plugin/Plugin.scala +++ b/src/main/scala/gitbucket/core/plugin/Plugin.scala @@ -1,7 +1,8 @@ package gitbucket.core.plugin import javax.servlet.ServletContext -import gitbucket.core.controller.ControllerBase +import gitbucket.core.controller.{Context, ControllerBase} +import gitbucket.core.model.Account import gitbucket.core.service.SystemSettingsService.SystemSettings import gitbucket.core.util.ControlUtil._ import gitbucket.core.util.Version @@ -80,12 +81,22 @@ /** * Override to add global menus. */ - val globalMenus: Seq[GlobalMenu] = Nil + val globalMenus: Seq[(Context) => Option[Link]] = Nil /** * Override to add global menus. */ - def globalMenus(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[GlobalMenu] = Nil + def globalMenus(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[(Context) => Option[Link]] = Nil + + /** + * Override to add profile tabs. + */ + val profileTabs: Seq[(Account, Context) => Option[Link]] = Nil + + /** + * Override to add profile tabs. + */ + def profileTabs(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[(Account, Context) => Option[Link]] = Nil /** * This method is invoked in initialization of plugin system. @@ -110,8 +121,11 @@ (receiveHooks ++ receiveHooks(registry, context, settings)).foreach { receiveHook => registry.addReceiveHook(receiveHook) } - (globalMenus ++ globalMenus(registry, context, settings)).foreach { menu => - registry.addGlobalMenu(menu) + (globalMenus ++ globalMenus(registry, context, settings)).foreach { globalMenu => + registry.addGlobalMenu(globalMenu) + } + (profileTabs ++ profileTabs(registry, context, settings)).foreach { profileTab => + registry.addProfileTab(profileTab) } } diff --git a/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala b/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala index 3b22750..e11e7d3 100644 --- a/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala +++ b/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala @@ -3,11 +3,10 @@ import java.io.{File, FilenameFilter, InputStream} import java.net.URLClassLoader import javax.servlet.ServletContext -import javax.servlet.http.{HttpServletRequest, HttpServletResponse} import gitbucket.core.controller.{Context, ControllerBase} +import gitbucket.core.model.Account import gitbucket.core.service.ProtectedBranchService.ProtectedBranchReceiveHook -import gitbucket.core.service.RepositoryService.RepositoryInfo import gitbucket.core.service.SystemSettingsService.SystemSettings import gitbucket.core.util.ControlUtil._ import gitbucket.core.util.Directory._ @@ -33,7 +32,8 @@ private val receiveHooks = new ListBuffer[ReceiveHook] receiveHooks += new ProtectedBranchReceiveHook() - private val globalMenus = new ListBuffer[GlobalMenu] + private val globalMenus = new ListBuffer[(Context) => Option[Link]] + private val profileTabs = new ListBuffer[(Account, Context) => Option[Link]] def addPlugin(pluginInfo: PluginInfo): Unit = { plugins += pluginInfo @@ -109,23 +109,17 @@ def getReceiveHooks: Seq[ReceiveHook] = receiveHooks.toSeq - def addGlobalMenu(menu: GlobalMenu): Unit = { + def addGlobalMenu(menu: (Context) => Option[Link]): Unit = { globalMenus += menu } - def getGlobalMenus: Seq[GlobalMenu] = globalMenus.toSeq + def getGlobalMenus: Seq[(Context) => Option[Link]] = globalMenus.toSeq -// private case class GlobalAction( -// method: String, -// path: String, -// function: (HttpServletRequest, HttpServletResponse, Context) => Any -// ) -// -// private case class RepositoryAction( -// method: String, -// path: String, -// function: (HttpServletRequest, HttpServletResponse, Context, RepositoryInfo) => Any -// ) + def addProfileTab(tab: (Account, Context) => Option[Link]): Unit = { + profileTabs += tab + } + + def getProfileTabs: Seq[(Account, Context) => Option[Link]] = profileTabs.toSeq } @@ -209,9 +203,7 @@ } -abstract class GlobalMenu { - def createLink(context: Context): Option[(String, String)] -} +case class Link(id: String, label: String, path: String) case class PluginInfo( pluginId: String, diff --git a/src/main/twirl/gitbucket/core/account/main.scala.html b/src/main/twirl/gitbucket/core/account/main.scala.html index 17f6424..dd4450b 100644 --- a/src/main/twirl/gitbucket/core/account/main.scala.html +++ b/src/main/twirl/gitbucket/core/account/main.scala.html @@ -33,6 +33,11 @@ } else {