mirror of
https://github.com/haiwen/seahub.git
synced 2025-04-27 19:05:16 +00:00
fix django2 syntax
This commit is contained in:
parent
64ad908637
commit
05a55b38c4
@ -187,13 +187,13 @@ class ShareLinkZipTaskView(APIView):
|
||||
# permission check
|
||||
# check if login required
|
||||
if SHARE_LINK_LOGIN_REQUIRED and \
|
||||
not request.user.is_authenticated():
|
||||
not request.user.is_authenticated:
|
||||
error_msg = 'Permission denied.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
|
||||
# check share link audit
|
||||
if is_pro_version() and ENABLE_SHARE_LINK_AUDIT and \
|
||||
not request.user.is_authenticated() and \
|
||||
not request.user.is_authenticated and \
|
||||
not request.session.get('anonymous_email'):
|
||||
error_msg = 'Permission denied.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
|
@ -579,7 +579,7 @@ class ShareLinkOnlineOfficeLock(APIView):
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||
|
||||
if SHARE_LINK_LOGIN_REQUIRED and \
|
||||
not request.user.is_authenticated():
|
||||
not request.user.is_authenticated:
|
||||
error_msg = 'Permission denied.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
|
||||
@ -652,13 +652,13 @@ class ShareLinkDirents(APIView):
|
||||
|
||||
# check if login required
|
||||
if SHARE_LINK_LOGIN_REQUIRED and \
|
||||
not request.user.is_authenticated():
|
||||
not request.user.is_authenticated:
|
||||
error_msg = 'Permission denied.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
|
||||
# check share link audit
|
||||
if is_pro_version() and ENABLE_SHARE_LINK_AUDIT and \
|
||||
not request.user.is_authenticated() and \
|
||||
not request.user.is_authenticated and \
|
||||
not request.session.get('anonymous_email'):
|
||||
error_msg = 'Permission denied.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
@ -757,13 +757,13 @@ class ShareLinkUpload(APIView):
|
||||
|
||||
# check if login required
|
||||
if SHARE_LINK_LOGIN_REQUIRED and \
|
||||
not request.user.is_authenticated():
|
||||
not request.user.is_authenticated:
|
||||
error_msg = 'Permission denied.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
|
||||
# check share link audit
|
||||
if is_pro_version() and ENABLE_SHARE_LINK_AUDIT and \
|
||||
not request.user.is_authenticated() and \
|
||||
not request.user.is_authenticated and \
|
||||
not request.session.get('anonymous_email'):
|
||||
error_msg = 'Permission denied.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
@ -855,13 +855,13 @@ class ShareLinkUploadDone(APIView):
|
||||
|
||||
# check if login required
|
||||
if SHARE_LINK_LOGIN_REQUIRED and \
|
||||
not request.user.is_authenticated():
|
||||
not request.user.is_authenticated:
|
||||
error_msg = 'Permission denied.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
|
||||
# check share link audit
|
||||
if is_pro_version() and ENABLE_SHARE_LINK_AUDIT and \
|
||||
not request.user.is_authenticated() and \
|
||||
not request.user.is_authenticated and \
|
||||
not request.session.get('anonymous_email'):
|
||||
error_msg = 'Permission denied.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
|
@ -38,7 +38,7 @@ def login_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME):
|
||||
to the log-in page if necessary.
|
||||
"""
|
||||
actual_decorator = user_passes_test(
|
||||
lambda u: u.is_authenticated(),
|
||||
lambda u: u.is_authenticated,
|
||||
redirect_field_name=redirect_field_name
|
||||
)
|
||||
if function:
|
||||
@ -66,7 +66,7 @@ def login_required_ajax(function=None,redirect_field_name=None):
|
||||
if not request.is_ajax():
|
||||
raise Http404
|
||||
|
||||
if request.user.is_authenticated():
|
||||
if request.user.is_authenticated:
|
||||
return view_func(request, *args, **kwargs)
|
||||
else:
|
||||
content_type = 'application/json; charset=utf-8'
|
||||
|
@ -30,7 +30,7 @@ class AuthenticationMiddleware(MiddlewareMixin):
|
||||
request, 'session'
|
||||
), "The Django authentication middleware requires session middleware to be installed. Edit your MIDDLEWARE setting to insert 'django.contrib.sessions.middleware.SessionMiddleware'."
|
||||
request.__class__.user = LazyUser()
|
||||
if request.user.is_authenticated() and not request.user.is_active:
|
||||
if request.user.is_authenticated and not request.user.is_active:
|
||||
request.session.clear()
|
||||
request.session.delete()
|
||||
return None
|
||||
@ -92,8 +92,7 @@ class SeafileRemoteUserMiddleware(MiddlewareMixin):
|
||||
# If specified header doesn't exist then remove any existing
|
||||
# authenticated remote-user, or return (leaving request.user set to
|
||||
# AnonymousUser by the AuthenticationMiddleware).
|
||||
if self.force_logout_if_no_header and request.user.is_authenticated(
|
||||
):
|
||||
if self.force_logout_if_no_header and request.user.is_authenticated:
|
||||
self._remove_invalid_user(request)
|
||||
return
|
||||
|
||||
@ -103,7 +102,7 @@ class SeafileRemoteUserMiddleware(MiddlewareMixin):
|
||||
# If the user is already authenticated and that user is the user we are
|
||||
# getting passed in the headers, then the correct user is already
|
||||
# persisted in the session and we don't need to continue.
|
||||
if request.user.is_authenticated():
|
||||
if request.user.is_authenticated:
|
||||
if request.user.get_username() == self.clean_username(
|
||||
username, request):
|
||||
if request.user.is_staff:
|
||||
|
@ -120,9 +120,11 @@ class AnonymousUser(object):
|
||||
def get_and_delete_messages(self):
|
||||
return []
|
||||
|
||||
@property
|
||||
def is_anonymous(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def is_authenticated(self):
|
||||
return False
|
||||
|
||||
|
@ -92,7 +92,7 @@ def login(request, template_name='registration/login.html',
|
||||
"""Displays the login form and handles the login action."""
|
||||
|
||||
redirect_to = request.GET.get(redirect_field_name, '')
|
||||
if request.user.is_authenticated():
|
||||
if request.user.is_authenticated:
|
||||
if redirect_to:
|
||||
return HttpResponseRedirect(redirect_to)
|
||||
else:
|
||||
|
@ -312,6 +312,7 @@ class User(object):
|
||||
def __unicode__(self):
|
||||
return self.username
|
||||
|
||||
@property
|
||||
def is_anonymous(self):
|
||||
"""
|
||||
Always returns False. This is a way of comparing User objects to
|
||||
@ -319,6 +320,7 @@ class User(object):
|
||||
"""
|
||||
return False
|
||||
|
||||
@property
|
||||
def is_authenticated(self):
|
||||
"""
|
||||
Always return True. This is a way to tell if the user has been
|
||||
|
@ -43,7 +43,7 @@ def org_user_exists(org_id, username):
|
||||
|
||||
########## helper functions
|
||||
def is_group_staff(group, user):
|
||||
if user.is_anonymous():
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
return seaserv.check_group_staff(group.id, user.username)
|
||||
|
||||
@ -81,7 +81,7 @@ def group_check(func):
|
||||
group.is_staff = False
|
||||
group.is_pub = False
|
||||
|
||||
if not request.user.is_authenticated():
|
||||
if not request.user.is_authenticated:
|
||||
if not group.is_pub:
|
||||
login_url = settings.LOGIN_URL
|
||||
path = urlquote(request.get_full_path())
|
||||
|
@ -8,7 +8,7 @@ def inst_admin_required(func):
|
||||
Decorator for views check whether user is a institution admin.
|
||||
"""
|
||||
def _decorated(request, *args, **kwargs):
|
||||
if request.user.is_authenticated() and request.user.inst_admin is True:
|
||||
if request.user.is_authenticated and request.user.inst_admin is True:
|
||||
return func(request, *args, **kwargs)
|
||||
raise Http404
|
||||
return _decorated
|
||||
|
@ -8,7 +8,7 @@ from .handlers import get_password_hash, PASSWORD_HASH_KEY
|
||||
class CheckPasswordHash(MiddlewareMixin):
|
||||
"""Logout user if value of hash key in session is not equal to current password hash"""
|
||||
def process_view(self, request, *args, **kwargs):
|
||||
if getattr(request.user, 'is_authenticated') and request.user.is_authenticated():
|
||||
if getattr(request.user, 'is_authenticated') and request.user.is_authenticated:
|
||||
if request.user.enc_password == '!':
|
||||
# Disable for LDAP/Shibboleth/SAML/... users.
|
||||
return None
|
||||
|
@ -21,7 +21,7 @@ def share_link_audit(func):
|
||||
return func(request, fileshare, *args, **kwargs)
|
||||
|
||||
# no audit for authenticated user, since we've already got email address
|
||||
if request.user.is_authenticated():
|
||||
if request.user.is_authenticated:
|
||||
return func(request, fileshare, *args, **kwargs)
|
||||
|
||||
# anonymous user
|
||||
@ -60,7 +60,7 @@ def share_link_audit(func):
|
||||
def share_link_login_required(func):
|
||||
|
||||
def _decorated(request, *args, **kwargs):
|
||||
if not request.user.is_authenticated() \
|
||||
if not request.user.is_authenticated \
|
||||
and settings.SHARE_LINK_LOGIN_REQUIRED:
|
||||
return redirect_to_login(request)
|
||||
else:
|
||||
|
@ -20,7 +20,7 @@ def otp_required(view=None, redirect_field_name='next', login_url=None, if_confi
|
||||
login_url = settings.OTP_LOGIN_URL
|
||||
|
||||
def test(user):
|
||||
return user.is_verified() or (if_configured and user.is_authenticated() and not user_has_device(user))
|
||||
return user.is_verified() or (if_configured and user.is_authenticated and not user_has_device(user))
|
||||
|
||||
decorator = user_passes_test(test, login_url=login_url, redirect_field_name=redirect_field_name)
|
||||
|
||||
|
@ -45,7 +45,7 @@ class OTPMiddleware(MiddlewareMixin):
|
||||
user.otp_device = None
|
||||
user.is_verified = IsVerified(user)
|
||||
|
||||
if user.is_anonymous():
|
||||
if user.is_anonymous:
|
||||
return None
|
||||
|
||||
device_id = request.session.get(DEVICE_ID_SESSION_KEY)
|
||||
@ -80,7 +80,7 @@ class ForceTwoFactorAuthMiddleware(MiddlewareMixin):
|
||||
if user is None:
|
||||
return None
|
||||
|
||||
if user.is_anonymous():
|
||||
if user.is_anonymous:
|
||||
return None
|
||||
|
||||
if not self.filter_request(request):
|
||||
|
@ -15,7 +15,7 @@ def devices_for_user(user):
|
||||
|
||||
:rtype: iterable
|
||||
"""
|
||||
if user.is_anonymous():
|
||||
if user.is_anonymous:
|
||||
return
|
||||
|
||||
for model in TOTPDevice, PhoneDevice, StaticDevice:
|
||||
@ -43,7 +43,7 @@ def user_has_device(user):
|
||||
return has_device
|
||||
|
||||
def default_device(user):
|
||||
if not user or user.is_anonymous():
|
||||
if not user or user.is_anonymous:
|
||||
return
|
||||
|
||||
for device in devices_for_user(user):
|
||||
|
@ -238,7 +238,7 @@ def is_device_remembered(request_header, user):
|
||||
return False
|
||||
|
||||
# User must be authenticated, otherwise this function is wrong used.
|
||||
assert user.is_authenticated()
|
||||
assert user.is_authenticated
|
||||
|
||||
SessionStore = import_module(settings.SESSION_ENGINE).SessionStore
|
||||
s = SessionStore(request_header)
|
||||
|
@ -61,7 +61,7 @@ class OTPRequiredMixin(object):
|
||||
return self.verification_url and str(self.verification_url)
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if not request.user.is_authenticated() or \
|
||||
if not request.user.is_authenticated or \
|
||||
(not request.user.is_verified() and default_device(request.user)):
|
||||
# If the user has not authenticated raise or redirect to the login
|
||||
# page. Also if the user just enabled two-factor authentication and
|
||||
|
@ -859,7 +859,7 @@ def i18n(request):
|
||||
lang = settings.LANGUAGE_CODE
|
||||
|
||||
# set language code to user profile if user is logged in
|
||||
if not request.user.is_anonymous():
|
||||
if not request.user.is_anonymous:
|
||||
p = Profile.objects.get_profile_by_user(request.user.username)
|
||||
if p is not None:
|
||||
# update exist record
|
||||
@ -1102,7 +1102,7 @@ def client_token_login(request):
|
||||
pass
|
||||
|
||||
if user:
|
||||
if request.user.is_authenticated() and request.user.username == user.username:
|
||||
if request.user.is_authenticated and request.user.username == user.username:
|
||||
pass
|
||||
else:
|
||||
request.client_token_login = True
|
||||
|
@ -1178,7 +1178,7 @@ def view_shared_file(request, fileshare):
|
||||
|
||||
if filetype in (DOCUMENT, SPREADSHEET):
|
||||
|
||||
if not request.user.is_authenticated():
|
||||
if not request.user.is_authenticated:
|
||||
username = ANONYMOUS_EMAIL
|
||||
else:
|
||||
username = request.user.username
|
||||
@ -1387,7 +1387,7 @@ def view_file_via_shared_dir(request, fileshare):
|
||||
|
||||
if filetype in (DOCUMENT, SPREADSHEET):
|
||||
|
||||
if not request.user.is_authenticated():
|
||||
if not request.user.is_authenticated:
|
||||
username = ANONYMOUS_EMAIL
|
||||
else:
|
||||
username = request.user.username
|
||||
@ -1749,7 +1749,7 @@ def _check_office_convert_perm(request, repo_id, path, ret):
|
||||
return True
|
||||
return False
|
||||
else:
|
||||
return request.user.is_authenticated() and \
|
||||
return request.user.is_authenticated and \
|
||||
check_folder_permission(request, repo_id, '/') is not None
|
||||
|
||||
def _check_cluster_internal_token(request, file_id):
|
||||
|
@ -90,7 +90,7 @@ class Wiki(models.Model):
|
||||
if self.permission == 'public':
|
||||
return True
|
||||
else: # private
|
||||
if not request.user.is_authenticated():
|
||||
if not request.user.is_authenticated:
|
||||
return False
|
||||
repo_perm = check_folder_permission(request, self.repo_id, '/')
|
||||
if not repo_perm:
|
||||
|
@ -80,7 +80,7 @@ class ShibbolethRemoteUserMiddleware(RemoteUserMiddleware):
|
||||
# If the user is already authenticated and that user is the user we are
|
||||
# getting passed in the headers, then the correct user is already
|
||||
# persisted in the session and we don't need to continue.
|
||||
if request.user.is_authenticated():
|
||||
if request.user.is_authenticated:
|
||||
if request.user.username == username:
|
||||
if request.user.is_staff:
|
||||
update_sudo_mode_ts(request)
|
||||
|
@ -86,8 +86,8 @@ class AttributesTest(unittest.TestCase):
|
||||
self.assertEqual(user.email, 'Sample_Developer@school.edu')
|
||||
self.assertEqual(user.first_name, 'Sample')
|
||||
self.assertEqual(user.last_name, 'Developer')
|
||||
self.assertTrue(user.is_authenticated())
|
||||
self.assertFalse(user.is_anonymous())
|
||||
self.assertTrue(user.is_authenticated)
|
||||
self.assertFalse(user.is_anonymous)
|
||||
|
||||
class LogoutTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
@ -18,7 +18,7 @@ def terms_required(view_func):
|
||||
@wraps(view_func, assigned=available_attrs(view_func))
|
||||
def _wrapped_view(request, *args, **kwargs):
|
||||
"""Method to wrap the view passed in"""
|
||||
if not request.user.is_authenticated() or TermsAndConditions.agreed_to_latest(request.user):
|
||||
if not request.user.is_authenticated or TermsAndConditions.agreed_to_latest(request.user):
|
||||
return view_func(request, *args, **kwargs)
|
||||
|
||||
currentPath = request.path
|
||||
|
@ -30,7 +30,7 @@ class TermsAndConditionsRedirectMiddleware(MiddlewareMixin):
|
||||
current_path = request.META['PATH_INFO']
|
||||
protected_path = is_path_protected(current_path)
|
||||
|
||||
if request.user.is_authenticated() and protected_path:
|
||||
if request.user.is_authenticated and protected_path:
|
||||
for term in TermsAndConditions.get_active_list():
|
||||
if not TermsAndConditions.agreed_to_latest(request.user, term):
|
||||
return redirect_to_terms_accept(current_path, term)
|
||||
|
@ -69,7 +69,7 @@ class AcceptTermsView(CreateView):
|
||||
|
||||
def form_valid(self, form):
|
||||
"""Override of CreateView method, assigns default values based on user situation"""
|
||||
if self.request.user.is_authenticated():
|
||||
if self.request.user.is_authenticated:
|
||||
form.instance.username = self.request.user.username
|
||||
else: #Get user out of saved pipeline from django-socialauth
|
||||
# no support for social auth right now.
|
||||
|
Loading…
Reference in New Issue
Block a user