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

Checks for membership functions

parent 80349981
......@@ -503,7 +503,7 @@ def accept_membership(project_application_id, user, request_user=None):
project_id = get_project_id_of_application_id(project_application_id)
return do_accept_membership(project_id, user, request_user)
def do_accept_membership_checks(project, request_user):
def do_accept_membership_checks(project, membership, request_user):
checkAllowed(project, request_user)
checkAlive(project)
......@@ -514,11 +514,15 @@ def do_accept_membership_checks(project, request_user):
if project.violates_members_limit(adding=1):
raise PermissionDenied(_(astakos_messages.MEMBER_NUMBER_LIMIT_REACHED))
if membership != ProjectMembership.REQUESTED:
m = _(astakos_messages.NOT_MEMBERSHIP_REQUEST)
raise PermissionDenied(m)
def do_accept_membership(project_id, user, request_user=None):
project = get_project_for_update(project_id)
do_accept_membership_checks(project, request_user)
membership = get_membership_for_update(project, user)
do_accept_membership_checks(project, membership, request_user)
membership.accept()
sync_projects()
......@@ -535,15 +539,19 @@ def reject_membership(project_application_id, user, request_user=None):
project_id = get_project_id_of_application_id(project_application_id)
return do_reject_membership(project_id, user, request_user)
def do_reject_membership_checks(project, request_user):
def do_reject_membership_checks(project, membership, request_user):
checkAllowed(project, request_user)
checkAlive(project)
if membership != ProjectMembership.REQUESTED:
m = _(astakos_messages.NOT_MEMBERSHIP_REQUEST)
raise PermissionDenied(m)
def do_reject_membership(project_id, user, request_user=None):
project = get_project_for_update(project_id)
do_reject_membership_checks(project, request_user)
membership = get_membership_for_update(project, user)
do_reject_membership_checks(project, membership, request_user)
membership.reject()
membership_change_notify(project, membership.person, 'rejected')
......@@ -567,11 +575,15 @@ def do_remove_membership_checks(project, membership, request_user=None):
if leave_policy == CLOSED_POLICY:
raise PermissionDenied(_(astakos_messages.MEMBER_LEAVE_POLICY_CLOSED))
if membership.state not in ProjectMembership.ACCEPTED_STATES:
m = _(astakos_messages.NOT_ACCEPTED_MEMBERSHIP)
raise PermissionDenied(m)
def do_remove_membership(project_id, user, request_user=None):
project = get_project_for_update(project_id)
do_remove_membership_checks(project, request_user)
membership = get_membership_for_update(project, user)
do_remove_membership_checks(project, membership, request_user)
membership.remove()
sync_projects()
......@@ -585,9 +597,9 @@ def enroll_member(project_application_id, user, request_user=None):
def do_enroll_member(project_id, user, request_user=None):
project = get_project_for_update(project_id)
do_accept_membership_checks(project, request_user)
membership = create_membership(project_id, user)
do_accept_membership_checks(project, membership, request_user)
membership.accept()
sync_projects()
......@@ -603,18 +615,21 @@ def leave_project(project_application_id, user_id):
project_id = get_project_id_of_application_id(project_application_id)
return do_leave_project(project_id, user_id)
def do_leave_project_checks(project):
def do_leave_project_checks(project, membership):
checkAlive(project)
leave_policy = project.application.member_leave_policy
if leave_policy == CLOSED_POLICY:
raise PermissionDenied(_(astakos_messages.MEMBER_LEAVE_POLICY_CLOSED))
if membership.state not in ProjectMembership.ACCEPTED_STATES:
m = _(astakos_messages.NOT_ACCEPTED_MEMBERSHIP)
raise PermissionDenied(m)
def do_leave_project(project_id, user_id):
project = get_project_for_update(project_id)
do_leave_project_checks(project)
membership = get_membership_for_update(project, user_id)
do_leave_project_checks(project, membership)
leave_policy = project.application.member_leave_policy
if leave_policy == AUTO_ACCEPT_POLICY:
......@@ -643,9 +658,8 @@ def do_join_project_checks(project):
def do_join_project(project_id, user_id):
project = get_project_for_update(project_id)
do_join_project_checks(project)
membership = create_membership(project, user_id)
do_join_project_checks(project)
join_policy = project.application.member_join_policy
if (join_policy == AUTO_ACCEPT_POLICY and
......
......@@ -171,6 +171,7 @@ MEMBER_NUMBER_LIMIT_REACHED = 'You have reached the maximum number
MEMBER_JOIN_POLICY_CLOSED = 'The Project\'s member join policy is closed.'
MEMBER_LEAVE_POLICY_CLOSED = 'The project\'s member leave policy is closed.'
NOT_MEMBERSHIP_REQUEST = 'This is not a valid membership request.'
NOT_ACCEPTED_MEMBERSHIP = 'This is not an accepted membership.'
MEMBERSHIP_REQUEST_EXISTS = 'The membership request already exists.'
NO_APPLICANT = 'Project application requires an applicant. None found.'
INVALID_PROJECT_START_DATE = 'Project start date should be equal or greater than the current date'
......
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