本文整理汇总了Python中seahub.views.check_repo_access_permission函数的典型用法代码示例。如果您正苦于以下问题:Python check_repo_access_permission函数的具体用法?Python check_repo_access_permission怎么用?Python check_repo_access_permission使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_repo_access_permission函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _decorated
def _decorated(request, repo_id, *args, **kwargs):
if request.method != 'POST' or not request.is_ajax():
raise Http404
result = {}
content_type = 'application/json; charset=utf-8'
repo = get_repo(repo_id)
if not repo:
result['error'] = _(u'Library does not exist.')
return HttpResponse(json.dumps(result), status=400,
content_type=content_type)
# permission checking
username = request.user.username
if check_repo_access_permission(repo.id, request.user) != 'rw':
result['error'] = _('Permission denied')
return HttpResponse(json.dumps(result), status=403,
content_type=content_type)
# arguments validation
parent_dir = request.GET.get('parent_dir')
obj_file_names = request.POST.getlist('file_names')
obj_dir_names = request.POST.getlist('dir_names')
dst_repo_id = request.POST.get('dst_repo')
dst_path = request.POST.get('dst_path')
if not (parent_dir and dst_repo_id and dst_path) and not (obj_file_names or obj_dir_names):
result['error'] = _('Argument missing')
return HttpResponse(json.dumps(result), status=400,
content_type=content_type)
# check file path
for obj_name in obj_file_names + obj_dir_names:
if len(dst_path+obj_name) > settings.MAX_PATH:
result['error'] = _('Destination path is too long for %s.') % obj_name
return HttpResponse(json.dumps(result), status=400,
content_type=content_type)
# check whether user has write permission to dest repo
if check_repo_access_permission(dst_repo_id, request.user) != 'rw':
result['error'] = _('Permission denied')
return HttpResponse(json.dumps(result), status=403,
content_type=content_type)
# when dst is the same as src
if repo_id == dst_repo_id and parent_dir == dst_path:
result['error'] = _('Invalid destination path')
return HttpResponse(json.dumps(result), status=400, content_type=content_type)
return func(repo_id, parent_dir, dst_repo_id, dst_path, obj_file_names, obj_dir_names, username)
示例2: get_upload_url
def get_upload_url(request, repo_id):
username = request.user.username
if check_repo_access_permission(repo_id, request.user) == "rw":
token = seafile_api.get_fileserver_access_token(repo_id, "dummy", "upload", username)
return gen_file_upload_url(token, "upload")
else:
return ""
示例3: get_file_content_by_commit_and_path
def get_file_content_by_commit_and_path(request, repo_id, commit_id, path, file_enc):
try:
obj_id = seafserv_threaded_rpc.get_file_id_by_commit_and_path( \
repo_id, commit_id, path)
except:
return None, 'bad path'
if not obj_id or obj_id == EMPTY_SHA1:
return '', None
else:
permission = check_repo_access_permission(repo_id, request.user)
if permission:
# Get a token to visit file
token = seafserv_rpc.web_get_access_token(repo_id,
obj_id,
'view',
request.user.username)
else:
return None, 'permission denied'
filename = os.path.basename(path)
inner_path = gen_inner_file_get_url(token, filename)
try:
err, file_content, encoding = repo_file_get(inner_path, file_enc)
except Exception, e:
return None, 'error when read file from fileserver: %s' % e
return file_content, err
示例4: check_group_folder_perm_args
def check_group_folder_perm_args(from_user, repo_id, path, group_id, perm = None):
if not seafile_api.get_repo(repo_id):
return {'error': _(u'Library does not exist.'), 'status': 400}
if check_repo_access_permission(repo_id, from_user) != 'rw':
return {'error': _('Permission denied'), 'status': 403}
if perm is not None:
# add or toggle folder perm
if seafile_api.get_dir_id_by_path(repo_id, path) is None:
return {'error': _('Invalid path'), 'status': 400}
if perm != 'r' and perm != 'rw':
return {'error': _('Invalid folder permission'), 'status': 400}
if not path.startswith('/'):
return {'error': _('Path should start with "/"'), 'status': 400}
if path != '/' and path.endswith('/'):
return {'error': _('Path should NOT ends with "/"'), 'status': 400}
if not seaserv.get_group(group_id):
return {'error': _('Invalid group'), 'status': 400}
return {'success': True}
示例5: check_user_folder_perm_args
def check_user_folder_perm_args(from_user, repo_id, path, to_user, perm=None):
if not seafile_api.get_repo(repo_id):
return {'error': _(u'Library does not exist.'), 'status': 400}
if check_repo_access_permission(repo_id, from_user) != 'rw':
return {'error': _('Permission denied'), 'status': 403}
if perm is not None:
# add or toggle folder perm
if seafile_api.get_dir_id_by_path(repo_id, path) is None:
return {'error': _('Invalid path'), 'status': 400}
if perm != 'r' and perm != 'rw':
return {'error': _('Invalid folder permission'), 'status': 400}
if not path.startswith('/'):
return {'error': _('Path should start with "/"'), 'status': 400}
if path != '/' and path.endswith('/'):
return {'error': _('Path should NOT ends with "/"'), 'status': 400}
try:
user = User.objects.get(email = to_user)
except User.DoesNotExist:
user = None
if user is None:
return {'error': _('Invalid username, should be a user already registered'), 'status': 400}
return {'success': True}
示例6: thumbnail_get
def thumbnail_get(request, repo_id, obj_id, size=THUMBNAIL_DEFAULT_SIZE):
# permission check
token = request.GET.get('t', None)
path = request.GET.get('p', None)
if token and path:
fileshare = FileShare.objects.get_valid_file_link_by_token(token)
if not fileshare or not path.startswith(fileshare.path) or \
fileshare.repo_id != repo_id:
# check if is valid download link share token and
# if is a valid repo/dir belonged to this file share
return HttpResponse()
else:
if not request.user.is_authenticated():
return HttpResponse()
elif check_repo_access_permission(repo_id, request.user) is None:
return HttpResponse()
thumbnail_file = os.path.join(THUMBNAIL_ROOT, size, obj_id)
with open(thumbnail_file, 'rb') as f:
file_content = f.read()
# Prepare response
content_type, content_encoding = mimetypes.guess_type(thumbnail_file)
response = HttpResponse(content=file_content, mimetype=content_type)
if content_encoding:
response['Content-Encoding'] = content_encoding
return response
示例7: get_upload_url
def get_upload_url(request, repo_id):
username = request.user.username
if check_repo_access_permission(repo_id, request.user) == 'rw':
token = seafile_api.get_fileserver_access_token(repo_id, 'dummy',
'upload', username)
return gen_file_upload_url(token, 'upload')
else:
return ''
示例8: repo_history_view
def repo_history_view(request, repo_id):
"""View repo in history.
"""
repo = get_repo(repo_id)
if not repo:
raise Http404
username = request.user.username
path = get_path_from_request(request)
user_perm = check_repo_access_permission(repo.id, request.user)
if user_perm is None:
return render_to_response("repo_access_deny.html", {"repo": repo}, context_instance=RequestContext(request))
try:
server_crypto = UserOptions.objects.is_server_crypto(username)
except CryptoOptionNotSetError:
# Assume server_crypto is ``False`` if this option is not set.
server_crypto = False
if (
repo.encrypted
and (repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto))
and not is_password_set(repo.id, username)
):
return render_to_response(
"decrypt_repo_form.html",
{
"repo": repo,
"next": get_next_url_from_request(request) or reverse("repo", args=[repo.id]),
"force_server_crypto": FORCE_SERVER_CRYPTO,
},
context_instance=RequestContext(request),
)
commit_id = request.GET.get("commit_id", None)
if commit_id is None:
return HttpResponseRedirect(reverse("repo", args=[repo.id]))
current_commit = get_commit(repo.id, repo.version, commit_id)
if not current_commit:
current_commit = get_commit(repo.id, repo.version, repo.head_cmmt_id)
file_list, dir_list = get_repo_dirents(request, repo, current_commit, path)
zipped = get_nav_path(path, repo.name)
return render_to_response(
"repo_history_view.html",
{
"repo": repo,
"user_perm": user_perm,
"current_commit": current_commit,
"dir_list": dir_list,
"file_list": file_list,
"path": path,
"zipped": zipped,
},
context_instance=RequestContext(request),
)
示例9: get_ajax_update_url
def get_ajax_update_url(request, repo_id):
"""Get file upload url for AJAX.
"""
username = request.user.username
if check_repo_access_permission(repo_id, request.user) == 'rw':
token = seafile_api.get_httpserver_access_token(repo_id, 'dummy',
'update', username)
return gen_file_upload_url(token, 'update-aj')
else:
return ''
示例10: download_file
def download_file(request, repo_id, obj_id):
"""Download file.
Arguments:
- `request`:
- `repo_id`:
- `obj_id`:
"""
username = request.user.username
repo = get_repo(repo_id)
if not repo:
raise Http404
if repo.encrypted and not seafile_api.is_password_set(repo_id, username):
return HttpResponseRedirect(reverse("repo", args=[repo_id]))
# If vistor's file shared token in url params matches the token in db,
# then we know the vistor is from file shared link.
share_token = request.GET.get("t", "")
fileshare = FileShare.objects.get(token=share_token) if share_token else None
shared_by = None
if fileshare:
from_shared_link = True
shared_by = fileshare.username
else:
from_shared_link = False
if from_shared_link:
# check whether owner's traffic over the limit
if user_traffic_over_limit(fileshare.username):
messages.error(request, _(u"Unable to access file: share link traffic is used up."))
next = request.META.get("HTTP_REFERER", settings.SITE_ROOT)
return HttpResponseRedirect(next)
# Permission check and generate download link
path = request.GET.get("p", "")
if (
check_repo_access_permission(repo_id, request.user)
or get_file_access_permission(repo_id, path, username)
or from_shared_link
):
# Get a token to access file
token = seafserv_rpc.web_get_access_token(repo_id, obj_id, "download", username)
else:
messages.error(request, _(u"Unable to download file"))
next = request.META.get("HTTP_REFERER", settings.SITE_ROOT)
return HttpResponseRedirect(next)
# send stats message
if from_shared_link:
try:
file_size = seafile_api.get_file_size(repo.store_id, repo.version, obj_id)
send_message("seahub.stats", "file-download\t%s\t%s\t%s\t%s" % (repo.id, shared_by, obj_id, file_size))
except Exception, e:
logger.error("Error when sending file-download message: %s" % str(e))
示例11: rename_dirent
def rename_dirent(request, repo_id):
"""
Rename a file/dir in a repo, with ajax
"""
if request.method != 'POST' or not request.is_ajax():
raise Http404
result = {}
username = request.user.username
content_type = 'application/json; charset=utf-8'
repo = get_repo(repo_id)
if not repo:
result['error'] = _(u'Library does not exist.')
return HttpResponse(json.dumps(result), status=400,
content_type=content_type)
# permission checking
if check_repo_access_permission(repo.id, request.user) != 'rw':
result['error'] = _('Permission denied')
return HttpResponse(json.dumps(result), status=403,
content_type=content_type)
# form validation
form = RepoRenameDirentForm(request.POST)
if form.is_valid():
oldname = form.cleaned_data["oldname"]
newname = form.cleaned_data["newname"]
else:
result['error'] = str(form.errors.values()[0])
return HttpResponse(json.dumps(result), status=400,
content_type=content_type)
if newname == oldname:
return HttpResponse(json.dumps({'success': True}),
content_type=content_type)
# argument checking
parent_dir = request.GET.get('parent_dir', None)
if not parent_dir:
result['error'] = _('Argument missing')
return HttpResponse(json.dumps(result), status=400,
content_type=content_type)
# rename duplicate name
newname = check_filename_with_rename(repo_id, parent_dir, newname)
# rename file/dir
try:
seafile_api.rename_file(repo_id, parent_dir, oldname, newname, username)
except SearpcError, e:
result['error'] = str(e)
return HttpResponse(json.dumps(result), status=500,
content_type=content_type)
示例12: get_blks_update_url
def get_blks_update_url(request, repo_id):
'''
Get update url for encrypted file (uploaded in blocks)
'''
username = request.user.username
if check_repo_access_permission(repo_id, request.user) == 'rw':
token = seafile_api.get_httpserver_access_token(repo_id, 'dummy',
'update-blks', username)
return gen_file_upload_url(token, 'update-blks-aj')
else:
return ''
示例13: repo_history_view
def repo_history_view(request, repo_id):
"""View repo in history.
"""
repo = get_repo(repo_id)
if not repo:
raise Http404
username = request.user.username
path = get_path_from_request(request)
user_perm = check_repo_access_permission(repo.id, request.user)
if user_perm is None:
return render_to_response('repo_access_deny.html', {
'repo': repo,
}, context_instance=RequestContext(request))
try:
server_crypto = UserOptions.objects.is_server_crypto(username)
except CryptoOptionNotSetError:
# Assume server_crypto is ``False`` if this option is not set.
server_crypto = False
if repo.encrypted and \
(repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto)) \
and not is_password_set(repo.id, username):
return render_to_response('decrypt_repo_form.html', {
'repo': repo,
'next': get_next_url_from_request(request) or \
reverse('repo', args=[repo.id]),
'force_server_crypto': FORCE_SERVER_CRYPTO,
}, context_instance=RequestContext(request))
commit_id = request.GET.get('commit_id', None)
if commit_id is None:
return HttpResponseRedirect(reverse('repo', args=[repo.id]))
current_commit = get_commit(repo.id, repo.version, commit_id)
if not current_commit:
current_commit = get_commit(repo.id, repo.version, repo.head_cmmt_id)
file_list, dir_list = get_repo_dirents(request, repo, current_commit, path)
zipped = get_nav_path(path, repo.name)
search_repo_id = None if repo.encrypted else repo.id
return render_to_response('repo_history_view.html', {
'repo': repo,
'user_perm': user_perm,
'current_commit': current_commit,
'dir_list': dir_list,
'file_list': file_list,
'path': path,
'zipped': zipped,
'search_repo_id': search_repo_id,
}, context_instance=RequestContext(request))
示例14: thumbnail_get
def thumbnail_get(request, repo_id, obj_id, size=THUMBNAIL_DEFAULT_SIZE):
permission = check_repo_access_permission(repo_id, request.user)
if permission is None:
raise Http404
thumbnail_file = os.path.join(THUMBNAIL_ROOT, size, obj_id)
try:
with open(thumbnail_file, 'rb') as f:
thumbnail = f.read()
f.close()
return HttpResponse(thumbnail, 'image/' + THUMBNAIL_EXTENSION)
except IOError:
return HttpResponse()
示例15: get_shared_upload_link
def get_shared_upload_link(request):
"""
Handle ajax request to generate dir upload link.
"""
content_type = 'application/json; charset=utf-8'
repo_id = request.GET.get('repo_id', '')
path = request.GET.get('p', '')
use_passwd = True if int(request.POST.get('use_passwd', '0')) == 1 else False
passwd = request.POST.get('passwd') if use_passwd else None
if not (repo_id and path):
err = _('Invalid arguments')
data = json.dumps({'error': err})
return HttpResponse(data, status=400, content_type=content_type)
if path == '/': # can not share root dir
err = _('You cannot share the library in this way.')
data = json.dumps({'error': err})
return HttpResponse(data, status=400, content_type=content_type)
else:
if path[-1] != '/': # append '/' at end of path
path += '/'
repo = seaserv.get_repo(repo_id)
user_perm = check_repo_access_permission(repo.id, request.user)
if user_perm == 'r':
messages.error(request, _(u'Permission denied'))
return HttpResponse(status=403, content_type=content_type)
elif user_perm == 'rw':
l = UploadLinkShare.objects.filter(repo_id=repo_id).filter(
username=request.user.username).filter(path=path)
if len(l) > 0:
upload_link = l[0]
token = upload_link.token
else:
username = request.user.username
uls = UploadLinkShare.objects.create_upload_link_share(
username, repo_id, path, passwd)
token = uls.token
shared_upload_link = gen_shared_upload_link(token)
data = json.dumps({'token': token, 'shared_upload_link': shared_upload_link})
return HttpResponse(data, status=200, content_type=content_type)
else:
messages.error(request, _(u'Operation failed'))
return HttpResponse(json.dumps(), status=500, content_type=content_type)