1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-06 01:12:03 +00:00

Fix default repo re-creation bug when web login after desktop

This commit is contained in:
zhengxie
2016-02-01 11:54:02 +08:00
parent 55a23c6926
commit 52b661147e
4 changed files with 111 additions and 8 deletions

View File

@@ -3020,7 +3020,7 @@ class DefaultRepoView(APIView):
"""
Get user's default library.
"""
authentication_classes = (TokenAuthentication, )
authentication_classes = (TokenAuthentication, SessionAuthentication)
permission_classes = (IsAuthenticated, )
throttle_classes = (UserRateThrottle, )
@@ -3037,10 +3037,13 @@ class DefaultRepoView(APIView):
def default_repo_info(self, repo_id):
repo_json = {
'exists': True,
'repo_id': repo_id
'exists': False,
}
if repo_id is not None:
repo_json['exists'] = True
repo_json['repo_id'] = repo_id
return Response(repo_json)
def post(self, request):

View File

@@ -1186,6 +1186,14 @@ def create_default_library(request):
- `username`:
"""
username = request.user.username
# Disable user guide no matter user permission error or creation error,
# so that the guide popup only show once.
UserOptions.objects.disable_user_guide(username)
if not request.user.permissions.can_add_repo():
return
if is_org_context(request):
org_id = request.user.org.org_id
default_repo = seafile_api.create_org_repo(name=_("My Library"),
@@ -1213,7 +1221,6 @@ def create_default_library(request):
return
UserOptions.objects.set_default_repo(username, default_repo)
return default_repo
def get_owned_repo_list(request):
@@ -1262,10 +1269,7 @@ def libraries(request):
max_upload_file_size = get_max_upload_file_size()
guide_enabled = UserOptions.objects.is_user_guide_enabled(username)
if guide_enabled:
if request.user.permissions.can_add_repo():
create_default_library(request)
# only show guide once
UserOptions.objects.disable_user_guide(username)
folder_perm_enabled = True if is_pro_version() and ENABLE_FOLDER_PERM else False
can_add_pub_repo = True if is_org_repo_creation_allowed(request) else False

View File

@@ -0,0 +1,31 @@
import json
from django.core.urlresolvers import reverse
from seahub.options.models import UserOptions
from seahub.test_utils import BaseTestCase
class DefaultRepoTest(BaseTestCase):
def setUp(self):
self.login_as(self.user)
self.endpoint = reverse('api2-defaultrepo')
def test_default_repo_missing_on_get(self):
resp = self.client.get(self.endpoint)
json_resp = json.loads(resp.content)
assert json_resp['exists'] is False
def test_create_default_repo_on_post(self):
username = self.user.username
assert UserOptions.objects.get_default_repo(username) is None
assert UserOptions.objects.is_user_guide_enabled(username) is True
resp = self.client.post(self.endpoint)
json_resp = json.loads(resp.content)
assert json_resp['exists'] is True
assert len(json_resp['repo_id']) == 36
assert UserOptions.objects.get_default_repo(username) is not None
# so that, default repo won't be created again during web login
assert UserOptions.objects.is_user_guide_enabled(username) is False

View File

@@ -0,0 +1,65 @@
from django.core.urlresolvers import reverse
from constance import config
from seahub.options.models import UserOptions
from seahub.test_utils import BaseTestCase
class LibrariesTest(BaseTestCase):
def setUp(self):
self.url = reverse('libraries')
def test_user_guide(self):
self.login_as(self.user)
username = self.user.username
assert UserOptions.objects.get_default_repo(username) is None
assert UserOptions.objects.is_user_guide_enabled(username) is True
resp = self.client.get(self.url)
self.assertEqual(200, resp.status_code)
self.assertTemplateUsed(resp, 'libraries.html')
assert resp.context['guide_enabled'] is True
resp = self.client.get(self.url)
assert resp.context['guide_enabled'] is False
assert UserOptions.objects.get_default_repo(username) is not None
assert UserOptions.objects.is_user_guide_enabled(username) is False
def test_pub_repo_creation_config(self):
# user
self.login_as(self.user)
config.ENABLE_ORGANIZATION_LIBRARY = 1
assert bool(config.ENABLE_ORGANIZATION_LIBRARY) is True
resp = self.client.get(self.url)
self.assertEqual(200, resp.status_code)
assert resp.context['can_add_pub_repo'] is True
config.ENABLE_ORGANIZATION_LIBRARY = 0
assert bool(config.ENABLE_ORGANIZATION_LIBRARY) is False
resp = self.client.get(self.url)
self.assertEqual(200, resp.status_code)
assert resp.context['can_add_pub_repo'] is False
# logout
self.client.logout()
# admin
self.login_as(self.admin)
config.ENABLE_ORGANIZATION_LIBRARY = 1
assert bool(config.ENABLE_ORGANIZATION_LIBRARY) is True
resp = self.client.get(self.url)
self.assertEqual(200, resp.status_code)
assert resp.context['can_add_pub_repo'] is True
config.ENABLE_ORGANIZATION_LIBRARY = 0
assert bool(config.ENABLE_ORGANIZATION_LIBRARY) is False
resp = self.client.get(self.url)
self.assertEqual(200, resp.status_code)
assert resp.context['can_add_pub_repo'] is True