Eric Fischer
2018-05-02 10:03:50 -04:00
parent a1869d67f2
commit e18448e27d
79 changed files with 137 additions and 137 deletions

View File

@@ -201,7 +201,7 @@ def _can_view_courseware_with_prerequisites(user, course): # pylint: disable=in
return (
_is_prerequisites_disabled()
or _has_staff_access_to_descriptor(user, course, course.id)
or user.is_anonymous()
or user.is_anonymous
or _has_fulfilled_prerequisites(user, [course.id])
)
@@ -250,7 +250,7 @@ def _can_enroll_courselike(user, courselike):
# If using a registration method to restrict enrollment (e.g., Shibboleth)
if settings.FEATURES.get('RESTRICT_ENROLL_BY_REG_METHOD') and enrollment_domain:
if user is not None and user.is_authenticated() and \
if user is not None and user.is_authenticated and \
ExternalAuthMap.objects.filter(user=user, external_domain=enrollment_domain):
debug("Allow: external_auth of " + enrollment_domain)
reg_method_ok = True
@@ -263,7 +263,7 @@ def _can_enroll_courselike(user, courselike):
# they may enroll, except if the CEA has already been used by a different user.
# Note that as dictated by the legacy database schema, the filter call includes
# a `course_id` kwarg which requires a CourseKey.
if user is not None and user.is_authenticated():
if user is not None and user.is_authenticated:
cea = CourseEnrollmentAllowed.objects.filter(email=user.email, course_id=course_key).first()
if cea and cea.valid_for_user(user):
return ACCESS_GRANTED
@@ -667,7 +667,7 @@ def _has_access_to_course(user, access_level, course_key):
access_level = string, either "staff" or "instructor"
"""
if user is None or (not user.is_authenticated()):
if user is None or (not user.is_authenticated):
debug("Deny: no user or anon user")
return ACCESS_DENIED

View File

@@ -31,7 +31,7 @@ def user_timezone_locale_prefs(request):
'user_timezone': None,
'user_language': None,
}
if hasattr(request, 'user') and request.user.is_authenticated():
if hasattr(request, 'user') and request.user.is_authenticated:
try:
user_preferences = get_user_preferences(request.user)
except (UserNotFound, UserAPIInternalError):

View File

@@ -29,7 +29,7 @@ def user_can_skip_entrance_exam(user, course):
"""
if not course_has_entrance_exam(course):
return True
if not user.is_authenticated():
if not user.is_authenticated:
return False
if has_access(user, 'staff', course):
return True
@@ -47,7 +47,7 @@ def user_has_passed_entrance_exam(user, course):
"""
if not course_has_entrance_exam(course):
return True
if not user.is_authenticated():
if not user.is_authenticated:
return False
return get_entrance_exam_content(user, course) is None

View File

@@ -27,7 +27,7 @@ class CacheCourseIdMiddleware(object):
"""
Add a course_id to user request session.
"""
if request.user.is_authenticated():
if request.user.is_authenticated:
match = COURSE_REGEX.match(request.build_absolute_uri())
course_id = None
if match:

View File

@@ -728,7 +728,7 @@ class FieldDataCache(object):
"""
Add all `descriptors` to this FieldDataCache.
"""
if self.user.is_authenticated():
if self.user.is_authenticated:
self.scorable_locations.update(desc.location for desc in descriptors if desc.has_score)
for scope, fields in self._fields_to_cache(descriptors).items():
if scope not in self.cache:
@@ -815,7 +815,7 @@ class FieldDataCache(object):
Raises: KeyError if key isn't found in the cache
"""
if key.scope.user == UserScope.ONE and not self.user.is_anonymous():
if key.scope.user == UserScope.ONE and not self.user.is_anonymous:
# If we're getting user data, we expect that the key matches the
# user we were constructed for.
assert key.user_id == self.user.id
@@ -842,7 +842,7 @@ class FieldDataCache(object):
by_scope = defaultdict(dict)
for key, value in kv_dict.iteritems():
if key.scope.user == UserScope.ONE and not self.user.is_anonymous():
if key.scope.user == UserScope.ONE and not self.user.is_anonymous:
# If we're getting user data, we expect that the key matches the
# user we were constructed for.
assert key.user_id == self.user.id
@@ -875,7 +875,7 @@ class FieldDataCache(object):
if self.read_only:
return
if key.scope.user == UserScope.ONE and not self.user.is_anonymous():
if key.scope.user == UserScope.ONE and not self.user.is_anonymous:
# If we're getting user data, we expect that the key matches the
# user we were constructed for.
assert key.user_id == self.user.id
@@ -896,7 +896,7 @@ class FieldDataCache(object):
Returns: bool
"""
if key.scope.user == UserScope.ONE and not self.user.is_anonymous():
if key.scope.user == UserScope.ONE and not self.user.is_anonymous:
# If we're getting user data, we expect that the key matches the
# user we were constructed for.
assert key.user_id == self.user.id
@@ -916,7 +916,7 @@ class FieldDataCache(object):
Returns: datetime if there was a modified date, or None otherwise
"""
if key.scope.user == UserScope.ONE and not self.user.is_anonymous():
if key.scope.user == UserScope.ONE and not self.user.is_anonymous:
# If we're getting user data, we expect that the key matches the
# user we were constructed for.
assert key.user_id == self.user.id

