def test_permissions_on_custom_links(client, settings): """ we honour permissions for the rendering of custom links """ user = UserFactory() user2 = UserFactory(permissions=("books.view_book", )) url = reverse("admin:index") settings.JAZZMIN_SETTINGS = override_jazzmin_settings( custom_links={ "books": [{ "name": "Make Messages", "url": "make_messages", "icon": "fa-comments", "permissions": ["books.view_book"], }] }) client.force_login(user) response = client.get(url) assert parse_sidemenu(response) == {"Global": ["/en/admin/"]} client.force_login(user2) response = client.get(url) assert parse_sidemenu(response) == { "Global": ["/en/admin/"], "Books": ["/make_messages/", "/en/admin/books/book/"] }
def test_side_menu(admin_client, settings): """ All menu tweaking settings work as expected """ url = reverse('admin:index') response = admin_client.get(url) assert parse_sidemenu(response) == { 'Global': ['/admin/'], 'Polls': [ '/admin/polls/choice/', '/admin/polls/poll/', '/admin/polls/vote/', '/make_messages/' ], 'Administration': ['/admin/admin/logentry/'], 'Authentication and Authorization': ['/admin/auth/group/', '/admin/auth/user/'] } settings.JAZZMIN_SETTINGS['hide_models'] = ['auth.user'] response = admin_client.get(url) assert parse_sidemenu(response) == { 'Global': ['/admin/'], 'Polls': [ '/admin/polls/choice/', '/admin/polls/poll/', '/admin/polls/vote/', '/make_messages/' ], 'Administration': ['/admin/admin/logentry/'], 'Authentication and Authorization': ['/admin/auth/group/'] }
def test_permissions_on_custom_links(client, settings): """ we honour permissions for the rendering of custom links """ user = user_with_permissions() user2 = user_with_permissions('polls.view_poll') url = reverse('admin:index') settings.JAZZMIN_SETTINGS['custom_links'] = { 'polls': [{ 'name': 'Make Messages', 'url': 'make_messages', 'icon': 'fa-comments', 'permissions': ['polls.view_poll'] }] } client.force_login(user) response = client.get(url) assert parse_sidemenu(response) == {'Global': ['/admin/']} client.force_login(user2) response = client.get(url) assert parse_sidemenu(response) == { 'Global': ['/admin/'], 'Polls': ['/admin/polls/poll/', '/make_messages/'] }
def test_no_permission(client): """ When our user has no permissions at all, they see no menu or dashboard """ user = user_with_permissions() url = reverse('admin:index') client.force_login(user) response = client.get(url) assert parse_sidemenu(response) == {'Global': ['/admin/']}
def test_no_view_permission(client): """ When our user has no view permission, they dont see things they are not supposed to """ user = user_with_permissions('polls.change_poll') url = reverse('admin:index') client.force_login(user) response = client.get(url) assert parse_sidemenu(response) == {'Global': ['/admin/']}
def test_side_menu(admin_client, settings): """ All menu tweaking settings work as expected """ url = reverse("admin:index") response = admin_client.get(url) assert parse_sidemenu(response) == { "Administration": ["/en/admin/admin/logentry/"], "Authentication and Authorization": ["/en/admin/auth/group/", "/en/admin/auth/user/"], "Books": [ "/en/admin/books/author/", "/en/admin/books/book/", "/en/admin/books/genre/" ], "Global": ["/en/admin/"], "Loans": [ "/make_messages/", "/en/admin/loans/bookloan/", "/en/admin/loans/library/" ], } settings.JAZZMIN_SETTINGS = override_jazzmin_settings( hide_models=["auth.user"]) response = admin_client.get(url) assert parse_sidemenu(response) == { "Global": ["/en/admin/"], "Authentication and Authorization": ["/en/admin/auth/group/"], "Books": [ "/en/admin/books/author/", "/en/admin/books/book/", "/en/admin/books/genre/" ], "Loans": [ "/make_messages/", "/en/admin/loans/bookloan/", "/en/admin/loans/library/" ], "Administration": ["/en/admin/admin/logentry/"], }
def test_side_menu(admin_client, settings): """ All menu tweaking settings work as expected """ url = reverse("admin:index") response = admin_client.get(url) assert parse_sidemenu(response) == { "Global": ["/admin/"], "Polls": [ "/admin/polls/allfields/", "/admin/polls/campaign/", "/admin/polls/cheese/", "/admin/polls/choice/", "/admin/polls/poll/", "/admin/polls/vote/", "/make_messages/", ], "Administration": ["/admin/admin/logentry/"], "Authentication and Authorization": ["/admin/auth/group/", "/admin/auth/user/"], } settings.JAZZMIN_SETTINGS["hide_models"] = ["auth.user"] response = admin_client.get(url) assert parse_sidemenu(response) == { "Global": ["/admin/"], "Polls": [ "/admin/polls/allfields/", "/admin/polls/campaign/", "/admin/polls/cheese/", "/admin/polls/choice/", "/admin/polls/poll/", "/admin/polls/vote/", "/make_messages/", ], "Administration": ["/admin/admin/logentry/"], "Authentication and Authorization": ["/admin/auth/group/"], }
def test_no_permission(client): """ When our user has no permissions at all, they see no menu or dashboard As in Plain old Django Admin """ user = UserFactory(permissions=[]) url = reverse("admin:index") client.force_login(user) response = client.get(url) assert parse_sidemenu(response) == {"Global": ["/en/admin/"]}
def test_permissions_on_custom_links(client, settings): """ we honour permissions for the rendering of custom links """ user = user_with_permissions() user2 = user_with_permissions("polls.view_poll") url = reverse("admin:index") settings.JAZZMIN_SETTINGS["custom_links"] = { "polls": [ {"name": "Make Messages", "url": "make_messages", "icon": "fa-comments", "permissions": ["polls.view_poll"]} ] } client.force_login(user) response = client.get(url) assert parse_sidemenu(response) == {"Global": ["/admin/"]} client.force_login(user2) response = client.get(url) assert parse_sidemenu(response) == {"Global": ["/admin/"], "Polls": ["/admin/polls/poll/", "/make_messages/"]}
def test_delete_but_no_view_permission(client): """ When our user has delete but no view/change permission, menu items render out, but with no links As in Plain old Django Admin """ user = user_with_permissions("polls.delete_poll") url = reverse("admin:index") client.force_login(user) response = client.get(url) assert parse_sidemenu(response) == {"Global": ['/admin/'], 'Polls': [None]}
def test_delete_but_no_view_permission(client): """ When our user has delete but no view/change permission, menu items render out, but with no links As in Plain old Django Admin """ user = UserFactory(permissions=["books.delete_book"]) url = reverse("admin:index") client.force_login(user) response = client.get(url) assert parse_sidemenu(response) == { "Global": ["/en/admin/"], "Books": [None] }