Skip to content

Commit bb3f755

Browse files
author
Marcelo Rodrigues Da Silva Soares
committed
Merge branch 'feat/create_database_notification' into 'dev'
Database create notification See merge request dbdev/dbaas!15
2 parents e7c4d4c + c4bfd1d commit bb3f755

File tree

4 files changed

+74
-8
lines changed

4 files changed

+74
-8
lines changed

dbaas/notification/tasks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def create_database(
151151
database_create.set_success()
152152
task.set_status_success('Database created')
153153
database_create.database.finish_task()
154+
email_notifications.notify_new_database_creation(database_create)
154155
else:
155156
database_create.set_error()
156157
task.set_status_error(
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<h2>{{ database_name }} database was created</h2>
2+
3+
Database <a href="{{ database_url }}">{{ database_name }}</a> was created in DBaaS in environment {{ environment }} by user {{ user }}.
4+
<br><br>
5+
The database features are:
6+
- Offering: {{ offering }}
7+
- Database type: {{ database_type }}
8+
- Disk size: {{ disk_size }}
9+
<br><br>
10+
Any questions please contact the DBDevops responsible for your team.
11+
<br><br>
12+
13+
{% if database.team.email %}
14+
You are receiving this email because in our records you are in team {{ database.team.name }}.<br>
15+
If this is not right, contact the DBaaS system administrators.
16+
{% else %}
17+
<h3>Team {{ database.team.name }} has no email set!</h3>
18+
{% endif %}
19+
<br><br><br>
20+
Regards,<br>
21+
DBaaS notification robot<br>
22+
{{domain}}<br>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Database {{ database_name }} was created in DBaaS in environment {{ environment }} by user {{ user }}.
2+
3+
The database features are:
4+
- Offering: {{ offering }}
5+
- Database type: {{ database_type }}
6+
- Disc size: {{ disk_size }}
7+
8+
Any questions please contact the DBDevops responsible for your team.
9+
10+
{% if database.team.email %}
11+
You are receiving this email because in our records you are in team {{ database.team.name }}.<br>
12+
If this is not right, contact the DBaaS system administrators.
13+
{% else %}
14+
Team {{ database.team.name }} has no email set!
15+
{% endif %}
16+
17+
Regards,
18+
DBaaS notification robot
19+
{{domain}}

dbaas/util/email_notifications.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def get_domain():
1414
domain = Site.objects.get(id=1).domain
1515
if not domain.startswith('http'):
1616
return "http://" + domain
17-
1817
return domain
1918

2019

@@ -29,25 +28,50 @@ def email_to(team):
2928

3029

3130
def get_database_url(uuid):
32-
return get_domain() + reverse('admin:logical_database_hosts',
33-
kwargs={'id': uuid})
31+
return get_domain() + reverse('admin:logical_database_hosts', kwargs={'id': uuid})
32+
33+
34+
def notify_new_database_creation(database=None):
35+
subject = _("[DBAAS] a new database has just been created: {} by {}".format(database.name, database.team.name))
36+
template = "database_create_notification"
37+
addr_from = Configuration.get_by_name("email_addr_from")
38+
addr_to = Configuration.get_by_name_as_list("new_user_notify_email")
39+
domain = get_domain()
40+
41+
context = {
42+
"database": database,
43+
"database_name": database.name,
44+
"offering": database.infra.offering.name,
45+
"environment": database.environment.name,
46+
"database_type": database.infra.engine.name,
47+
"disk_size": database.infra.disk_offering.name,
48+
"user": database.user,
49+
"database_url": domain + reverse('admin:account_team_changelist'),
50+
"domain": domain
51+
}
52+
LOG.debug("user: %s | addr_from: %s | addr_to: %s" % (database.user, addr_from, addr_to))
53+
if database.user and addr_from and addr_to:
54+
send_mail_template(
55+
subject, template, addr_from, addr_to, fail_silently=False, attachments=None, context=context
56+
)
57+
else:
58+
LOG.warning("could not send email for new user creation")
3459

3560

3661
def notify_new_user_creation(user=None):
3762
subject = _("[DBAAS] a new user has just been created: %s" % user.username)
3863
template = "new_user_notification"
3964
addr_from = Configuration.get_by_name("email_addr_from")
4065
addr_to = Configuration.get_by_name_as_list("new_user_notify_email")
66+
4167
context = {}
4268
context['user'] = user
4369
domain = get_domain()
4470
context['url'] = domain + reverse('admin:account_team_changelist')
45-
LOG.debug("user: %s | addr_from: %s | addr_to: %s" %
46-
(user, addr_from, addr_to))
71+
LOG.debug("user: %s | addr_from: %s | addr_to: %s" % (user, addr_from, addr_to))
4772
if user and addr_from and addr_to:
4873
send_mail_template(
49-
subject, template, addr_from, addr_to,
50-
fail_silently=False, attachments=None, context=context
74+
subject, template, addr_from, addr_to, fail_silently=False, attachments=None, context=context
5175
)
5276
else:
5377
LOG.warning("could not send email for new user creation")
@@ -163,7 +187,7 @@ def upgrade_offering_notification(database, resize_target):
163187
current_offering = database.databaseinfra.offering
164188
future_offering = database.get_future_offering(resize_target)
165189

166-
subject = _('[DBaaS] Database {} auto upgrade offering to {}').format(database, future_offering.name)
190+
subject = _('[DBaaS] Database {} is being auto upgrade offering to {}').format(database, future_offering.name)
167191
template = "auto_upgrade_offering_notification"
168192

169193
context = {

0 commit comments

Comments
 (0)