0001-workflows-don-t-try-to-load-a-role-with-None-as-id-3.patch
tests/workflow/test_all.py | ||
---|---|---|
730 | 730 |
assert formdata.workflow_roles == {} |
731 | 731 | |
732 | 732 | |
733 |
def test_roles(pub): |
|
733 |
def test_roles(two_pubs): |
|
734 |
pub = two_pubs |
|
735 |
pub.role_class.wipe() |
|
736 |
role = pub.role_class(name='xxx') |
|
737 |
role.store() |
|
738 | ||
734 | 739 |
user = pub.user_class() |
735 | 740 |
user.store() |
736 | 741 | |
... | ... | |
746 | 751 |
item.perform(formdata) |
747 | 752 |
assert not pub.user_class.get(user.id).roles |
748 | 753 | |
749 |
item.role_id = '1' |
|
754 |
item.role_id = str(role.id) |
|
755 |
item.perform(formdata) |
|
756 |
assert pub.user_class.get(user.id).roles == [str(role.id)] |
|
757 | ||
758 |
# check django template |
|
759 |
user.roles = None |
|
760 |
user.store() |
|
761 |
item.role_id = '{{ "%s" }}' % role.id |
|
762 |
item.perform(formdata) |
|
763 |
assert pub.user_class.get(user.id).roles == [str(role.id)] |
|
764 | ||
765 |
# check python expression |
|
766 |
user.roles = None |
|
767 |
user.store() |
|
768 |
item.role_id = '="%s"' % role.id |
|
750 | 769 |
item.perform(formdata) |
751 |
assert pub.user_class.get(user.id).roles == ['1'] |
|
770 |
assert pub.user_class.get(user.id).roles == [str(role.id)] |
|
771 | ||
772 |
# check python expression returning None |
|
773 |
user.roles = None |
|
774 |
user.store() |
|
775 |
item.role_id = '=None' |
|
776 |
item.perform(formdata) |
|
777 |
assert not pub.user_class.get(user.id).roles |
|
752 | 778 | |
779 |
# tests for remove role action |
|
753 | 780 |
user.roles = None |
754 | 781 |
user.store() |
755 | 782 |
item = RemoveRoleWorkflowStatusItem() |
... | ... | |
757 | 784 |
item.perform(formdata) |
758 | 785 |
assert not pub.user_class.get(user.id).roles |
759 | 786 | |
760 |
item.role_id = '1'
|
|
787 |
item.role_id = str(role.id)
|
|
761 | 788 |
item.perform(formdata) |
762 | 789 |
assert not pub.user_class.get(user.id).roles |
763 | 790 | |
764 |
user.roles = ['1']
|
|
791 |
user.roles = [str(role.id)]
|
|
765 | 792 |
user.store() |
766 | 793 |
item.perform(formdata) |
767 | 794 |
assert not pub.user_class.get(user.id).roles |
768 | 795 | |
769 |
user.roles = ['2', '1']
|
|
796 |
user.roles = [str(role.id), '2']
|
|
770 | 797 |
user.store() |
771 | 798 |
item.perform(formdata) |
772 | 799 |
assert pub.user_class.get(user.id).roles == ['2'] |
wcs/workflows.py | ||
---|---|---|
2289 | 2289 | |
2290 | 2290 |
def get_computed_role_id(self, role_id): |
2291 | 2291 |
new_role_id = self.compute(str(role_id)) |
2292 |
if not new_role_id: |
|
2293 |
return None |
|
2292 | 2294 |
if get_publisher().role_class.get(new_role_id, ignore_errors=True): |
2293 | 2295 |
return new_role_id |
2294 | 2296 |
# computed value, not an id, try to get role by slug |
2295 |
- |