diff --git a/seahub/api2/endpoints/account.py b/seahub/api2/endpoints/account.py index 191f626da8..c33a40b504 100644 --- a/seahub/api2/endpoints/account.py +++ b/seahub/api2/endpoints/account.py @@ -30,6 +30,7 @@ json_content_type = 'application/json; charset=utf-8' def get_account_info(user): email = user.username d_profile = DetailedProfile.objects.get_detailed_profile_by_user(email) + profile = Profile.objects.get_profile_by_user(email) info = {} info['email'] = email @@ -39,6 +40,7 @@ def get_account_info(user): info['is_staff'] = user.is_staff info['is_active'] = user.is_active info['create_time'] = user.ctime + info['login_id'] = profile.login_id if profile else '' info['total'] = seafile_api.get_user_quota(email) info['usage'] = seafile_api.get_user_self_usage(email) @@ -108,10 +110,18 @@ class Account(APIView): profile = Profile.objects.get_profile_by_user(email) if profile is None: profile = Profile(user=email) - profile.nickname = name profile.save() + # update account loginid + loginid = request.data.get("login_id", '').strip() + if loginid != '': + profile = Profile.objects.get_profile_by_user(email) + if profile is None: + profile = Profile(user=email) + profile.login_id = loginid + profile.save() + # update account detailed profile department = request.data.get("department", None) if department is not None: @@ -165,6 +175,18 @@ class Account(APIView): return api_error(status.HTTP_400_BAD_REQUEST, _(u"Name should not include '/'.")) + #argument check for loginid + loginid = request.data.get("login_id", None) + if loginid is not None: + loginid = loginid.strip() + if loginid == "": + return api_error(status.HTTP_400_BAD_REQUEST, + _(u"Login id can't be empty")) + usernamebyloginid = Profile.objects.get_username_by_login_id(loginid) + if usernamebyloginid is not None: + return api_error(status.HTTP_400_BAD_REQUEST, + _(u"Login id %s already exists." % loginid)) + # argument check for department department = request.data.get("department", None) if department is not None: diff --git a/seahub/base/accounts.py b/seahub/base/accounts.py index 1efecd04c3..9e638fdf33 100644 --- a/seahub/base/accounts.py +++ b/seahub/base/accounts.py @@ -253,6 +253,10 @@ class User(object): ccnet_api.remove_emailuser(source, username) Profile.objects.delete_profile_by_user(username) + if settings.ENABLE_TERMS_AND_CONDITIONS: + from termsandconditions.models import UserTermsAndConditions + UserTermsAndConditions.objects.filter(username=username).delete() + def get_and_delete_messages(self): messages = [] return messages diff --git a/seahub/settings.py b/seahub/settings.py index 5a8e71ee15..fc2297b504 100644 --- a/seahub/settings.py +++ b/seahub/settings.py @@ -520,11 +520,14 @@ THUMBNAIL_EXTENSION = 'png' THUMBNAIL_DEFAULT_SIZE = 48 THUMBNAIL_SIZE_FOR_GRID = 192 - # size(MB) limit for generate thumbnail THUMBNAIL_IMAGE_SIZE_LIMIT = 20 THUMBNAIL_IMAGE_ORIGINAL_SIZE_LIMIT = 256 +# video thumbnails +ENABLE_VIDEO_THUMBNAIL = False +THUMBNAIL_VIDEO_FRAME_TIME = 5 # use the frame at 5 second as thumbnail + # template for create new office file OFFICE_TEMPLATE_ROOT = os.path.join(MEDIA_ROOT, 'office-template') diff --git a/seahub/templates/sysadmin/userinfo.html b/seahub/templates/sysadmin/userinfo.html index 416a19d343..997e3e3826 100644 --- a/seahub/templates/sysadmin/userinfo.html +++ b/seahub/templates/sysadmin/userinfo.html @@ -53,6 +53,18 @@ +
{% trans "Login ID" %}
+
+ + {% if profile and profile.login_id %} + {{ profile.login_id }} + {% else %} + -- + {% endif %} + + +
+
{% trans "Department" %}
@@ -98,6 +110,13 @@ +
{% csrf_token %} +

