本文整理汇总了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函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:Pablohn26,项目名称:seahub,代码行数:52,代码来源:ajax.py
示例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 ""
开发者ID:vikingliu,项目名称:seahub,代码行数:7,代码来源:repo.py
示例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
开发者ID:bits4beats,项目名称:seahub,代码行数:28,代码来源:file.py
示例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}
开发者ID:biddyweb,项目名称:seahub,代码行数:25,代码来源:repo.py
示例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}
开发者ID:biddyweb,项目名称:seahub,代码行数:30,代码来源:repo.py
示例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
开发者ID:joshbmarshall,项目名称:seahub,代码行数:27,代码来源:views.py
示例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 ''
开发者ID:bits4beats,项目名称:seahub,代码行数:8,代码来源:repo.py
示例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),
)
开发者ID:vikingliu,项目名称:seahub,代码行数:57,代码来源:repo.py
示例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 ''
开发者ID:chu888chu888,项目名称:Seafile-seahub,代码行数:10,代码来源:repo.py
示例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))
开发者ID:vikingliu,项目名称:seahub,代码行数:55,代码来源:file.py
示例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)
开发者ID:Pablohn26,项目名称:seahub,代码行数:54,代码来源:ajax.py
示例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 ''
开发者ID:chu888chu888,项目名称:Seafile-seahub,代码行数:11,代码来源:repo.py
示例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))
开发者ID:rutsky,项目名称:seahub,代码行数:52,代码来源:repo.py
示例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()
开发者ID:ggkitsas,项目名称:seahub,代码行数:14,代码来源:views.py
示例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)
开发者ID:allo-,项目名称:seahub,代码行数:49,代码来源:views.py
示例16: get_current_commit
def get_current_commit(request, repo_id):
if not request.is_ajax():
raise Http404
content_type = 'application/json; charset=utf-8'
repo = get_repo(repo_id)
if not repo:
err_msg = _(u'Library does not exist.')
return HttpResponse(json.dumps({'error': err_msg}),
status=400, content_type=content_type)
username = request.user.username
user_perm = check_repo_access_permission(repo.id, request.user)
if user_perm is None:
err_msg = _(u'Permission denied.')
return HttpResponse(json.dumps({'error': err_msg}),
status=403, content_type=content_type)
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 seafile_api.is_password_set(repo.id, username):
err_msg = _(u'Library is encrypted.')
return HttpResponse(json.dumps({'error': err_msg}),
status=403, content_type=content_type)
head_commit = get_commit(repo.head_cmmt_id)
if not head_commit:
err_msg = _(u'Error: no head commit id')
return HttpResponse(json.dumps({'error': err_msg}),
status=500, content_type=content_type)
if new_merge_with_no_conflict(head_commit):
head_commit = get_commit_before_new_merge(head_commit)
ctx = {
'repo': repo,
'current_commit': head_commit
}
html = render_to_string('snippets/current_commit.html', ctx,
context_instance=RequestContext(request))
return HttpResponse(json.dumps({'html': html}),
content_type=content_type)
开发者ID:Pablohn26,项目名称:seahub,代码行数:48,代码来源:ajax.py
示例17: get_dirents
def get_dirents(request, repo_id):
"""
Get dirents in a dir for file tree
"""
if not request.is_ajax():
raise Http404
content_type = 'application/json; charset=utf-8'
username = request.user.username
# permission checking
user_perm = check_repo_access_permission(repo_id, request.user)
if user_perm is None:
err_msg = _(u"You don't have permission to access the library.")
return HttpResponse(json.dumps({"err_msg": err_msg}), status=403,
content_type=content_type)
path = request.GET.get('path', '')
dir_only = request.GET.get('dir_only', False)
all_dir = request.GET.get('all_dir', False)
if not path:
err_msg = _(u"No path.")
return HttpResponse(json.dumps({"err_msg": err_msg}), status=400,
content_type=content_type)
# get dirents for every path element
if all_dir:
all_dirents = []
path_eles = path.split('/')[:-1]
for i, x in enumerate(path_eles):
ele_path = '/'.join(path_eles[:i+1]) + '/'
try:
ele_path_dirents = seafile_api.list_dir_by_path(repo_id, ele_path.encode('utf-8'))
except SearpcError, e:
ele_path_dirents = []
ds = []
for d in ele_path_dirents:
if stat.S_ISDIR(d.mode):
ds.append(d.obj_name)
all_dirents.append(ds)
return HttpResponse(json.dumps(all_dirents), content_type=content_type)
开发者ID:Pablohn26,项目名称:seahub,代码行数:42,代码来源:ajax.py
示例18: get_file_view_path_and_perm
def get_file_view_path_and_perm(request, repo_id, obj_id, path):
""" Get path and the permission to view file.
Returns:
outer fileserver file url, inner fileserver file url, permission
"""
username = request.user.username
filename = os.path.basename(path)
# user_perm = get_file_access_permission(repo_id, path, username) or \
# get_repo_access_permission(repo_id, username)
user_perm = check_repo_access_permission(repo_id, request.user)
if user_perm is None:
return ('', '', user_perm)
else:
# Get a token to visit file
token = web_get_access_token(repo_id, obj_id, 'view', username)
outer_url = gen_file_get_url(token, filename)
inner_url = gen_inner_file_get_url(token, filename)
return (outer_url, inner_url, user_perm)
开发者ID:bits4beats,项目名称:seahub,代码行数:20,代码来源:file.py
示例19: delete_dirent
def delete_dirent(request, repo_id):
"""
Delete a file/dir with ajax.
"""
if not request.is_ajax():
raise Http404
content_type = 'application/json; charset=utf-8'
repo = get_repo(repo_id)
if not repo:
err_msg = _(u'Library does not exist.')
return HttpResponse(json.dumps({'error': err_msg}),
status=400, content_type=content_type)
# permission checking
username = request.user.username
if check_repo_access_permission(repo.id, request.user) != 'rw':
err_msg = _(u'Permission denied.')
return HttpResponse(json.dumps({'error': err_msg}),
status=403, content_type=content_type)
# argument checking
parent_dir = request.GET.get("parent_dir", None)
dirent_name = request.GET.get("name", None)
if not (parent_dir and dirent_name):
err_msg = _(u'Argument missing.')
return HttpResponse(json.dumps({'error': err_msg}),
status=400, content_type=content_type)
# delete file/dir
try:
seafile_api.del_file(repo_id, parent_dir, dirent_name, username)
return HttpResponse(json.dumps({'success': True}),
content_type=content_type)
except SearpcError, e:
logger.error(e)
err_msg = _(u'Internal error. Failed to delete %s.') % dirent_name
return HttpResponse(json.dumps({'error': err_msg}),
status=500, content_type=content_type)
开发者ID:Pablohn26,项目名称:seahub,代码行数:40,代码来源:ajax.py
示例20: delete_dirents
def delete_dirents(request, repo_id):
"""
Delete multi files/dirs with ajax.
"""
if not request.is_ajax():
raise Http404
content_type = 'application/json; charset=utf-8'
repo = get_repo(repo_id)
if not repo:
err_msg = _(u'Library does not exist.')
return HttpResponse(json.dumps({'error': err_msg}),
status=400, content_type=content_type)
# permission checking
username = request.user.username
if check_repo_access_permission(repo.id, request.user) != 'rw':
err_msg = _(u'Permission denied.')
return HttpResponse(json.dumps({'error': err_msg}),
status=403, content_type=content_type)
# argument checking
parent_dir = request.GET.get("parent_dir")
dirents_names = request.POST.getlist('dirents_names')
if not (parent_dir and dirents_names):
err_msg = _(u'Argument missing.')
return HttpResponse(json.dumps({'error': err_msg}),
status=400, content_type=content_type)
deleted = []
undeleted = []
for dirent_name in dirents_names:
try:
seafile_api.del_file(repo_id, parent_dir, dirent_name, username)
deleted.append(dirent_name)
except SearpcError, e:
logger.error(e)
undeleted.append(dirent_name)
开发者ID:Pablohn26,项目名称:seahub,代码行数:39,代码来源:ajax.py
注:本文中的seahub.views.check_repo_access_permission函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论