mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-31 22:54:11 +00:00
update api err msg and common.ajaxErrorHandler
This commit is contained in:
@@ -585,7 +585,7 @@ class Search(APIView):
|
||||
def repo_download_info(request, repo_id, gen_sync_token=True):
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
# generate download url for client
|
||||
relay_id = get_session_info().id
|
||||
@@ -860,7 +860,7 @@ class PubRepos(APIView):
|
||||
# List public repos
|
||||
if not request.user.permissions.can_view_org():
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'You do not have permission to view pub repos.')
|
||||
'You do not have permission to view public libraries.')
|
||||
|
||||
repos_json = []
|
||||
public_repos = list_inner_pub_repos(request)
|
||||
@@ -954,20 +954,22 @@ def set_repo_password(request, repo, password):
|
||||
|
||||
def check_set_repo_password(request, repo):
|
||||
if not check_permission(repo.id, request.user.username):
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to access this repo.')
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'You do not have permission to access this library.')
|
||||
|
||||
if repo.encrypted:
|
||||
password = request.REQUEST.get('password', default=None)
|
||||
if not password:
|
||||
return api_error(HTTP_440_REPO_PASSWD_REQUIRED,
|
||||
'Repo password is needed.')
|
||||
'Library password is needed.')
|
||||
|
||||
return set_repo_password(request, repo, password)
|
||||
|
||||
def check_repo_access_permission(request, repo):
|
||||
if not seafile_api.check_repo_access_permission(repo.id,
|
||||
request.user.username):
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to access this repo.')
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'You do not have permission to access this library.')
|
||||
|
||||
class Repo(APIView):
|
||||
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
||||
@@ -977,12 +979,12 @@ class Repo(APIView):
|
||||
def get(self, request, repo_id, format=None):
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
username = request.user.username
|
||||
if not is_repo_accessible(repo.id, username):
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'You do not have permission to get repo.')
|
||||
'You do not have permission to access this library.')
|
||||
|
||||
# check whether user is repo owner
|
||||
if is_org_context(request):
|
||||
@@ -1021,14 +1023,14 @@ class Repo(APIView):
|
||||
def post(self, request, repo_id, format=None):
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
op = request.GET.get('op', 'setpassword')
|
||||
if op == 'checkpassword':
|
||||
magic = request.REQUEST.get('magic', default=None)
|
||||
if not magic:
|
||||
return api_error(HTTP_441_REPO_PASSWD_MAGIC_REQUIRED,
|
||||
'Repo password magic is needed.')
|
||||
'Library password magic is needed.')
|
||||
resp = check_repo_access_permission(request, repo)
|
||||
if resp:
|
||||
return resp
|
||||
@@ -1056,13 +1058,13 @@ class Repo(APIView):
|
||||
is_owner = True if username == repo_owner else False
|
||||
if not is_owner:
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'Only library owner can perform this operation.')
|
||||
'You do not have permission to rename this library.')
|
||||
|
||||
if edit_repo(repo_id, repo_name, repo_desc, username):
|
||||
return Response("success")
|
||||
else:
|
||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
"Unable to rename repo")
|
||||
"Unable to rename library")
|
||||
|
||||
return Response("unsupported operation")
|
||||
|
||||
@@ -1081,7 +1083,7 @@ class Repo(APIView):
|
||||
is_owner = True if username == repo_owner else False
|
||||
if not is_owner:
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'Only library owner can perform this operation.')
|
||||
'You do not have permission to delete this library.')
|
||||
|
||||
seafile_api.remove_repo(repo_id)
|
||||
return Response('success', status=status.HTTP_200_OK)
|
||||
@@ -1122,7 +1124,7 @@ class DownloadRepo(APIView):
|
||||
username = request.user.username
|
||||
if not is_repo_accessible(repo_id, username):
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'You do not have permission to get repo.')
|
||||
'You do not have permission to access this library.')
|
||||
|
||||
return repo_download_info(request, repo_id)
|
||||
|
||||
@@ -1134,15 +1136,17 @@ class RepoPublic(APIView):
|
||||
def post(self, request, repo_id, format=None):
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
if check_permission(repo_id, request.user.username) != 'rw':
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to access this repo.')
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'You do not have permission to access this library.')
|
||||
|
||||
try:
|
||||
seafile_api.add_inner_pub_repo(repo_id, "r")
|
||||
except:
|
||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, 'Unable to make repo public')
|
||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
'Unable to make library public')
|
||||
|
||||
return HttpResponse(json.dumps({'success': True}), status=200,
|
||||
content_type=json_content_type)
|
||||
@@ -1150,15 +1154,17 @@ class RepoPublic(APIView):
|
||||
def delete(self, request, repo_id, format=None):
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
if check_permission(repo_id, request.user.username) != 'rw':
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to access this repo.')
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'You do not have permission to access this library.')
|
||||
|
||||
try:
|
||||
seafile_api.remove_inner_pub_repo(repo_id)
|
||||
except:
|
||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, 'Unable to make repo private')
|
||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
'Unable to make library private')
|
||||
|
||||
return HttpResponse(json.dumps({'success': True}), status=200,
|
||||
content_type=json_content_type)
|
||||
@@ -1172,7 +1178,7 @@ class RepoOwner(APIView):
|
||||
def get(self, request, repo_id, format=None):
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
if is_org_context(request):
|
||||
repo_owner = seafile_api.get_org_repo_owner(repo.id)
|
||||
@@ -1191,7 +1197,8 @@ class UploadLinkView(APIView):
|
||||
def get(self, request, repo_id, format=None):
|
||||
parent_dir = request.GET.get('p', '/')
|
||||
if check_folder_permission(request, repo_id, parent_dir) != 'rw':
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to access this folder.')
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'You do not have permission to access this folder.')
|
||||
|
||||
if check_quota(repo_id) < 0:
|
||||
return api_error(HTTP_520_OPERATION_FAILED, 'Above quota')
|
||||
@@ -1209,7 +1216,8 @@ class UpdateLinkView(APIView):
|
||||
def get(self, request, repo_id, format=None):
|
||||
parent_dir = request.GET.get('p', '/')
|
||||
if check_folder_permission(request, repo_id, parent_dir) != 'rw':
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to access this folder.')
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'You do not have permission to access this folder.')
|
||||
|
||||
if check_quota(repo_id) < 0:
|
||||
return api_error(HTTP_520_OPERATION_FAILED, 'Above quota')
|
||||
@@ -1227,7 +1235,8 @@ class UploadBlksLinkView(APIView):
|
||||
def get(self, request, repo_id, format=None):
|
||||
parent_dir = request.GET.get('p', '/')
|
||||
if check_folder_permission(request, repo_id, parent_dir) != 'rw':
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to access this folder.')
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'You do not have permission to access this folder.')
|
||||
|
||||
if check_quota(repo_id) < 0:
|
||||
return api_error(HTTP_520_OPERATION_FAILED, 'Above quota')
|
||||
@@ -1245,7 +1254,8 @@ class UpdateBlksLinkView(APIView):
|
||||
def get(self, request, repo_id, format=None):
|
||||
parent_dir = request.GET.get('p', '/')
|
||||
if check_folder_permission(request, repo_id, parent_dir) != 'rw':
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to access this folder.')
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'You do not have permission to access this folder.')
|
||||
|
||||
if check_quota(repo_id) < 0:
|
||||
return api_error(HTTP_520_OPERATION_FAILED, 'Above quota')
|
||||
@@ -1417,12 +1427,12 @@ class OpDeleteView(APIView):
|
||||
def post(self, request, repo_id, format=None):
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
username = request.user.username
|
||||
if not is_repo_writable(repo.id, username):
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'You do not have permission to delete file.')
|
||||
'You do not have permission to delete this file.')
|
||||
|
||||
resp = check_repo_access_permission(request, repo)
|
||||
if resp:
|
||||
@@ -1458,7 +1468,7 @@ class OpMoveView(APIView):
|
||||
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
username = request.user.username
|
||||
parent_dir = request.GET.get('p', '/')
|
||||
@@ -1471,10 +1481,12 @@ class OpMoveView(APIView):
|
||||
'Missing argument.')
|
||||
|
||||
if check_folder_permission(request, repo_id, parent_dir) != 'rw':
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to move file of this folder.')
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'You do not have permission to move file in this folder.')
|
||||
|
||||
if check_folder_permission(request, dst_repo, dst_dir) != 'rw':
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to move file to destination folder.')
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'You do not have permission to move file to destination folder.')
|
||||
|
||||
if repo_id == dst_repo and parent_dir == dst_dir:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST,
|
||||
@@ -1507,7 +1519,7 @@ class OpCopyView(APIView):
|
||||
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
username = request.user.username
|
||||
parent_dir = request.GET.get('p', '/')
|
||||
@@ -1520,13 +1532,15 @@ class OpCopyView(APIView):
|
||||
'Missing argument.')
|
||||
|
||||
if check_folder_permission(request, repo_id, parent_dir) is None:
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to copy file of this folder.')
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'You do not have permission to copy file of this folder.')
|
||||
|
||||
if check_folder_permission(request, dst_repo, dst_dir) != 'rw':
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to copy file to destination folder.')
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'You do not have permission to copy file to destination folder.')
|
||||
|
||||
if not get_repo(dst_repo):
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
if seafile_api.get_dir_id_by_path(repo_id, parent_dir) is None or \
|
||||
seafile_api.get_dir_id_by_path(dst_repo, dst_dir) is None:
|
||||
@@ -1572,7 +1586,7 @@ class StarredFileView(APIView):
|
||||
path = unquote(request.POST.get('p', '').encode('utf-8'))
|
||||
if not (repo_id and path):
|
||||
return api_error(status.HTTP_400_BAD_REQUEST,
|
||||
'Repo_id or path is missing.')
|
||||
'Library ID or path is missing.')
|
||||
|
||||
if path[-1] == '/': # Should not contain '/' at the end of path.
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, 'Invalid file path.')
|
||||
@@ -1591,7 +1605,7 @@ class StarredFileView(APIView):
|
||||
path = request.GET.get('p', '')
|
||||
if not (repo_id and path):
|
||||
return api_error(status.HTTP_400_BAD_REQUEST,
|
||||
'Repo_id or path is missing.')
|
||||
'Library ID or path is missing.')
|
||||
|
||||
if path[-1] == '/': # Should not contain '/' at the end of path.
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, 'Invalid file path.')
|
||||
@@ -1613,7 +1627,7 @@ class FileView(APIView):
|
||||
# view file
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
resp = check_repo_access_permission(request, repo)
|
||||
if resp:
|
||||
@@ -1646,13 +1660,14 @@ class FileView(APIView):
|
||||
# rename, move or create file
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
path = request.GET.get('p', '')
|
||||
username = request.user.username
|
||||
parent_dir = os.path.dirname(path)
|
||||
if check_folder_permission(request, repo_id, parent_dir) != 'rw':
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to access this folder.')
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'You do not have permission to access this folder.')
|
||||
|
||||
if not path or path[0] != '/':
|
||||
return api_error(status.HTTP_400_BAD_REQUEST,
|
||||
@@ -1674,10 +1689,10 @@ class FileView(APIView):
|
||||
newname = request.POST.get('newname', '')
|
||||
if not newname:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST,
|
||||
'Newname is missing')
|
||||
'New name is missing')
|
||||
newname = unquote(newname.encode('utf-8'))
|
||||
if len(newname) > settings.MAX_UPLOAD_FILE_NAME_LEN:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, 'Newname too long')
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, 'New name is too long')
|
||||
|
||||
parent_dir = os.path.dirname(path)
|
||||
parent_dir_utf8 = parent_dir.encode('utf-8')
|
||||
@@ -1756,7 +1771,7 @@ class FileView(APIView):
|
||||
|
||||
dst_repo = get_repo(dst_repo_id)
|
||||
if not dst_repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
if request.GET.get('reloaddir', '').lower() == 'true':
|
||||
return reloaddir(request, dst_repo, dst_dir)
|
||||
@@ -1799,7 +1814,7 @@ class FileView(APIView):
|
||||
def put(self, request, repo_id, format=None):
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
path = request.DATA.get('p', '')
|
||||
file_id = seafile_api.get_file_id_by_path(repo_id, path)
|
||||
@@ -1850,7 +1865,7 @@ class FileView(APIView):
|
||||
# delete file
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
username = request.user.username
|
||||
if not is_repo_writable(repo.id, username):
|
||||
@@ -1968,7 +1983,7 @@ class FileRevert(APIView):
|
||||
|
||||
parent_dir = os.path.dirname(path)
|
||||
if check_folder_permission(request, repo_id, parent_dir) != 'rw':
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to access this folder.')
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'You do not have permission to access this folder.')
|
||||
|
||||
path = unquote(path.encode('utf-8'))
|
||||
commit_id = unquote(request.DATA.get('commit_id', '').encode('utf-8'))
|
||||
@@ -1977,7 +1992,7 @@ class FileRevert(APIView):
|
||||
path, request.user.username)
|
||||
except SearpcError as e:
|
||||
logger.error(e)
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, 'Server error')
|
||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, "Internal error")
|
||||
|
||||
return HttpResponse(json.dumps({"ret": ret}), status=200, content_type=json_content_type)
|
||||
|
||||
@@ -2017,7 +2032,7 @@ class FileHistory(APIView):
|
||||
-1, -1)
|
||||
except SearpcError as e:
|
||||
logger.error(e)
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, 'Server error')
|
||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, "Internal error")
|
||||
|
||||
if not commits:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'File not found.')
|
||||
@@ -2049,7 +2064,7 @@ class FileSharedLinkView(APIView):
|
||||
if share_type.lower() == 'download':
|
||||
|
||||
if check_file_permission(request, repo_id, path) is None:
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'permission denied')
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied')
|
||||
|
||||
expire = request.DATA.get('expire', None)
|
||||
if expire:
|
||||
@@ -2108,7 +2123,7 @@ class FileSharedLinkView(APIView):
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, 'Invalid path')
|
||||
|
||||
if check_folder_permission(request, repo_id, path) != 'rw':
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'permission denied')
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied')
|
||||
|
||||
# generate upload link
|
||||
uls = UploadLinkShare.objects.get_upload_link_by_path(username, repo_id, path)
|
||||
@@ -2141,7 +2156,7 @@ class DirView(APIView):
|
||||
# list dir
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
resp = check_repo_access_permission(request, repo)
|
||||
if resp:
|
||||
@@ -2175,7 +2190,7 @@ class DirView(APIView):
|
||||
# new dir
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
path = request.GET.get('p', '')
|
||||
|
||||
@@ -2196,7 +2211,7 @@ class DirView(APIView):
|
||||
|
||||
parent_dir = os.path.dirname(path)
|
||||
if check_folder_permission(request, repo_id, parent_dir) != 'rw':
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to access this folder.')
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'You do not have permission to access this folder.')
|
||||
|
||||
parent_dir_utf8 = parent_dir.encode('utf-8')
|
||||
new_dir_name = os.path.basename(path)
|
||||
@@ -2221,7 +2236,7 @@ class DirView(APIView):
|
||||
return resp
|
||||
elif operation.lower() == 'rename':
|
||||
if check_folder_permission(request, repo.id, path) != 'rw':
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to access this folder.')
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'You do not have permission to access this folder.')
|
||||
|
||||
if not is_repo_writable(repo.id, username):
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
@@ -2232,7 +2247,7 @@ class DirView(APIView):
|
||||
|
||||
newname = request.POST.get('newname', '')
|
||||
if not newname:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, "newname is mandatory.")
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, "New name is mandatory.")
|
||||
|
||||
if newname == old_dir_name:
|
||||
return Response('success', status=status.HTTP_200_OK)
|
||||
@@ -2248,7 +2263,7 @@ class DirView(APIView):
|
||||
except SearpcError, e:
|
||||
logger.error(e)
|
||||
return api_error(HTTP_520_OPERATION_FAILED,
|
||||
'Failed to rename directory.')
|
||||
'Failed to rename folder.')
|
||||
# elif operation.lower() == 'move':
|
||||
# pass
|
||||
else:
|
||||
@@ -2259,7 +2274,7 @@ class DirView(APIView):
|
||||
# delete dir or file
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
username = request.user.username
|
||||
if not is_repo_writable(repo.id, username):
|
||||
@@ -2271,7 +2286,7 @@ class DirView(APIView):
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, 'Path is missing.')
|
||||
|
||||
if check_folder_permission(request, repo_id, path) != 'rw':
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to access this folder.')
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'You do not have permission to access this folder.')
|
||||
|
||||
if path == '/': # Can not delete root path.
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, 'Path is invalid.')
|
||||
@@ -2300,7 +2315,7 @@ class DirDownloadView(APIView):
|
||||
def get(self, request, repo_id, format=None):
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
path = request.GET.get('p', None)
|
||||
if path is None:
|
||||
@@ -2401,7 +2416,7 @@ class DirSubRepoView(APIView):
|
||||
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
result['error'] = 'Repo not found.'
|
||||
result['error'] = 'Library not found.'
|
||||
return HttpResponse(json.dumps(result), status=404, content_type=json_content_type)
|
||||
|
||||
if not (path and name):
|
||||
@@ -2555,7 +2570,7 @@ class SharedFilesView(APIView):
|
||||
return HttpResponse(json.dumps({}), status=200, content_type=json_content_type)
|
||||
else:
|
||||
return api_error(status.HTTP_403_FORBIDDEN,
|
||||
'You do not have permission to get repo.')
|
||||
'You do not have permission to access this library.')
|
||||
|
||||
class VirtualRepos(APIView):
|
||||
authentication_classes = (TokenAuthentication, )
|
||||
@@ -2596,7 +2611,7 @@ class PrivateSharedFileView(APIView):
|
||||
repo_id = fileshare.repo_id
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, "Repo not found")
|
||||
return api_error(status.HTTP_404_NOT_FOUND, "Library not found")
|
||||
|
||||
path = fileshare.path.rstrip('/') # Normalize file path
|
||||
file_name = os.path.basename(path)
|
||||
@@ -2630,7 +2645,7 @@ class SharedFileView(APIView):
|
||||
repo_id = fileshare.repo_id
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, "Repo not found")
|
||||
return api_error(status.HTTP_404_NOT_FOUND, "Library not found")
|
||||
|
||||
path = fileshare.path.rstrip('/') # Normalize file path
|
||||
file_name = os.path.basename(path)
|
||||
@@ -2676,7 +2691,7 @@ class SharedFileDetailView(APIView):
|
||||
repo_id = fileshare.repo_id
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, "Repo not found")
|
||||
return api_error(status.HTTP_404_NOT_FOUND, "Library not found")
|
||||
|
||||
path = fileshare.path.rstrip('/') # Normalize file path
|
||||
file_name = os.path.basename(path)
|
||||
@@ -2734,7 +2749,7 @@ class PrivateSharedFileDetailView(APIView):
|
||||
repo_id = fileshare.repo_id
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, "Repo not found")
|
||||
return api_error(status.HTTP_404_NOT_FOUND, "Library not found")
|
||||
|
||||
path = fileshare.path.rstrip('/') # Normalize file path
|
||||
file_name = os.path.basename(path)
|
||||
@@ -2971,13 +2986,13 @@ class SharedRepo(APIView):
|
||||
share_type = request.GET.get('share_type', '')
|
||||
if not share_type:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST,
|
||||
'share_type is required.')
|
||||
'Share type is required.')
|
||||
|
||||
if share_type == 'personal':
|
||||
user = request.GET.get('user', '')
|
||||
if not user:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST,
|
||||
'user is required.')
|
||||
'User is required.')
|
||||
|
||||
if not is_valid_username(user):
|
||||
return api_error(status.HTTP_400_BAD_REQUEST,
|
||||
@@ -2988,20 +3003,20 @@ class SharedRepo(APIView):
|
||||
group_id = request.GET.get('group_id', '')
|
||||
if not group_id:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST,
|
||||
'group_id is required.')
|
||||
'Group ID is required.')
|
||||
|
||||
try:
|
||||
group_id = int(group_id)
|
||||
except ValueError:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST,
|
||||
'group_id is not valid.')
|
||||
'Group ID is not valid.')
|
||||
|
||||
seafile_api.unset_group_repo(repo_id, int(group_id), username)
|
||||
elif share_type == 'public':
|
||||
unset_inner_pub_repo(repo_id)
|
||||
else:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST,
|
||||
'share_type can only be personal or group or public.')
|
||||
'Share type can only be personal or group or public.')
|
||||
|
||||
return Response('success', status=status.HTTP_200_OK)
|
||||
|
||||
@@ -3044,7 +3059,7 @@ class SharedRepo(APIView):
|
||||
usernames += users.split(",")
|
||||
if not user and not users:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST,
|
||||
'user or users (comma separated are mandatory) are not provided')
|
||||
'User or users (comma separated are mandatory) are not provided')
|
||||
for u in usernames:
|
||||
if not u:
|
||||
continue
|
||||
@@ -3089,7 +3104,7 @@ class SharedRepo(APIView):
|
||||
group_id = int(group_id)
|
||||
except ValueError:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST,
|
||||
'Group id must be integer.')
|
||||
'Group ID must be integer.')
|
||||
|
||||
from_email = seafile_api.get_repo_owner(repo_id)
|
||||
group = get_group(group_id)
|
||||
@@ -3126,7 +3141,7 @@ class SharedRepo(APIView):
|
||||
'Failed to share library to public.')
|
||||
else:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST,
|
||||
'share_type can only be personal or group or public.')
|
||||
'Share type can only be personal or group or public.')
|
||||
|
||||
return Response('success', status=status.HTTP_200_OK)
|
||||
|
||||
@@ -3165,7 +3180,7 @@ class EventsView(APIView):
|
||||
try:
|
||||
start = int(start)
|
||||
except ValueError:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, 'start id must be integer')
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, 'Start id must be integer')
|
||||
|
||||
email = request.user.username
|
||||
events_count = 15
|
||||
@@ -3321,7 +3336,7 @@ class Groups(APIView):
|
||||
# permission check
|
||||
username = request.user.username
|
||||
if not seaserv.check_group_staff(group_id, username):
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to delete group')
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'You do not have permission to delete group')
|
||||
|
||||
# delete group
|
||||
if is_org_context(request):
|
||||
@@ -3346,14 +3361,14 @@ class Groups(APIView):
|
||||
# permission check
|
||||
username = request.user.username
|
||||
if not seaserv.check_group_staff(group.id, username):
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Forbid to rename group')
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'You do not have permission to rename group')
|
||||
|
||||
operation = request.POST.get('operation', '')
|
||||
if operation.lower() == 'rename':
|
||||
newname = request.POST.get('newname', '')
|
||||
if not newname:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST,
|
||||
'Newname is missing')
|
||||
'New name is missing')
|
||||
|
||||
try:
|
||||
rename_group_with_new_name(request, group.id, newname)
|
||||
@@ -3381,11 +3396,11 @@ class GroupMembers(APIView):
|
||||
try:
|
||||
group_id_int = int(group_id)
|
||||
except ValueError:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, 'Invalid group id')
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, 'Invalid group ID')
|
||||
|
||||
group = get_group(group_id_int)
|
||||
if not group:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Unable to find group')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Group not found')
|
||||
|
||||
if not is_group_staff(group, request.user):
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Only administrators can add group members')
|
||||
@@ -3408,11 +3423,11 @@ class GroupMembers(APIView):
|
||||
try:
|
||||
group_id_int = int(group_id)
|
||||
except ValueError:
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, 'Invalid group id')
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, 'Invalid group ID')
|
||||
|
||||
group = get_group(group_id_int)
|
||||
if not group:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Unable to find group')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Group not found')
|
||||
|
||||
if not is_group_staff(group, request.user):
|
||||
return api_error(status.HTTP_403_FORBIDDEN, 'Only administrators can remove group members')
|
||||
@@ -3671,7 +3686,7 @@ class GroupMsgView(APIView):
|
||||
def get(self, request, group, msg_id, format=None):
|
||||
msg = get_group_message_json(group.id, msg_id, True)
|
||||
if not msg:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Messageg not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Message not found.')
|
||||
|
||||
UserNotification.objects.seen_group_msg_reply_notice(request.user.username, msg_id)
|
||||
return Response(msg)
|
||||
@@ -3681,7 +3696,7 @@ class GroupMsgView(APIView):
|
||||
try:
|
||||
group_msg = GroupMessage.objects.get(group_id=group.id, id=msg_id)
|
||||
except GroupMessage.DoesNotExist:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Messageg not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Message not found.')
|
||||
|
||||
msg = request.POST.get('message')
|
||||
msg_reply = MessageReply()
|
||||
@@ -4271,7 +4286,7 @@ class OfficeGenerateView(APIView):
|
||||
# check arguments
|
||||
repo = get_repo(repo_id)
|
||||
if not repo:
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Repo not found.')
|
||||
return api_error(status.HTTP_404_NOT_FOUND, 'Library not found.')
|
||||
|
||||
|
||||
path = request.GET.get('p', '/').rstrip('/')
|
||||
|
@@ -44,14 +44,8 @@ define([
|
||||
_this.remove();
|
||||
Common.feedback(gettext("Successfully unstared {placeholder}").replace('{placeholder}', Common.HTMLescape(file_name)), 'success');
|
||||
},
|
||||
error: function(xhr) {
|
||||
var err;
|
||||
if (xhr.responseText) {
|
||||
err = $.parseJSON(xhr.responseText).error;
|
||||
} else {
|
||||
err = gettext("Failed. Please check the network.");
|
||||
}
|
||||
Common.feedback(err, 'error');
|
||||
error: function (xhr) {
|
||||
Common.ajaxErrorHandler(xhr);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@@ -151,7 +151,18 @@ define([
|
||||
|
||||
ajaxErrorHandler: function(xhr, textStatus, errorThrown) {
|
||||
if (xhr.responseText) {
|
||||
this.feedback($.parseJSON(xhr.responseText).error, 'error');
|
||||
|
||||
var parsed_resp = $.parseJSON(xhr.responseText);
|
||||
|
||||
if (parsed_resp.hasOwnProperty('error')) {
|
||||
/* error msg from seahub ajax */
|
||||
this.feedback(parsed_resp.error, 'error');
|
||||
} else if (parsed_resp.hasOwnProperty('error_msg')) {
|
||||
/* error msg from seahub api */
|
||||
this.feedback(parsed_resp.error_msg, 'error');
|
||||
} else {
|
||||
this.feedback(gettext("Error"), 'error');
|
||||
}
|
||||
} else {
|
||||
this.feedback(gettext("Failed. Please check the network."), 'error');
|
||||
}
|
||||
|
Reference in New Issue
Block a user