1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-22 16:56:57 +00:00

admin-rename-lib

This commit is contained in:
wangjianhui 2018-09-15 13:21:40 +08:00
parent 8d196077bf
commit 06c9fb65cc

View File

@ -278,7 +278,7 @@ class AdminLibrary(APIView):
return Response({'success': True})
def put(self, request, repo_id, format=None):
""" transfer a library
""" transfer a library, rename a library
Permission checking:
1. only admin can perform this action.
@ -288,11 +288,24 @@ class AdminLibrary(APIView):
error_msg = 'Library %s not found.' % repo_id
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
new_owner = request.data.get('owner', None)
if not new_owner:
error_msg = 'owner invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
new_repo_name = request.data.get('name', None)
if new_repo_name:
try:
res = seafile_api.edit_repo(repo_id, new_repo_name, '', None)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
if res == -1:
e = 'Admin rename failed: ID of library is %s, edit_repo api called failed.' % \
repo_id
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
new_owner = request.data.get('owner', None)
if new_owner:
try:
new_owner_obj = User.objects.get(email=new_owner)
except User.DoesNotExist: