From ced3f67ab12341efdee7114bf25b7592fb15ed0e Mon Sep 17 00:00:00 2001 From: Adam Palay Date: Fri, 2 May 2014 15:28:59 -0400 Subject: [PATCH 1/3] fix authentication check in auth --- common/djangoapps/student/auth.py | 2 +- common/djangoapps/student/tests/test_authz.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/common/djangoapps/student/auth.py b/common/djangoapps/student/auth.py index 97583f69dc..e373bec0a7 100644 --- a/common/djangoapps/student/auth.py +++ b/common/djangoapps/student/auth.py @@ -72,7 +72,7 @@ def _check_caller_authority(caller, role): :param caller: a user :param role: an AccessRole """ - if not (caller.is_authenticated and caller.is_active): + if not (caller.is_authenticated() and caller.is_active): raise PermissionDenied # superuser if GlobalStaff().has_user(caller): diff --git a/common/djangoapps/student/tests/test_authz.py b/common/djangoapps/student/tests/test_authz.py index dee2eb84f4..d5d9e8ba29 100644 --- a/common/djangoapps/student/tests/test_authz.py +++ b/common/djangoapps/student/tests/test_authz.py @@ -76,8 +76,10 @@ class CreatorGroupTest(TestCase): """ Tests that adding to creator group fails if user is not authenticated """ - with mock.patch.dict('django.conf.settings.FEATURES', - {'DISABLE_COURSE_CREATION': False, "ENABLE_CREATOR_GROUP": True}): + with mock.patch.dict( + 'django.conf.settings.FEATURES', + {'DISABLE_COURSE_CREATION': False, "ENABLE_CREATOR_GROUP": True} + ): anonymous_user = AnonymousUser() role = CourseCreatorRole() add_users(self.admin, role, anonymous_user) @@ -87,8 +89,10 @@ class CreatorGroupTest(TestCase): """ Tests that adding to creator group fails if user is not active """ - with mock.patch.dict('django.conf.settings.FEATURES', - {'DISABLE_COURSE_CREATION': False, "ENABLE_CREATOR_GROUP": True}): + with mock.patch.dict( + 'django.conf.settings.FEATURES', + {'DISABLE_COURSE_CREATION': False, "ENABLE_CREATOR_GROUP": True} + ): self.user.is_active = False add_users(self.admin, CourseCreatorRole(), self.user) self.assertFalse(has_access(self.user, CourseCreatorRole())) @@ -108,7 +112,7 @@ class CreatorGroupTest(TestCase): def test_add_user_to_group_requires_authenticated(self): with self.assertRaises(PermissionDenied): - self.admin.is_authenticated = False + self.admin.is_authenticated = mock.Mock(return_value=False) add_users(self.admin, CourseCreatorRole(), self.user) def test_remove_user_from_group_requires_staff_access(self): @@ -123,7 +127,7 @@ class CreatorGroupTest(TestCase): def test_remove_user_from_group_requires_authenticated(self): with self.assertRaises(PermissionDenied): - self.admin.is_authenticated = False + self.admin.is_authenticated = mock.Mock(return_value=False) remove_users(self.admin, CourseCreatorRole(), self.user) From a35e359482fc3fc65b7952b4d0f63522c5bde0c3 Mon Sep 17 00:00:00 2001 From: Adam Palay Date: Fri, 2 May 2014 15:31:08 -0400 Subject: [PATCH 2/3] add logging to course import --- cms/djangoapps/contentstore/views/import_export.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cms/djangoapps/contentstore/views/import_export.py b/cms/djangoapps/contentstore/views/import_export.py index b450eef1df..244cae95d6 100644 --- a/cms/djangoapps/contentstore/views/import_export.py +++ b/cms/djangoapps/contentstore/views/import_export.py @@ -238,6 +238,9 @@ def import_handler(request, tag=None, package_id=None, branch=None, version_guid # Send errors to client with stage at which error occurred. except Exception as exception: # pylint: disable=W0703 + log.exception( + "error importing course at {0}".format(new_location) + ) return JsonResponse( { 'ErrMsg': str(exception), From 3d3e15ca1b369818984f60b278a09f4cb4f1b045 Mon Sep 17 00:00:00 2001 From: Adam Palay Date: Mon, 5 May 2014 10:05:04 -0400 Subject: [PATCH 3/3] remove new_location from logging --- cms/djangoapps/contentstore/views/import_export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cms/djangoapps/contentstore/views/import_export.py b/cms/djangoapps/contentstore/views/import_export.py index 244cae95d6..f67810e83c 100644 --- a/cms/djangoapps/contentstore/views/import_export.py +++ b/cms/djangoapps/contentstore/views/import_export.py @@ -239,7 +239,7 @@ def import_handler(request, tag=None, package_id=None, branch=None, version_guid # Send errors to client with stage at which error occurred. except Exception as exception: # pylint: disable=W0703 log.exception( - "error importing course at {0}".format(new_location) + "error importing course" ) return JsonResponse( {