422 raise out_of_band.LoginRequest(message_fmt=login_message_fmt) |
422 raise out_of_band.LoginRequest(message_fmt=login_message_fmt) |
423 |
423 |
424 @allowDeveloper |
424 @allowDeveloper |
425 @denySidebar |
425 @denySidebar |
426 def checkIsGroupActive(self, django_args, group_logic): |
426 def checkIsGroupActive(self, django_args, group_logic): |
427 """Raises an alternate HTTP response if Group state is not active. |
427 """Raises an alternate HTTP response if Group status is not active. |
428 |
428 |
429 Args: |
429 Args: |
430 django_args: a dictionary with django's arguments |
430 django_args: a dictionary with django's arguments |
431 |
431 |
432 Raises: |
432 Raises: |
433 AccessViolationResponse: |
433 AccessViolationResponse: |
434 * if no Group is found |
434 * if no Group is found |
435 * if the Group state is not active |
435 * if the Group status is not active |
436 """ |
436 """ |
437 |
437 |
438 fields = {'link_id': django_args['link_id']} |
438 fields = {'link_id': django_args['link_id']} |
439 |
439 |
440 if django_args.get('scope_path'): |
440 if django_args.get('scope_path'): |
441 fields['scope_path'] = django_args['scope_path'] |
441 fields['scope_path'] = django_args['scope_path'] |
442 |
442 |
443 group_entity = group_logic.logic.getFromFieldsOr404(**fields) |
443 group_entity = group_logic.logic.getFromFieldsOr404(**fields) |
444 |
444 |
445 if group_entity.state == 'active': |
445 if group_entity.status == 'active': |
446 return |
446 return |
447 |
447 |
448 # TODO tell the user that this group is not active |
448 # TODO tell the user that this group is not active |
449 self.deny(django_args) |
449 self.deny(django_args) |
450 |
450 |
451 |
451 |
452 def checkCanMakeRequestToGroup(self, django_args, group_logic): |
452 def checkCanMakeRequestToGroup(self, django_args, group_logic): |
453 """Raises an alternate HTTP response if the specified group is not in an |
453 """Raises an alternate HTTP response if the specified group is not in an |
454 active state. |
454 active status. |
455 |
455 |
456 Note that state hasn't been implemented yet |
456 Note that status hasn't been implemented yet |
457 |
457 |
458 Args: |
458 Args: |
459 group_logic: Logic module for the type of group which the request is for |
459 group_logic: Logic module for the type of group which the request is for |
460 """ |
460 """ |
461 |
461 |
463 group_logic.logic, django_args['scope_path']) |
463 group_logic.logic, django_args['scope_path']) |
464 |
464 |
465 if not group_entity: |
465 if not group_entity: |
466 raise out_of_band.Error(DEF_GROUP_NOT_FOUND_MSG, status=404) |
466 raise out_of_band.Error(DEF_GROUP_NOT_FOUND_MSG, status=404) |
467 |
467 |
468 if group_entity.state != 'active': |
468 if group_entity.status != 'active': |
469 # TODO tell the user that this group is not active |
469 # TODO tell the user that this group is not active |
470 self.deny(django_args) |
470 self.deny(django_args) |
471 |
471 |
472 return |
472 return |
473 |
473 |
474 def checkCanCreateFromRequest(self, django_args, role_name): |
474 def checkCanCreateFromRequest(self, django_args, role_name): |
475 """Raises an alternate HTTP response if the specified request does not exist |
475 """Raises an alternate HTTP response if the specified request does not exist |
476 or if it's state is not group_accepted. Also when the group this request |
476 or if it's status is not group_accepted. Also when the group this request |
477 is from is in an inactive or invalid state access will be denied. |
477 is from is in an inactive or invalid status access will be denied. |
478 """ |
478 """ |
479 |
479 |
480 self.checkIsUser(django_args) |
480 self.checkIsUser(django_args) |
481 |
481 |
482 user_entity = user_logic.getForCurrentAccount() |
482 user_entity = user_logic.getForCurrentAccount() |
488 'scope_path': django_args['scope_path'], |
488 'scope_path': django_args['scope_path'], |
489 'role': role_name} |
489 'role': role_name} |
490 |
490 |
491 request_entity = request_logic.getFromFieldsOr404(**fields) |
491 request_entity = request_logic.getFromFieldsOr404(**fields) |
492 |
492 |
493 if request_entity.state != 'group_accepted': |
493 if request_entity.status != 'group_accepted': |
494 # TODO tell the user that this request has not been accepted yet |
494 # TODO tell the user that this request has not been accepted yet |
495 self.deny(django_args) |
495 self.deny(django_args) |
496 |
496 |
497 if request_entity.scope.state in ['invalid', 'inactive']: |
497 if request_entity.scope.status in ['invalid', 'inactive']: |
498 # TODO tell the user that it is not possible to create this role anymore |
498 # TODO tell the user that it is not possible to create this role anymore |
499 self.deny(django_args) |
499 self.deny(django_args) |
500 |
500 |
501 return |
501 return |
502 |
502 |
503 def checkCanProcessRequest(self, django_args, role_name): |
503 def checkCanProcessRequest(self, django_args, role_name): |
504 """Raises an alternate HTTP response if the specified request does not exist |
504 """Raises an alternate HTTP response if the specified request does not exist |
505 or if it's state is completed or denied. Also Raises an alternate HTTP response |
505 or if it's status is completed or denied. Also Raises an alternate HTTP response |
506 whenever the group in the request is not active. |
506 whenever the group in the request is not active. |
507 """ |
507 """ |
508 |
508 |
509 fields = {'link_id': django_args['link_id'], |
509 fields = {'link_id': django_args['link_id'], |
510 'scope_path': django_args['scope_path'], |
510 'scope_path': django_args['scope_path'], |
511 'role': role_name} |
511 'role': role_name} |
512 |
512 |
513 request_entity = request_logic.getFromFieldsOr404(**fields) |
513 request_entity = request_logic.getFromFieldsOr404(**fields) |
514 |
514 |
515 if request_entity.state in ['completed', 'denied']: |
515 if request_entity.status in ['completed', 'denied']: |
516 # TODO tell the user that this request has been processed |
516 # TODO tell the user that this request has been processed |
517 self.deny(django_args) |
517 self.deny(django_args) |
518 |
518 |
519 if request_entity.scope.state != 'active': |
519 if request_entity.scope.status != 'active': |
520 # TODO tell the user that this group cannot process requests |
520 # TODO tell the user that this group cannot process requests |
521 self.deny(django_args) |
521 self.deny(django_args) |
522 |
522 |
523 return |
523 return |
524 |
524 |
525 def checkIsMyGroupAcceptedRequest(self, django_args): |
525 def checkIsMyGroupAcceptedRequest(self, django_args): |
526 """Raises an alternate HTTP response if the specified request does not exist |
526 """Raises an alternate HTTP response if the specified request does not exist |
527 or if it's state is not group_accepted. |
527 or if it's status is not group_accepted. |
528 """ |
528 """ |
529 |
529 |
530 self.checkIsUser(django_args) |
530 self.checkIsUser(django_args) |
531 |
531 |
532 user_entity = user_logic.getForCurrentAccount() |
532 user_entity = user_logic.getForCurrentAccount() |
574 scope_path = django_args['scope_path'] |
574 scope_path = django_args['scope_path'] |
575 if 'link_id' in django_args: |
575 if 'link_id' in django_args: |
576 scope_path = django_args['link_id'] |
576 scope_path = django_args['link_id'] |
577 |
577 |
578 fields = {'user': self.user, |
578 fields = {'user': self.user, |
579 'state': 'active'} |
579 'status': 'active'} |
580 |
580 |
581 if scope_path: |
581 if scope_path: |
582 fields['scope_path'] = scope_path |
582 fields['scope_path'] = scope_path |
583 |
583 |
584 host = host_logic.getForFields(fields, unique=True) |
584 host = host_logic.getForFields(fields, unique=True) |
841 'scope_path': django_args['scope_path'], |
841 'scope_path': django_args['scope_path'], |
842 } |
842 } |
843 |
843 |
844 role_entity = role_logic.logic.getFromFieldsOr404(**fields) |
844 role_entity = role_logic.logic.getFromFieldsOr404(**fields) |
845 |
845 |
846 if role_entity.state != 'active': |
846 if role_entity.status != 'active': |
847 # cannot manage this entity |
847 # cannot manage this entity |
848 self.deny(django_args) |
848 self.deny(django_args) |
849 |
849 |
850 fields = {'link_id': self.user.link_id, |
850 fields = {'link_id': self.user.link_id, |
851 'scope_path': django_args['scope_path'], |
851 'scope_path': django_args['scope_path'], |
852 'state' : 'active' |
852 'status' : 'active' |
853 } |
853 } |
854 |
854 |
855 manage_entity = manage_role_logic.logic.getForFields(fields, unique=True) |
855 manage_entity = manage_role_logic.logic.getForFields(fields, unique=True) |
856 |
856 |
857 if not manage_entity: |
857 if not manage_entity: |