mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 22:45:51 +01:00
Provides Slick Session to plug-ins via ThreadLocal
This commit is contained in:
11
src/main/scala/plugin/Sessions.scala
Normal file
11
src/main/scala/plugin/Sessions.scala
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package plugin
|
||||||
|
|
||||||
|
import slick.jdbc.JdbcBackend.Session
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides Slick Session to Plug-ins.
|
||||||
|
*/
|
||||||
|
object Sessions {
|
||||||
|
val sessions = new ThreadLocal[Session]
|
||||||
|
implicit def session: Session = sessions.get()
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import service.SystemSettingsService
|
|||||||
import util.Keys
|
import util.Keys
|
||||||
import app.Context
|
import app.Context
|
||||||
import plugin.Results._
|
import plugin.Results._
|
||||||
|
import plugin.Sessions._
|
||||||
|
|
||||||
class PluginActionFilter extends Filter with SystemSettingsService {
|
class PluginActionFilter extends Filter with SystemSettingsService {
|
||||||
|
|
||||||
@@ -27,24 +28,28 @@ class PluginActionFilter extends Filter with SystemSettingsService {
|
|||||||
// Create Context
|
// Create Context
|
||||||
val loginAccount = req.getSession.getAttribute(Keys.Session.LoginAccount).asInstanceOf[Account]
|
val loginAccount = req.getSession.getAttribute(Keys.Session.LoginAccount).asInstanceOf[Account]
|
||||||
implicit val context = Context(loadSystemSettings(), Option(loginAccount), req)
|
implicit val context = Context(loadSystemSettings(), Option(loginAccount), req)
|
||||||
|
sessions.set(Database.getSession(req))
|
||||||
// Invoke global action
|
try {
|
||||||
action(req, res, context) match {
|
// Invoke global action
|
||||||
// TODO to be type classes?
|
action(req, res, context) match {
|
||||||
case x: String =>
|
// TODO to be type classes?
|
||||||
res.setContentType("text/plain; charset=UTF-8")
|
case x: String =>
|
||||||
res.getWriter.write(x)
|
res.setContentType("text/plain; charset=UTF-8")
|
||||||
res.getWriter.flush()
|
res.getWriter.write(x)
|
||||||
case x: Html =>
|
res.getWriter.flush()
|
||||||
res.setContentType("text/html; charset=UTF-8")
|
case x: Html =>
|
||||||
// TODO title of plugin action
|
res.setContentType("text/html; charset=UTF-8")
|
||||||
res.getWriter.write(html.main("TODO")(x).body)
|
// TODO title of plugin action
|
||||||
res.getWriter.flush()
|
res.getWriter.write(html.main("TODO")(x).body)
|
||||||
case Redirect(x) =>
|
res.getWriter.flush()
|
||||||
res.sendRedirect(x)
|
case Redirect(x) =>
|
||||||
case Fragment(x) =>
|
res.sendRedirect(x)
|
||||||
res.getWriter.write(x.body)
|
case Fragment(x) =>
|
||||||
res.getWriter.flush()
|
res.getWriter.write(x.body)
|
||||||
|
res.getWriter.flush()
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
sessions.remove()
|
||||||
}
|
}
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
chain.doFilter(req, res)
|
chain.doFilter(req, res)
|
||||||
@@ -52,4 +57,4 @@ class PluginActionFilter extends Filter with SystemSettingsService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user