View File

@@ -582,7 +582,7 @@ def get_module_system_for_user(
Returns:
nothing (but the side effect is that module is re-bound to real_user)
"""
if user.is_authenticated():
if user.is_authenticated:
err_msg = ("rebind_noauth_module_to_user can only be called from a module bound to "
"an anonymous user")
log.error(err_msg)
@@ -943,10 +943,10 @@ def handle_xblock_callback(request, course_id, usage_id, handler, suffix=None):
"""
# NOTE (CCB): Allow anonymous GET calls (e.g. for transcripts). Modifying this view is simpler than updating
# the XBlocks to use `handle_xblock_callback_noauth`...which is practically identical to this view.
if request.method != 'GET' and not request.user.is_authenticated():
if request.method != 'GET' and not request.user.is_authenticated:
return HttpResponseForbidden()
request.user.known = request.user.is_authenticated()
request.user.known = request.user.is_authenticated
try:
course_key = CourseKey.from_string(course_id)
@@ -1119,7 +1119,7 @@ def xblock_view(request, course_id, usage_id, view_name):
" see FEATURES['ENABLE_XBLOCK_VIEW_ENDPOINT']")
raise Http404
if not request.user.is_authenticated():
if not request.user.is_authenticated:
raise PermissionDenied
try:

View File

