1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-09 10:50:24 +00:00

replace path with UUID (#2500)

This commit is contained in:
C_Q
2018-11-05 12:15:30 +08:00
committed by Daniel Pan
parent 1fd579fb44
commit 9987aa0ad9
5 changed files with 44 additions and 12 deletions

View File

@@ -95,7 +95,7 @@ class DraftReview extends React.Component {
msg_s = msg_s.replace('%(reviewID)s', reviewID); msg_s = msg_s.replace('%(reviewID)s', reviewID);
Toast.success(msg_s); Toast.success(msg_s);
}).catch(() => { }).catch(() => {
let msg_s = gettext('Failed to close review %(reviewID)s.') let msg_s = gettext('Failed to publish review %(reviewID)s.')
msg_s = msg_s.replace('%(reviewID)s', reviewID); msg_s = msg_s.replace('%(reviewID)s', reviewID);
Toast.error(msg_s); Toast.error(msg_s);
}); });

View File

@@ -1,5 +1,6 @@
# Copyright (c) 2012-2016 Seafile Ltd. # Copyright (c) 2012-2016 Seafile Ltd.
import os import os
import posixpath
from rest_framework import status from rest_framework import status
from rest_framework.authentication import SessionAuthentication from rest_framework.authentication import SessionAuthentication
@@ -106,12 +107,13 @@ class DraftReviewView(APIView):
return api_error(status.HTTP_409_CONFLICT, return api_error(status.HTTP_409_CONFLICT,
'There is a conflict between the draft and the original file') 'There is a conflict between the draft and the original file')
origin_file_path = r.origin_file_path uuid = r.origin_file_uuid
origin_file_path = posixpath.join(uuid.parent_path, uuid.filename)
# if it is a new draft # if it is a new draft
# case1. '/path/test(draft).md' ---> '/path/test.md' # case1. '/path/test(draft).md' ---> '/path/test.md'
# case2. '/path/test(dra.md' ---> '/path/test(dra.md' # case2. '/path/test(dra.md' ---> '/path/test(dra.md'
if d.draft_file_path == r.origin_file_path: if d.draft_file_path == origin_file_path:
new_draft_dir = os.path.dirname(origin_file_path) new_draft_dir = os.path.dirname(origin_file_path)
new_draft_name = os.path.basename(origin_file_path) new_draft_name = os.path.basename(origin_file_path)
@@ -129,7 +131,6 @@ class DraftReviewView(APIView):
origin_file_path = new_draft_dir + '/' + new_draft_name origin_file_path = new_draft_dir + '/' + new_draft_name
r.draft_file_path = origin_file_path r.draft_file_path = origin_file_path
r.origin_file_path = origin_file_path
# get draft published version # get draft published version
file_id = seafile_api.get_file_id_by_path(r.origin_repo_id, origin_file_path) file_id = seafile_api.get_file_id_by_path(r.origin_repo_id, origin_file_path)

View File

@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.15 on 2018-11-02 10:07
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('tags', '0001_initial'),
('drafts', '0003_reviewcomment'),
]
operations = [
migrations.RemoveField(
model_name='draftreview',
name='origin_file_path',
),
migrations.AddField(
model_name='draftreview',
name='origin_file_uuid',
field=models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, to='tags.FileUUIDMap'),
preserve_default=False,
),
]

View File