{% trans "Set user Login ID" %}

+
+

+ +
+
{% csrf_token %}

{% trans "Set user storage limit" %}

MB @@ -300,6 +319,10 @@ $('#set-name').click(function() { $("#set-name-form").modal({appendTo: "#main"}); $('#simplemodal-container').css({'width':'auto', 'height':'auto'}); }); +$('#set-loginid').click(function () { + $("#set-loginid-form").modal({appendTo:"#main"}); + $('#simplemodal-container').css({'width':'auto', 'height':'auto'}); +}) $('#set-dept').click(function() { $("#set-dept-form").modal({appendTo: "#main"}); $('#simplemodal-container').css({'width':'auto', 'height':'auto'}); @@ -351,6 +374,43 @@ $('#set-name-form').submit(function() { return false; }); +$('#set-loginid-form').submit(function() { + var loginid = $.trim($('[name="loginid"]', $(this)).val()); + var $loginid = $('#loginid'); + var $error = $('.error', $(this)); + var $submitBtn = $('[type="submit"]', $(this)); + if (!loginid){ + $error.html("{% trans "Login id can't be empty" %}").show(); + return false; + } + disable($submitBtn); + + $.ajax({ + url: '{% url 'api2-account' email %}', + type: 'PUT', + dataType: 'json', + cache: false, + beforeSend: prepareCSRFToken, + data: {'login_id': loginid}, + success: function(data) { + $loginid.html(HTMLescape(data['login_id'])); + $.modal.close(); + }, + error: function(xhr, textStatus, errorThrown) { + var err_msg; + if (xhr.responseText) { + err_msg = $.parseJSON(xhr.responseText).error_msg; + } else { + err_msg = "{% trans "Failed. Please check the network." %}"; + } + $error.html(err_msg).show(); + enable($submitBtn); + } + }); + + return false; +}); + $('#set-dept-form').submit(function() { var department = $.trim($('[name="department"]', $(this)).val()); var $department = $('#department'); diff --git a/seahub/thumbnail/utils.py b/seahub/thumbnail/utils.py index ed80b0655e..9a6ddb00d0 100644 --- a/seahub/thumbnail/utils.py +++ b/seahub/thumbnail/utils.py @@ -8,24 +8,24 @@ import logging from StringIO import StringIO from PIL import Image -try: - from moviepy.editor import VideoFileClip - _ENABLE_VIDEO_THUMBNAIL = True -except ImportError: - _ENABLE_VIDEO_THUMBNAIL = False from seaserv import get_file_id_by_path, get_repo, get_file_size, \ seafile_api from seahub.utils import gen_inner_file_get_url, get_file_type_and_ext from seahub.utils.file_types import VIDEO from seahub.settings import THUMBNAIL_IMAGE_SIZE_LIMIT, \ - THUMBNAIL_EXTENSION, THUMBNAIL_ROOT, THUMBNAIL_IMAGE_ORIGINAL_SIZE_LIMIT + THUMBNAIL_EXTENSION, THUMBNAIL_ROOT, THUMBNAIL_IMAGE_ORIGINAL_SIZE_LIMIT,\ + ENABLE_VIDEO_THUMBNAIL, THUMBNAIL_VIDEO_FRAME_TIME # Get an instance of a logger logger = logging.getLogger(__name__) -if _ENABLE_VIDEO_THUMBNAIL: - logger.debug('Video thumbnail is enabled.') +if ENABLE_VIDEO_THUMBNAIL: + try: + from moviepy.editor import VideoFileClip + logger.debug('Video thumbnail is enabled.') + except ImportError: + logger.error("Could not find moviepy installed.") else: logger.debug('Video thumbnail is disabled.') @@ -106,7 +106,7 @@ def generate_thumbnail(request, repo_id, size, path): if filetype == VIDEO: # video thumbnails - if _ENABLE_VIDEO_THUMBNAIL: + if ENABLE_VIDEO_THUMBNAIL: return create_video_thumbnails(repo, file_id, path, size, thumbnail_file, file_size) else: @@ -137,7 +137,8 @@ def create_video_thumbnails(repo, file_id, path, size, thumbnail_file, file_size inner_path = gen_inner_file_get_url(token, os.path.basename(path)) clip = VideoFileClip(inner_path) tmp_path = str(os.path.join(tempfile.gettempdir(), '%s.png' % file_id[:8])) - clip.save_frame(tmp_path, t=5) # save the frame in 5 second + + clip.save_frame(tmp_path, t=THUMBNAIL_VIDEO_FRAME_TIME) t2 = timeit.default_timer() logger.debug('Create thumbnail of [%s](size: %s) takes: %s' % (path, file_size, (t2 - t1))) diff --git a/tests/api/endpoints/test_account.py b/tests/api/endpoints/test_account.py index 1adb35b828..7365ffd216 100644 --- a/tests/api/endpoints/test_account.py +++ b/tests/api/endpoints/test_account.py @@ -45,7 +45,40 @@ class AccountTest(BaseTestCase): def _do_update(self): return self.client.put( reverse('api2-account', args=[self.user1.username]), - 'password=654321&is_staff=1&is_active=0&name=user1&storage=102400', + 'password=654321&is_staff=1&is_active=0&name=user1&storage=102400&login_id=hello', + 'application/x-www-form-urlencoded', + ) + + def _do_update_name(self): + return self.client.put( + reverse('api2-account', args=[self.user1.username]), + 'name=user1', + 'application/x-www-form-urlencoded', + ) + + def _do_update_loginid(self): + return self.client.put( + reverse('api2-account', args=[self.user1.username]), + 'login_id=hello', + 'application/x-www-form-urlencoded', + ) + + def _do_update_loginid_useemptystring(self): + return self.client.put( + reverse('api2-account', args=[self.user1.username]), + 'login_id=', + 'application/x-www-form-urlencoded', + ) + + def _do_update_loginid_sendagain(self): + self.client.put( + reverse('api2-account', args=[self.user1.username]), + 'login_id=test', + 'application/x-www-form-urlencoded', + ) + return self.client.put( + reverse('api2-account', args=[self.user1.username]), + 'login_id=test', 'application/x-www-form-urlencoded', ) @@ -77,7 +110,7 @@ class AccountTest(BaseTestCase): resp = self._do_get_info() json_resp = json.loads(resp.content) - assert len(json_resp) == 9 + assert len(json_resp) == 10 assert json_resp['email'] == self.user1.username assert json_resp['is_staff'] is False assert json_resp['is_active'] is True @@ -99,11 +132,39 @@ class AccountTest(BaseTestCase): '654321')) self.assertTrue(User.objects.get(self.user1.username).is_staff) self.assertFalse(User.objects.get(self.user1.username).is_active) + self.assertEqual(Profile.objects.get_profile_by_user( + self.user1.username).login_id, 'hello') self.assertEqual(Profile.objects.get_profile_by_user( self.user1.username).nickname, 'user1') self.assertEqual(seafile_api.get_user_quota( self.user1.username), 102400000000) + def test_update_name(self): + """only test name""" + self.login_as(self.admin) + resp = self._do_update_name() + self.assertEqual(Profile.objects.get_profile_by_user( + self.user1.username).nickname, 'user1') + + def test_update_loginid(self): + """only test loginid""" + self.login_as(self.admin) + resp = self._do_update_loginid() + self.assertEqual(Profile.objects.get_profile_by_user( + self.user1.username).login_id, 'hello') + + def test_update_loginid_useemptystring(self): + """test loginid, longid send the empty""" + self.login_as(self.admin) + resp = self._do_update_loginid_useemptystring() + self.assertEqual(400, resp.status_code) + + def test_update_loginid_sendagain(self): + """test loginid,sent twice""" + self.login_as(self.admin) + resp = self._do_update_loginid_sendagain() + self.assertEqual(400, resp.status_code) + def test_refresh_profile_cache_after_update(self): self.login_as(self.admin) self.assertEqual(email2nickname(self.user1.username),