##// END OF EJS Templates
automation: enabled automated check for new versions.
milka -
r4634:836f1886 stable
parent child Browse files
Show More
@@ -0,0 +1,32 b''
1 ## -*- coding: utf-8 -*-
2 <%inherit file="base.mako"/>
3
4 <%def name="subject()" filter="n,trim,whitespace_filter">
5 New Version of RhodeCode is available !
6 </%def>
7
8 ## plain text version of the email. Empty by default
9 <%def name="body_plaintext()" filter="n,trim">
10 A new version of RhodeCode is available!
11
12 Your version: ${current_ver}
13 New version: ${latest_ver}
14
15 Release notes:
16
17 https://docs.rhodecode.com/RhodeCode-Enterprise/release-notes/release-notes-${latest_ver}.html
18 </%def>
19
20 ## BODY GOES BELOW
21
22 <h3>A new version of RhodeCode is available!</h3>
23 <br/>
24 Your version: ${current_ver}<br/>
25 New version: <strong>${latest_ver}</strong><br/>
26
27 <h4>Release notes</h4>
28
29 <a href="https://docs.rhodecode.com/RhodeCode-Enterprise/release-notes/release-notes-${latest_ver}.html">
30 https://docs.rhodecode.com/RhodeCode-Enterprise/release-notes/release-notes-${latest_ver}.html
31 </a>
32
@@ -102,6 +102,11 b' Check if we should use full-topic or min'
102 'date': datetime.datetime.now(),
102 'date': datetime.datetime.now(),
103 },
103 },
104
104
105 'update_available': {
106 'current_ver': '4.23.0',
107 'latest_ver': '4.24.0',
108 },
109
105 'exception': {
110 'exception': {
106 'email_prefix': '[RHODECODE ERROR]',
111 'email_prefix': '[RHODECODE ERROR]',
107 'exc_id': exc_traceback['exc_id'],
112 'exc_id': exc_traceback['exc_id'],
@@ -33,9 +33,9 b' from email.utils import formatdate'
33
33
34 import rhodecode
34 import rhodecode
35 from rhodecode.lib import audit_logger
35 from rhodecode.lib import audit_logger
36 from rhodecode.lib.celerylib import get_logger, async_task, RequestContextTask
36 from rhodecode.lib.celerylib import get_logger, async_task, RequestContextTask, run_task
37 from rhodecode.lib import hooks_base
37 from rhodecode.lib import hooks_base
38 from rhodecode.lib.utils2 import safe_int, str2bool
38 from rhodecode.lib.utils2 import safe_int, str2bool, aslist
39 from rhodecode.model.db import (
39 from rhodecode.model.db import (
40 Session, IntegrityError, true, Repository, RepoGroup, User)
40 Session, IntegrityError, true, Repository, RepoGroup, User)
41
41
@@ -338,15 +338,39 b' def repo_maintenance(repoid):'
338
338
339
339
340 @async_task(ignore_result=True)
340 @async_task(ignore_result=True)
341 def check_for_update():
341 def check_for_update(send_email_notification=True, email_recipients=None):
342 from rhodecode.model.update import UpdateModel
342 from rhodecode.model.update import UpdateModel
343 from rhodecode.model.notification import EmailNotificationModel
344
345 log = get_logger(check_for_update)
343 update_url = UpdateModel().get_update_url()
346 update_url = UpdateModel().get_update_url()
344 cur_ver = rhodecode.__version__
347 cur_ver = rhodecode.__version__
345
348
346 try:
349 try:
347 data = UpdateModel().get_update_data(update_url)
350 data = UpdateModel().get_update_data(update_url)
348 latest = data['versions'][0]
351
349 UpdateModel().store_version(latest['version'])
352 current_ver = UpdateModel().get_stored_version(fallback=cur_ver)
353 latest_ver = data['versions'][0]['version']
354 UpdateModel().store_version(latest_ver)
355
356 if send_email_notification:
357 log.debug('Send email notification is enabled. '
358 'Current RhodeCode version: %s, latest known: %s', current_ver, latest_ver)
359 if UpdateModel().is_outdated(current_ver, latest_ver):
360
361 email_kwargs = {
362 'current_ver': current_ver,
363 'latest_ver': latest_ver,
364 }
365
366 (subject, email_body, email_body_plaintext) = EmailNotificationModel().render_email(
367 EmailNotificationModel.TYPE_UPDATE_AVAILABLE, **email_kwargs)
368
369 email_recipients = aslist(email_recipients, sep=',') or \
370 [user.email for user in User.get_all_super_admins()]
371 run_task(send_email, email_recipients, subject,
372 email_body_plaintext, email_body)
373
350 except Exception:
374 except Exception:
351 pass
375 pass
352
376
@@ -343,6 +343,7 b' class EmailNotificationModel(BaseModel):'
343 TYPE_PASSWORD_RESET_CONFIRMATION = 'password_reset_confirmation'
343 TYPE_PASSWORD_RESET_CONFIRMATION = 'password_reset_confirmation'
344 TYPE_EMAIL_TEST = 'email_test'
344 TYPE_EMAIL_TEST = 'email_test'
345 TYPE_EMAIL_EXCEPTION = 'exception'
345 TYPE_EMAIL_EXCEPTION = 'exception'
346 TYPE_UPDATE_AVAILABLE = 'update_available'
346 TYPE_TEST = 'test'
347 TYPE_TEST = 'test'
347
348
348 email_types = {
349 email_types = {
@@ -352,6 +353,8 b' class EmailNotificationModel(BaseModel):'
352 'rhodecode:templates/email_templates/test.mako',
353 'rhodecode:templates/email_templates/test.mako',
353 TYPE_EMAIL_EXCEPTION:
354 TYPE_EMAIL_EXCEPTION:
354 'rhodecode:templates/email_templates/exception_tracker.mako',
355 'rhodecode:templates/email_templates/exception_tracker.mako',
356 TYPE_UPDATE_AVAILABLE:
357 'rhodecode:templates/email_templates/update_available.mako',
355 TYPE_EMAIL_TEST:
358 TYPE_EMAIL_TEST:
356 'rhodecode:templates/email_templates/email_test.mako',
359 'rhodecode:templates/email_templates/email_test.mako',
357 TYPE_REGISTRATION:
360 TYPE_REGISTRATION:
@@ -60,11 +60,11 b' class UpdateModel(BaseModel):'
60 Session().add(setting)
60 Session().add(setting)
61 Session().commit()
61 Session().commit()
62
62
63 def get_stored_version(self):
63 def get_stored_version(self, fallback=None):
64 obj = SettingsModel().get_setting_by_name(self.UPDATE_SETTINGS_KEY)
64 obj = SettingsModel().get_setting_by_name(self.UPDATE_SETTINGS_KEY)
65 if obj:
65 if obj:
66 return obj.app_settings_value
66 return obj.app_settings_value
67 return '0.0.0'
67 return fallback or '0.0.0'
68
68
69 def _sanitize_version(self, version):
69 def _sanitize_version(self, version):
70 """
70 """
General Comments 0
You need to be logged in to leave comments. Login now