Commit 5c19e96f authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

Several fixes

parent c93e0444
......@@ -45,6 +45,7 @@ from django.contrib.auth import (
from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.core.exceptions import PermissionDenied
from django.db import IntegrityError
from urllib import quote
from urlparse import urljoin
......@@ -63,7 +64,9 @@ from astakos.im.settings import (
PROJECT_MEMBERSHIP_CHANGE_SUBJECT)
from astakos.im.notifications import build_notification, NotificationError
from astakos.im.models import (
ProjectMembership, ProjectApplication, trigger_sync)
AstakosUser, ProjectMembership, ProjectApplication, Project,
trigger_sync, get_closed_join, get_auto_accept_join,
get_auto_accept_leave, get_closed_leave)
import astakos.im.messages as astakos_messages
......@@ -424,7 +427,7 @@ def get_project_by_application_id(project_application_id):
def get_user_by_id(user_id):
try:
return AstakosUser.objects.get(user__id=user_id)
return AstakosUser.objects.get(id=user_id)
except AstakosUser.DoesNotExist:
raise IOError(_(astakos_messages.UNKNOWN_USER_ID) % user_id)
......@@ -433,7 +436,7 @@ def create_membership(project_application_id, user_id):
project = get_project_by_application_id(project_application_id)
m = ProjectMembership(
project=project,
person__id=user_id,
person=user_id,
request_date=datetime.now())
except IntegrityError, e:
raise IOError(_(astakos_messages.MEMBERSHIP_REQUEST_EXISTS))
......@@ -441,9 +444,9 @@ def create_membership(project_application_id, user_id):
m.save()
def get_membership(project, user):
if isinstace(project, int):
if isinstance(project, int):
project = get_project_by_application_id(project)
if isinstace(user, int):
if isinstance(user, int):
user = get_user_by_id(user)
try:
return ProjectMembership.objects.select_related().get(
......@@ -452,7 +455,7 @@ def get_membership(project, user):
except ProjectMembership.DoesNotExist:
raise IOError(_(astakos_messages.NOT_MEMBERSHIP_REQUEST))
def accept_membership(request, project, user, request_user=None):
def accept_membership(project, user, request_user=None):
"""
Raises:
django.core.exceptions.PermissionDenied
......@@ -460,14 +463,14 @@ def accept_membership(request, project, user, request_user=None):
"""
membership = get_membership(project, user)
if request_user and \
(not membership.project.current_application.owner == request_user and \
(not membership.project.application.owner == request_user and \
not request_user.is_superuser):
raise PermissionDenied(_(astakos_messages.NOT_ALLOWED))
if not self.project.is_alive:
if not membership.project.is_alive:
raise PermissionDenied(
_(astakos_messages.NOT_ALIVE_PROJECT) % membership.project.__dict__)
if len(self.project.approved_members) + 1 > \
self.project.definition.limit_on_members_number:
if len(membership.project.approved_members) + 1 > \
membership.project.application.limit_on_members_number:
raise PermissionDenied(_(astakos_messages.MEMBER_NUMBER_LIMIT_REACHED))
membership.accept()
......@@ -476,10 +479,10 @@ def accept_membership(request, project, user, request_user=None):
try:
notification = build_notification(
settings.SERVER_EMAIL,
[self.person.email],
_(PROJECT_MEMBERSHIP_CHANGE_SUBJECT) % membership.project.definition.__dict__,
[membership.person.email],
_(PROJECT_MEMBERSHIP_CHANGE_SUBJECT) % membership.project.__dict__,
template='im/projects/project_membership_change_notification.txt',
dictionary={'object':membership.project.current_application, 'action':'accepted'})
dictionary={'object':membership.project.application, 'action':'accepted'})
notification.send()
except NotificationError, e:
logger.error(e.messages)
......@@ -493,21 +496,21 @@ def reject_membership(project, user, request_user=None):
"""
membership = get_membership(project, user)
if request_user and \
(not membership.project.current_application.owner == request_user and \
(not membership.project.application.owner == request_user and \
not request_user.is_superuser):
raise PermissionDenied(_(astakos_messages.NOT_ALLOWED))
if not membership.project.is_alive:
raise PermissionDenied(_(astakos_messages.NOT_ALIVE_PROJECT) % project.__dict__)
raise PermissionDenied(_(astakos_messages.NOT_ALIVE_PROJECT) % membership.project.__dict__)
membership.reject()
try:
notification = build_notification(
settings.SERVER_EMAIL,
[self.person.email],
_(PROJECT_MEMBERSHIP_CHANGE_SUBJECT) % self.project.definition.__dict__,
[membership.person.email],
_(PROJECT_MEMBERSHIP_CHANGE_SUBJECT) % membership.project.__dict__,
template='im/projects/project_membership_change_notification.txt',
dictionary={'object':self.project.current_application, 'action':'rejected'})
dictionary={'object':membership.project.application, 'action':'rejected'})
notification.send()
except NotificationError, e:
logger.error(e.messages)
......@@ -521,10 +524,10 @@ def remove_membership(project, user, request_user=None):
"""
membership = get_membership(project, user)
if request_user and \
(not membership.project.current_application.owner == request_user and \
(not membership.project.application.owner == request_user and \
not request_user.is_superuser):
raise PermissionDenied(_(astakos_messages.NOT_ALLOWED))
if not self.project.is_alive:
if not membership.project.is_alive:
raise PermissionDenied(_(astakos_messages.NOT_ALIVE_PROJECT) % membership.project.__dict__)
membership.remove()
......@@ -533,10 +536,10 @@ def remove_membership(project, user, request_user=None):
try:
notification = build_notification(
settings.SERVER_EMAIL,
[self.person.email],
_(PROJECT_MEMBERSHIP_CHANGE_SUBJECT) % membership.project.definition.__dict__,
[membership.person.email],
_(PROJECT_MEMBERSHIP_CHANGE_SUBJECT) % membership.project.__dict__,
template='im/projects/project_membership_change_notification.txt',
dictionary={'object':membership.project.current_application, 'action':'removed'})
dictionary={'object':membership.project.application, 'action':'removed'})
notification.send()
except NotificationError, e:
logger.error(e.messages)
......@@ -549,7 +552,7 @@ def leave_project(project_application_id, user_id):
IOError
"""
project = get_project_by_application_id(project_application_id)
leave_policy = project.current_application.definition.member_join_policy
leave_policy = project.application.member_join_policy
if leave_policy == get_closed_leave():
raise PermissionDenied(_(astakos_messages.MEMBER_LEAVE_POLICY_CLOSED))
......@@ -569,7 +572,7 @@ def join_project(project_application_id, user_id):
IOError
"""
project = get_project_by_application_id(project_application_id)
join_policy = project.current_application.definition.member_join_policy
join_policy = project.application.member_join_policy
if join_policy == get_closed_join():
raise PermissionDenied(_(astakos_messages.MEMBER_JOIN_POLICY_CLOSED))
......@@ -600,13 +603,15 @@ def submit_application(
def approve_application(application):
application.approve()
print '>>>'
trigger_sync()
print '<<<'
try:
notification = build_notification(
settings.SERVER_EMAIL,
[self.owner.email],
_(PROJECT_APPROVED_SUBJECT) % application.definition.__dict__,
[application.owner.email],
_(PROJECT_APPROVED_SUBJECT) % application.__dict__,
template='im/projects/project_approval_notification.txt',
dictionary={'object':application})
notification.send()
......
......@@ -1659,10 +1659,10 @@ class Project(models.Model):
# try:
# notification = build_notification(
# settings.SERVER_EMAIL,
# [self.current_application.owner.email],
# [self.application.owner.email],
# _(PROJECT_TERMINATION_SUBJECT) % self.__dict__,
# template='im/projects/project_termination_notification.txt',
# dictionary={'object':self.current_application}
# dictionary={'object':self.application}
# ).send()
# except NotificationError, e:
# logger.error(e.messages)
......@@ -1675,10 +1675,10 @@ class Project(models.Model):
# try:
# notification = build_notification(
# settings.SERVER_EMAIL,
# [self.current_application.owner.email],
# _(PROJECT_SUSPENSION_SUBJECT) % self.definition.__dict__,
# [self.application.owner.email],
# _(PROJECT_SUSPENSION_SUBJECT) % self.__dict__,
# template='im/projects/project_suspension_notification.txt',
# dictionary={'object':self.current_application}
# dictionary={'object':self.application}
# ).send()
# except NotificationError, e:
# logger.error(e.messages)
......@@ -1752,6 +1752,7 @@ class ProjectMembership(models.Model):
self.save()
def remove(self):
state = self.state
if state != self.ACCEPTED:
m = _("%s: attempt to remove in state '%s'") % (self, state)
raise AssertionError(m)
......@@ -1761,6 +1762,7 @@ class ProjectMembership(models.Model):
self.save()
def reject(self):
state = self.state
if state != self.REQUESTED:
m = _("%s: attempt to remove in state '%s'") % (self, state)
raise AssertionError(m)
......@@ -1800,9 +1802,9 @@ class ProjectMembership(models.Model):
add_append(QuotaLimits(
holder = holder,
resource = new_grant.resource.name,
capacity = new_grant.capacity,
import_limit = new_grant.import_limit,
export_limit = new_grant.export_limit))
capacity = new_grant.member_capacity,
import_limit = new_grant.member_import_limit,
export_limit = new_grant.member_export_limit))
return (sub_list, add_list)
......@@ -1866,6 +1868,7 @@ def sync_projects():
serial = new_serial()
pending = objects.filter(state=PENDING)
print '###', pending
for membership in pending:
if membership.pending_application:
......
--- A translation in English follows ---
Η αίτησή σας για το project {{object.definition.name}} έχει γίνει δεκτή.
Η αίτησή σας για το project {{object.name}} έχει γίνει δεκτή.
--
Your project application request ({{object.definition.name}}) has been approved.
\ No newline at end of file
Your project application request ({{object.name}}) has been approved.
\ No newline at end of file
--- A translation in English follows ---
{% if action == 'accepted' %}
Η συμμετοχή σας στο project {{object.definition.name}} έχει γίνει δεκτή.
Η συμμετοχή σας στο project {{object.name}} έχει γίνει δεκτή.
{% else %}
{% if action == 'rejected' %}
Η συμμετοχή σας στο project {{object.definition.name}} έχει απορριφθεί.
Η συμμετοχή σας στο project {{object.name}} έχει απορριφθεί.
{% else %}
Η συμμετοχή σας στο project {{object.definition.name}} έχει διαγραφεί.
Η συμμετοχή σας στο project {{object.name}} έχει διαγραφεί.
{% endif %}
{% endif %}
--
Your project membership ({{object.definition.name}}) has been {{action}}.
\ No newline at end of file
Your project membership ({{object.name}}) has been {{action}}.
\ No newline at end of file
--- A translation in English follows ---
Tο project {{object.definition.name}} έχει ανασταλεί.
Tο project {{object.name}} έχει ανασταλεί.
--
Your project application request ({{object.definition.name}}) has been suspended.
\ No newline at end of file
Your project application request ({{object.name}}) has been suspended.
\ No newline at end of file
--- A translation in English follows ---
Το project {{object.definition.name}} έχει τερματιστεί.
Το project {{object.name}} έχει τερματιστεί.
--
Your project application request ({{object.definition.name}}) has been terminated.
\ No newline at end of file
Your project application request ({{object.name}}) has been terminated.
\ No newline at end of file
......@@ -1337,13 +1337,14 @@ def project_all(request):
@login_required
@transaction.commit_manually
def project_join(request, application_id):
next = request.POST.get('next')
next = request.GET.get('next')
if not next:
return HttpResponseBadRequest(
_(astakos_messages.MISSING_NEXT_PARAMETER))
rollback = False
try:
application_id = int(application_id)
join_project(application_id, request.user)
except (IOError, PermissionDenied), e:
messages.error(request, e)
......@@ -1352,16 +1353,14 @@ def project_join(request, application_id):
messages.error(request, _(astakos_messages.GENERIC_ERROR))
rollback = True
else:
return project_detail(request, id)
return project_detail(request, application_id)
finally:
if rollback:
transaction.rollback()
else:
transaction.commit()
next = restrict_next(
request.POST.get('next'),
domain=COOKIE_DOMAIN)
next = restrict_next(next, domain=COOKIE_DOMAIN)
return redirect(next)
@require_http_methods(["POST"])
......@@ -1369,19 +1368,20 @@ def project_join(request, application_id):
@login_required
@transaction.commit_manually
def project_leave(request, application_id):
next = request.POST.get('next')
next = request.GET.get('next')
if not next:
return HttpResponseBadRequest(
_(astakos_messages.MISSING_NEXT_PARAMETER))
rollback = False
try:
application_id = int(application_id)
leave_project(application_id, request.user)
except (IOError, PermissionDenied), e:
messages.error(request, e)
except BaseException, e:
logger.exception(e)
messages.error(_(astakos_messages.GENERIC_ERRO))
messages.error(request, _(astakos_messages.GENERIC_ERROR))
rollback = True
finally:
if rollback:
......@@ -1389,9 +1389,7 @@ def project_leave(request, application_id):
else:
transaction.commit()
next = restrict_next(
request.POST.get('next'),
domain=COOKIE_DOMAIN)
next = restrict_next(next, domain=COOKIE_DOMAIN)
return redirect(next)
@require_http_methods(["GET"])
......@@ -1401,12 +1399,14 @@ def project_leave(request, application_id):
def project_approve_member(request, application_id, user_id):
rollback = False
try:
application_id = int(application_id)
user_id = int(user_id)
m = accept_membership(application_id, user_id, request.user)
except (IOError, PermissionDenied), e:
messages.error(request, e)
except BaseException, e:
logger.exception(e)
messages.error(_(astakos_messages.GENERIC_ERRO))
messages.error(request, _(astakos_messages.GENERIC_ERROR))
rollback = True
else:
realname = m.person.realname
......@@ -1426,12 +1426,14 @@ def project_approve_member(request, application_id, user_id):
def project_remove_member(request, application_id, user_id):
rollback = False
try:
application_id = int(application_id)
user_id = int(user_id)
m = remove_membership(application_id, user_id, request.user)
except (IOError, PermissionDenied), e:
messages.error(request, e)
except BaseException, e:
logger.exception(e)
messages.error(_(astakos_messages.GENERIC_ERRO))
messages.error(request, _(astakos_messages.GENERIC_ERROR))
rollback = True
else:
realname = m.person.realname
......@@ -1451,12 +1453,14 @@ def project_remove_member(request, application_id, user_id):
def project_reject_member(request, application_id, user_id):
rollback = False
try:
application_id = int(application_id)
user_id = int(user_id)
m = reject_membership(application_id, user_id, request.user)
except (IOError, PermissionDenied), e:
messages.error(request, e)
except BaseException, e:
logger.exception(e)
messages.error(_(astakos_messages.GENERIC_ERRO))
messages.error(request, _(astakos_messages.GENERIC_ERROR))
rollback = True
else:
realname = m.person.realname
......
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