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

@@ -33,7 +33,7 @@ def index(request):
"""
Redirects to main page -- info page if user authenticated, or marketing if not
"""
if request.user.is_authenticated():
if request.user.is_authenticated:
# Only redirect to dashboard if user has
# courses in his/her dashboard. Otherwise UX is a bit cryptic.
# In this case, we want to have the user stay on a course catalog

View File

@@ -39,7 +39,7 @@ def request_certificate(request):
then if and only if they pass, do they get a certificate issued.
"""
if request.method == "POST":
if request.user.is_authenticated():
if request.user.is_authenticated:
username = request.user.username
student = User.objects.get(username=username)
course_key = CourseKey.from_string(request.POST.get('course_id'))

View File

@@ -19,9 +19,9 @@ class ApiKeyOrModelPermission(BasePermission):
class IsAuthenticatedOrActivationOverridden(BasePermission):
""" Considers the account activation override switch when determining the authentication status of the user """
def has_permission(self, request, view):
if not request.user.is_authenticated() and is_account_activation_requirement_disabled():
if not request.user.is_authenticated and is_account_activation_requirement_disabled():
try:
request.user = User.objects.get(id=request.session._session_cache['_auth_user_id'])
except DoesNotExist:
pass
return request.user.is_authenticated()
return request.user.is_authenticated

View File

@@ -73,7 +73,7 @@ class OrderView(APIView):
""" HTTP handler. """
# If the account activation requirement is disabled for this installation, override the
# anonymous user object attached to the request with the actual user object (if it exists)
if not request.user.is_authenticated() and is_account_activation_requirement_disabled():
if not request.user.is_authenticated and is_account_activation_requirement_disabled():
try:
request.user = User.objects.get(id=request.session._session_cache['_auth_user_id'])
except User.DoesNotExist:

View File

@@ -85,7 +85,7 @@ class EcommerceService(object):
Boolean
"""
user_is_active = user.is_active or is_account_activation_requirement_disabled()
allow_user = user_is_active or user.is_anonymous()
allow_user = user_is_active or user.is_anonymous
return allow_user and self.config.checkout_on_ecommerce_service
def payment_page_url(self):

View File

@@ -41,7 +41,7 @@ def get_course_goal(user, course_key):
If the user is anonymous or a course goal does not exist, returns None.
"""
if user.is_anonymous():
if user.is_anonymous:
return None
course_goals = models.CourseGoal.objects.filter(user=user, course_key=course_key)

View File

@@ -48,7 +48,7 @@ class WikiAccessMiddleware(object):
return
# wiki pages are login required
if not request.user.is_authenticated():
if not request.user.is_authenticated:
return redirect(reverse('signin_user'), next=request.path)
course_id = course_id_from_url(request.path)

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(

View File

@@ -752,7 +752,7 @@ def upload(request, course_id): # ajax upload file to a question or answer
try:
# TODO authorization
#may raise exceptions.PermissionDenied
#if request.user.is_anonymous():
#if request.user.is_anonymous:
# msg = _('Sorry, anonymous users cannot upload files')
# raise exceptions.PermissionDenied(msg)

View File

@@ -30,7 +30,7 @@ class EdxNotesTab(EnrolledTab):
if not settings.FEATURES.get("ENABLE_EDXNOTES") or is_harvard_notes_enabled(course):
return False
if user and not user.is_authenticated():
if user and not user.is_authenticated:
return False
return course.edxnotes

View File

@@ -32,7 +32,7 @@ def check_and_get_upgrade_link_and_date(user, enrollment=None, course=None):
if enrollment is None:
enrollment = CourseEnrollment.get_enrollment(user, course.id)
if user.is_authenticated() and verified_upgrade_link_is_valid(enrollment):
if user.is_authenticated and verified_upgrade_link_is_valid(enrollment):
return (
verified_upgrade_deadline_link(user, course),
enrollment.upgrade_deadline

View File

@@ -105,7 +105,7 @@ class GradeViewMixin(DeveloperErrorViewMixin):
Ensures that the user is authenticated (e.g. not an AnonymousUser), unless DEBUG mode is enabled.
"""
super(GradeViewMixin, self).perform_authentication(request)
if request.user.is_anonymous():
if request.user.is_anonymous:
raise AuthenticationFailed

View File

@@ -39,7 +39,7 @@ class ProgramsFragmentView(EdxFragmentView):
mobile_only = False
programs_config = kwargs.get('programs_config') or ProgramsApiConfig.current()
if not programs_config.enabled or not user.is_authenticated():
if not programs_config.enabled or not user.is_authenticated:
raise Http404
meter = ProgramProgressMeter(request.site, user, mobile_only=mobile_only)
@@ -76,7 +76,7 @@ class ProgramDetailsFragmentView(EdxFragmentView):
def render_to_fragment(self, request, program_uuid, **kwargs):
"""View details about a specific program."""
programs_config = kwargs.get('programs_config') or ProgramsApiConfig.current()
if not programs_config.enabled or not request.user.is_authenticated():
if not programs_config.enabled or not request.user.is_authenticated:
raise Http404
meter = ProgramProgressMeter(request.site, request.user, uuid=program_uuid)

View File

