45 |
45 |
|
46 |
46 |
from synnefo.lib import join_urls
|
47 |
47 |
from astakos.im.models import AstakosUser, Invitation, ProjectMembership, \
|
48 |
|
ProjectApplication, Project, Chain, new_chain
|
|
48 |
ProjectApplication, Project, new_chain
|
49 |
49 |
from astakos.im.quotas import qh_sync_user, get_pending_app_quota, \
|
50 |
50 |
register_pending_apps, qh_sync_project, qh_sync_locked_users, \
|
51 |
51 |
get_users_for_update, members_to_sync
|
... | ... | |
267 |
267 |
raise IOError(m)
|
268 |
268 |
|
269 |
269 |
|
270 |
|
def get_chain_for_update(chain_id):
|
|
270 |
def get_project_for_update(project_id):
|
271 |
271 |
try:
|
272 |
|
return Chain.objects.get_for_update(chain=chain_id)
|
273 |
|
except Chain.DoesNotExist:
|
274 |
|
m = _(astakos_messages.UNKNOWN_PROJECT_ID) % chain_id
|
|
272 |
return Project.objects.get_for_update(id=project_id)
|
|
273 |
except Project.DoesNotExist:
|
|
274 |
m = _(astakos_messages.UNKNOWN_PROJECT_ID) % project_id
|
275 |
275 |
raise IOError(m)
|
276 |
276 |
|
277 |
277 |
|
278 |
|
def get_chain_of_application_for_update(app_id):
|
|
278 |
def get_project_of_application_for_update(app_id):
|
279 |
279 |
app = get_application(app_id)
|
280 |
|
return Chain.objects.get_for_update(chain=app.chain_id)
|
|
280 |
return get_project_for_update(app.chain_id)
|
281 |
281 |
|
282 |
282 |
|
283 |
283 |
def get_application(application_id):
|
... | ... | |
288 |
288 |
raise IOError(m)
|
289 |
289 |
|
290 |
290 |
|
291 |
|
def get_chain_of_membership_for_update(memb_id):
|
|
291 |
def get_project_of_membership_for_update(memb_id):
|
292 |
292 |
m = get_membership_by_id(memb_id)
|
293 |
|
return get_chain_for_update(m.project_id)
|
|
293 |
return get_project_for_update(m.project_id)
|
294 |
294 |
|
295 |
295 |
|
296 |
296 |
def get_user_by_id(user_id):
|
... | ... | |
367 |
367 |
|
368 |
368 |
|
369 |
369 |
def accept_membership(memb_id, request_user=None):
|
370 |
|
get_chain_of_membership_for_update(memb_id)
|
|
370 |
project = get_project_of_membership_for_update(memb_id)
|
371 |
371 |
membership = get_membership_by_id(memb_id)
|
372 |
372 |
if not membership.can_accept():
|
373 |
373 |
m = _(astakos_messages.NOT_MEMBERSHIP_REQUEST)
|
374 |
374 |
raise PermissionDenied(m)
|
375 |
375 |
|
376 |
|
project = membership.project
|
377 |
376 |
accept_membership_checks(project, request_user)
|
378 |
377 |
user = membership.person
|
379 |
378 |
membership.accept()
|
... | ... | |
391 |
390 |
|
392 |
391 |
|
393 |
392 |
def reject_membership(memb_id, request_user=None):
|
394 |
|
get_chain_of_membership_for_update(memb_id)
|
|
393 |
project = get_project_of_membership_for_update(memb_id)
|
395 |
394 |
membership = get_membership_by_id(memb_id)
|
396 |
395 |
if not membership.can_reject():
|
397 |
396 |
m = _(astakos_messages.NOT_MEMBERSHIP_REQUEST)
|
398 |
397 |
raise PermissionDenied(m)
|
399 |
398 |
|
400 |
|
project = membership.project
|
401 |
399 |
reject_membership_checks(project, request_user)
|
402 |
400 |
user = membership.person
|
403 |
401 |
membership.reject()
|
... | ... | |
413 |
411 |
|
414 |
412 |
|
415 |
413 |
def cancel_membership(memb_id, request_user):
|
416 |
|
get_chain_of_membership_for_update(memb_id)
|
|
414 |
project = get_project_of_membership_for_update(memb_id)
|
417 |
415 |
|
418 |
416 |
membership = get_membership_by_id(memb_id)
|
419 |
417 |
if not membership.can_cancel():
|
... | ... | |
441 |
439 |
|
442 |
440 |
|
443 |
441 |
def remove_membership(memb_id, request_user=None):
|
444 |
|
get_chain_of_membership_for_update(memb_id)
|
|
442 |
project = get_project_of_membership_for_update(memb_id)
|
445 |
443 |
membership = get_membership_by_id(memb_id)
|
446 |
444 |
if not membership.can_remove():
|
447 |
445 |
m = _(astakos_messages.NOT_ACCEPTED_MEMBERSHIP)
|
448 |
446 |
raise PermissionDenied(m)
|
449 |
447 |
|
450 |
|
project = membership.project
|
451 |
448 |
remove_membership_checks(project, request_user)
|
452 |
449 |
user = membership.person
|
453 |
450 |
membership.remove()
|
... | ... | |
460 |
457 |
|
461 |
458 |
|
462 |
459 |
def enroll_member(project_id, user, request_user=None):
|
463 |
|
get_chain_for_update(project_id)
|
464 |
|
project = get_project_by_id(project_id)
|
|
460 |
project = get_project_for_update(project_id)
|
465 |
461 |
accept_membership_checks(project, request_user)
|
466 |
462 |
|
467 |
463 |
try:
|
... | ... | |
503 |
499 |
|
504 |
500 |
|
505 |
501 |
def leave_project(memb_id, request_user):
|
506 |
|
get_chain_of_membership_for_update(memb_id)
|
|
502 |
project = get_project_of_membership_for_update(memb_id)
|
507 |
503 |
|
508 |
504 |
membership = get_membership_by_id(memb_id)
|
509 |
505 |
if not membership.can_leave():
|
... | ... | |
560 |
556 |
|
561 |
557 |
|
562 |
558 |
def join_project(project_id, request_user):
|
563 |
|
get_chain_for_update(project_id)
|
564 |
|
project = get_project_by_id(project_id)
|
|
559 |
project = get_project_for_update(project_id)
|
565 |
560 |
join_project_checks(project)
|
566 |
561 |
|
567 |
562 |
try:
|
... | ... | |
605 |
600 |
|
606 |
601 |
project = None
|
607 |
602 |
if project_id is not None:
|
608 |
|
get_chain_for_update(project_id)
|
609 |
|
project = Project.objects.get(id=project_id)
|
|
603 |
project = get_project_for_update(project_id)
|
610 |
604 |
|
611 |
605 |
if (request_user and
|
612 |
606 |
(not project.application.owner == request_user and
|
... | ... | |
662 |
656 |
|
663 |
657 |
|
664 |
658 |
def cancel_application(application_id, request_user=None, reason=""):
|
665 |
|
get_chain_of_application_for_update(application_id)
|
|
659 |
get_project_of_application_for_update(application_id)
|
666 |
660 |
application = get_application(application_id)
|
667 |
661 |
checkAllowed(application, request_user)
|
668 |
662 |
|
... | ... | |
678 |
672 |
|
679 |
673 |
|
680 |
674 |
def dismiss_application(application_id, request_user=None, reason=""):
|
681 |
|
get_chain_of_application_for_update(application_id)
|
|
675 |
get_project_of_application_for_update(application_id)
|
682 |
676 |
application = get_application(application_id)
|
683 |
677 |
checkAllowed(application, request_user)
|
684 |
678 |
|
... | ... | |
692 |
686 |
|
693 |
687 |
|
694 |
688 |
def deny_application(application_id, request_user=None, reason=""):
|
695 |
|
get_chain_of_application_for_update(application_id)
|
|
689 |
get_project_of_application_for_update(application_id)
|
696 |
690 |
application = get_application(application_id)
|
697 |
691 |
|
698 |
692 |
checkAllowed(application, request_user, admin_only=True)
|
... | ... | |
726 |
720 |
|
727 |
721 |
|
728 |
722 |
def approve_application(app_id, request_user=None, reason=""):
|
729 |
|
get_chain_of_application_for_update(app_id)
|
|
723 |
project = get_project_of_application_for_update(app_id)
|
730 |
724 |
application = get_application(app_id)
|
731 |
|
project = application.chain
|
732 |
725 |
|
733 |
726 |
checkAllowed(application, request_user, admin_only=True)
|
734 |
727 |
|
... | ... | |
770 |
763 |
|
771 |
764 |
|
772 |
765 |
def terminate(project_id, request_user=None):
|
773 |
|
get_chain_for_update(project_id)
|
774 |
|
project = get_project_by_id(project_id)
|
|
766 |
project = get_project_for_update(project_id)
|
775 |
767 |
checkAllowed(project, request_user, admin_only=True)
|
776 |
768 |
checkAlive(project)
|
777 |
769 |
|
... | ... | |
783 |
775 |
|
784 |
776 |
|
785 |
777 |
def suspend(project_id, request_user=None):
|
786 |
|
get_chain_for_update(project_id)
|
787 |
|
project = get_project_by_id(project_id)
|
|
778 |
project = get_project_for_update(project_id)
|
788 |
779 |
checkAllowed(project, request_user, admin_only=True)
|
789 |
780 |
checkAlive(project)
|
790 |
781 |
|
... | ... | |
796 |
787 |
|
797 |
788 |
|
798 |
789 |
def resume(project_id, request_user=None):
|
799 |
|
get_chain_for_update(project_id)
|
800 |
|
project = get_project_by_id(project_id)
|
|
790 |
project = get_project_for_update(project_id)
|
801 |
791 |
checkAllowed(project, request_user, admin_only=True)
|
802 |
792 |
|
803 |
793 |
if not project.is_suspended:
|