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

Merge pull request #1901 from haiwen/update-test

update tests of shared repos
This commit is contained in:
xiez 2017-11-14 16:37:20 +08:00 committed by GitHub
commit 50dfa96e0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -14,6 +14,7 @@ from seahub.api2.utils import api_error
from seahub.api2.authentication import TokenAuthentication from seahub.api2.authentication import TokenAuthentication
from seahub.api2.throttling import UserRateThrottle from seahub.api2.throttling import UserRateThrottle
from seahub.profile.models import Profile from seahub.profile.models import Profile
from seahub.base.accounts import User
from seahub.utils import is_org_context, is_valid_username, send_perm_audit_msg from seahub.utils import is_org_context, is_valid_username, send_perm_audit_msg
from seahub.base.templatetags.seahub_tags import email2nickname, email2contact_email from seahub.base.templatetags.seahub_tags import email2nickname, email2contact_email
from seahub.share.models import ExtraSharePermission, ExtraGroupsSharePermission from seahub.share.models import ExtraSharePermission, ExtraGroupsSharePermission
@ -72,6 +73,13 @@ class SharedRepos(APIView):
result['modifier_contact_email'] = email2contact_email(repo.last_modifier) result['modifier_contact_email'] = email2contact_email(repo.last_modifier)
if repo.share_type == 'personal': if repo.share_type == 'personal':
try:
User.objects.get(email=repo.user)
except User.DoesNotExist:
seafile_api.remove_share(repo.repo_id,
username, repo.user)
continue
result['user_name'] = email2nickname(repo.user) result['user_name'] = email2nickname(repo.user)
result['user_email'] = repo.user result['user_email'] = repo.user
result['contact_email'] = Profile.objects.get_contact_email_by_user(repo.user) result['contact_email'] = Profile.objects.get_contact_email_by_user(repo.user)
@ -79,6 +87,10 @@ class SharedRepos(APIView):
if repo.share_type == 'group': if repo.share_type == 'group':
group = ccnet_api.get_group(repo.group_id) group = ccnet_api.get_group(repo.group_id)
if not group:
seafile_api.unset_group_repo(repo.repo_id,
repo.group_id, username)
continue
result['group_id'] = repo.group_id result['group_id'] = repo.group_id
result['group_name'] = group.group_name result['group_name'] = group.group_name
gids.append(repo.group_id) gids.append(repo.group_id)

View File

@ -101,6 +101,20 @@ class SharedReposTest(BaseTestCase):
assert json_resp[0]['share_type'] == 'public' assert json_resp[0]['share_type'] == 'public'
def test_get_with_invalid_repo_permission(self): def test_get_with_invalid_repo_permission(self):
user_shared_repos = \
seafile_api.get_share_out_repo_list(self.admin_name, -1, -1)
for repo in user_shared_repos:
seafile_api.remove_share(repo.repo_id, self.admin_name, repo.user)
group_shared_repos = seafile_api.get_group_repos_by_owner(self.admin_name)
for repo in group_shared_repos:
seafile_api.unset_group_repo(repo.repo_id, repo.group_id, self.admin_name)
public_shared_repos = seafile_api.list_inner_pub_repos_by_owner(self.admin_name)
for repo in public_shared_repos:
seafile_api.remove_inner_pub_repo(repo.repo_id)
self.share_repo_to_user() self.share_repo_to_user()
self.share_repo_to_group() self.share_repo_to_group()
self.share_repo_to_public() self.share_repo_to_public()