0002-misc-show-unlogged-only-cells-to-superuser-45846.patch
combo/data/models.py | ||
---|---|---|
76 | 76 | |
77 | 77 | |
78 | 78 |
def element_is_visible(element, user=None, ignore_superuser=False): |
79 |
if user is not None and user.is_superuser and not ignore_superuser: |
|
80 |
return True |
|
79 | 81 |
if element.public: |
80 | 82 |
if getattr(element, 'restricted_to_unlogged', None) is True: |
81 | 83 |
return user is None or user.is_anonymous |
82 | 84 |
return True |
83 | 85 |
if user is None or user.is_anonymous: |
84 | 86 |
return False |
85 |
if user.is_superuser and not ignore_superuser: |
|
86 |
return True |
|
87 | 87 |
page_groups = element.groups.all() |
88 | 88 |
if not page_groups: |
89 | 89 |
groups_ok = True |
tests/test_cells.py | ||
---|---|---|
1485 | 1485 |
) |
1486 | 1486 |
) |
1487 | 1487 | |
1488 |
assert "<p>Public text</p>" not in resp.text
|
|
1488 |
assert resp.pyquery('.shown-because-admin').text() == 'Public text'
|
|
1489 | 1489 |
assert "<p>Private text</p>" in resp.text |
1490 | 1490 | |
1491 | 1491 | |
... | ... | |
1738 | 1738 |
response = app.get('/test/', user='superuser') |
1739 | 1739 | |
1740 | 1740 |
assert 'Always visible' in response |
1741 |
assert 'Visible to unlogged only' not in response
|
|
1741 |
assert 'Visible to unlogged only' in response |
|
1742 | 1742 |
assert 'Visible to logged only' in response |
1743 | 1743 |
assert 'Visible only to members of group' in response |
1744 | 1744 |
assert 'Visible only to non-members of group' in response |
1745 |
assert response.pyquery('.shown-because-admin').text() == 'Visible only to members of group' |
|
1745 |
assert {response.pyquery(elt).text() for elt in response.pyquery('.shown-because-admin')} == { |
|
1746 |
'Visible to unlogged only', |
|
1747 |
'Visible only to members of group', |
|
1748 |
} |
|
1746 | 1749 | |
1747 | 1750 |
def test_superuser_with_role(self, app, group): |
1748 | 1751 |
User.objects.create(username='superuser', is_superuser=True).groups.add(group) |
1749 | 1752 |
response = app.get('/test/', user='superuser') |
1750 | 1753 | |
1751 | 1754 |
assert 'Always visible' in response |
1752 |
assert 'Visible to unlogged only' not in response
|
|
1755 |
assert 'Visible to unlogged only' in response |
|
1753 | 1756 |
assert 'Visible to logged only' in response |
1754 | 1757 |
assert 'Visible only to members of group' in response |
1755 | 1758 |
assert 'Visible only to non-members of group' in response |
1756 |
assert response.pyquery('.shown-because-admin').text() == 'Visible only to non-members of group' |
|
1759 |
assert {response.pyquery(elt).text() for elt in response.pyquery('.shown-because-admin')} == { |
|
1760 |
'Visible to unlogged only', |
|
1761 |
'Visible only to non-members of group', |
|
1762 |
} |
tests/test_family.py | ||
---|---|---|
35 | 35 |
email = 'foo@example.net' |
36 | 36 |
is_authenticated = True |
37 | 37 |
is_anonymous = False |
38 |
is_superuser = False |
|
38 | 39 | |
39 | 40 |
def get_name_id(self): |
40 | 41 |
return 'xyz' |
tests/test_public.py | ||
---|---|---|
81 | 81 | |
82 | 82 |
app = login(app) |
83 | 83 |
resp = app.get('/', status=200) |
84 |
assert not 'Foobar' in resp.text
|
|
84 |
assert resp.pyquery('.shown-because-admin').text() == 'Foobar'
|
|
85 | 85 | |
86 | 86 | |
87 | 87 |
@pytest.mark.skipif('mellon is None') |
tests/wcs/utils.py | ||
---|---|---|
475 | 475 |
email = 'foo@example.net' |
476 | 476 |
is_authenticated = True |
477 | 477 |
is_anonymous = False |
478 |
is_superuser = False |
|
478 | 479 | |
479 | 480 |
def get_name_id(self): |
480 | 481 |
return 'xyz' |
481 |
- |