@@ -19,7 +19,7 @@ class EnrolledTab(CourseTab):
"""
@classmethod
def is_enabled(cls, course, user=None):
return user and user.is_authenticated() and \
return user and user.is_authenticated and \
bool(CourseEnrollment.is_enrolled(user, course.id) or has_access(user, 'staff', course, course.id))
@@ -119,7 +119,7 @@ class TextbookTabsBase(CourseTab):
@classmethod
def is_enabled(cls, course, user=None):
return user is None or user.is_authenticated()
return user is None or user.is_authenticated
@classmethod
def items(cls, course):

View File

@@ -265,7 +265,7 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient):
else:
user = User.objects.get(username=username)
if user.is_anonymous():
if user.is_anonymous:
# Anonymous users cannot be persisted to the database, so let's just use
# what we have.
return

View File

@@ -97,7 +97,7 @@ class CoursewareIndex(View):
"""
self.course_key = CourseKey.from_string(course_id)
if not (request.user.is_authenticated() or self.enable_anonymous_courseware_access):
if not (request.user.is_authenticated or self.enable_anonymous_courseware_access):
return redirect_to_login(request.get_full_path())
self.original_chapter_url_name = chapter
@@ -156,7 +156,7 @@ class CoursewareIndex(View):
self._save_positions()
self._prefetch_and_bind_section()
if not request.user.is_authenticated():
if not request.user.is_authenticated:
qs = urllib.urlencode({
'course_id': self.course_key,
'enrollment_action': 'enroll',
@@ -218,7 +218,7 @@ class CoursewareIndex(View):
"""
redeemed_registration_codes = []
if self.request.user.is_authenticated():
if self.request.user.is_authenticated:
self.real_user = User.objects.prefetch_related("groups").get(id=self.real_user.id)
redeemed_registration_codes = CourseRegistrationCode.objects.filter(
course_id=self.course_key,
@@ -255,7 +255,7 @@ class CoursewareIndex(View):
"""
language_preference = settings.LANGUAGE_CODE
if self.request.user.is_authenticated():
if self.request.user.is_authenticated:
language_preference = get_user_preference(self.real_user, LANGUAGE_KEY)
return language_preference
@@ -484,12 +484,12 @@ class CoursewareIndex(View):
# NOTE (CCB): Pull the position from the URL for un-authenticated users. Otherwise, pull the saved
# state from the data store.
position = None if self.request.user.is_authenticated() else self.position
position = None if self.request.user.is_authenticated else self.position
section_context = {
'activate_block_id': self.request.GET.get('activate_block_id'),
'requested_child': self.request.GET.get("child"),
'progress_url': reverse('progress', kwargs={'course_id': unicode(self.course_key)}),
'user_authenticated': self.request.user.is_authenticated(),
'user_authenticated': self.request.user.is_authenticated,
'position': position,
}
if previous_of_active_section:

View File

@@ -185,7 +185,7 @@ def user_groups(user):
"""
TODO (vshnayder): This is not used. When we have a new plan for groups, adjust appropriately.
"""
if not user.is_authenticated():
if not user.is_authenticated:
return []
# TODO: Rewrite in Django
@@ -335,7 +335,7 @@ def course_info(request, course_id):
# LEARNER-1697: Transition banner messages to new Course Home (DONE)
# if user is not enrolled in a course then app will show enroll/get register link inside course info page.
user_is_enrolled = CourseEnrollment.is_enrolled(user, course.id)
show_enroll_banner = request.user.is_authenticated() and not user_is_enrolled
show_enroll_banner = request.user.is_authenticated and not user_is_enrolled
# If the user is not enrolled but this is a course that does not support
# direct enrollment then redirect them to the dashboard.
@@ -358,7 +358,7 @@ def course_info(request, course_id):
# Construct the dates fragment
dates_fragment = None
if request.user.is_authenticated():
if request.user.is_authenticated:
# TODO: LEARNER-611: Remove enable_course_home_improvements
if SelfPacedConfiguration.current().enable_course_home_improvements:
# Shared code with the new Course Home (DONE)
@@ -520,7 +520,7 @@ class CourseTabView(EdxFragmentView):
"""
Register messages to be shown to the user if they have limited access.
"""
if request.user.is_anonymous():
if request.user.is_anonymous:
PageLevelMessages.register_warning_message(
request,
Text(_("To see course content, {sign_in_link} or {register_link}.")).format(
@@ -677,7 +677,7 @@ def registered_for_course(course, user):
"""
if user is None:
return False
if user.is_authenticated():
if user.is_authenticated:
return CourseEnrollment.is_enrolled(user, course.id)
else:
return False
@@ -785,7 +785,7 @@ def course_about(request, course_id):
_is_shopping_cart_enabled = is_shopping_cart_enabled()
if _is_shopping_cart_enabled:
if request.user.is_authenticated():
if request.user.is_authenticated:
cart = shoppingcart.models.Order.get_cart_for_user(request.user)
in_cart = shoppingcart.models.PaidCourseRegistration.contained_in_order(cart, course_key) or \
shoppingcart.models.CourseRegCodeItem.contained_in_order(cart, course_key)
@@ -1360,7 +1360,7 @@ def generate_user_cert(request, course_id):
"""
if not request.user.is_authenticated():
if not request.user.is_authenticated:
log.info(u"Anon user trying to generate certificate for %s", course_id)
return HttpResponseBadRequest(
_('You must be signed in to {platform_name} to create a certificate.').format(