@@ -116,7 +116,7 @@ class AuthenticateLtiUserTest(TestCase):
def test_authentication_with_authenticated_user(self, create_user, switch_user):
lti_user = self.create_lti_user_model()
self.request.user = lti_user.edx_user
assert self.request.user.is_authenticated()
assert self.request.user.is_authenticated
users.authenticate_lti_user(self.request, self.lti_user_id, self.lti_consumer)
self.assertFalse(create_user.called)
self.assertFalse(switch_user.called)
@@ -133,7 +133,7 @@ class AuthenticateLtiUserTest(TestCase):
def test_authentication_with_wrong_user(self, create_user, switch_user):
lti_user = self.create_lti_user_model()
self.request.user = self.old_user
assert self.request.user.is_authenticated()
assert self.request.user.is_authenticated
users.authenticate_lti_user(self.request, self.lti_user_id, self.lti_consumer)
self.assertFalse(create_user.called)
switch_user.assert_called_with(self.request, lti_user, self.lti_consumer)

View File

@@ -35,7 +35,7 @@ def authenticate_lti_user(request, lti_user_id, lti_consumer):
# This is the first time that the user has been here. Create an account.
lti_user = create_lti_user(lti_user_id, lti_consumer)
if not (request.user.is_authenticated() and
if not (request.user.is_authenticated and
request.user == lti_user.edx_user):
# The user is not authenticated, or is logged in as somebody else.
# Switch them to the LTI user

View File

@@ -123,7 +123,7 @@ def ajax_enable(request):
user, this has no effect. Otherwise, a preference is created with the
unsubscribe token (an encryption of the username) as the value.username
"""
if not request.user.is_authenticated():
if not request.user.is_authenticated:
raise PermissionDenied
enable_notifications(request.user)
@@ -139,7 +139,7 @@ def ajax_disable(request):
This view should be invoked by an AJAX POST call. It returns status 204
(no content) or an error.
"""
if not request.user.is_authenticated():
if not request.user.is_authenticated:
raise PermissionDenied
delete_user_preference(request.user, NOTIFICATION_PREF_KEY)
@@ -155,7 +155,7 @@ def ajax_status(request):
This view should be invoked by an AJAX GET call. It returns status 200,
with a JSON-formatted payload, or an error.
"""
if not request.user.is_authenticated():
if not request.user.is_authenticated:
raise PermissionDenied
qs = UserPreference.objects.filter(

View File

@@ -23,7 +23,7 @@ def user_has_cart_context_processor(request):
"""
return (
# user is logged in and
request.user.is_authenticated() and
request.user.is_authenticated and
# do we have the feature turned on
is_shopping_cart_enabled() and
# does the user actually have a cart (optimized query to prevent creation of a cart when not needed)

View File

@@ -170,7 +170,7 @@ class Order(models.Model):
If a item_type is passed in, then we check to see if the cart has at least one of
those types of OrderItems
"""
if not user.is_authenticated():
if not user.is_authenticated:
return False
cart = cls.get_cart_for_user(user)

View File

@@ -106,7 +106,7 @@ def add_course_to_cart(request, course_id):
"""
assert isinstance(course_id, basestring)
if not request.user.is_authenticated():
if not request.user.is_authenticated:
log.info(u"Anon user trying to add course %s to cart", course_id)
return HttpResponseForbidden(_('You must be logged-in to add to a shopping cart'))
cart = Order.get_cart_for_user(request.user)

View File

@@ -76,7 +76,7 @@ def login_and_registration_form(request, initial_mode="login"):
# Determine the URL to redirect to following login/registration/third_party_auth
redirect_to = get_next_url_for_login_page(request)
# If we're already logged in, redirect to the dashboard
if request.user.is_authenticated():
if request.user.is_authenticated:
return redirect(redirect_to)
# Retrieve the form descriptions from the user API
@@ -206,12 +206,12 @@ def password_change_request_handler(request):
user = request.user
# Prefer logged-in user's email
email = user.email if user.is_authenticated() else request.POST.get('email')
email = user.email if user.is_authenticated else request.POST.get('email')
if email:
try:
request_password_change(email, request.is_secure())
user = user if user.is_authenticated() else User.objects.get(email=email)
user = user if user.is_authenticated else User.objects.get(email=email)
destroy_oauth_tokens(user)
except UserNotFound:
AUDIT_LOG.info("Invalid password reset attempt")

View File

@@ -31,7 +31,7 @@ class ContactUsView(View):
current_site_name = current_site_name.replace(".", "_")
tags.append("site_name_{site}".format(site=current_site_name))
if request.user.is_authenticated():
if request.user.is_authenticated:
context['course_id'] = request.session.get('course_id', '')
context['user_enrollments'] = CourseEnrollment.enrollments_for_user_with_overviews_preload(request.user)
enterprise_learner_data = enterprise_api.get_enterprise_learner_data(user=request.user)

View File

@@ -182,7 +182,7 @@ class SurveyAnswer(TimeStampedModel):
Returns whether a user has any answers for a given SurveyForm for a course
This can be used to determine if a user has taken a CourseSurvey.
"""
if user.is_anonymous():
if user.is_anonymous:
return False
return SurveyAnswer.objects.filter(form=form, user=user).exists()

View File

@@ -27,7 +27,7 @@ def is_survey_required_and_unanswered(user, course_descriptor):
return False
# anonymous users do not need to answer the survey
if user.is_anonymous():
if user.is_anonymous:
return False
# course staff do not need to answer survey