mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 06:55:54 +01:00
(refs #464)Add a new parameter to specify request method for plugin actions
This commit is contained in:
@@ -166,8 +166,8 @@ object PluginSystem extends PluginService {
|
|||||||
case class PluginRepository(id: String, url: String)
|
case class PluginRepository(id: String, url: String)
|
||||||
case class GlobalMenu(label: String, url: String, icon: String, condition: Context => Boolean)
|
case class GlobalMenu(label: String, url: String, icon: String, condition: Context => Boolean)
|
||||||
case class RepositoryMenu(label: String, name: String, url: String, icon: String, condition: Context => Boolean)
|
case class RepositoryMenu(label: String, name: String, url: String, icon: String, condition: Context => Boolean)
|
||||||
case class Action(path: String, security: Security, function: (HttpServletRequest, HttpServletResponse) => Any)
|
case class Action(method: String, path: String, security: Security, function: (HttpServletRequest, HttpServletResponse, Context) => Any)
|
||||||
case class RepositoryAction(path: String, security: Security, function: (HttpServletRequest, HttpServletResponse, RepositoryInfo) => Any)
|
case class RepositoryAction(method: String, path: String, security: Security, function: (HttpServletRequest, HttpServletResponse, Context, RepositoryInfo) => Any)
|
||||||
case class Button(label: String, href: String)
|
case class Button(label: String, href: String)
|
||||||
case class JavaScript(filter: String => Boolean, script: String)
|
case class JavaScript(filter: String => Boolean, script: String)
|
||||||
|
|
||||||
|
|||||||
@@ -36,12 +36,12 @@ class ScalaPlugin(val id: String, val version: String,
|
|||||||
globalMenuList += GlobalMenu(label, url, icon, condition)
|
globalMenuList += GlobalMenu(label, url, icon, condition)
|
||||||
}
|
}
|
||||||
|
|
||||||
def addGlobalAction(path: String, security: Security = All())(function: (HttpServletRequest, HttpServletResponse) => Any): Unit = {
|
def addGlobalAction(method: String, path: String, security: Security = All())(function: (HttpServletRequest, HttpServletResponse, Context) => Any): Unit = {
|
||||||
globalActionList += Action(path, security, function)
|
globalActionList += Action(method, path, security, function)
|
||||||
}
|
}
|
||||||
|
|
||||||
def addRepositoryAction(path: String, security: Security = All())(function: (HttpServletRequest, HttpServletResponse, RepositoryInfo) => Any): Unit = {
|
def addRepositoryAction(method: String, path: String, security: Security = All())(function: (HttpServletRequest, HttpServletResponse, Context, RepositoryInfo) => Any): Unit = {
|
||||||
repositoryActionList += RepositoryAction(path, security, function)
|
repositoryActionList += RepositoryAction(method, path, security, function)
|
||||||
}
|
}
|
||||||
|
|
||||||
def addJavaScript(filter: String => Boolean, script: String): Unit = {
|
def addJavaScript(filter: String => Boolean, script: String): Unit = {
|
||||||
|
|||||||
@@ -32,13 +32,15 @@ class PluginActionInvokeFilter extends Filter with SystemSettingsService with Re
|
|||||||
|
|
||||||
private def processGlobalAction(path: String, request: HttpServletRequest, response: HttpServletResponse)
|
private def processGlobalAction(path: String, request: HttpServletRequest, response: HttpServletResponse)
|
||||||
(implicit session: Session): Boolean = {
|
(implicit session: Session): Boolean = {
|
||||||
plugin.PluginSystem.globalActions.find(_.path == path).map { action =>
|
plugin.PluginSystem.globalActions.find(x =>
|
||||||
|
x.method.toLowerCase == request.getMethod.toLowerCase && x.path == path
|
||||||
|
).map { action =>
|
||||||
val loginAccount = request.getSession.getAttribute(Keys.Session.LoginAccount).asInstanceOf[Account]
|
val loginAccount = request.getSession.getAttribute(Keys.Session.LoginAccount).asInstanceOf[Account]
|
||||||
val systemSettings = loadSystemSettings()
|
val systemSettings = loadSystemSettings()
|
||||||
implicit val context = app.Context(systemSettings, Option(loginAccount), request)
|
implicit val context = app.Context(systemSettings, Option(loginAccount), request)
|
||||||
|
|
||||||
if(authenticate(action.security, context)){
|
if(authenticate(action.security, context)){
|
||||||
val result = action.function(request, response)
|
val result = action.function(request, response, context)
|
||||||
result match {
|
result match {
|
||||||
case x: String => renderGlobalHtml(request, response, context, x)
|
case x: String => renderGlobalHtml(request, response, context, x)
|
||||||
case x: Html => renderGlobalHtml(request, response, context, x.toString)
|
case x: Html => renderGlobalHtml(request, response, context, x.toString)
|
||||||
@@ -68,7 +70,7 @@ class PluginActionInvokeFilter extends Filter with SystemSettingsService with Re
|
|||||||
if(authenticate(action.security, context, repository)){
|
if(authenticate(action.security, context, repository)){
|
||||||
val result = try {
|
val result = try {
|
||||||
PluginConnectionHolder.threadLocal.set(session.conn)
|
PluginConnectionHolder.threadLocal.set(session.conn)
|
||||||
action.function(request, response, repository)
|
action.function(request, response, context, repository)
|
||||||
} finally {
|
} finally {
|
||||||
PluginConnectionHolder.threadLocal.remove()
|
PluginConnectionHolder.threadLocal.remove()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user