83 'You do not have the required role.') |
83 'You do not have the required role.') |
84 |
84 |
85 DEF_NOT_YOUR_ENTITY_MSG = ugettext( |
85 DEF_NOT_YOUR_ENTITY_MSG = ugettext( |
86 'This entity does not belong to you.') |
86 'This entity does not belong to you.') |
87 |
87 |
|
88 DEF_NO_ACTIVE_ENTITY_MSG = ugettext( |
|
89 'There is no such active entity.') |
|
90 |
88 DEF_NO_ACTIVE_GROUP_MSG = ugettext( |
91 DEF_NO_ACTIVE_GROUP_MSG = ugettext( |
89 'There is no such active group.') |
92 'There is no such active group.') |
90 |
93 |
91 DEF_NO_ACTIVE_ROLE_MSG = ugettext( |
94 DEF_NO_ACTIVE_ROLE_MSG = ugettext( |
92 'There is no such active role.') |
95 'There is no such active role.') |
580 |
583 |
581 @allowDeveloper |
584 @allowDeveloper |
582 @denySidebar |
585 @denySidebar |
583 def checkIsActive(self, django_args, logic, |
586 def checkIsActive(self, django_args, logic, |
584 field_name='scope_path', filter_field='link_id'): |
587 field_name='scope_path', filter_field='link_id'): |
585 """Raises an alternate HTTP response if Group status is not active. |
588 """Raises an alternate HTTP response if the entity is not active. |
586 |
589 |
587 Args: |
590 Args: |
588 django_args: a dictionary with django's arguments |
591 django_args: a dictionary with django's arguments |
|
592 logic: the logic that should be used to look up the entity |
|
593 field_name: the name of the field that should be copied verbatim |
|
594 If a format string is specified it will be formatted with |
|
595 the specified django_args. |
|
596 filter_field: the name of the field to which scope_path should be set |
589 |
597 |
590 Raises: |
598 Raises: |
591 AccessViolationResponse: |
599 AccessViolationResponse: |
592 * if no Group is found |
600 * if no Group is found |
593 * if the Group status is not active |
601 * if the Group status is not active |
594 """ |
602 """ |
595 |
603 |
596 self.checkIsUser(django_args) |
604 self.checkIsUser(django_args) |
597 |
605 |
598 if field_name and (field_name not in django_args): |
|
599 self.deny(django_args) |
|
600 |
|
601 fields = { |
606 fields = { |
602 filter_field: django_args[filter_field], |
607 filter_field: django_args[filter_field], |
603 'status': 'active', |
608 'status': 'active', |
604 } |
609 } |
605 |
610 |
606 if field_name: |
611 if field_name: |
607 fields['scope_path'] = django_args[field_name] |
612 # convert to a format string if desired |
|
613 if field_name.find('%') == -1: |
|
614 field_name = ''.join(['%(', field_name, ')s']) |
|
615 |
|
616 try: |
|
617 fields['scope_path'] = field_name % django_args |
|
618 except KeyError, e: |
|
619 self.deny(django_args) |
608 |
620 |
609 entity = logic.getForFields(fields, unique=True) |
621 entity = logic.getForFields(fields, unique=True) |
610 |
622 |
611 if entity: |
623 if entity: |
612 return |
624 return |
613 |
625 |
614 raise out_of_band.AccessViolation(message_fmt=DEF_NO_ACTIVE_GROUP_MSG) |
626 raise out_of_band.AccessViolation(message_fmt=DEF_NO_ACTIVE_ENTITY_MSG) |
615 |
627 |
616 def checkHasActiveRoleForScope(self, django_args, logic, field_name=None): |
628 def checkHasActiveRoleForScope(self, django_args, logic, field_name=None): |
617 """Checks that the user has the specified active role. |
629 """Checks that the user has the specified active role. |
618 """ |
630 """ |
619 |
631 |