mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-19 18:29:23 +00:00
Merge branch '7.0'
This commit is contained in:
@@ -79,7 +79,7 @@ class MainPanel extends Component {
|
|||||||
const errMessage = (<div className="message err-tip">{gettext('Folder does not exist.')}</div>);
|
const errMessage = (<div className="message err-tip">{gettext('Folder does not exist.')}</div>);
|
||||||
return (
|
return (
|
||||||
<div className="main-panel wiki-main-panel o-hidden">
|
<div className="main-panel wiki-main-panel o-hidden">
|
||||||
<div className="main-panel-north panel-top border-left-show">
|
<div className={`main-panel-north panel-top ${this.props.permission === 'rw' ? 'border-left-show' : ''}`}>
|
||||||
{!username &&
|
{!username &&
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<div className="cur-view-toolbar">
|
<div className="cur-view-toolbar">
|
||||||
|
@@ -142,6 +142,9 @@ ul,ol,li {
|
|||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
}
|
}
|
||||||
|
.cur-view-path .sf-heading {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.vh {
|
.vh {
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
|
@@ -3,9 +3,12 @@
|
|||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import posixpath
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
from seaserv import seafile_api
|
||||||
|
|
||||||
from seahub.base.fields import LowerCaseCharField
|
from seahub.base.fields import LowerCaseCharField
|
||||||
from seahub.utils import normalize_file_path,normalize_dir_path
|
from seahub.utils import normalize_file_path,normalize_dir_path
|
||||||
|
|
||||||
@@ -29,6 +32,7 @@ class FileUUIDMapManager(models.Manager):
|
|||||||
return:
|
return:
|
||||||
uuid of filemap
|
uuid of filemap
|
||||||
"""
|
"""
|
||||||
|
repo_id, parent_path = self.model.get_origin_repo_id_and_parent_path(repo_id, parent_path)
|
||||||
uuid = self.get_fileuuidmap_by_path(repo_id, parent_path, filename, is_dir)
|
uuid = self.get_fileuuidmap_by_path(repo_id, parent_path, filename, is_dir)
|
||||||
if not uuid:
|
if not uuid:
|
||||||
uuid = self.model(repo_id=repo_id, parent_path=parent_path,
|
uuid = self.model(repo_id=repo_id, parent_path=parent_path,
|
||||||
@@ -46,6 +50,7 @@ class FileUUIDMapManager(models.Manager):
|
|||||||
return:
|
return:
|
||||||
return uuid if it's exist,otherwise return None
|
return uuid if it's exist,otherwise return None
|
||||||
"""
|
"""
|
||||||
|
repo_id, parent_path = self.model.get_origin_repo_id_and_parent_path(repo_id, parent_path)
|
||||||
md5_repo_id_parent_path = self.model.md5_repo_id_parent_path(repo_id, parent_path)
|
md5_repo_id_parent_path = self.model.md5_repo_id_parent_path(repo_id, parent_path)
|
||||||
uuid = super(FileUUIDMapManager, self).filter(
|
uuid = super(FileUUIDMapManager, self).filter(
|
||||||
repo_id_parent_path_md5=md5_repo_id_parent_path,
|
repo_id_parent_path_md5=md5_repo_id_parent_path,
|
||||||
@@ -57,6 +62,7 @@ class FileUUIDMapManager(models.Manager):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def get_fileuuidmaps_by_parent_path(self, repo_id, parent_path):
|
def get_fileuuidmaps_by_parent_path(self, repo_id, parent_path):
|
||||||
|
repo_id, parent_path = self.model.get_origin_repo_id_and_parent_path(repo_id, parent_path)
|
||||||
parent_path = FileUUIDMap.normalize_path(parent_path)
|
parent_path = FileUUIDMap.normalize_path(parent_path)
|
||||||
uuids = super(FileUUIDMapManager, self).filter(
|
uuids = super(FileUUIDMapManager, self).filter(
|
||||||
repo_id=repo_id, parent_path=parent_path
|
repo_id=repo_id, parent_path=parent_path
|
||||||
@@ -196,6 +202,14 @@ class FileUUIDMap(models.Model):
|
|||||||
def normalize_path(self, path):
|
def normalize_path(self, path):
|
||||||
return path.rstrip('/') if path != '/' else '/'
|
return path.rstrip('/') if path != '/' else '/'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_origin_repo_id_and_parent_path(cls, repo_id, parent_path):
|
||||||
|
repo = seafile_api.get_repo(repo_id)
|
||||||
|
if repo.is_virtual:
|
||||||
|
repo_id = repo.origin_repo_id
|
||||||
|
parent_path = posixpath.join(repo.origin_path, parent_path.strip('/'))
|
||||||
|
return repo_id, parent_path
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.parent_path = self.normalize_path(self.parent_path)
|
self.parent_path = self.normalize_path(self.parent_path)
|
||||||
if not self.repo_id_parent_path_md5:
|
if not self.repo_id_parent_path_md5:
|
||||||
|
@@ -6,10 +6,17 @@ from seahub.tags.models import FileUUIDMap
|
|||||||
|
|
||||||
|
|
||||||
class FileCommentManagerTest(BaseTestCase):
|
class FileCommentManagerTest(BaseTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.repo_id = self.repo.id
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.remove_repo()
|
||||||
|
|
||||||
def test_can_add(self):
|
def test_can_add(self):
|
||||||
assert len(FileComment.objects.all()) == 0
|
assert len(FileComment.objects.all()) == 0
|
||||||
|
|
||||||
o = FileComment.objects.add(repo_id='xxx', parent_path='/foo/bar',
|
o = FileComment.objects.add(repo_id=self.repo_id, parent_path='/foo/bar',
|
||||||
item_name='test.txt',
|
item_name='test.txt',
|
||||||
author=self.user.username,
|
author=self.user.username,
|
||||||
comment='test comment')
|
comment='test comment')
|
||||||
@@ -20,49 +27,56 @@ class FileCommentManagerTest(BaseTestCase):
|
|||||||
assert len(FileComment.objects.all()) == 0
|
assert len(FileComment.objects.all()) == 0
|
||||||
|
|
||||||
o = FileComment.objects.add_by_file_path(
|
o = FileComment.objects.add_by_file_path(
|
||||||
repo_id='xxx', file_path='/foo/bar/test.txt',
|
repo_id=self.repo_id, file_path='/foo/bar/test.txt',
|
||||||
author=self.user.username, comment='test comment')
|
author=self.user.username, comment='test comment')
|
||||||
|
|
||||||
assert o.uuid.parent_path == '/foo/bar'
|
assert o.uuid.parent_path == '/foo/bar'
|
||||||
assert len(FileComment.objects.all()) == 1
|
assert len(FileComment.objects.all()) == 1
|
||||||
|
|
||||||
def test_get_by_file_path(self):
|
def test_get_by_file_path(self):
|
||||||
o1 = FileComment.objects.add(repo_id='xxx', parent_path='/foo/bar/',
|
o1 = FileComment.objects.add(repo_id=self.repo_id, parent_path='/foo/bar/',
|
||||||
item_name='test.txt',
|
item_name='test.txt',
|
||||||
author=self.user.username,
|
author=self.user.username,
|
||||||
comment='test comment 1')
|
comment='test comment 1')
|
||||||
o2 = FileComment.objects.add(repo_id='xxx', parent_path='/foo/bar',
|
o2 = FileComment.objects.add(repo_id=self.repo_id, parent_path='/foo/bar',
|
||||||
item_name='test.txt',
|
item_name='test.txt',
|
||||||
author=self.user.username,
|
author=self.user.username,
|
||||||
comment='test comment 2')
|
comment='test comment 2')
|
||||||
assert len(FileComment.objects.get_by_file_path('xxx', '/foo/bar/test.txt')) == 2
|
assert len(FileComment.objects.get_by_file_path(self.repo_id, '/foo/bar/test.txt')) == 2
|
||||||
|
|
||||||
def test_get_by_parent_path(self):
|
def test_get_by_parent_path(self):
|
||||||
o1 = FileComment.objects.add(repo_id='xxx', parent_path='/foo/bar/',
|
o1 = FileComment.objects.add(repo_id=self.repo_id, parent_path='/foo/bar/',
|
||||||
item_name='test1.txt',
|
item_name='test1.txt',
|
||||||
author=self.user.username,
|
author=self.user.username,
|
||||||
comment='comment 1')
|
comment='comment 1')
|
||||||
o2 = FileComment.objects.add(repo_id='xxx', parent_path='/foo/bar',
|
o2 = FileComment.objects.add(repo_id=self.repo_id, parent_path='/foo/bar',
|
||||||
item_name='test2.txt',
|
item_name='test2.txt',
|
||||||
author=self.user.username,
|
author=self.user.username,
|
||||||
comment='comment 2')
|
comment='comment 2')
|
||||||
assert len(FileComment.objects.get_by_parent_path('xxx', '/foo/bar/')) == 2
|
assert len(FileComment.objects.get_by_parent_path(self.repo_id, '/foo/bar/')) == 2
|
||||||
assert len(FileComment.objects.get_by_parent_path('xxx', '/foo/bar')) == 2
|
assert len(FileComment.objects.get_by_parent_path(self.repo_id, '/foo/bar')) == 2
|
||||||
|
|
||||||
|
|
||||||
class FileCommentTest(BaseTestCase):
|
class FileCommentTest(BaseTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.repo_id = self.repo.id
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.remove_repo()
|
||||||
|
|
||||||
def test_md5_repo_id_parent_path(self):
|
def test_md5_repo_id_parent_path(self):
|
||||||
md5 = FileUUIDMap.md5_repo_id_parent_path('xxx', '/')
|
md5 = FileUUIDMap.md5_repo_id_parent_path(self.repo_id, '/')
|
||||||
assert md5 == hashlib.md5('xxx' + '/').hexdigest()
|
assert md5 == hashlib.md5(self.repo_id + '/').hexdigest()
|
||||||
|
|
||||||
md5 = FileUUIDMap.md5_repo_id_parent_path('xxx', '/foo')
|
md5 = FileUUIDMap.md5_repo_id_parent_path(self.repo_id, '/foo')
|
||||||
assert md5 == hashlib.md5('xxx' + '/foo').hexdigest()
|
assert md5 == hashlib.md5(self.repo_id + '/foo').hexdigest()
|
||||||
|
|
||||||
md5 = FileUUIDMap.md5_repo_id_parent_path('xxx', '/foo/')
|
md5 = FileUUIDMap.md5_repo_id_parent_path(self.repo_id, '/foo/')
|
||||||
assert md5 == hashlib.md5('xxx' + '/foo').hexdigest()
|
assert md5 == hashlib.md5(self.repo_id + '/foo').hexdigest()
|
||||||
|
|
||||||
def test_normalize_path(self):
|
def test_normalize_path(self):
|
||||||
o = FileComment.objects.add(repo_id='xxx', parent_path='/foo/bar/',
|
o = FileComment.objects.add(repo_id=self.repo_id, parent_path='/foo/bar/',
|
||||||
item_name='test.txt',
|
item_name='test.txt',
|
||||||
author=self.user.username,
|
author=self.user.username,
|
||||||
comment='test comment')
|
comment='test comment')
|
||||||
@@ -70,7 +84,7 @@ class FileCommentTest(BaseTestCase):
|
|||||||
|
|
||||||
def test_can_save(self):
|
def test_can_save(self):
|
||||||
assert len(FileComment.objects.all()) == 0
|
assert len(FileComment.objects.all()) == 0
|
||||||
uuid = FileUUIDMap.objects.get_or_create_fileuuidmap('xxx', '/foo/bar/', 'test.txt', False)
|
uuid = FileUUIDMap.objects.get_or_create_fileuuidmap(self.repo_id, '/foo/bar/', 'test.txt', False)
|
||||||
FileComment(uuid=uuid, author=self.user.username,
|
FileComment(uuid=uuid, author=self.user.username,
|
||||||
comment='test comment').save()
|
comment='test comment').save()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user