Skip to content

Commit 57d647e

Browse files
committed
(refs #1)Create NOTIFICATIONS_ACCOUNT table.
1 parent 9df656c commit 57d647e

File tree

9 files changed

+68
-6
lines changed

9 files changed

+68
-6
lines changed

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name := "gitbucket-notifications-plugin"
22

33
organization := "io.github.gitbucket"
4-
version := "1.0.0"
5-
scalaVersion := "2.12.2"
4+
version := "1.1.0"
5+
scalaVersion := "2.12.3"
66

77
lazy val root = (project in file(".")).enablePlugins(SbtTwirl)
88

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.13.15
1+
sbt.version=0.13.16
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<changeSet>
3+
<!--================================================================================================-->
4+
<!-- NOTIFICATIONS_ACCOUNT -->
5+
<!--================================================================================================-->
6+
<createTable tableName="NOTIFICATIONS_ACCOUNT">
7+
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
8+
<column name="DISABLE_EMAIL" type="boolean" nullable="false"/>
9+
</createTable>
10+
11+
<addPrimaryKey constraintName="IDX_NOTIFICATIONS_ACCOUNT_PK" tableName="NOTIFICATIONS_ACCOUNT" columnNames="USER_NAME"/>
12+
<addForeignKeyConstraint constraintName="IDX_NOTIFICATIONS_ACCOUNT_FK0" baseTableName="NOTIFICATIONS_ACCOUNT" baseColumnNames="USER_NAME" referencedTableName="ACCOUNT" referencedColumnNames="USER_NAME"/>
13+
14+
</changeSet>

src/main/scala/Plugin.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import gitbucket.core.controller.Context
22
import gitbucket.core.model.Issue
3+
import gitbucket.core.plugin.Link
34
import gitbucket.core.service.RepositoryService.RepositoryInfo
45
import gitbucket.core.util.Implicits.request2Session
56
import gitbucket.notifications._
@@ -18,6 +19,9 @@ class Plugin extends gitbucket.core.plugin.Plugin {
1819
override val versions = List(
1920
new Version("1.0.0",
2021
new LiquibaseMigration("update/gitbucket-notifications_1.0.xml")
22+
),
23+
new Version("1.1.0",
24+
new LiquibaseMigration("update/gitbucket-notifications_1.1.xml")
2125
)
2226
)
2327

@@ -58,4 +62,15 @@ class Plugin extends gitbucket.core.plugin.Plugin {
5862
}
5963
)
6064

65+
override val accountSettingMenus = Seq(
66+
(context: Context) =>
67+
context.loginAccount map { account =>
68+
Link(
69+
id = "notifications",
70+
label = "Notifications",
71+
path = s"/${account.userName}/_notifications"
72+
)
73+
}
74+
)
75+
6176
}

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ package gitbucket.notifications.controller
33
import gitbucket.core.controller.ControllerBase
44
import gitbucket.core.service.{AccountService, IssuesService, RepositoryService}
55
import gitbucket.core.util.Implicits._
6-
import gitbucket.core.util.ReadableUsersAuthenticator
6+
import gitbucket.core.util.{OneselfAuthenticator, ReadableUsersAuthenticator}
77
import gitbucket.core.util.SyntaxSugars._
88
import gitbucket.notifications.model.Watch
99
import gitbucket.notifications.service.NotificationsService
1010
import org.scalatra.Ok
1111

1212
class NotificationsController extends NotificationsControllerBase
13-
with NotificationsService with RepositoryService with AccountService with IssuesService with ReadableUsersAuthenticator
13+
with NotificationsService with RepositoryService with AccountService with IssuesService
14+
with ReadableUsersAuthenticator with OneselfAuthenticator
1415

1516
trait NotificationsControllerBase extends ControllerBase {
16-
self: NotificationsService with RepositoryService with AccountService with IssuesService with ReadableUsersAuthenticator =>
17+
self: NotificationsService with RepositoryService with AccountService with IssuesService
18+
with ReadableUsersAuthenticator with OneselfAuthenticator =>
1719

1820
ajaxPost("/:owner/:repository/watch")(readableUsersOnly { repository =>
1921
params.get("notification").flatMap(Watch.Notification.valueOf).map { notification =>
@@ -33,4 +35,11 @@ trait NotificationsControllerBase extends ControllerBase {
3335
}
3436
})
3537

38+
get("/:userName/_notifications")(oneselfOnly {
39+
val userName = params("userName")
40+
getAccountByUserName(userName).map { account =>
41+
gitbucket.notifications.html.settings(disableEmail(account.userName))
42+
} getOrElse NotFound()
43+
})
44+
3645
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package gitbucket.notifications.model
2+
3+
trait NotificationsAccountComponent { self: gitbucket.core.model.Profile =>
4+
import profile.api._
5+
6+
lazy val NotificationsAccounts = TableQuery[NotificationsAccounts]
7+
8+
class NotificationsAccounts(tag: Tag) extends Table[NotificationsAccount](tag, "NOTIFICATIONS_ACCOUNT") {
9+
val userName = column[String]("USER_NAME")
10+
val disableEmail = column[Boolean]("DISABLE_EMAIL")
11+
def * = (userName, disableEmail) <> (NotificationsAccount.tupled, NotificationsAccount.unapply)
12+
}
13+
}
14+
15+
case class NotificationsAccount(
16+
userName: String,
17+
disableEmail: Boolean
18+
)

src/main/scala/gitbucket/notifications/model/Profile.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ import gitbucket.core.model._
55
object Profile extends CoreProfile
66
with IssueNotificationComponent
77
with WatchComponent
8+
with NotificationsAccountComponent

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ trait NotificationsService {
4242
)
4343
}
4444

45+
def disableEmail(userName: String)(implicit s: Session): Boolean = {
46+
NotificationsAccounts.filter(_.userName === userName.bind).firstOption.exists(_.disableEmail)
47+
}
48+
4549
def autoSubscribeUsersForRepository(owner: String, repository: String)(implicit s: Session): List[String] = {
4650
// individual repository's owner
4751
owner ::
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@(disableEmail: Boolean)(implicit context: gitbucket.core.controller.Context)

0 commit comments

Comments
 (0)