1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-11 11:51:27 +00:00
Files
seahub/seahub/api2/endpoints/shared_repos.py

358 lines
14 KiB
Python
Raw Normal View History

2016-07-26 10:47:45 +08:00
# Copyright (c) 2012-2016 Seafile Ltd.
2016-06-30 15:06:43 +08:00
import logging
from rest_framework.authentication import SessionAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework import status
import seaserv
from seaserv import seafile_api, ccnet_api
from seahub.api2.utils import api_error
from seahub.api2.authentication import TokenAuthentication
from seahub.api2.throttling import UserRateThrottle
from seahub.profile.models import Profile
2016-06-30 15:06:43 +08:00
from seahub.utils import is_org_context, is_valid_username, send_perm_audit_msg
Add preview related share perms Squashed commit of the following: commit 12f52311df704e48c282b2a47f59f7a283cfa5c5 Author: zhengxie <xiez1989@gmail.com> Date: Tue Sep 11 15:14:34 2018 +0800 [API] Update client sync and list dir items apis commit bc18d19dc0f648732c5933c6918d8e784fc0f910 Author: llj <lingjun.li1@gmail.com> Date: Tue Sep 4 12:22:10 2018 +0800 Add preview related share perms Squashed commit of the following: commit 658bdbdc7acf262f2c0abb0387cf3142b2d8ee37 Author: llj <lingjun.li1@gmail.com> Date: Tue Sep 4 12:17:47 2018 +0800 [library icon title] added title for 'admin' permission commit 51a088fd7987e2307e5666facb6627d42a7843ec Author: zhengxie <xiez1989@gmail.com> Date: Sat Sep 1 15:33:09 2018 +0800 Add preview related share perms Squashed commit of the following: commit 42fe21ef0ba3bad4fb68dc5283194cb34eb7775a Author: llj <lingjun.li1@gmail.com> Date: Sat Sep 1 13:33:59 2018 +0800 [icon tip] modified library/folder icon title commit 077fecdce80bce966296a1735896a24bf32c282f Author: zhengxie <xiez1989@gmail.com> Date: Mon Aug 27 11:05:34 2018 +0800 Add preview related share perms Squashed commit of the following: commit 5783325eb25d7298ea3db7f59595446d122889e5 Author: llj <lingjun.li1@gmail.com> Date: Fri Aug 24 21:14:59 2018 +0800 fixup commit 5f4f4025221f4026a4e7a9bc1c7bba5d6decf5a9 Author: zhengxie <xiez1989@gmail.com> Date: Fri Aug 24 20:55:41 2018 +0800 Fix wopi perm commit 632744cd5e56f8812af0efe523cf5751bbf57b66 Author: zhengxie <xiez1989@gmail.com> Date: Fri Aug 24 17:29:31 2018 +0800 Add preview related share perms Squashed commit of the following: commit 683296449601960d76a2d0245dab694ab16f67b2 Author: llj <lingjun.li1@gmail.com> Date: Fri Aug 24 15:54:59 2018 +0800 modification after adding 2 new permissions commit 3eff1ec06fc7566942b736261a1d5b613d706117 Author: llj <lingjun.li1@gmail.com> Date: Thu Aug 23 14:58:33 2018 +0800 [permission] added 2 new permissions for 'share' & 'folder permission' commit 73a0bfc6560860ac11e96a675fe789a984a194c8 Author: zhengxie <xiez1989@gmail.com> Date: Fri Aug 24 16:34:47 2018 +0800 Add prevew related perms in history file view and text_diff commit 533b3ff0ca4aa5564ecc87456772b70eedfa816f Author: zhengxie <xiez1989@gmail.com> Date: Fri Aug 24 13:49:28 2018 +0800 Add prevew related perms on file views commit 03db78a841baddf6c042988358d20417f06be4ae Author: zhengxie <xiez1989@gmail.com> Date: Thu Aug 23 10:56:17 2018 +0800 [api2] Update repo perms and add is pro version check commit c025319fe56658da3a3dc077743ee016ac5acd4d Author: ilearnit <helloworld.c@outlook.com> Date: Wed Aug 22 11:09:27 2018 +0800 update perm copy/download/share commit ea19ab4c695c99c0c2817616f2177bebae0777a2 Author: zhengxie <xiez1989@gmail.com> Date: Mon Aug 20 16:00:11 2018 +0800 wip: add repo preview related perms. Updated APIs: 1. [api2] group libraries 2. [api2] dir shared items 3. [api2] share link zip tasks Updated Views: 1. wiki & wopi 2. ajax copy/download files/dirs
2018-09-14 11:21:25 +08:00
from seahub.utils.repo import get_available_repo_perms
from seahub.base.templatetags.seahub_tags import email2nickname, email2contact_email
from seahub.share.models import ExtraSharePermission, ExtraGroupsSharePermission, \
CustomSharePermissions
from seahub.share.utils import update_user_dir_permission, update_group_dir_permission,\
check_user_share_out_permission, check_group_share_out_permission, \
normalize_custom_permission_name
2016-06-30 15:06:43 +08:00
logger = logging.getLogger(__name__)
2016-06-30 15:06:43 +08:00
class SharedRepos(APIView):
authentication_classes = (TokenAuthentication, SessionAuthentication)
permission_classes = (IsAuthenticated,)
throttle_classes = (UserRateThrottle,)
def get(self, request, format=None):
""" List all shared out repos.
Permission checking:
1. all authenticated user can perform this action.
"""
shared_repos = []
username = request.user.username
try:
if is_org_context(request):
org_id = request.user.org.org_id
shared_repos += seafile_api.get_org_share_out_repo_list(org_id, username, -1, -1)
shared_repos += seafile_api.get_org_group_repos_by_owner(org_id, username)
shared_repos += seafile_api.list_org_inner_pub_repos_by_owner(org_id, username)
2016-06-30 15:06:43 +08:00
else:
shared_repos += seafile_api.get_share_out_repo_list(username, -1, -1)
shared_repos += seafile_api.get_group_repos_by_owner(username)
if not request.cloud_mode:
shared_repos += seafile_api.list_inner_pub_repos_by_owner(username)
2016-06-30 15:06:43 +08:00
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
repo_id_list = []
for repo in shared_repos:
if repo.is_virtual:
continue
repo_id = repo.repo_id
repo_id_list.append(repo_id)
custom_permission_dict = {}
custom_permissions = CustomSharePermissions.objects.filter(repo_id__in=repo_id_list)
for custom_permission in custom_permissions:
custom_id = f'custom-{custom_permission.id}'
custom_permission_dict[custom_id] = custom_permission.name
2016-06-30 15:06:43 +08:00
returned_result = []
Python3 master (#4076) * delete thridpart/social_django * delete social_django in seahub/urls.py * delete social_django in seahub/settings.py * delete seahub/notifications/management/commands/send_wxwork_notices.py * delete social_django in code annotation * delete seahub/social_core * delete tests/seahub/social_core * delete social_core in seahub/urls.py * delete social_core in seahub/settings.py * change app_label to auth in SocialAuthUser model * 2to3 asserts * 2to3 basestring * 2to3 dict * 2to3 except * 2to3 filter * 2to3 future * 2to3 has_key * 2to3 idioms * 2to3 import * 2to3 imports * 2to3 long * 2to3 map * 2to3 next * 2to3 numliterals * 2to3 print * 2to3 raise * 2to3 raw_input * 2to3 reduce * 2to3 reload * 2to3 set_literal * 2to3 unicode * 2to3 urllib * 2to3 ws_comma * 2to3 xrange * 2to3 zip * add pymysql in __init__.py * fix encode and decode in seahub/cconvert.py * fix seafserv_rpc.is_passwd_set in seahub/views/__init__.py * fix smart_unicode to smart_text * fix force_unicode to force_text * delete seaserv.get_session_info * delete seaserv.ccnet_rpc * fix indent error in seahub/auth/middleware.py * update dev-requirements * update test-requirements * update requirements * fix StringIO to BytesIO in thumbnail * fix seaserv.list_inner_pub_repos to seafile_api.get_inner_pub_repo_list * fix seaserv.list_org_inner_pub_repos to seafile_api.list_org_inner_pub_repos * add logger in seahub/utils/__init__.py * fix sort cmp in seahub/views/__init__.py * fix sort cmp in seahub/base/management/commands/export_file_access_log.py * fix sort cmp in seahub/api2/endpoints/repo_trash.py * fix sort cmp in seahub/api2/endpoints/shared_repos.py * fix sort cmp in seahub/api2/endpoints/shared_folders.py * fix sort cmp in seahub/wiki/views.py * fix sort cmp in seahub/api2/endpoints/wiki_pages.py * fix sort cmp in seahub/api2/endpoints/group_libraries.py * fix sort cmp in seahub/base/models.py * fix sort cmp in seahub/api2/endpoints/upload_links.py * fix sort cmp in seahub/views/ajax.py * fix sort cmp in seahub/api2/views.py * fix sort cmp in seahub/views/wiki.py * fix sort cmp in seahub/api2/endpoints/repos.py * fix sort cmp in seahub/api2/endpoints/starred_items.py * fix sort cmp in seahub/views/file.py * fix sort cmp in seahub/api2/endpoints/dir.py * fix sort cmp in seahub/api2/endpoints/share_links.py * fix cmp to cmp_to_key in seahub/api2/endpoints/admin/device_trusted_ip.py * fix cmp to cmp_to_key in tests/api/endpoints/admin/test_device_trusted_ip.py * delete encode('utf-8') in seafile_api.list_dir_by_commit_and_path * delete encode('utf-8') in is_file_starred * delete encode('utf-8') in seafile_api.list_dir_by_path * delete path.encode('utf-8') in seahub/views/file.py * fix os.write to add encode('utf-8') * add encode('utf-8') for hashlib * add encode('utf-8') for hmac * fix with open(file, 'wb') for binary file * fix encode and decode in seahub/utils/hasher.py * fix next in thirdpart/shibboleth/views.py * fix next in seahub/profile/views.py * fix next in seahub/notifications/views.py * fix next in seahub/institutions/views.py * fix next in seahub/options/views.py * fix next in seahub/share/views.py * fix next in seahub/avatar/views.py * fix next in seahub/views/__init__.py * fix next in seahub/group/views.py * fix next in seahub/views/wiki.py * fix next in seahub/views/sysadmin.py * fix next in seahub/views/file.py * fix string.lowercase to string.ascii_lowercase in test * fix open file add 'rb' in test * fix self.user.username in test * add migrations in file_participants * fix list_org_inner_pub_repos to list_org_inner_pub_repos_by_owner * fix from seaserv import is_passwd_set to seafile_api.is_password_set * fix assert bytes resp.content in test * fix seafile_api.get_inner_pub_repo_list to seafile_api.list_inner_pub_repos_by_owner * fix seafile_api.is_passwd_set to seafile_api.is_password_set * fix AccountsApiTest assert length * rewrite sort_devices cmp to operator.lt * fix bytes + str in seahub/api2/views.py * fix assert bytes resp.content in test * fix hashlib encode in seahub/thirdpart/registration/models.py * change app_label to base in SocialAuthUser * fix base64 encode in seahub/base/database_storage/database_storage.py * fix assert bytes resp.content * remove path.decode in def mkstemp() * remove path.decode in FpathToLinkTest * remove str decode in FileTagTest * remove mock_write_xls.assert_called_once() in SysUserAdminExportExcelTest * fix urllib assert in FilesApiTest * fix link fields in FileCommentsTest * fix get_related_users_by_repo() * fix assert list in GetRepoSharedUsersTest * fix create user in AccountTest * fix repeated key in dict seahub/api2/views.py * add drone.yml * update nginx conf in test * update test conf in test * update dist and push after test success * update drone conf to dist and push * fix assert in BeSharedReposTest * fix seafile_api.list_org_inner_pub_repos_by_owner(org_id, username) to seafile_api.list_org_inner_pub_repos(org_id) * fix seafile_api.list_inner_pub_repos_by_owner(username) to seafile_api.get_inner_pub_repo_list() * update pyjwt requirement * update dist branch in drone * add SKIP in dist and push * fix StringIO to BytesIO in seahub/avatar/models.py * fix if org_id > 0 to if org_id and org_id > 0 * remove payment * fix StringIO to BytesIO in seahub/base/database_storage/database_storage.py * fix send_message to seafile_api.publish_event in seahub/drafts/utils.py * fix send_message to seafile_api.publish_event in seahub/api2/views.py * fix send_message to seafile_api.publish_event in seahub/api2/endpoints/repos.py * fix send_message to seafile_api.publish_event in seahub/views/file.py * fix send_message to seafile_api.publish_event in seahub/utils/__init__.py * fix image_file.read encode in seahub/base/database_storage/database_storage.py * fix DatabaseStorageTest * remove .travis.yml * drone branch include master
2019-09-11 11:46:43 +08:00
shared_repos.sort(key=lambda x: x.repo_name)
usernames = []
gids = []
2016-06-30 15:06:43 +08:00
for repo in shared_repos:
if repo.is_virtual:
continue
2016-06-30 15:06:43 +08:00
result = {}
result['repo_id'] = repo.repo_id
result['repo_name'] = repo.repo_name
result['encrypted'] = repo.encrypted
2016-06-30 15:06:43 +08:00
result['share_type'] = repo.share_type
result['share_permission'] = repo.permission
result['share_permission_name'] = custom_permission_dict.get(repo.permission, '')
result['modifier_email'] = repo.last_modifier
result['modifier_name'] = email2nickname(repo.last_modifier)
result['modifier_contact_email'] = email2contact_email(repo.last_modifier)
2016-06-30 15:06:43 +08:00
if repo.share_type == 'personal':
result['user_name'] = email2nickname(repo.user)
result['user_email'] = repo.user
result['contact_email'] = Profile.objects.get_contact_email_by_user(repo.user)
usernames.append((repo.repo_id, repo.user))
2016-06-30 15:06:43 +08:00
if repo.share_type == 'group':
group = ccnet_api.get_group(repo.group_id)
result['group_id'] = repo.group_id
result['group_name'] = group.group_name if group else ''
gids.append(repo.group_id)
2016-06-30 15:06:43 +08:00
returned_result.append(result)
user_admins = ExtraSharePermission.objects.batch_is_admin(usernames)
group_admins = ExtraGroupsSharePermission.objects.batch_get_repos_with_admin_permission(gids)
for result in returned_result:
if result['share_type'] == 'group':
result['is_admin'] = (result['repo_id'], result['group_id']) in group_admins
elif result['share_type'] == 'personal':
result['is_admin'] = (result['repo_id'], result['user_email']) in user_admins
2016-06-30 15:06:43 +08:00
return Response(returned_result)
class SharedRepo(APIView):
authentication_classes = (TokenAuthentication, SessionAuthentication)
permission_classes = (IsAuthenticated,)
throttle_classes = (UserRateThrottle,)
def put(self, request, repo_id, format=None):
""" Update permission of a shared repo.
Permission checking:
1. Only repo owner can update.
"""
# argument check
permission = request.data.get('permission', None)
Add preview related share perms Squashed commit of the following: commit 12f52311df704e48c282b2a47f59f7a283cfa5c5 Author: zhengxie <xiez1989@gmail.com> Date: Tue Sep 11 15:14:34 2018 +0800 [API] Update client sync and list dir items apis commit bc18d19dc0f648732c5933c6918d8e784fc0f910 Author: llj <lingjun.li1@gmail.com> Date: Tue Sep 4 12:22:10 2018 +0800 Add preview related share perms Squashed commit of the following: commit 658bdbdc7acf262f2c0abb0387cf3142b2d8ee37 Author: llj <lingjun.li1@gmail.com> Date: Tue Sep 4 12:17:47 2018 +0800 [library icon title] added title for 'admin' permission commit 51a088fd7987e2307e5666facb6627d42a7843ec Author: zhengxie <xiez1989@gmail.com> Date: Sat Sep 1 15:33:09 2018 +0800 Add preview related share perms Squashed commit of the following: commit 42fe21ef0ba3bad4fb68dc5283194cb34eb7775a Author: llj <lingjun.li1@gmail.com> Date: Sat Sep 1 13:33:59 2018 +0800 [icon tip] modified library/folder icon title commit 077fecdce80bce966296a1735896a24bf32c282f Author: zhengxie <xiez1989@gmail.com> Date: Mon Aug 27 11:05:34 2018 +0800 Add preview related share perms Squashed commit of the following: commit 5783325eb25d7298ea3db7f59595446d122889e5 Author: llj <lingjun.li1@gmail.com> Date: Fri Aug 24 21:14:59 2018 +0800 fixup commit 5f4f4025221f4026a4e7a9bc1c7bba5d6decf5a9 Author: zhengxie <xiez1989@gmail.com> Date: Fri Aug 24 20:55:41 2018 +0800 Fix wopi perm commit 632744cd5e56f8812af0efe523cf5751bbf57b66 Author: zhengxie <xiez1989@gmail.com> Date: Fri Aug 24 17:29:31 2018 +0800 Add preview related share perms Squashed commit of the following: commit 683296449601960d76a2d0245dab694ab16f67b2 Author: llj <lingjun.li1@gmail.com> Date: Fri Aug 24 15:54:59 2018 +0800 modification after adding 2 new permissions commit 3eff1ec06fc7566942b736261a1d5b613d706117 Author: llj <lingjun.li1@gmail.com> Date: Thu Aug 23 14:58:33 2018 +0800 [permission] added 2 new permissions for 'share' & 'folder permission' commit 73a0bfc6560860ac11e96a675fe789a984a194c8 Author: zhengxie <xiez1989@gmail.com> Date: Fri Aug 24 16:34:47 2018 +0800 Add prevew related perms in history file view and text_diff commit 533b3ff0ca4aa5564ecc87456772b70eedfa816f Author: zhengxie <xiez1989@gmail.com> Date: Fri Aug 24 13:49:28 2018 +0800 Add prevew related perms on file views commit 03db78a841baddf6c042988358d20417f06be4ae Author: zhengxie <xiez1989@gmail.com> Date: Thu Aug 23 10:56:17 2018 +0800 [api2] Update repo perms and add is pro version check commit c025319fe56658da3a3dc077743ee016ac5acd4d Author: ilearnit <helloworld.c@outlook.com> Date: Wed Aug 22 11:09:27 2018 +0800 update perm copy/download/share commit ea19ab4c695c99c0c2817616f2177bebae0777a2 Author: zhengxie <xiez1989@gmail.com> Date: Mon Aug 20 16:00:11 2018 +0800 wip: add repo preview related perms. Updated APIs: 1. [api2] group libraries 2. [api2] dir shared items 3. [api2] share link zip tasks Updated Views: 1. wiki & wopi 2. ajax copy/download files/dirs
2018-09-14 11:21:25 +08:00
if permission not in get_available_repo_perms():
permission = normalize_custom_permission_name(permission)
if not permission:
error_msg = 'permission invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
2016-06-30 15:06:43 +08:00
share_type = request.data.get('share_type', None)
if not share_type:
error_msg = 'share_type invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
if share_type not in ('personal', 'group', 'public'):
error_msg = "share_type can only be 'personal' or 'group' or 'public'."
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
# recourse check
repo = seafile_api.get_repo(repo_id)
if not repo:
error_msg = 'Library %s not found.' % repo_id
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
# permission check
username = request.user.username
if is_org_context(request):
repo_owner = seafile_api.get_org_repo_owner(repo_id)
else:
repo_owner = seafile_api.get_repo_owner(repo_id)
if username != repo_owner:
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
# update share permission
if share_type == 'personal':
shared_to = request.data.get('user', None)
if not shared_to or not is_valid_username(shared_to):
error_msg = 'user invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
try:
if is_org_context(request):
org_id = request.user.org.org_id
update_user_dir_permission(repo_id, '/', repo_owner, shared_to, permission, org_id)
2016-06-30 15:06:43 +08:00
else:
update_user_dir_permission(repo_id, '/', repo_owner, shared_to, permission)
2016-06-30 15:06:43 +08:00
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
send_perm_audit_msg('modify-repo-perm', username,
shared_to, repo_id, '/', permission)
2016-06-30 15:06:43 +08:00
if share_type == 'group':
group_id = request.data.get('group_id', None)
if not group_id:
error_msg = 'group_id invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
try:
group_id = int(group_id)
except ValueError:
error_msg = 'group_id must be integer.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
group = ccnet_api.get_group(group_id)
if not group:
error_msg = 'Group %s not found.' % group_id
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
try:
if is_org_context(request):
org_id = request.user.org.org_id
update_group_dir_permission(repo_id, '/', repo_owner, group_id, permission, org_id)
2016-06-30 15:06:43 +08:00
else:
update_group_dir_permission(repo_id, '/', repo_owner, group_id, permission)
2016-06-30 15:06:43 +08:00
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
send_perm_audit_msg('modify-repo-perm', username,
group_id, repo_id, '/', permission)
2016-06-30 15:06:43 +08:00
if share_type == 'public':
2016-06-30 15:06:43 +08:00
try:
if is_org_context(request):
org_id = request.user.org.org_id
seafile_api.set_org_inner_pub_repo(org_id, repo_id, permission)
2016-06-30 15:06:43 +08:00
else:
if not request.user.permissions.can_add_public_repo():
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
2016-06-30 15:06:43 +08:00
seafile_api.add_inner_pub_repo(repo_id, permission)
2016-06-30 15:06:43 +08:00
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
send_perm_audit_msg('modify-repo-perm', username,
'all', repo_id, '/', permission)
2016-06-30 15:06:43 +08:00
return Response({'success': True})
def delete(self, request, repo_id, format=None):
""" Unshare a repo.
Permission checking:
1. Only repo owner and system admin can unshare a publib library.
2016-06-30 15:06:43 +08:00
"""
# argument check
share_type = request.GET.get('share_type', None)
if not share_type:
error_msg = 'share_type invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
if share_type not in ('personal', 'group', 'public'):
error_msg = "share_type can only be 'personal' or 'group' or 'public'."
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
# resource check
repo = seafile_api.get_repo(repo_id)
if not repo:
return api_error(status.HTTP_404_NOT_FOUND, 'Library %s not found.' % repo_id)
# permission check
username = request.user.username
if is_org_context(request):
repo_owner = seafile_api.get_org_repo_owner(repo_id)
else:
repo_owner = seafile_api.get_repo_owner(repo_id)
if not request.user.is_staff and not username == repo_owner:
2016-06-30 15:06:43 +08:00
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
# delete share
org_id = None
is_org = False
2016-06-30 15:06:43 +08:00
if is_org_context(request):
org_id = request.user.org.org_id
is_org = True
2016-06-30 15:06:43 +08:00
if share_type == 'personal':
user = request.GET.get('user', None)
if not user or not is_valid_username(user):
error_msg = 'user invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
permission = check_user_share_out_permission(repo_id, '/', user, is_org)
2016-06-30 15:06:43 +08:00
try:
if org_id:
seafile_api.org_remove_share(org_id, repo_id,
username, user)
else:
seafile_api.remove_share(repo_id, username, user)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
send_perm_audit_msg('delete-repo-perm', username, user,
repo_id, '/', permission)
2016-06-30 15:06:43 +08:00
if share_type == 'group':
group_id = request.GET.get('group_id', None)
if not group_id:
error_msg = 'group_id invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
try:
group_id = int(group_id)
except ValueError:
error_msg = 'group_id must be integer.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
permission = check_group_share_out_permission(repo_id, '/', group_id, is_org)
2016-06-30 15:06:43 +08:00
try:
if is_org:
2016-06-30 15:06:43 +08:00
seaserv.del_org_group_repo(repo_id, org_id, group_id)
else:
seafile_api.unset_group_repo(repo_id, group_id, username)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
send_perm_audit_msg('delete-repo-perm', username, group_id,
repo_id, '/', permission)
if share_type == 'public':
pub_repos = []
if org_id:
Python3 master (#4076) * delete thridpart/social_django * delete social_django in seahub/urls.py * delete social_django in seahub/settings.py * delete seahub/notifications/management/commands/send_wxwork_notices.py * delete social_django in code annotation * delete seahub/social_core * delete tests/seahub/social_core * delete social_core in seahub/urls.py * delete social_core in seahub/settings.py * change app_label to auth in SocialAuthUser model * 2to3 asserts * 2to3 basestring * 2to3 dict * 2to3 except * 2to3 filter * 2to3 future * 2to3 has_key * 2to3 idioms * 2to3 import * 2to3 imports * 2to3 long * 2to3 map * 2to3 next * 2to3 numliterals * 2to3 print * 2to3 raise * 2to3 raw_input * 2to3 reduce * 2to3 reload * 2to3 set_literal * 2to3 unicode * 2to3 urllib * 2to3 ws_comma * 2to3 xrange * 2to3 zip * add pymysql in __init__.py * fix encode and decode in seahub/cconvert.py * fix seafserv_rpc.is_passwd_set in seahub/views/__init__.py * fix smart_unicode to smart_text * fix force_unicode to force_text * delete seaserv.get_session_info * delete seaserv.ccnet_rpc * fix indent error in seahub/auth/middleware.py * update dev-requirements * update test-requirements * update requirements * fix StringIO to BytesIO in thumbnail * fix seaserv.list_inner_pub_repos to seafile_api.get_inner_pub_repo_list * fix seaserv.list_org_inner_pub_repos to seafile_api.list_org_inner_pub_repos * add logger in seahub/utils/__init__.py * fix sort cmp in seahub/views/__init__.py * fix sort cmp in seahub/base/management/commands/export_file_access_log.py * fix sort cmp in seahub/api2/endpoints/repo_trash.py * fix sort cmp in seahub/api2/endpoints/shared_repos.py * fix sort cmp in seahub/api2/endpoints/shared_folders.py * fix sort cmp in seahub/wiki/views.py * fix sort cmp in seahub/api2/endpoints/wiki_pages.py * fix sort cmp in seahub/api2/endpoints/group_libraries.py * fix sort cmp in seahub/base/models.py * fix sort cmp in seahub/api2/endpoints/upload_links.py * fix sort cmp in seahub/views/ajax.py * fix sort cmp in seahub/api2/views.py * fix sort cmp in seahub/views/wiki.py * fix sort cmp in seahub/api2/endpoints/repos.py * fix sort cmp in seahub/api2/endpoints/starred_items.py * fix sort cmp in seahub/views/file.py * fix sort cmp in seahub/api2/endpoints/dir.py * fix sort cmp in seahub/api2/endpoints/share_links.py * fix cmp to cmp_to_key in seahub/api2/endpoints/admin/device_trusted_ip.py * fix cmp to cmp_to_key in tests/api/endpoints/admin/test_device_trusted_ip.py * delete encode('utf-8') in seafile_api.list_dir_by_commit_and_path * delete encode('utf-8') in is_file_starred * delete encode('utf-8') in seafile_api.list_dir_by_path * delete path.encode('utf-8') in seahub/views/file.py * fix os.write to add encode('utf-8') * add encode('utf-8') for hashlib * add encode('utf-8') for hmac * fix with open(file, 'wb') for binary file * fix encode and decode in seahub/utils/hasher.py * fix next in thirdpart/shibboleth/views.py * fix next in seahub/profile/views.py * fix next in seahub/notifications/views.py * fix next in seahub/institutions/views.py * fix next in seahub/options/views.py * fix next in seahub/share/views.py * fix next in seahub/avatar/views.py * fix next in seahub/views/__init__.py * fix next in seahub/group/views.py * fix next in seahub/views/wiki.py * fix next in seahub/views/sysadmin.py * fix next in seahub/views/file.py * fix string.lowercase to string.ascii_lowercase in test * fix open file add 'rb' in test * fix self.user.username in test * add migrations in file_participants * fix list_org_inner_pub_repos to list_org_inner_pub_repos_by_owner * fix from seaserv import is_passwd_set to seafile_api.is_password_set * fix assert bytes resp.content in test * fix seafile_api.get_inner_pub_repo_list to seafile_api.list_inner_pub_repos_by_owner * fix seafile_api.is_passwd_set to seafile_api.is_password_set * fix AccountsApiTest assert length * rewrite sort_devices cmp to operator.lt * fix bytes + str in seahub/api2/views.py * fix assert bytes resp.content in test * fix hashlib encode in seahub/thirdpart/registration/models.py * change app_label to base in SocialAuthUser * fix base64 encode in seahub/base/database_storage/database_storage.py * fix assert bytes resp.content * remove path.decode in def mkstemp() * remove path.decode in FpathToLinkTest * remove str decode in FileTagTest * remove mock_write_xls.assert_called_once() in SysUserAdminExportExcelTest * fix urllib assert in FilesApiTest * fix link fields in FileCommentsTest * fix get_related_users_by_repo() * fix assert list in GetRepoSharedUsersTest * fix create user in AccountTest * fix repeated key in dict seahub/api2/views.py * add drone.yml * update nginx conf in test * update test conf in test * update dist and push after test success * update drone conf to dist and push * fix assert in BeSharedReposTest * fix seafile_api.list_org_inner_pub_repos_by_owner(org_id, username) to seafile_api.list_org_inner_pub_repos(org_id) * fix seafile_api.list_inner_pub_repos_by_owner(username) to seafile_api.get_inner_pub_repo_list() * update pyjwt requirement * update dist branch in drone * add SKIP in dist and push * fix StringIO to BytesIO in seahub/avatar/models.py * fix if org_id > 0 to if org_id and org_id > 0 * remove payment * fix StringIO to BytesIO in seahub/base/database_storage/database_storage.py * fix send_message to seafile_api.publish_event in seahub/drafts/utils.py * fix send_message to seafile_api.publish_event in seahub/api2/views.py * fix send_message to seafile_api.publish_event in seahub/api2/endpoints/repos.py * fix send_message to seafile_api.publish_event in seahub/views/file.py * fix send_message to seafile_api.publish_event in seahub/utils/__init__.py * fix image_file.read encode in seahub/base/database_storage/database_storage.py * fix DatabaseStorageTest * remove .travis.yml * drone branch include master
2019-09-11 11:46:43 +08:00
pub_repos = seafile_api.list_org_inner_pub_repos(org_id)
2016-06-30 15:06:43 +08:00
if not request.cloud_mode:
Python3 master (#4076) * delete thridpart/social_django * delete social_django in seahub/urls.py * delete social_django in seahub/settings.py * delete seahub/notifications/management/commands/send_wxwork_notices.py * delete social_django in code annotation * delete seahub/social_core * delete tests/seahub/social_core * delete social_core in seahub/urls.py * delete social_core in seahub/settings.py * change app_label to auth in SocialAuthUser model * 2to3 asserts * 2to3 basestring * 2to3 dict * 2to3 except * 2to3 filter * 2to3 future * 2to3 has_key * 2to3 idioms * 2to3 import * 2to3 imports * 2to3 long * 2to3 map * 2to3 next * 2to3 numliterals * 2to3 print * 2to3 raise * 2to3 raw_input * 2to3 reduce * 2to3 reload * 2to3 set_literal * 2to3 unicode * 2to3 urllib * 2to3 ws_comma * 2to3 xrange * 2to3 zip * add pymysql in __init__.py * fix encode and decode in seahub/cconvert.py * fix seafserv_rpc.is_passwd_set in seahub/views/__init__.py * fix smart_unicode to smart_text * fix force_unicode to force_text * delete seaserv.get_session_info * delete seaserv.ccnet_rpc * fix indent error in seahub/auth/middleware.py * update dev-requirements * update test-requirements * update requirements * fix StringIO to BytesIO in thumbnail * fix seaserv.list_inner_pub_repos to seafile_api.get_inner_pub_repo_list * fix seaserv.list_org_inner_pub_repos to seafile_api.list_org_inner_pub_repos * add logger in seahub/utils/__init__.py * fix sort cmp in seahub/views/__init__.py * fix sort cmp in seahub/base/management/commands/export_file_access_log.py * fix sort cmp in seahub/api2/endpoints/repo_trash.py * fix sort cmp in seahub/api2/endpoints/shared_repos.py * fix sort cmp in seahub/api2/endpoints/shared_folders.py * fix sort cmp in seahub/wiki/views.py * fix sort cmp in seahub/api2/endpoints/wiki_pages.py * fix sort cmp in seahub/api2/endpoints/group_libraries.py * fix sort cmp in seahub/base/models.py * fix sort cmp in seahub/api2/endpoints/upload_links.py * fix sort cmp in seahub/views/ajax.py * fix sort cmp in seahub/api2/views.py * fix sort cmp in seahub/views/wiki.py * fix sort cmp in seahub/api2/endpoints/repos.py * fix sort cmp in seahub/api2/endpoints/starred_items.py * fix sort cmp in seahub/views/file.py * fix sort cmp in seahub/api2/endpoints/dir.py * fix sort cmp in seahub/api2/endpoints/share_links.py * fix cmp to cmp_to_key in seahub/api2/endpoints/admin/device_trusted_ip.py * fix cmp to cmp_to_key in tests/api/endpoints/admin/test_device_trusted_ip.py * delete encode('utf-8') in seafile_api.list_dir_by_commit_and_path * delete encode('utf-8') in is_file_starred * delete encode('utf-8') in seafile_api.list_dir_by_path * delete path.encode('utf-8') in seahub/views/file.py * fix os.write to add encode('utf-8') * add encode('utf-8') for hashlib * add encode('utf-8') for hmac * fix with open(file, 'wb') for binary file * fix encode and decode in seahub/utils/hasher.py * fix next in thirdpart/shibboleth/views.py * fix next in seahub/profile/views.py * fix next in seahub/notifications/views.py * fix next in seahub/institutions/views.py * fix next in seahub/options/views.py * fix next in seahub/share/views.py * fix next in seahub/avatar/views.py * fix next in seahub/views/__init__.py * fix next in seahub/group/views.py * fix next in seahub/views/wiki.py * fix next in seahub/views/sysadmin.py * fix next in seahub/views/file.py * fix string.lowercase to string.ascii_lowercase in test * fix open file add 'rb' in test * fix self.user.username in test * add migrations in file_participants * fix list_org_inner_pub_repos to list_org_inner_pub_repos_by_owner * fix from seaserv import is_passwd_set to seafile_api.is_password_set * fix assert bytes resp.content in test * fix seafile_api.get_inner_pub_repo_list to seafile_api.list_inner_pub_repos_by_owner * fix seafile_api.is_passwd_set to seafile_api.is_password_set * fix AccountsApiTest assert length * rewrite sort_devices cmp to operator.lt * fix bytes + str in seahub/api2/views.py * fix assert bytes resp.content in test * fix hashlib encode in seahub/thirdpart/registration/models.py * change app_label to base in SocialAuthUser * fix base64 encode in seahub/base/database_storage/database_storage.py * fix assert bytes resp.content * remove path.decode in def mkstemp() * remove path.decode in FpathToLinkTest * remove str decode in FileTagTest * remove mock_write_xls.assert_called_once() in SysUserAdminExportExcelTest * fix urllib assert in FilesApiTest * fix link fields in FileCommentsTest * fix get_related_users_by_repo() * fix assert list in GetRepoSharedUsersTest * fix create user in AccountTest * fix repeated key in dict seahub/api2/views.py * add drone.yml * update nginx conf in test * update test conf in test * update dist and push after test success * update drone conf to dist and push * fix assert in BeSharedReposTest * fix seafile_api.list_org_inner_pub_repos_by_owner(org_id, username) to seafile_api.list_org_inner_pub_repos(org_id) * fix seafile_api.list_inner_pub_repos_by_owner(username) to seafile_api.get_inner_pub_repo_list() * update pyjwt requirement * update dist branch in drone * add SKIP in dist and push * fix StringIO to BytesIO in seahub/avatar/models.py * fix if org_id > 0 to if org_id and org_id > 0 * remove payment * fix StringIO to BytesIO in seahub/base/database_storage/database_storage.py * fix send_message to seafile_api.publish_event in seahub/drafts/utils.py * fix send_message to seafile_api.publish_event in seahub/api2/views.py * fix send_message to seafile_api.publish_event in seahub/api2/endpoints/repos.py * fix send_message to seafile_api.publish_event in seahub/views/file.py * fix send_message to seafile_api.publish_event in seahub/utils/__init__.py * fix image_file.read encode in seahub/base/database_storage/database_storage.py * fix DatabaseStorageTest * remove .travis.yml * drone branch include master
2019-09-11 11:46:43 +08:00
pub_repos = seafile_api.get_inner_pub_repo_list()
2016-06-30 15:06:43 +08:00
try:
if org_id:
seaserv.seafserv_threaded_rpc.unset_org_inner_pub_repo(org_id, repo_id)
else:
seafile_api.remove_inner_pub_repo(repo_id)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
permission = ''
for repo in pub_repos:
if repo.repo_id == repo_id:
permission = repo.permission
break
if permission:
send_perm_audit_msg('delete-repo-perm', username, 'all', repo_id, '/', permission)
return Response({'success': True})