[Notice] Announcing the End of Demo Server [Read me]

YobiUpdate: Show a notification bar to site admin
Show a notification bar which has a link to the latest release of Yobi if update is available. Site Administrator can hide the bar and then Yobi never shows the bar until itself restarts. Yobi checks for updates every day basically. You can configure the interval by modifying application.update.notification.interval.
@59566d492772f4b14a0873e57ff03c0e6581142b
--- app/Global.java
+++ app/Global.java
... | ... | @@ -69,6 +69,7 @@ |
69 | 69 |
NotificationMail.onStart(); |
70 | 70 |
NotificationEvent.onStart(); |
71 | 71 |
Attachment.onStart(); |
72 |
+ YobiUpdate.onStart(); |
|
72 | 73 |
} |
73 | 74 |
|
74 | 75 |
private boolean equalsDefaultSecret() { |
--- app/controllers/SiteApp.java
+++ app/controllers/SiteApp.java
... | ... | @@ -252,21 +252,28 @@ |
252 | 252 |
} |
253 | 253 |
|
254 | 254 |
/** |
255 |
+ * Hide the notification for Yobi updates. |
|
256 |
+ */ |
|
257 |
+ public static Result unwatchUpdate() { |
|
258 |
+ YobiUpdate.isWatched = false; |
|
259 |
+ return ok(); |
|
260 |
+ } |
|
261 |
+ |
|
262 |
+ /** |
|
255 | 263 |
* Show the page to update Yobi. |
256 | 264 |
*/ |
257 | 265 |
public static Result update() throws GitAPIException { |
258 | 266 |
String currentVersion = null; |
259 |
- String versionToUpdate = null; |
|
260 | 267 |
Exception exception = null; |
261 | 268 |
|
262 | 269 |
try { |
263 | 270 |
currentVersion = Config.getCurrentVersion(); |
264 |
- versionToUpdate = YobiUpdate.fetchVersionToUpdate(); |
|
271 |
+ YobiUpdate.refreshVersionToUpdate(); |
|
265 | 272 |
} catch (Exception e) { |
266 | 273 |
exception = e; |
267 | 274 |
} |
268 | 275 |
|
269 |
- return ok(update.render( |
|
270 |
- "title.siteSetting", currentVersion, versionToUpdate, exception)); |
|
276 |
+ return ok(update.render("title.siteSetting", currentVersion, |
|
277 |
+ YobiUpdate.versionToUpdate, exception)); |
|
271 | 278 |
} |
272 | 279 |
} |
--- app/models/YobiUpdate.java
+++ app/models/YobiUpdate.java
... | ... | @@ -38,16 +38,53 @@ |
38 | 38 |
import java.util.concurrent.TimeUnit; |
39 | 39 |
|
40 | 40 |
public class YobiUpdate { |
41 |
+ private static final Long UPDATE_NOTIFICATION_INITDELAY_IN_MILLIS = Configuration.root() |
|
42 |
+ .getMilliseconds("application.update.notification.initdelay", 5 * 1000L); |
|
43 |
+ private static final Long UPDATE_NOTIFICATION_INTERVAL_IN_MILLIS = Configuration.root() |
|
44 |
+ .getMilliseconds("application.update.notification.interval", 60 * 60 * 1000L); |
|
41 | 45 |
private static final String UPDATE_REPOSITORY_URL = Configuration.root() |
42 | 46 |
.getString("application.update.repositoryUrl", "http://demo.yobi.io/naver/Yobi"); |
43 | 47 |
private static final String RELEASE_URL_FORMAT = Configuration.root() |
44 | 48 |
.getString("application.update.releaseUrlFormat", |
45 | 49 |
"https://github.com/naver/yobi/releases/tag/v%s"); |
46 | 50 |
|
51 |
+ public static String versionToUpdate = null; |
|
52 |
+ |
|
53 |
+ public static boolean isWatched = true; |
|
54 |
+ |
|
55 |
+ public static void onStart() { |
|
56 |
+ if (UPDATE_NOTIFICATION_INTERVAL_IN_MILLIS <= 0) { |
|
57 |
+ return; |
|
58 |
+ } |
|
59 |
+ |
|
60 |
+ Akka.system().scheduler().schedule( |
|
61 |
+ Duration.create(UPDATE_NOTIFICATION_INITDELAY_IN_MILLIS, TimeUnit.MILLISECONDS), |
|
62 |
+ Duration.create(UPDATE_NOTIFICATION_INTERVAL_IN_MILLIS, TimeUnit.MILLISECONDS), |
|
63 |
+ new Runnable() { |
|
64 |
+ public void run() { |
|
65 |
+ try { |
|
66 |
+ refreshVersionToUpdate(); |
|
67 |
+ } catch (Exception e) { |
|
68 |
+ play.Logger.warn("Failed to fetch the latest Yobi version to update", e); |
|
69 |
+ } |
|
70 |
+ } |
|
71 |
+ }, |
|
72 |
+ Akka.system().dispatcher() |
|
73 |
+ ); |
|
74 |
+ } |
|
75 |
+ |
|
76 |
+ public static String getReleaseUrl() throws GitAPIException { |
|
77 |
+ return getReleaseUrl(versionToUpdate); |
|
78 |
+ } |
|
79 |
+ |
|
47 | 80 |
public static String getReleaseUrl(String version) throws GitAPIException { |
48 | 81 |
return String.format(RELEASE_URL_FORMAT, version); |
49 | 82 |
} |
50 | 83 |
|
84 |
+ public static void refreshVersionToUpdate() throws GitAPIException { |
|
85 |
+ versionToUpdate = fetchVersionToUpdate(); |
|
86 |
+ } |
|
87 |
+ |
|
51 | 88 |
/** |
52 | 89 |
* Fetch the latest version to update. |
53 | 90 |
* |
--- app/views/layout.scala.html
+++ app/views/layout.scala.html
... | ... | @@ -40,6 +40,7 @@ |
40 | 40 |
</head> |
41 | 41 |
|
42 | 42 |
<body class="@theme"> |
43 |
+@partial_update_notification() |
|
43 | 44 |
@content |
44 | 45 |
@common.scripts() |
45 | 46 |
</body> |
+++ app/views/partial_update_notification.scala.html
... | ... | @@ -0,0 +1,29 @@ |
1 | +@** | |
2 | +* Yobi, Project Hosting SW | |
3 | +* | |
4 | +* Copyright 2014 NAVER Corp. | |
5 | +* http://yobi.io | |
6 | +* | |
7 | +* @Author Yi EungJun | |
8 | +* | |
9 | +* Licensed under the Apache License, Version 2.0 (the "License"); | |
10 | +* you may not use this file except in compliance with the License. | |
11 | +* You may obtain a copy of the License at | |
12 | +* | |
13 | +* http://www.apache.org/licenses/LICENSE-2.0 | |
14 | +* | |
15 | +* Unless required by applicable law or agreed to in writing, software | |
16 | +* distributed under the License is distributed on an "AS IS" BASIS, | |
17 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
18 | +* See the License for the specific language governing permissions and | |
19 | +* limitations under the License. | |
20 | +**@ | |
21 | + | |
22 | +@import models.YobiUpdate | |
23 | + | |
24 | +@if(UserApp.currentUser().isSiteManager() && YobiUpdate.isWatched && YobiUpdate.versionToUpdate != null){ | |
25 | +<p class="center-txt"> | |
26 | +<a href="@YobiUpdate.getReleaseUrl()">@Messages("site.update.notification", YobiUpdate.versionToUpdate)</a> | |
27 | +<button type="button" data-request-method="post" data-request-uri="@routes.SiteApp.unwatchUpdate()" class="ybtn ybtn-small">@Messages("site.update.notification.hide", YobiUpdate.versionToUpdate)</button> | |
28 | +</p> | |
29 | +} |
--- conf/application.conf.default
+++ conf/application.conf.default
... | ... | @@ -129,6 +129,8 @@ |
129 | 129 |
|
130 | 130 |
# Software Update |
131 | 131 |
# ~~~~~~~~~~~~~~~ |
132 |
+# Check for updates of Yobi at this interval if it is grater than 0. |
|
133 |
+application.update.notification.interval = 1d |
|
132 | 134 |
# A url to the git repository for Yobi releases. |
133 | 135 |
application.update.repositoryUrl = "https://github.com/naver/yobi" |
134 | 136 |
# A format to construct the url to latest Yobi release. "%s" is a format |
--- conf/messages
+++ conf/messages
... | ... | @@ -678,6 +678,8 @@ |
678 | 678 |
site.update.isAvailable = Yobi {0} is available |
679 | 679 |
site.update.isNotNecessary = You are using the latest version |
680 | 680 |
site.update.error = Failed to check for updates because of the following error: |
681 |
+site.update.notification = Software update: Yobi {0} is available |
|
682 |
+site.update.notification.hide = Hide |
|
681 | 683 |
site.user.delete = Delete user |
682 | 684 |
site.user.deleteConfirm = Are you sure you want this user to leave? |
683 | 685 |
site.userList.deleteAlert = This user cannot be deleted because this user is the only manager of the project. |
--- conf/messages.ko
+++ conf/messages.ko
... | ... | @@ -678,6 +678,8 @@ |
678 | 678 |
site.update.error = 다음과 같이 에러가 발생하여 업데이트 할 버전을 확인하지 못했습니다. |
679 | 679 |
site.update.isAvailable = Yobi {0} 버전으로 업데이트 할 수 있습니다 |
680 | 680 |
site.update.isNotNecessary = 현재 최신 버전을 사용중입니다 |
681 |
+site.update.notification = 업데이트 알림: Yobi {0} 버전이 나왔습니다 |
|
682 |
+site.update.notification.hide = 숨기기 |
|
681 | 683 |
site.user.delete = 사용자 삭제 |
682 | 684 |
site.user.deleteConfirm = 정말로 해당 사용자를 사이트에서 탈퇴시키겠습니까? |
683 | 685 |
site.userList.deleteAlert = 프로젝트의 유일한 관리자이므로 사이트에서 삭제할 수 없습니다. |
--- conf/routes
+++ conf/routes
... | ... | @@ -71,6 +71,7 @@ |
71 | 71 |
DELETE /sites/project/delete/:projectId controllers.SiteApp.deleteProject(projectId:Long) |
72 | 72 |
POST /sites/toggleAccountLock controllers.SiteApp.toggleAccountLock(loginId: String, state: String ?= null, query: String ?= null) |
73 | 73 |
GET /sites/update controllers.SiteApp.update() |
74 |
+POST /sites/unwatchUpdate controllers.SiteApp.unwatchUpdate() |
|
74 | 75 |
GET /lostPassword controllers.PasswordResetApp.lostPassword |
75 | 76 |
POST /lostPassword controllers.PasswordResetApp.requestResetPasswordEmail() |
76 | 77 |
GET /resetPassword controllers.PasswordResetApp.resetPasswordForm(s:String) |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?