Commit 9f717bb7 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis Committed by Georgios D. Tsoukalas
Browse files

Add membership notifications

parent a7f83de7
......@@ -70,6 +70,7 @@ from astakos.im.models import (
PendingMembershipError, get_resource_names, new_chain)
from astakos.im.project_notif import (
membership_change_notify, membership_enroll_notify,
membership_request_notify, membership_leave_request_notify,
application_submit_notify, application_approve_notify,
application_deny_notify,
project_termination_notify, project_suspension_notify)
......@@ -615,13 +616,16 @@ def leave_project(project_id, user_id):
m = _(astakos_messages.NOT_ACCEPTED_MEMBERSHIP)
raise PermissionDenied(m)
auto_accepted = False
leave_policy = project.application.member_leave_policy
if leave_policy == AUTO_ACCEPT_POLICY:
membership.remove()
auto_accepted = True
else:
membership.leave_request_date = datetime.now()
membership.save()
return membership
membership_leave_request_notify(project, membership.person)
return auto_accepted
def join_project_checks(project):
checkAlive(project)
......@@ -644,11 +648,16 @@ def join_project(project_id, user_id):
join_project_checks(project)
membership = create_membership(project, user_id)
auto_accepted = False
join_policy = project.application.member_join_policy
if (join_policy == AUTO_ACCEPT_POLICY and
not project.violates_members_limit(adding=1)):
membership.accept()
return membership
auto_accepted = True
else:
membership_request_notify(project, membership.person)
return auto_accepted
def submit_application(kw, request_user=None):
......
......@@ -65,7 +65,7 @@ EMAIL_CHANGE_REGISTERED = 'Your request for changing your emai
OBJECT_CREATED = 'The %(verbose_name)s was created successfully.'
USER_JOINED_GROUP = 'User %(realname)s joined the project.'
USER_LEFT_GROUP = 'User %(realname)s left the project.'
USER_MEMBERSHIP_REJECTED = 'User\'s %(realname)s request to join the project has been rejected.'
USER_MEMBERSHIP_REJECTED = '%(realname)s\'s request to join the project has been rejected.'
MEMBER_REMOVED = 'User %(realname)s has been successfully removed from the project.'
BILLING_ERROR = 'Service response status: %(status)d'
LOGOUT_SUCCESS = 'Logged out successfully.'
......@@ -185,9 +185,12 @@ UNKNOWN_PROJECT_APPLICATION_ID = 'There is no project application ide
UNKNOWN_PROJECT_ID = 'There is no project identified by %s.'
UNKNOWN_IDENTIFIER = 'Unknown identifier.'
PENDING_MEMBERSHIP_LEAVE = 'Your request is pending moderation by the Project owner.'
USER_JOINED_PROJECT = '%(realname)s has joined the Project.'
USER_LEFT_PROJECT = '%(realname)s has left the Project.'
USER_JOIN_REQUEST_SUBMITED = 'Your request to join the project has been submitted successfully.'
USER_MEMBERSHIP_ACCEPTED = '%(realname)s has been accepted in the project.'
USER_LEFT_PROJECT = 'You have left the project.'
USER_LEAVE_REQUEST_SUBMITTED = 'Your request to leave the project has been submitted successfully.'
USER_JOIN_REQUEST_SUBMITTED = 'Your request to join the project has been submitted successfully.'
USER_JOINED_PROJECT = 'You have joined the project.'
USER_REQUEST_CANCELLED = 'Your request to join the project has been cancelled.'
APPLICATION_CANNOT_APPROVE = "Cannot approve application %s in state '%s'"
APPLICATION_CANNOT_DENY = "Cannot deny application %s in state '%s'"
......
......@@ -42,6 +42,30 @@ def membership_enroll_notify(project, user):
except NotificationError, e:
logger.error(e.message)
def membership_request_notify(project, requested_user):
try:
notification = build_notification(
SENDER,
[project.application.owner.email],
_(settings.PROJECT_MEMBERSHIP_REQUEST_SUBJECT) % project.__dict__,
template= 'im/projects/project_membership_request_notification.txt',
dictionary={'object':project, 'user':requested_user.realname})
notification.send()
except NotificationError, e:
logger.error(e.message)
def membership_leave_request_notify(project, requested_user):
try:
notification = build_notification(
SENDER,
[project.application.owner.email],
_(settings.PROJECT_MEMBERSHIP_LEAVE_REQUEST_SUBJECT) % project.__dict__,
template= 'im/projects/project_membership_leave_request_notification.txt',
dictionary={'object':project, 'user':requested_user.realname})
notification.send()
except NotificationError, e:
logger.error(e.message)
def application_submit_notify(application):
try:
notification = build_notification(
......
......@@ -164,6 +164,12 @@ PROJECT_MEMBERSHIP_CHANGE_SUBJECT = getattr(
PROJECT_MEMBERSHIP_ENROLL_SUBJECT = getattr(
settings, 'ASTAKOS_PROJECT_MEMBERSHIP_ENROLL_SUBJECT',
'%s alpha2 testing project enrollment (%%(name)s)' % SITENAME)
PROJECT_MEMBERSHIP_REQUEST_SUBJECT = getattr(
settings, 'ASTAKOS_PROJECT_MEMBERSHIP_REQUEST_SUBJECT',
'%s alpha2 testing project membership request (%%(name)s)' % SITENAME)
PROJECT_MEMBERSHIP_LEAVE_REQUEST_SUBJECT = getattr(
settings, 'ASTAKOS_PROJECT_MEMBERSHIP_LEAVE_REQUEST_SUBJECT',
'%s alpha2 testing project membership leave request (%%(name)s)' % SITENAME)
# Set the quota holder component URI
QUOTAHOLDER_URL = getattr(settings, 'ASTAKOS_QUOTAHOLDER_URL', '')
......
--- A translation in English follows ---
Ο χρήστης {{user}} επιθυμεί να διαγραφεί από το project {{object.name}}.
--
User {{user}} requests to leave project {{object.name}}.
--- A translation in English follows ---
Ο χρήστης {{user}} επιθυμεί να συμμετάσχει στο project {{object.name}}.
--
User {{user}} requests to join project {{object.name}}.
......@@ -1343,9 +1343,12 @@ def project_join(request, chain_id, ctx=None):
try:
chain_id = int(chain_id)
join_project(chain_id, request.user)
# TODO: distinct messages for request/auto accept ???
messages.success(request, _(astakos_messages.USER_JOIN_REQUEST_SUBMITED))
auto_accepted = join_project(chain_id, request.user)
if auto_accepted:
m = _(astakos_messages.USER_JOINED_PROJECT)
else:
m = _(astakos_messages.USER_JOIN_REQUEST_SUBMITTED)
messages.success(request, m)
except (IOError, PermissionDenied), e:
messages.error(request, e)
except BaseException, e:
......@@ -1367,7 +1370,12 @@ def project_leave(request, chain_id, ctx=None):
try:
chain_id = int(chain_id)
leave_project(chain_id, request.user)
auto_accepted = leave_project(chain_id, request.user)
if auto_accepted:
m = _(astakos_messages.USER_LEFT_PROJECT)
else:
m = _(astakos_messages.USER_LEAVE_REQUEST_SUBMITTED)
messages.success(request, m)
except (IOError, PermissionDenied), e:
messages.error(request, e)
except PendingMembershipError as e:
......@@ -1392,6 +1400,8 @@ def project_cancel(request, chain_id, ctx=None):
try:
chain_id = int(chain_id)
cancel_membership(chain_id, request.user)
m = _(astakos_messages.USER_REQUEST_CANCELLED)
messages.success(request, m)
except (IOError, PermissionDenied), e:
messages.error(request, e)
except PendingMembershipError as e:
......@@ -1425,7 +1435,7 @@ def project_accept_member(request, chain_id, user_id, ctx=None):
ctx.mark_rollback()
else:
realname = escape(m.person.realname)
msg = _(astakos_messages.USER_JOINED_PROJECT) % locals()
msg = _(astakos_messages.USER_MEMBERSHIP_ACCEPTED) % locals()
messages.success(request, msg)
return redirect(reverse('project_detail', args=(chain_id,)))
......@@ -1473,7 +1483,7 @@ def project_reject_member(request, chain_id, user_id, ctx=None):
ctx.mark_rollback()
else:
realname = escape(m.person.realname)
msg = _(astakos_messages.USER_LEFT_PROJECT) % locals()
msg = _(astakos_messages.USER_MEMBERSHIP_REJECTED) % locals()
messages.success(request, msg)
return redirect(reverse('project_detail', args=(chain_id,)))
......
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