def view_shared_upload_link(request, token): assert token is not None # Checked by URLconf uploadlink = UploadLinkShare.objects.get_valid_upload_link_by_token(token) if uploadlink is None: raise Http404 if uploadlink.is_encrypted(): if not check_share_link_access(request.user.username, token): d = {"token": token, "view_name": "view_shared_upload_link"} if request.method == "POST": post_values = request.POST.copy() post_values["enc_password"] = uploadlink.password form = SharedLinkPasswordForm(post_values) d["form"] = form if form.is_valid(): # set cache for non-anonymous user if request.user.is_authenticated(): set_share_link_access(request.user.username, token) else: return render_to_response( "share_access_validation.html", d, context_instance=RequestContext(request) ) else: return render_to_response("share_access_validation.html", d, context_instance=RequestContext(request)) username = uploadlink.username repo_id = uploadlink.repo_id path = uploadlink.path dir_name = os.path.basename(path[:-1]) repo = get_repo(repo_id) if not repo: raise Http404 uploadlink.view_cnt = F("view_cnt") + 1 uploadlink.save() no_quota = True if seaserv.check_quota(repo_id) < 0 else False token = seafile_api.get_fileserver_access_token(repo_id, "dummy", "upload", request.user.username) ajax_upload_url = gen_file_upload_url(token, "upload-aj") return render_to_response( "view_shared_upload_link.html", { "repo": repo, "token": token, "path": path, "username": username, "dir_name": dir_name, "max_upload_file_size": seaserv.MAX_UPLOAD_FILE_SIZE, "no_quota": no_quota, "ajax_upload_url": ajax_upload_url, "uploadlink": uploadlink, }, context_instance=RequestContext(request), )
def view_shared_upload_link(request, token): assert token is not None # Checked by URLconf uploadlink = UploadLinkShare.objects.get_valid_upload_link_by_token(token) if uploadlink is None: raise Http404 if uploadlink.is_encrypted() and not check_share_link_access( request, token, is_upload_link=True): d = {'token': token, 'view_name': 'view_shared_upload_link', } if request.method == 'POST': post_values = request.POST.copy() post_values['enc_password'] = uploadlink.password form = SharedLinkPasswordForm(post_values) d['form'] = form if form.is_valid(): set_share_link_access(request, token, is_upload_link=True) else: return render_to_response('share_access_validation.html', d, context_instance=RequestContext(request)) else: return render_to_response('share_access_validation.html', d, context_instance=RequestContext(request)) username = uploadlink.username repo_id = uploadlink.repo_id repo = get_repo(repo_id) if not repo: raise Http404 path = uploadlink.path if path == '/': # use repo name as dir name if share whole library dir_name = repo.name else: dir_name = os.path.basename(path[:-1]) repo = get_repo(repo_id) if not repo: raise Http404 uploadlink.view_cnt = F('view_cnt') + 1 uploadlink.save() no_quota = True if seaserv.check_quota(repo_id) < 0 else False return render_to_response('view_shared_upload_link.html', { 'repo': repo, 'path': path, 'username': username, 'dir_name': dir_name, 'max_upload_file_size': seaserv.MAX_UPLOAD_FILE_SIZE, 'no_quota': no_quota, 'uploadlink': uploadlink, 'enable_upload_folder': ENABLE_UPLOAD_FOLDER, 'enable_resumable_fileupload': ENABLE_RESUMABLE_FILEUPLOAD, }, context_instance=RequestContext(request))
def view_shared_upload_link(request, token): assert token is not None # Checked by URLconf uploadlink = UploadLinkShare.objects.get_valid_upload_link_by_token(token) if uploadlink is None: raise Http404 if uploadlink.is_encrypted(): if not check_share_link_access(request.user.username, token): d = {'token': token, 'view_name': 'view_shared_upload_link', } if request.method == 'POST': post_values = request.POST.copy() post_values['enc_password'] = uploadlink.password form = SharedLinkPasswordForm(post_values) d['form'] = form if form.is_valid(): # set cache for non-anonymous user if request.user.is_authenticated(): set_share_link_access(request.user.username, token) else: return render_to_response('share_access_validation.html', d, context_instance=RequestContext(request)) else: return render_to_response('share_access_validation.html', d, context_instance=RequestContext(request)) username = uploadlink.username repo_id = uploadlink.repo_id path = uploadlink.path dir_name = os.path.basename(path[:-1]) repo = get_repo(repo_id) if not repo: raise Http404 uploadlink.view_cnt = F('view_cnt') + 1 uploadlink.save() no_quota = True if seaserv.check_quota(repo_id) < 0 else False token = seafile_api.get_fileserver_access_token(repo_id, 'dummy', 'upload', request.user.username) ajax_upload_url = gen_file_upload_url(token, 'upload-aj') return render_to_response('view_shared_upload_link.html', { 'repo': repo, 'token': token, 'path': path, 'username': username, 'dir_name': dir_name, 'max_upload_file_size': seaserv.MAX_UPLOAD_FILE_SIZE, 'no_quota': no_quota, 'ajax_upload_url': ajax_upload_url, 'uploadlink': uploadlink, 'enable_upload_folder': ENABLE_UPLOAD_FOLDER, }, context_instance=RequestContext(request))
def view_shared_upload_link(request, token): assert token is not None # Checked by URLconf uploadlink = UploadLinkShare.objects.get_valid_upload_link_by_token(token) if uploadlink is None: raise Http404 password_check_passed, err_msg = check_share_link_common( request, uploadlink, is_upload_link=True) if not password_check_passed: d = { 'token': token, 'view_name': 'view_shared_upload_link', 'err_msg': err_msg } return render_to_response( 'share_access_validation.html', d, context_instance=RequestContext(request)) username = uploadlink.username repo_id = uploadlink.repo_id repo = get_repo(repo_id) if not repo: raise Http404 path = uploadlink.path if path == '/': # use repo name as dir name if share whole library dir_name = repo.name else: dir_name = os.path.basename(path[:-1]) repo = get_repo(repo_id) if not repo: raise Http404 uploadlink.view_cnt = F('view_cnt') + 1 uploadlink.save() no_quota = True if seaserv.check_quota(repo_id) < 0 else False return render_to_response( 'view_shared_upload_link.html', { 'repo': repo, 'path': path, 'username': username, 'dir_name': dir_name, 'max_upload_file_size': seaserv.MAX_UPLOAD_FILE_SIZE, 'no_quota': no_quota, 'uploadlink': uploadlink, 'enable_upload_folder': ENABLE_UPLOAD_FOLDER, 'enable_resumable_fileupload': ENABLE_RESUMABLE_FILEUPLOAD, }, context_instance=RequestContext(request))
def get(self, request, repo_id, format=None): if check_permission(repo_id, request.user.username) != 'rw': return api_error(status.HTTP_403_FORBIDDEN, "Can not access repo") if check_quota(repo_id) < 0: return api_error(HTTP_520_OPERATION_FAILED, 'Above quota') token = seafserv_rpc.web_get_access_token(repo_id, 'dummy', 'update', request.user.username) url = gen_file_upload_url(token, 'update-api') return Response(url)
def view_shared_upload_link(request, uploadlink): token = uploadlink.token password_check_passed, err_msg = check_share_link_common(request, uploadlink, is_upload_link=True) if not password_check_passed: d = {'token': token, 'view_name': 'view_shared_upload_link', 'err_msg': err_msg} return render(request, 'share_access_validation.html', d) username = uploadlink.username repo_id = uploadlink.repo_id repo = get_repo(repo_id) if not repo: raise Http404 path = uploadlink.path if path == '/': # use repo name as dir name if share whole library dir_name = repo.name else: dir_name = os.path.basename(path[:-1]) repo = get_repo(repo_id) if not repo: raise Http404 if repo.encrypted or \ seafile_api.check_permission_by_path(repo_id, '/', username) != 'rw': return render_error(request, _(u'Permission denied')) uploadlink.view_cnt = F('view_cnt') + 1 uploadlink.save() no_quota = True if seaserv.check_quota(repo_id) < 0 else False return render(request, 'view_shared_upload_link.html', { 'repo': repo, 'path': path, 'username': username, 'dir_name': dir_name, 'max_upload_file_size': seaserv.MAX_UPLOAD_FILE_SIZE, 'no_quota': no_quota, 'uploadlink': uploadlink, 'enable_upload_folder': ENABLE_UPLOAD_FOLDER, 'enable_resumable_fileupload': ENABLE_RESUMABLE_FILEUPLOAD, 'max_number_of_files_for_fileupload': MAX_NUMBER_OF_FILES_FOR_FILEUPLOAD, })
def is_no_quota(repo_id): return True if seaserv.check_quota(repo_id) < 0 else False
def is_no_quota(self): return True if check_quota(self.repo_id) < 0 else False
def list_lib_dir(request, repo_id): ''' New ajax API for list library directory ''' content_type = 'application/json; charset=utf-8' result = {} repo = get_repo(repo_id) if not repo: err_msg = _('Library does not exist.') return HttpResponse(json.dumps({'error': err_msg}), status=400, content_type=content_type) username = request.user.username path = request.GET.get('p', '/') path = normalize_dir_path(path) dir_id = seafile_api.get_dir_id_by_path(repo.id, path) if not dir_id: err_msg = 'Folder not found.' return HttpResponse(json.dumps({'error': err_msg}), status=404, content_type=content_type) # perm for current dir user_perm = check_folder_permission(request, repo_id, path) if not user_perm: return convert_repo_path_when_can_not_view_folder( request, repo_id, path) if repo.encrypted \ and not seafile_api.is_password_set(repo.id, username): err_msg = _('Library is encrypted.') return HttpResponse(json.dumps({ 'error': err_msg, 'lib_need_decrypt': True }), status=403, content_type=content_type) head_commit = get_commit(repo.id, repo.version, repo.head_cmmt_id) if not head_commit: err_msg = _('Error: no head commit id') return HttpResponse(json.dumps({'error': err_msg}), status=500, content_type=content_type) dir_list = [] file_list = [] dirs = seafserv_threaded_rpc.list_dir_with_perm(repo_id, path, dir_id, username, -1, -1) starred_files = get_dir_starred_files(username, repo_id, path) for dirent in dirs: dirent.last_modified = dirent.mtime if stat.S_ISDIR(dirent.mode): dpath = posixpath.join(path, dirent.obj_name) if dpath[-1] != '/': dpath += '/' dir_list.append(dirent) else: if repo.version == 0: file_size = seafile_api.get_file_size(repo.store_id, repo.version, dirent.obj_id) else: file_size = dirent.size dirent.file_size = file_size if file_size else 0 dirent.starred = False fpath = posixpath.join(path, dirent.obj_name) if fpath in starred_files: dirent.starred = True file_list.append(dirent) 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) result["repo_owner"] = repo_owner result["is_repo_owner"] = False result["has_been_shared_out"] = False result["is_admin"] = is_repo_admin(username, repo_id) if repo_owner == username: result["is_repo_owner"] = True try: result["has_been_shared_out"] = repo_has_been_shared_out( request, repo_id) except Exception as e: logger.error(e) if result["is_admin"]: result["has_been_shared_out"] = True result["is_virtual"] = repo.is_virtual result["repo_name"] = repo.name result["user_perm"] = user_perm # check quota for fileupload result["no_quota"] = True if seaserv.check_quota(repo.id) < 0 else False result["encrypted"] = repo.encrypted dirent_list = [] for d in dir_list: d_ = {} d_['is_dir'] = True d_['obj_name'] = d.obj_name d_['last_modified'] = d.last_modified d_['last_update'] = translate_seahub_time(d.last_modified) d_['p_dpath'] = posixpath.join(path, d.obj_name) d_['perm'] = d.permission # perm for sub dir in current dir dirent_list.append(d_) size = int(request.GET.get('thumbnail_size', THUMBNAIL_DEFAULT_SIZE)) for f in file_list: f_ = {} f_['is_file'] = True f_['obj_name'] = f.obj_name f_['last_modified'] = f.last_modified f_['last_update'] = translate_seahub_time(f.last_modified) f_['starred'] = f.starred f_['file_size'] = filesizeformat(f.file_size) f_['obj_id'] = f.obj_id f_['perm'] = f.permission # perm for file in current dir if not repo.encrypted: # used for providing a way to determine # if send a request to create thumbnail. fileExt = os.path.splitext(f.obj_name)[1][1:].lower() file_type = FILEEXT_TYPE_MAP.get(fileExt) if file_type == IMAGE: f_['is_img'] = True if file_type == VIDEO and ENABLE_VIDEO_THUMBNAIL: f_['is_video'] = True if file_type == XMIND: f_['is_xmind'] = True if file_type in (IMAGE, XMIND) or \ (file_type == VIDEO and ENABLE_VIDEO_THUMBNAIL): # if thumbnail has already been created, return its src. # Then web browser will use this src to get thumbnail instead of # recreating it. thumbnail_file_path = os.path.join(THUMBNAIL_ROOT, str(size), f.obj_id) thumbnail_exist = os.path.exists(thumbnail_file_path) if thumbnail_exist: file_path = posixpath.join(path, f.obj_name) src = get_thumbnail_src(repo_id, size, file_path) f_['encoded_thumbnail_src'] = urlquote(src) if is_pro_version(): f_['is_locked'] = True if f.is_locked else False f_['lock_owner'] = f.lock_owner f_['lock_owner_name'] = email2nickname(f.lock_owner) f_['locked_by_me'] = False if f.lock_owner == username: f_['locked_by_me'] = True if f.lock_owner == ONLINE_OFFICE_LOCK_OWNER and \ user_perm == PERMISSION_READ_WRITE: f_['locked_by_me'] = True dirent_list.append(f_) result["dirent_list"] = dirent_list return HttpResponse(json.dumps(result), content_type=content_type)
def view_shared_upload_link(request, uploadlink): token = uploadlink.token password_check_passed, err_msg = check_share_link_common( request, uploadlink, is_upload_link=True) if not password_check_passed: d = { 'token': token, 'view_name': 'view_shared_upload_link', 'err_msg': err_msg } return render(request, 'share_access_validation.html', d) username = uploadlink.username repo_id = uploadlink.repo_id repo = get_repo(repo_id) if not repo: raise Http404 path = uploadlink.path if path == '/': # use repo name as dir name if share whole library dir_name = repo.name else: dir_name = os.path.basename(path[:-1]) repo = get_repo(repo_id) if not repo: raise Http404 if repo.encrypted or \ seafile_api.check_permission_by_path(repo_id, '/', username) != 'rw': return render_error(request, _('Permission denied')) uploadlink.view_cnt = F('view_cnt') + 1 uploadlink.save() no_quota = True if seaserv.check_quota(repo_id) < 0 else False return render( request, 'view_shared_upload_link.html', { 'repo': repo, 'path': path, 'username': username, 'dir_name': dir_name, 'max_upload_file_size': seaserv.MAX_UPLOAD_FILE_SIZE, 'no_quota': no_quota, 'uploadlink': uploadlink, 'enable_upload_folder': ENABLE_UPLOAD_FOLDER, 'enable_resumable_fileupload': ENABLE_RESUMABLE_FILEUPLOAD, 'max_number_of_files_for_fileupload': MAX_NUMBER_OF_FILES_FOR_FILEUPLOAD, })