Commit 7859714e authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

Separate function for enroll member

parent 12f1ec8e
......@@ -431,17 +431,20 @@ def get_user_by_id(user_id):
except AstakosUser.DoesNotExist:
raise IOError(_(astakos_messages.UNKNOWN_USER_ID) % user_id)
def create_membership(project_application_id, user_id):
def create_membership(project, user):
if isinstance(project, int):
project = get_project_by_application_id(project)
if isinstance(user, int):
user = get_user_by_id(user)
m = ProjectMembership(
project=project,
person=user,
request_date=datetime.now())
try:
project = get_project_by_application_id(project_application_id)
m = ProjectMembership(
project=project,
person=user_id,
request_date=datetime.now())
m.save()
except IntegrityError, e:
raise IOError(_(astakos_messages.MEMBERSHIP_REQUEST_EXISTS))
else:
m.save()
return m
def get_membership(project, user):
......@@ -546,6 +549,10 @@ def remove_membership(project, user, request_user=None):
logger.error(e.message)
return membership
def enroll_member(project, user, request_user=None):
membership = create_membership(project, user)
accept_membership(project, user, request_user)
def leave_project(project_application_id, user_id):
"""
Raises:
......
......@@ -187,7 +187,7 @@
{% else %}
<td>Pending
{% if user == object.owner %}
<a href="{% url project_approve_member object.id m.person.id %}?{% if page %}page={{ page }}{% endif %}{% if sorting %}&sorting={{sorting}}{% endif %}">Accept</a>
<a href="{% url project_accept_member object.id m.person.id %}?{% if page %}page={{ page }}{% endif %}{% if sorting %}&sorting={{sorting}}{% endif %}">Accept</a>
<a href="{% url project_reject_member object.id m.person.id %}?{% if page %}page={{ page }}{% endif %}{% if sorting %}&sorting={{sorting}}{% endif %}">Reject</a>
{% endif %}
</td>
......
......@@ -76,7 +76,7 @@ urlpatterns = patterns(
url(r'^project/(?P<application_id>\w+)/?$', 'project_detail', {}, name='project_detail'),
url(r'^project/(?P<application_id>\w+)/join/?$', 'project_join', {}, name='project_join'),
url(r'^project/(?P<application_id>\w+)/leave/?$', 'project_leave', {}, name='project_leave'),
url(r'^project/(?P<application_id>\w+)/(?P<user_id>\d+)/approve/?$', 'project_approve_member', {}, name='project_approve_member'),
url(r'^project/(?P<application_id>\w+)/(?P<user_id>\d+)/accept/?$', 'project_accept_member', {}, name='project_accept_member'),
url(r'^project/(?P<application_id>\w+)/(?P<user_id>\d+)/reject/?$', 'project_reject_member', {}, name='project_reject_member'),
url(r'^project/(?P<application_id>\w+)/(?P<user_id>\d+)/remove/?$', 'project_remove_member', {}, name='project_remove_member'),
......
......@@ -98,7 +98,7 @@ from astakos.im.functions import (
# send_group_creation_notification,
SendNotificationError,
accept_membership, reject_membership, remove_membership,
leave_project, join_project)
leave_project, join_project, enroll_member)
# from astakos.im.endpoints.qh import timeline_charge
from astakos.im.settings import (
COOKIE_DOMAIN, LOGOUT_NEXT,
......@@ -1188,6 +1188,7 @@ def project_update(request, application_id):
@login_required
@transaction.commit_manually
def project_detail(request, application_id):
resource_catalog = None
result = callpoint.list_resources()
if not result.is_success:
messages.error(
......@@ -1196,8 +1197,6 @@ def project_detail(request, application_id):
)
else:
resource_catalog = result.data
# resource_catalog = ResourcePresentation(RESOURCES_PRESENTATION_DATA)
# resource_catalog.update_from_result(result)
addmembers_form = AddProjectMembersForm()
if request.method == 'POST':
......@@ -1205,7 +1204,8 @@ def project_detail(request, application_id):
if addmembers_form.is_valid():
try:
rollback = False
map(lambda u: accept_membership(
application_id = int(application_id)
map(lambda u: enroll_member(
application_id,
u,
request_user=request.user),
......@@ -1370,7 +1370,7 @@ def project_leave(request, application_id):
@signed_terms_required
@login_required
@transaction.commit_manually
def project_approve_member(request, application_id, user_id):
def project_accept_member(request, application_id, user_id):
rollback = False
try:
application_id = int(application_id)
......@@ -1391,7 +1391,7 @@ def project_approve_member(request, application_id, user_id):
transaction.rollback()
else:
transaction.commit()
return project_detail(request, application_id)
return redirect(reverse('project_detail', args=(application_id,)))
@require_http_methods(["GET"])
@signed_terms_required
......@@ -1418,7 +1418,7 @@ def project_remove_member(request, application_id, user_id):
transaction.rollback()
else:
transaction.commit()
return project_detail(request, application_id)
return redirect(reverse('project_detail', args=(application_id,)))
@require_http_methods(["GET"])
@signed_terms_required
......@@ -1445,6 +1445,6 @@ def project_reject_member(request, application_id, user_id):
transaction.rollback()
else:
transaction.commit()
return project_detail(request, application_id)
return redirect(reverse('project_detail', args=(application_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