1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-04-27 11:01:14 +00:00

Merge branch '5.0'

This commit is contained in:
zhengxie 2015-12-05 16:30:56 +08:00
commit cf1d719ecf
5 changed files with 90 additions and 4 deletions

View File

@ -57,7 +57,7 @@ from seahub.message.models import UserMessage
from seahub.notifications.models import UserNotification
from seahub.options.models import UserOptions
from seahub.contacts.models import Contact
from seahub.profile.models import Profile
from seahub.profile.models import Profile, DetailedProfile
from seahub.shortcuts import get_first_object_or_none
from seahub.signals import (repo_created, repo_deleted,
share_file_to_user_successful)
@ -238,10 +238,17 @@ class AccountInfo(APIView):
def get(self, request, format=None):
info = {}
email = request.user.username
p = Profile.objects.get_profile_by_user(email)
d_p = DetailedProfile.objects.get_detailed_profile_by_user(email)
info['email'] = email
info['nickname'] = email2nickname(email)
info['name'] = email2nickname(email)
info['total'] = seafile_api.get_user_quota(email)
info['usage'] = seafile_api.get_user_self_usage(email)
info['login_id'] = p.login_id if p else ""
info['department'] = d_p.department if d_p else ""
info['contact_email'] = p.contact_email if p else ""
info['institution'] = p.institution if p else ""
return Response(info)
@ -372,6 +379,13 @@ class SearchUser(APIView):
def format_user_result(request, users, size):
results = []
# Get contact_emails from users' profiles
profiles = Profile.objects.filter(user__in=users)
contact_email_dict = {}
for e in profiles:
contact_email_dict[e.user] = e.contact_email
for email in users:
url, is_default, date_uploaded = api_avatar_url(email, size)
results.append({
@ -379,6 +393,7 @@ def format_user_result(request, users, size):
"avatar": avatar(email, size),
"avatar_url": request.build_absolute_uri(url),
"name": email2nickname(email),
"contact_email": contact_email_dict.get(email, ""),
})
return results
@ -2261,6 +2276,11 @@ class DirView(APIView):
create_parents = request.POST.get('create_parents', '').lower() in ('true', '1')
if not create_parents:
# check whether parent dir exists
if not seafile_api.get_dir_id_by_path(repo_id, parent_dir):
return api_error(status.HTTP_400_BAD_REQUEST,
'Parent dir does not exist')
new_dir_name = os.path.basename(path)
new_dir_name_utf8 = check_filename_with_rename_utf8(repo_id,
parent_dir,

View File

@ -93,7 +93,6 @@ class UserManager(object):
user.org = emailuser.org
user.source = emailuser.source
user.role = emailuser.role
user.source = emailuser.source
return user
@ -293,7 +292,6 @@ class AuthBackend(object):
user.org = emailuser.org
user.source = emailuser.source
user.role = emailuser.role
user.source = emailuser.source
return user

View File

@ -18,6 +18,10 @@ class AccountsApiTest(ApiTestBase):
self.assertEqual(info['email'], self.username)
self.assertIsNotNone(info['total'])
self.assertIsNotNone(info['usage'])
self.assertIsNotNone(info['login_id'])
self.assertIsNotNone(info['department'])
self.assertIsNotNone(info['contact_email'])
self.assertIsNotNone(info['institution'])
def test_list_accounts(self):
# Normal user can not list accounts

37
tests/api/test_dir.py Normal file
View File

@ -0,0 +1,37 @@
import json
import os
from django.core.urlresolvers import reverse
from seahub.test_utils import BaseTestCase
class DirTest(BaseTestCase):
def setUp(self):
self.login_as(self.user)
self.endpoint = reverse('DirView', args=[self.repo.id])
self.folder_name = os.path.basename(self.folder)
def tearDown(self):
self.remove_repo()
def test_can_list(self):
resp = self.client.get(self.endpoint)
json_resp = json.loads(resp.content)
self.assertEqual(200, resp.status_code)
assert len(json_resp) == 1
assert self.folder_name == json_resp[0]['name']
def test_can_create(self):
resp = self.client.post(self.endpoint + '?p=/new_dir', {
'operation': 'mkdir'
})
self.assertEqual(201, resp.status_code)
def test_create_with_nonexistent_parent(self):
resp = self.client.post(self.endpoint + '?p=/new_parent/new_dir', {
'operation': 'mkdir'
})
self.assertEqual(400, resp.status_code)

View File

@ -0,0 +1,27 @@
import json
from django.core.urlresolvers import reverse
from seahub.profile.models import Profile
from seahub.test_utils import BaseTestCase
class SearchUserTest(BaseTestCase):
def setUp(self):
self.login_as(self.user)
self.endpoint = reverse('search-user')
def test_can_search(self):
p = Profile.objects.add_or_update(self.user.email, nickname="test")
p.contact_email = 'new_mail@test.com'
p.save()
resp = self.client.get(self.endpoint + '?q=' + self.user.email)
json_resp = json.loads(resp.content)
self.assertEqual(200, resp.status_code)
assert json_resp['users'] is not None
assert json_resp['users'][0]['email'] == self.user.email
assert json_resp['users'][0]['avatar'] is not None
assert json_resp['users'][0]['avatar_url'] is not None
assert json_resp['users'][0]['name'] == 'test'
assert json_resp['users'][0]['contact_email'] == 'new_mail@test.com'