mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-20 02:48:51 +00:00
Merge branch '6.1'
Conflicts: seahub/api2/endpoints/admin/two_factor_auth.py seahub/profile/views.py seahub/views/sysadmin.py
This commit is contained in:
@@ -9,6 +9,7 @@ from seahub.api2.base import APIView
|
||||
from seahub.api2.throttling import UserRateThrottle
|
||||
from seahub.api2.utils import json_response, api_error
|
||||
from seahub.api2.authentication import TokenAuthentication
|
||||
from seahub.two_factor import devices_for_user
|
||||
|
||||
|
||||
class TwoFactorAuthView(APIView):
|
||||
@@ -21,14 +22,13 @@ class TwoFactorAuthView(APIView):
|
||||
error_msg = "email can not be empty"
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||
try:
|
||||
_user = User.objects.get(email=email)
|
||||
user = User.objects.get(email=email)
|
||||
except User.DoesNotExist:
|
||||
error_msg = "User %s not found" % email
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||
|
||||
from seahub.two_factor import devices_for_user
|
||||
devices = devices_for_user(_user)
|
||||
devices = devices_for_user(user)
|
||||
if devices:
|
||||
for device in devices:
|
||||
device.delete()
|
||||
return Response({'success':True}, status=status.HTTP_200_OK)
|
||||
return Response({'success': True}, status=status.HTTP_200_OK)
|
||||
|
@@ -4,7 +4,6 @@
|
||||
from django.db import models
|
||||
|
||||
from seahub.base.fields import LowerCaseCharField
|
||||
from seahub.settings import FORCE_SERVER_CRYPTO
|
||||
from seahub.utils import is_pro_version
|
||||
|
||||
KEY_SERVER_CRYPTO = "server_crypto"
|
||||
@@ -71,26 +70,9 @@ class UserOptionsManager(models.Manager):
|
||||
VAL_SERVER_CRYPTO_DISABLED)
|
||||
|
||||
def is_server_crypto(self, username):
|
||||
"""Check whether user is set server crypto. Returns ``True`` if
|
||||
server crypto is enabled, otherwise ``False``.
|
||||
|
||||
Raise ``CryptoOptionNotSetError`` if this option is not set.
|
||||
|
||||
NOTE: Always return ``True`` if ``FORCE_SERVER_CRYPTO`` is set to
|
||||
``True``.
|
||||
|
||||
Arguments:
|
||||
- `username`:
|
||||
"""Client crypto is deprecated, always return ``True``.
|
||||
"""
|
||||
if FORCE_SERVER_CRYPTO is True:
|
||||
return True
|
||||
|
||||
try:
|
||||
user_option = super(UserOptionsManager, self).get(
|
||||
email=username, option_key=KEY_SERVER_CRYPTO)
|
||||
return bool(int(user_option.option_val))
|
||||
except UserOptions.DoesNotExist:
|
||||
raise CryptoOptionNotSetError
|
||||
return True
|
||||
|
||||
def enable_user_guide(self, username):
|
||||
"""
|
||||
|
@@ -80,7 +80,6 @@ def edit_profile(request):
|
||||
'form': form,
|
||||
'server_crypto': server_crypto,
|
||||
"sub_lib_enabled": sub_lib_enabled,
|
||||
'force_server_crypto': settings.FORCE_SERVER_CRYPTO,
|
||||
'ENABLE_ADDRESSBOOK_OPT_IN': settings.ENABLE_ADDRESSBOOK_OPT_IN,
|
||||
'default_repo': default_repo,
|
||||
'owned_repos': owned_repos,
|
||||
|
@@ -307,9 +307,6 @@ USER_STRONG_PASSWORD_REQUIRED = False
|
||||
# Force user to change password when admin add/reset a user.
|
||||
FORCE_PASSWORD_CHANGE = True
|
||||
|
||||
# Using server side crypto by default, otherwise, let user choose crypto method.
|
||||
FORCE_SERVER_CRYPTO = True
|
||||
|
||||
# Enable or disable repo history setting
|
||||
ENABLE_REPO_HISTORY_SETTING = True
|
||||
|
||||
@@ -470,22 +467,24 @@ LOGGING = {
|
||||
'filters': {
|
||||
'require_debug_false': {
|
||||
'()': 'django.utils.log.RequireDebugFalse'
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
'handlers': {
|
||||
'default': {
|
||||
'level':'INFO',
|
||||
'class':'logging.handlers.RotatingFileHandler',
|
||||
'level': 'INFO',
|
||||
'class': 'logging.handlers.RotatingFileHandler',
|
||||
'filename': os.path.join(LOG_DIR, 'seahub.log'),
|
||||
'maxBytes': 1024*1024*10, # 10 MB
|
||||
'formatter':'standard',
|
||||
'maxBytes': 1024*1024*100, # 100 MB
|
||||
'backupCount': 5,
|
||||
'formatter': 'standard',
|
||||
},
|
||||
'request_handler': {
|
||||
'level':'INFO',
|
||||
'class':'logging.handlers.RotatingFileHandler',
|
||||
'filename': os.path.join(LOG_DIR, 'seahub_django_request.log'),
|
||||
'maxBytes': 1024*1024*10, # 10 MB
|
||||
'formatter':'standard',
|
||||
'level': 'INFO',
|
||||
'class': 'logging.handlers.RotatingFileHandler',
|
||||
'filename': os.path.join(LOG_DIR, 'seahub_django_request.log'),
|
||||
'maxBytes': 1024*1024*100, # 100 MB
|
||||
'backupCount': 5,
|
||||
'formatter': 'standard',
|
||||
},
|
||||
'mail_admins': {
|
||||
'level': 'ERROR',
|
||||
|
@@ -282,7 +282,9 @@ urlpatterns = patterns(
|
||||
|
||||
## admin::users
|
||||
url(r'^api/v2.1/admin/users/$', AdminUsers.as_view(), name='api-v2.1-admin-users'),
|
||||
url(r'^api/v2.1/admin/users/(?P<email>[^/]+)/$', AdminUser.as_view(), name='api-v2.1-admin-user'),
|
||||
# [^...] Matches any single character not in brackets
|
||||
# + Matches between one and unlimited times, as many times as possible
|
||||
url(r'^api/v2.1/admin/users/(?P<email>[^/]+@[^/]+)/$', AdminUser.as_view(), name='api-v2.1-admin-user'),
|
||||
|
||||
## admin::devices
|
||||
url(r'^api/v2.1/admin/devices/$', AdminDevices.as_view(), name='api-v2.1-admin-devices'),
|
||||
|
@@ -44,6 +44,7 @@ from seahub.invitations.models import Invitation
|
||||
from seahub.role_permissions.utils import get_available_roles, \
|
||||
get_available_admin_roles
|
||||
from seahub.role_permissions.models import AdminRole
|
||||
from seahub.two_factor.utils import default_device
|
||||
from seahub.utils import IS_EMAIL_CONFIGURED, string2list, is_valid_username, \
|
||||
is_pro_version, send_html_email, get_user_traffic_list, get_server_id, \
|
||||
handle_virus_record, get_virus_record_by_id, \
|
||||
@@ -719,15 +720,13 @@ def user_info(request, email):
|
||||
else:
|
||||
g.role = _('Member')
|
||||
|
||||
_user = User.objects.get(email=email)
|
||||
try:
|
||||
user = User.objects.get(email=email)
|
||||
except User.DoesNotExist:
|
||||
raise Http404
|
||||
|
||||
reference_id = _user.reference_id
|
||||
|
||||
_default_device = False
|
||||
_has_two_factor_auth = has_two_factor_auth()
|
||||
if _has_two_factor_auth:
|
||||
from seahub.two_factor.utils import default_device
|
||||
_default_device = default_device(_user)
|
||||
reference_id = user.reference_id
|
||||
user_default_device = default_device(user) if has_two_factor_auth() else False
|
||||
|
||||
return render_to_response(
|
||||
'sysadmin/userinfo.html', {
|
||||
@@ -742,8 +741,8 @@ def user_info(request, email):
|
||||
'user_shared_links': user_shared_links,
|
||||
'enable_sys_admin_view_repo': ENABLE_SYS_ADMIN_VIEW_REPO,
|
||||
'personal_groups': personal_groups,
|
||||
'two_factor_auth_enabled': _has_two_factor_auth,
|
||||
'default_device': _default_device,
|
||||
'two_factor_auth_enabled': has_two_factor_auth(),
|
||||
'default_device': user_default_device,
|
||||
'reference_id': reference_id if reference_id else '',
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
|
@@ -12,7 +12,7 @@ class UserPermissionsTest(BaseTestCase):
|
||||
self.remove_user(self.user.email)
|
||||
|
||||
def test_get_user_role(self):
|
||||
assert self.user.role is None
|
||||
assert not self.user.role
|
||||
assert get_user_role(self.user) == DEFAULT_USER
|
||||
|
||||
User.objects.update_role(self.user.email, 'test_role')
|
||||
|
Reference in New Issue
Block a user