Skip to content

Commit 067e8c1

Browse files
committed
(refs #1)Add account settings to disable email notification.
1 parent 57d647e commit 067e8c1

File tree

6 files changed

+42
-7
lines changed

6 files changed

+42
-7
lines changed

src/main/scala/Plugin.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class Plugin extends gitbucket.core.plugin.Plugin {
2020
new Version("1.0.0",
2121
new LiquibaseMigration("update/gitbucket-notifications_1.0.xml")
2222
),
23-
new Version("1.1.0",
24-
new LiquibaseMigration("update/gitbucket-notifications_1.1.xml")
23+
new Version("1.3.0",
24+
new LiquibaseMigration("update/gitbucket-notifications_1.3.xml")
2525
)
2626
)
2727

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ trait NotificationsControllerBase extends ControllerBase {
3838
get("/:userName/_notifications")(oneselfOnly {
3939
val userName = params("userName")
4040
getAccountByUserName(userName).map { account =>
41-
gitbucket.notifications.html.settings(disableEmail(account.userName))
41+
gitbucket.notifications.html.settings(account, isDisableEmailNotification(account))
42+
} getOrElse NotFound()
43+
})
44+
45+
post("/:userName/_notifications")(oneselfOnly {
46+
val userName = params("userName")
47+
params.getAs[Boolean]("disable").map { disable =>
48+
updateEmailNotification(userName, disable)
49+
redirect(s"/${userName}/_notifications")
4250
} getOrElse NotFound()
4351
})
4452

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class IssueHook extends gitbucket.core.plugin.IssueHook
113113
getAccountByUserName(_)
114114
.filterNot (_.isGroupAccount)
115115
.filterNot (LDAPUtil.isDummyMailAddress)
116+
.filterNot (isDisableEmailNotification)
116117
.map (_.mailAddress)
117118
)
118119
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package gitbucket.notifications.service
22

3-
import gitbucket.core.model.Issue
3+
import gitbucket.core.model.{Account, Issue}
44
import gitbucket.core.service.{AccountService, IssuesService, RepositoryService}
55
import gitbucket.notifications.model._, Profile._
66
import profile.blockingApi._
@@ -42,8 +42,13 @@ trait NotificationsService {
4242
)
4343
}
4444

45-
def disableEmail(userName: String)(implicit s: Session): Boolean = {
46-
NotificationsAccounts.filter(_.userName === userName.bind).firstOption.exists(_.disableEmail)
45+
def isDisableEmailNotification(account: Account)(implicit s: Session): Boolean = {
46+
NotificationsAccounts.filter(_.userName === account.userName.bind).firstOption.exists(_.disableEmail)
47+
}
48+
49+
def updateEmailNotification(userName: String, disable: Boolean)(implicit s: Session): Unit = {
50+
NotificationsAccounts.filter(_.userName === userName.bind).delete
51+
if (disable) NotificationsAccounts insert NotificationsAccount(userName = userName, disableEmail = true)
4752
}
4853

4954
def autoSubscribeUsersForRepository(owner: String, repository: String)(implicit s: Session): List[String] = {
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
1-
@(disableEmail: Boolean)(implicit context: gitbucket.core.controller.Context)
1+
@(account: gitbucket.core.model.Account,
2+
disableEmail: Boolean)(implicit context: gitbucket.core.controller.Context)
3+
4+
@gitbucket.core.html.main("Notifications"){
5+
@gitbucket.core.account.html.menu("notifications", account.userName, account.isGroupAccount){
6+
<form method="POST" action="@context.path/@account.userName/_notifications">
7+
<div class="panel panel-default">
8+
<div class="panel-heading strong">Email notification preferences</div>
9+
<div class="panel-body">
10+
<fieldset class="form-group">
11+
<p class="muted">If checked, never be notified of anything.</p>
12+
<label for="disable">
13+
<input type="checkbox" name="disable" id="disable" value="true" @if(disableEmail){checked}/>
14+
Disable
15+
</label>
16+
</fieldset>
17+
<input type="submit" class="btn btn-success" value="Save"/>
18+
</div>
19+
</div>
20+
</form>
21+
}
22+
}

0 commit comments

Comments
 (0)