misc: show unlogged only cells to superuser (#45846)
In this case the .shown-because-admin class is present on the cell.
This commit is contained in:
parent
92e68e279a
commit
d29dc19ee9
|
@ -76,14 +76,14 @@ class PostException(Exception):
|
|||
|
||||
|
||||
def element_is_visible(element, user=None, ignore_superuser=False):
|
||||
if user is not None and user.is_superuser and not ignore_superuser:
|
||||
return True
|
||||
if element.public:
|
||||
if getattr(element, 'restricted_to_unlogged', None) is True:
|
||||
return user is None or user.is_anonymous
|
||||
return True
|
||||
if user is None or user.is_anonymous:
|
||||
return False
|
||||
if user.is_superuser and not ignore_superuser:
|
||||
return True
|
||||
page_groups = element.groups.all()
|
||||
if not page_groups:
|
||||
groups_ok = True
|
||||
|
|
|
@ -1504,7 +1504,7 @@ def test_page_cell_placeholder_restricted_visibility(app, admin_user):
|
|||
)
|
||||
)
|
||||
|
||||
assert "<p>Public text</p>" not in resp.text
|
||||
assert resp.pyquery('.shown-because-admin').text() == 'Public text'
|
||||
assert "<p>Private text</p>" in resp.text
|
||||
|
||||
|
||||
|
@ -1757,19 +1757,25 @@ class TestCellVisibility:
|
|||
response = app.get('/test/', user='superuser')
|
||||
|
||||
assert 'Always visible' in response
|
||||
assert 'Visible to unlogged only' not in response
|
||||
assert 'Visible to unlogged only' in response
|
||||
assert 'Visible to logged only' in response
|
||||
assert 'Visible only to members of group' in response
|
||||
assert 'Visible only to non-members of group' in response
|
||||
assert response.pyquery('.shown-because-admin').text() == 'Visible only to members of group'
|
||||
assert {elt.text() for elt in response.pyquery.items('.shown-because-admin')} == {
|
||||
'Visible to unlogged only',
|
||||
'Visible only to members of group',
|
||||
}
|
||||
|
||||
def test_superuser_with_role(self, app, group):
|
||||
User.objects.create(username='superuser', is_superuser=True).groups.add(group)
|
||||
response = app.get('/test/', user='superuser')
|
||||
|
||||
assert 'Always visible' in response
|
||||
assert 'Visible to unlogged only' not in response
|
||||
assert 'Visible to unlogged only' in response
|
||||
assert 'Visible to logged only' in response
|
||||
assert 'Visible only to members of group' in response
|
||||
assert 'Visible only to non-members of group' in response
|
||||
assert response.pyquery('.shown-because-admin').text() == 'Visible only to non-members of group'
|
||||
assert {elt.text() for elt in response.pyquery.items('.shown-because-admin')} == {
|
||||
'Visible to unlogged only',
|
||||
'Visible only to non-members of group',
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ class MockUserWithNameId:
|
|||
email = 'foo@example.net'
|
||||
is_authenticated = True
|
||||
is_anonymous = False
|
||||
is_superuser = False
|
||||
|
||||
def get_name_id(self):
|
||||
return 'xyz'
|
||||
|
|
|
@ -81,7 +81,7 @@ def test_page_contents_unlogged_only(app, admin_user):
|
|||
|
||||
app = login(app)
|
||||
resp = app.get('/', status=200)
|
||||
assert not 'Foobar' in resp.text
|
||||
assert resp.pyquery('.shown-because-admin').text() == 'Foobar'
|
||||
|
||||
|
||||
@pytest.mark.skipif('mellon is None')
|
||||
|
|
|
@ -481,6 +481,7 @@ class MockUserWithNameId:
|
|||
email = 'foo@example.net'
|
||||
is_authenticated = True
|
||||
is_anonymous = False
|
||||
is_superuser = False
|
||||
|
||||
def get_name_id(self):
|
||||
return 'xyz'
|
||||
|
|
Loading…
Reference in New Issue