mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-25 23:02:26 +00:00
Complete sub repo creation
This commit is contained in:
@@ -67,6 +67,7 @@ from seahub.utils import gen_file_get_url, gen_token, gen_file_upload_url, \
|
|||||||
gen_block_get_url, get_file_type_and_ext, HAS_FILE_SEARCH, \
|
gen_block_get_url, get_file_type_and_ext, HAS_FILE_SEARCH, \
|
||||||
gen_file_share_link, gen_dir_share_link, is_org_context, gen_shared_link, \
|
gen_file_share_link, gen_dir_share_link, is_org_context, gen_shared_link, \
|
||||||
get_org_user_events, calculate_repos_last_modify
|
get_org_user_events, calculate_repos_last_modify
|
||||||
|
from seahub.utils.repo import get_sub_repo_abbrev_origin_path
|
||||||
from seahub.utils.star import star_file, unstar_file
|
from seahub.utils.star import star_file, unstar_file
|
||||||
from seahub.utils.file_types import IMAGE, DOCUMENT
|
from seahub.utils.file_types import IMAGE, DOCUMENT
|
||||||
from seahub.utils.timeutils import utc_to_local
|
from seahub.utils.timeutils import utc_to_local
|
||||||
@@ -559,18 +560,11 @@ class Repos(APIView):
|
|||||||
repos_json.append(repo)
|
repos_json.append(repo)
|
||||||
|
|
||||||
if filter_by['sub']:
|
if filter_by['sub']:
|
||||||
def get_abbrev_origin_path(repo_name, path):
|
|
||||||
if len(path) > 20:
|
|
||||||
abbrev_path = path[-20:]
|
|
||||||
return repo_name + '/...' + abbrev_path
|
|
||||||
else:
|
|
||||||
return repo_name + path
|
|
||||||
|
|
||||||
# compose abbrev origin path for display
|
# compose abbrev origin path for display
|
||||||
sub_repos = []
|
sub_repos = []
|
||||||
sub_repos = get_virtual_repos_by_owner(request)
|
sub_repos = get_virtual_repos_by_owner(request)
|
||||||
for repo in sub_repos:
|
for repo in sub_repos:
|
||||||
repo.abbrev_origin_path = get_abbrev_origin_path(
|
repo.abbrev_origin_path = get_sub_repo_abbrev_origin_path(
|
||||||
repo.origin_repo_name, repo.origin_path)
|
repo.origin_repo_name, repo.origin_path)
|
||||||
|
|
||||||
sub_repos.sort(lambda x, y: cmp(y.last_modify, x.last_modify))
|
sub_repos.sort(lambda x, y: cmp(y.last_modify, x.last_modify))
|
||||||
|
@@ -74,3 +74,15 @@ def check_group_folder_perm_args(from_user, repo_id, path, group_id, perm = None
|
|||||||
|
|
||||||
return {'success': True}
|
return {'success': True}
|
||||||
|
|
||||||
|
def get_sub_repo_abbrev_origin_path(repo_name, origin_path):
|
||||||
|
"""Return abbrev path for sub repo based on `repo_name` and `origin_path`.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
- `repo_id`:
|
||||||
|
- `origin_path`:
|
||||||
|
"""
|
||||||
|
if len(origin_path) > 20:
|
||||||
|
abbrev_path = origin_path[-20:]
|
||||||
|
return repo_name + '/...' + abbrev_path
|
||||||
|
else:
|
||||||
|
return repo_name + origin_path
|
||||||
|
@@ -49,7 +49,7 @@ from seahub.utils import check_filename_with_rename, EMPTY_SHA1, \
|
|||||||
get_org_user_events, get_user_events, get_file_type_and_ext, \
|
get_org_user_events, get_user_events, get_file_type_and_ext, \
|
||||||
is_valid_username, send_perm_audit_msg
|
is_valid_username, send_perm_audit_msg
|
||||||
from seahub.utils.repo import check_group_folder_perm_args, \
|
from seahub.utils.repo import check_group_folder_perm_args, \
|
||||||
check_user_folder_perm_args
|
check_user_folder_perm_args, get_sub_repo_abbrev_origin_path
|
||||||
from seahub.utils.star import star_file, unstar_file
|
from seahub.utils.star import star_file, unstar_file
|
||||||
from seahub.base.accounts import User
|
from seahub.base.accounts import User
|
||||||
from seahub.thumbnail.utils import get_thumbnail_src, allow_generate_thumbnail
|
from seahub.thumbnail.utils import get_thumbnail_src, allow_generate_thumbnail
|
||||||
@@ -1255,17 +1255,35 @@ def sub_repo(request, repo_id):
|
|||||||
check if a dir has a corresponding sub_repo
|
check if a dir has a corresponding sub_repo
|
||||||
if it does not have, create one
|
if it does not have, create one
|
||||||
'''
|
'''
|
||||||
|
username = request.user.username
|
||||||
content_type = 'application/json; charset=utf-8'
|
content_type = 'application/json; charset=utf-8'
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
|
if not request.user.permissions.can_add_repo():
|
||||||
|
result['error'] = _(u"You do not have permission to create library")
|
||||||
|
return HttpResponse(json.dumps(result), status=403,
|
||||||
|
content_type=content_type)
|
||||||
|
|
||||||
|
origin_repo = seafile_api.get_repo(repo_id)
|
||||||
|
if origin_repo is None:
|
||||||
|
result['error'] = _('Repo not found.')
|
||||||
|
return HttpResponse(json.dumps(result), status=400,
|
||||||
|
content_type=content_type)
|
||||||
|
|
||||||
|
# perm check, only repo owner can create sub repo
|
||||||
|
repo_owner = seafile_api.get_repo_owner(origin_repo.id)
|
||||||
|
is_repo_owner = True if username == repo_owner else False
|
||||||
|
if not is_repo_owner:
|
||||||
|
result['error'] = _(u"You do not have permission to create library")
|
||||||
|
return HttpResponse(json.dumps(result), status=403,
|
||||||
|
content_type=content_type)
|
||||||
|
|
||||||
path = request.GET.get('p')
|
path = request.GET.get('p')
|
||||||
if not path:
|
if not path:
|
||||||
result['error'] = _('Argument missing')
|
result['error'] = _('Argument missing')
|
||||||
return HttpResponse(json.dumps(result), status=400, content_type=content_type)
|
return HttpResponse(json.dumps(result), status=400, content_type=content_type)
|
||||||
name = os.path.basename(path)
|
name = os.path.basename(path)
|
||||||
|
|
||||||
username = request.user.username
|
|
||||||
|
|
||||||
# check if the sub-lib exist
|
# check if the sub-lib exist
|
||||||
try:
|
try:
|
||||||
if is_org_context(request):
|
if is_org_context(request):
|
||||||
@@ -1275,7 +1293,8 @@ def sub_repo(request, repo_id):
|
|||||||
else:
|
else:
|
||||||
sub_repo = seafile_api.get_virtual_repo(repo_id, path, username)
|
sub_repo = seafile_api.get_virtual_repo(repo_id, path, username)
|
||||||
except SearpcError as e:
|
except SearpcError as e:
|
||||||
result['error'] = e.msg
|
logger.error(e)
|
||||||
|
result['error'] = _('Failed to create sub library, please try again later.')
|
||||||
return HttpResponse(json.dumps(result), status=500, content_type=content_type)
|
return HttpResponse(json.dumps(result), status=500, content_type=content_type)
|
||||||
|
|
||||||
if sub_repo:
|
if sub_repo:
|
||||||
@@ -1294,8 +1313,12 @@ def sub_repo(request, repo_id):
|
|||||||
username)
|
username)
|
||||||
result['sub_repo_id'] = sub_repo_id
|
result['sub_repo_id'] = sub_repo_id
|
||||||
result['name'] = name
|
result['name'] = name
|
||||||
except SearpcError, e:
|
result['abbrev_origin_path'] = get_sub_repo_abbrev_origin_path(
|
||||||
result['error'] = e.msg
|
origin_repo.name, path)
|
||||||
|
|
||||||
|
except SearpcError as e:
|
||||||
|
logger.error(e)
|
||||||
|
result['error'] = _('Failed to create sub library, please try again later.')
|
||||||
return HttpResponse(json.dumps(result), status=500, content_type=content_type)
|
return HttpResponse(json.dumps(result), status=500, content_type=content_type)
|
||||||
|
|
||||||
return HttpResponse(json.dumps(result), content_type=content_type)
|
return HttpResponse(json.dumps(result), content_type=content_type)
|
||||||
|
@@ -125,7 +125,7 @@ define([
|
|||||||
'name': data["name"],
|
'name': data["name"],
|
||||||
'origin_repo_id': ori_repo_id,
|
'origin_repo_id': ori_repo_id,
|
||||||
'origin_path': path,
|
'origin_path': path,
|
||||||
'abbrev_origin_path': '', // TODO
|
'abbrev_origin_path': data["abbrev_origin_path"],
|
||||||
'mtime': new Date().getTime() / 1000,
|
'mtime': new Date().getTime() / 1000,
|
||||||
'mtime_relative': gettext("Just now")
|
'mtime_relative': gettext("Just now")
|
||||||
}, {prepend: true});
|
}, {prepend: true});
|
||||||
|
Reference in New Issue
Block a user