Commit ac117e8c authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

Refactor notifications

parent 8e2973fd
......@@ -68,6 +68,10 @@ from astakos.im.models import (
AstakosUser, ProjectMembership, ProjectApplication, Project,
trigger_sync)
from astakos.im.models import submit_application as models_submit_application
from astakos.im.project_notif import (
membership_change_notify,
application_submit_notify, application_approve_notify,
project_termination_notify, project_suspension_notify)
import astakos.im.messages as astakos_messages
......@@ -475,16 +479,8 @@ def do_accept_membership(project_id, user, request_user=None):
membership.accept()
trigger_sync()
try:
notification = build_notification(
settings.SERVER_EMAIL,
[membership.person.email],
_(PROJECT_MEMBERSHIP_CHANGE_SUBJECT) % project.__dict__,
template='im/projects/project_membership_change_notification.txt',
dictionary={'object':project.application, 'action':'accepted'})
notification.send()
except NotificationError, e:
logger.error(e.message)
membership_change_notify(project, membership.person, 'accepted')
return membership
def reject_membership(project_application_id, user, request_user=None):
......@@ -507,16 +503,8 @@ def do_reject_membership(project_id, user, request_user=None):
membership = get_membership_for_update(project, user)
membership.reject()
try:
notification = build_notification(
settings.SERVER_EMAIL,
[membership.person.email],
_(PROJECT_MEMBERSHIP_CHANGE_SUBJECT) % project.__dict__,
template='im/projects/project_membership_change_notification.txt',
dictionary={'object':project.application, 'action':'rejected'})
notification.send()
except NotificationError, e:
logger.error(e.message)
membership_change_notify(project, membership.person, 'rejected')
return membership
def remove_membership(project_application_id, user, request_user=None):
......@@ -544,16 +532,8 @@ def do_remove_membership(project_id, user, request_user=None):
membership.remove()
trigger_sync()
try:
notification = build_notification(
settings.SERVER_EMAIL,
[membership.person.email],
_(PROJECT_MEMBERSHIP_CHANGE_SUBJECT) % project.__dict__,
template='im/projects/project_membership_change_notification.txt',
dictionary={'object':project.application, 'action':'removed'})
notification.send()
except NotificationError, e:
logger.error(e.message)
membership_change_notify(project, membership.person, 'removed')
return membership
def enroll_member(project_application_id, user, request_user=None):
......@@ -648,17 +628,8 @@ def submit_application(kw, request_user=None):
application = models_submit_application(**kw)
try:
notification = build_notification(
settings.SERVER_EMAIL,
[i[1] for i in settings.ADMINS],
_(PROJECT_CREATION_SUBJECT) % application.__dict__,
template='im/projects/project_creation_notification.txt',
dictionary={'object':application})
notification.send()
except NotificationError, e:
logger.error(e)
return application.id
application_submit_notify(application)
return application
def update_application(app_id, **kw):
app = ProjectApplication.objects.get(id=app_id)
......@@ -687,16 +658,7 @@ def approve_application(app):
application.approve()
trigger_sync()
try:
notification = build_notification(
settings.SERVER_EMAIL,
[application.owner.email],
_(PROJECT_APPROVED_SUBJECT) % application.__dict__,
template='im/projects/project_approval_notification.txt',
dictionary={'object':application})
notification.send()
except NotificationError, e:
logger.error(e.message)
application_approve_notify(application)
def terminate(project_id):
project = get_project_for_update(project_id)
......@@ -705,16 +667,7 @@ def terminate(project_id):
project.terminate()
trigger_sync()
try:
notification = build_notification(
settings.SERVER_EMAIL,
[project.application.owner.email],
_(PROJECT_TERMINATION_SUBJECT) % project.__dict__,
template='im/projects/project_termination_notification.txt',
dictionary={'object':project.application}
).send()
except NotificationError, e:
logger.error(e.message)
project_termination_notify(project)
def suspend(project_id):
project = get_project_by_id(project_id)
......@@ -722,13 +675,4 @@ def suspend(project_id):
project.save()
trigger_sync()
try:
notification = build_notification(
settings.SERVER_EMAIL,
[project.application.owner.email],
_(PROJECT_SUSPENSION_SUBJECT) % project.__dict__,
template='im/projects/project_suspension_notification.txt',
dictionary={'object':project.application}
).send()
except NotificationError, e:
logger.error(e.message)
project_suspension_notify(project)
import logging
from django.utils.translation import ugettext as _
import astakos.im.settings as settings
from astakos.im.notifications import build_notification, NotificationError
logger = logging.getLogger(__name__)
MEM_CHANGE_NOTIF = {
'subject' : _(settings.PROJECT_MEMBERSHIP_CHANGE_SUBJECT),
'template': 'im/projects/project_membership_change_notification.txt',
}
SENDER = settings.SERVER_EMAIL
ADMINS = settings.ADMINS
def membership_change_notify(project, user, action):
try:
notification = build_notification(
SENDER,
[user.email],
MEM_CHANGE_NOTIF['subject'] % project.__dict__,
template= MEM_CHANGE_NOTIF['template'],
dictionary={'object':project, 'action':action})
notification.send()
except NotificationError, e:
logger.error(e.message)
def application_submit_notify(application):
try:
notification = build_notification(
SENDER,
[i[1] for i in ADMINS],
_(settings.PROJECT_CREATION_SUBJECT) % application.__dict__,
template='im/projects/project_creation_notification.txt',
dictionary={'object':application})
notification.send()
except NotificationError, e:
logger.error(e.message)
def application_approve_notify(application):
try:
notification = build_notification(
SENDER,
[application.owner.email],
_(settings.PROJECT_APPROVED_SUBJECT) % application.__dict__,
template='im/projects/project_approval_notification.txt',
dictionary={'object':application})
notification.send()
except NotificationError, e:
logger.error(e.message)
def project_termination_notify(project):
try:
notification = build_notification(
SENDER,
[project.application.owner.email],
_(settings.PROJECT_TERMINATION_SUBJECT) % project.__dict__,
template='im/projects/project_termination_notification.txt',
dictionary={'object':project}
).send()
except NotificationError, e:
logger.error(e.message)
def project_suspension_notify(project):
try:
notification = build_notification(
SENDER,
[project.application.owner.email],
_(settings.PROJECT_SUSPENSION_SUBJECT) % project.__dict__,
template='im/projects/project_suspension_notification.txt',
dictionary={'object':project}
).send()
except NotificationError, e:
logger.error(e.message)
......@@ -33,6 +33,9 @@ INVITATIONS_PER_LEVEL = getattr(settings, 'ASTAKOS_INVITATIONS_PER_LEVEL', {
DEFAULT_CONTACT_EMAIL = getattr(
settings, 'ASTAKOS_DEFAULT_CONTACT_EMAIL', 'support@cloud.grnet.gr')
SERVER_EMAIL = getattr(settings, 'SERVER_EMAIL', None)
ADMINS = getattr(settings, 'ADMINS', None)
# Identity Management enabled modules
# Supported modules are: 'local', 'twitter' and 'shibboleth'
IM_MODULES = getattr(settings, 'ASTAKOS_IM_MODULES', ['local'])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment