Skip to content

Commit 0de03b9

Browse files
committed
Add Twirl plugin.
1 parent c2b40ff commit 0de03b9

File tree

7 files changed

+50
-18
lines changed

7 files changed

+50
-18
lines changed

build.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ organization := "io.github.gitbucket"
44
version := "1.0.0"
55
scalaVersion := "2.12.2"
66

7+
lazy val root = (project in file(".")).enablePlugins(SbtTwirl)
8+
79
libraryDependencies ++= Seq(
810
"io.github.gitbucket" %% "gitbucket" % "4.14.0-SNAPSHOT" % "provided",
911
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided"

project/plugins.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.3.2")

src/main/scala/Plugin.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import gitbucket.core.controller.Context
22
import gitbucket.core.model.Issue
33
import gitbucket.core.plugin.Link
44
import gitbucket.core.service.RepositoryService.RepositoryInfo
5+
import gitbucket.core.util.Implicits.request2Session
6+
import gitbucket.notifications.controller._
57
import gitbucket.notifications.service._
68
import io.github.gitbucket.solidbase.migration.LiquibaseMigration
79
import io.github.gitbucket.solidbase.model.Version
@@ -20,6 +22,10 @@ class Plugin extends gitbucket.core.plugin.Plugin {
2022
)
2123
)
2224

25+
override val controllers = Seq(
26+
"/*" -> new NotificationsController()
27+
)
28+
2329
override val accountHooks = Seq(new AccountHook)
2430
override val repositoryHooks = Seq(new RepositoryHook)
2531
override val issueHooks = Seq(new IssueHook)
@@ -38,8 +44,12 @@ class Plugin extends gitbucket.core.plugin.Plugin {
3844
override val issueSidebars = Seq(
3945
(issue: Issue, repository: RepositoryInfo, context: Context) =>
4046
context.loginAccount map { account =>
41-
// TODO DB access
42-
gitbucket.notifications.html.issue(false, issue, repository)
47+
implicit val session = request2Session(context.request)
48+
49+
gitbucket.notifications.html.issue(
50+
gitbucket.notifications.view.helpers.getNotificationUsers(issue).contains(account.userName),
51+
issue,
52+
repository)(context)
4353
}
4454
)
4555

src/main/scala/gitbucket/notifications/controller/NotificationsController.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ trait NotificationsControllerBase extends ControllerBase {
3434
} getOrElse NotFound()
3535
})
3636

37-
// TODO check exist issue
3837
ajaxPost("/:owner/:repository/issues/:id/notification")(readableUsersOnly { repository =>
39-
params.getAs[Boolean]("subscribed").map { subscribed =>
40-
updateIssueNotification(repository.owner, repository.name, params("id").toInt, context.loginAccount.get.userName, subscribed)
41-
Ok()
42-
} getOrElse NotFound()
38+
defining(repository.owner, repository.name) { case (owner, name) =>
39+
getIssue(owner, name, params("id")).flatMap { issue =>
40+
params.getAs[Boolean]("subscribed").map { subscribed =>
41+
updateIssueNotification(owner, name, issue.issueId, context.loginAccount.get.userName, subscribed)
42+
Ok()
43+
}
44+
} getOrElse NotFound()
45+
}
4346
})
4447

4548
}

src/main/scala/gitbucket/notifications/service/NotificationsHook.scala

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package gitbucket.notifications.service
22

33
import gitbucket.core.controller.Context
44
import gitbucket.core.model.{Account, Issue}
5-
import gitbucket.core.service.RepositoryService.RepositoryInfo
6-
import gitbucket.core.util.Notifier
5+
import gitbucket.core.service._, RepositoryService.RepositoryInfo
6+
import gitbucket.core.util.{LDAPUtil, Notifier}
77
import gitbucket.core.view.Markdown
88
import gitbucket.notifications.model.Profile._
99
import profile.blockingApi._
@@ -46,7 +46,11 @@ class RepositoryHook extends gitbucket.core.plugin.RepositoryHook {
4646

4747
}
4848

49-
class IssueHook extends gitbucket.core.plugin.IssueHook {
49+
class IssueHook extends gitbucket.core.plugin.IssueHook
50+
with NotificationsService
51+
with RepositoryService
52+
with AccountService
53+
with IssuesService {
5054

5155
override def created(issue: Issue, r: RepositoryInfo)(implicit context: Context): Unit = {
5256
Notifier().toNotify(
@@ -89,11 +93,10 @@ class IssueHook extends gitbucket.core.plugin.IssueHook {
8993
}
9094

9195

92-
protected val subject: (Issue, RepositoryInfo) => String =
93-
(issue, r) => s"[${r.owner}/${r.name}] ${issue.title} (#${issue.issueId})"
96+
protected def subject(issue: Issue, r: RepositoryInfo): String = s"[${r.owner}/${r.name}] ${issue.title} (#${issue.issueId})"
9497

95-
protected val message: (String, RepositoryInfo) => (String => String) => String =
96-
(content, r) => msg => msg(Markdown.toHtml(
98+
protected def message(content: String, r: RepositoryInfo)(msg: String => String)(implicit context: Context): String =
99+
msg(Markdown.toHtml(
97100
markdown = content,
98101
repository = r,
99102
enableWikiLink = false,
@@ -102,10 +105,16 @@ class IssueHook extends gitbucket.core.plugin.IssueHook {
102105
enableLineBreaks = false
103106
))
104107

105-
// TODO
106108
protected val recipients: Issue => Account => Session => Seq[String] = {
107109
issue => loginAccount => implicit session =>
108-
Seq("")
110+
getNotificationUsers(issue)
111+
.withFilter ( _ != loginAccount.userName ) // the operation in person is excluded
112+
.flatMap (
113+
getAccountByUserName(_)
114+
.filterNot (_.isGroupAccount)
115+
.filterNot (LDAPUtil.isDummyMailAddress)
116+
.map (_.mailAddress)
117+
)
109118
}
110119

111120
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package gitbucket.notifications.view
2+
3+
import gitbucket.core.service.{AccountService, IssuesService, RepositoryService}
4+
import gitbucket.notifications.service.NotificationsService
5+
6+
7+
object helpers extends NotificationsService with RepositoryService with AccountService with IssuesService

src/main/twirl/gitbucket/notifications/issue.scala.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@(subscribed: Boolean,
22
issue: gitbucket.core.model.Issue,
3-
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)
3+
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
44
@import gitbucket.core.view.helpers
55

66
<hr/>
@@ -19,7 +19,7 @@
1919
$('.issue-notification').click(function(){
2020
var $this = $(this);
2121
var subscribed = $this.data('subscribed');
22-
$.post('@helpers.url(repository)/issues/@issue.issueId/notification,
22+
$.post('@helpers.url(repository)/issues/@issue.issueId/notification',
2323
{ subscribed : subscribed },
2424
function(){
2525
if(subscribed == 'false'){

0 commit comments

Comments
 (0)