@@ -164,14 +164,11 @@ class DraftReviewManager(models.Manager):
if has_review: if has_review:
raise DraftReviewExist raise DraftReviewExist
uuid = draft.origin_file_uuid
file_path = posixpath.join(uuid.parent_path, uuid.filename)
draft_review = self.model(creator=creator, draft_review = self.model(creator=creator,
status='open', status='open',
draft_id=draft, draft_id=draft,
origin_repo_id=draft.origin_repo_id, origin_repo_id=draft.origin_repo_id,
origin_file_path=file_path, origin_file_uuid=draft.origin_file_uuid,
draft_file_path=draft.draft_file_path, draft_file_path=draft.draft_file_path,
origin_file_version=draft.origin_file_version) origin_file_version=draft.origin_file_version)
draft_review.save(using=self._db) draft_review.save(using=self._db)
@@ -183,7 +180,7 @@ class DraftReview(TimestampedModel):
creator = LowerCaseCharField(max_length=255, db_index=True) creator = LowerCaseCharField(max_length=255, db_index=True)
status = models.CharField(max_length=20) status = models.CharField(max_length=20)
origin_repo_id = models.CharField(max_length=36) origin_repo_id = models.CharField(max_length=36)
origin_file_path = models.CharField(max_length=1024) origin_file_uuid = models.ForeignKey(FileUUIDMap, on_delete=models.CASCADE)
draft_file_path = models.CharField(max_length=1024) draft_file_path = models.CharField(max_length=1024)
origin_file_version = models.CharField(max_length=100) origin_file_version = models.CharField(max_length=100)
publish_file_version = models.CharField(max_length=100, null=True) publish_file_version = models.CharField(max_length=100, null=True)
@@ -196,6 +193,9 @@ class DraftReview(TimestampedModel):
if not r_repo: if not r_repo:
raise DraftFileConflict raise DraftFileConflict
uuid = self.origin_file_uuid
file_path = posixpath.join(uuid.parent_path, uuid.filename)
return { return {
'id': self.pk, 'id': self.pk,
'creator': self.creator, 'creator': self.creator,
@@ -203,7 +203,7 @@ class DraftReview(TimestampedModel):
'creator_name': email2nickname(self.creator), 'creator_name': email2nickname(self.creator),
'draft_origin_repo_id': self.origin_repo_id, 'draft_origin_repo_id': self.origin_repo_id,
'draft_origin_repo_name': r_repo.name, 'draft_origin_repo_name': r_repo.name,
'draft_origin_file_path': self.origin_file_path, 'draft_origin_file_path': file_path,
'draft_origin_file_version': self.origin_file_version, 'draft_origin_file_version': self.origin_file_version,
'draft_publish_file_version': self.publish_file_version, 'draft_publish_file_version': self.publish_file_version,
'draft_file_path': self.draft_file_path, 'draft_file_path': self.draft_file_path,

View File

@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os import os
import posixpath
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
@@ -9,6 +10,7 @@ from seahub.views import check_folder_permission
from seahub.utils import render_permission_error from seahub.utils import render_permission_error
from seahub.drafts.models import Draft, DraftReview from seahub.drafts.models import Draft, DraftReview
@login_required @login_required
def drafts(request): def drafts(request):
return render(request, "react_app.html") return render(request, "react_app.html")
@@ -24,7 +26,9 @@ def review(request, pk):
d_r = get_object_or_404(DraftReview, pk=pk) d_r = get_object_or_404(DraftReview, pk=pk)
# check perm # check perm
file_path = d_r.origin_file_path uuid = d_r.origin_file_uuid
file_path = posixpath.join(uuid.parent_path, uuid.filename)
origin_repo_id = d_r.origin_repo_id origin_repo_id = d_r.origin_repo_id
if request.user.username: if request.user.username:
@@ -40,7 +44,7 @@ def review(request, pk):
"review_id": pk, "review_id": pk,
"draft_repo_id": d_r.origin_repo_id, "draft_repo_id": d_r.origin_repo_id,
"draft_origin_repo_id": d_r.origin_repo_id, "draft_origin_repo_id": d_r.origin_repo_id,
"draft_origin_file_path": d_r.origin_file_path, "draft_origin_file_path": file_path,
"draft_file_path": d_r.draft_file_path, "draft_file_path": d_r.draft_file_path,
"draft_file_name": draft_file_name, "draft_file_name": draft_file_name,
"origin_file_version": d_r.origin_file_version, "origin_file_version": d_r.origin_file_version,