def test_returns_false_if_has_privilege_but_is_not_admin(self, mock_user): """ Regardless of privilege, if not admin, this method should always return false """ mock_user.is_domain_admin.return_value = False with patch('corehq.apps.linked_domain.util.domain_has_privilege' ) as mock_domain_has_privilege: mock_domain_has_privilege.return_value = True result = can_user_access_linked_domains(mock_user, 'test') self.assertFalse(result)
def _inner(request, domain, *args, **kwargs): if not hasattr(request, 'couch_user'): raise Http404() couch_user = request.couch_user def call_view(): return view_func(request, domain, *args, **kwargs) if can_user_access_linked_domains(couch_user, domain): return call_view() else: return HttpResponseForbidden()
def test_returns_true_if_has_lite_release_management_and_is_admin( self, mock_user): mock_user.is_domain_admin.return_value = True def mock_handler(domain, privilege): return privilege == LITE_RELEASE_MANAGEMENT with patch('corehq.apps.linked_domain.util.domain_has_privilege' ) as mock_domain_has_privilege: mock_domain_has_privilege.side_effect = mock_handler result = can_user_access_linked_domains(mock_user, 'test') self.assertTrue(result)
def permissions_check(self, report, request, domain=None, is_navigation_check=False): from corehq.apps.linked_domain.util import can_user_access_linked_domains return can_user_access_linked_domains(request.couch_user, domain)
def test_returns_false_if_no_user(self): result = can_user_access_linked_domains(None, 'test') self.assertFalse(result)
def test_returns_false_if_no_domain(self, mock_user): result = can_user_access_linked_domains(mock_user, None) self.assertFalse(result)