mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-25 14:50:29 +00:00
comment-detail
This commit is contained in:
@@ -69,14 +69,15 @@ class FileCommentView(APIView):
|
|||||||
"""Update a comment, only comment author or repo owner can perform
|
"""Update a comment, only comment author or repo owner can perform
|
||||||
this op
|
this op
|
||||||
1.Change resolved of comment
|
1.Change resolved of comment
|
||||||
|
2.Add comment_detail
|
||||||
"""
|
"""
|
||||||
# argument check
|
# argument check
|
||||||
resolved = request.data.get('resolved')
|
resolved = request.data.get('resolved')
|
||||||
if resolved not in ('true', 'false'):
|
if resolved not in ('true', 'false', None):
|
||||||
error_msg = 'resolved invalid.'
|
error_msg = 'resolved invalid.'
|
||||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||||
|
|
||||||
comment_resolved = to_python_boolean(resolved)
|
detail = request.data.get('detail')
|
||||||
|
|
||||||
# resource check
|
# resource check
|
||||||
try:
|
try:
|
||||||
@@ -91,6 +92,8 @@ class FileCommentView(APIView):
|
|||||||
error_msg = 'Permission denied.'
|
error_msg = 'Permission denied.'
|
||||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||||
|
|
||||||
|
if resolved is not None:
|
||||||
|
comment_resolved = to_python_boolean(resolved)
|
||||||
try:
|
try:
|
||||||
file_comment.resolved = comment_resolved
|
file_comment.resolved = comment_resolved
|
||||||
file_comment.save()
|
file_comment.save()
|
||||||
@@ -98,6 +101,14 @@ class FileCommentView(APIView):
|
|||||||
logger.error(e)
|
logger.error(e)
|
||||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, 'Internal error.')
|
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, 'Internal error.')
|
||||||
|
|
||||||
|
if detail is not None:
|
||||||
|
try:
|
||||||
|
file_comment.detail = detail
|
||||||
|
file_comment.save()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(e)
|
||||||
|
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, 'Internal error.')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
avatar_size = int(request.GET.get('avatar_size', AVATAR_DEFAULT_SIZE))
|
avatar_size = int(request.GET.get('avatar_size', AVATAR_DEFAULT_SIZE))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@@ -20,6 +20,7 @@ from seahub.base.models import FileComment
|
|||||||
from seahub.utils.repo import get_repo_owner
|
from seahub.utils.repo import get_repo_owner
|
||||||
from seahub.signals import comment_file_successful
|
from seahub.signals import comment_file_successful
|
||||||
from seahub.api2.endpoints.utils import generate_links_header_for_paginator
|
from seahub.api2.endpoints.utils import generate_links_header_for_paginator
|
||||||
|
from seahub.views import check_folder_permission
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -41,6 +42,10 @@ class FileCommentsView(APIView):
|
|||||||
error_msg = 'resolved invalid.'
|
error_msg = 'resolved invalid.'
|
||||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||||
|
|
||||||
|
# permission check
|
||||||
|
if check_folder_permission(request, repo_id, '/') is None:
|
||||||
|
return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied.')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
avatar_size = int(request.GET.get('avatar_size',
|
avatar_size = int(request.GET.get('avatar_size',
|
||||||
AVATAR_DEFAULT_SIZE))
|
AVATAR_DEFAULT_SIZE))
|
||||||
@@ -79,33 +84,39 @@ class FileCommentsView(APIView):
|
|||||||
def post(self, request, repo_id, format=None):
|
def post(self, request, repo_id, format=None):
|
||||||
"""Post a comments of a file.
|
"""Post a comments of a file.
|
||||||
"""
|
"""
|
||||||
|
# argument check
|
||||||
path = request.GET.get('p', '/').rstrip('/')
|
path = request.GET.get('p', '/').rstrip('/')
|
||||||
if not path:
|
if not path:
|
||||||
return api_error(status.HTTP_400_BAD_REQUEST, 'Wrong path.')
|
return api_error(status.HTTP_400_BAD_REQUEST, 'Wrong path.')
|
||||||
|
|
||||||
|
comment = request.data.get('comment', '')
|
||||||
|
if not comment:
|
||||||
|
return api_error(status.HTTP_400_BAD_REQUEST, 'Comment can not be empty.')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
avatar_size = int(request.GET.get('avatar_size',
|
avatar_size = int(request.GET.get('avatar_size',
|
||||||
AVATAR_DEFAULT_SIZE))
|
AVATAR_DEFAULT_SIZE))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
avatar_size = AVATAR_DEFAULT_SIZE
|
avatar_size = AVATAR_DEFAULT_SIZE
|
||||||
|
|
||||||
|
# resource check
|
||||||
try:
|
try:
|
||||||
obj_id = seafile_api.get_file_id_by_path(repo_id,
|
file_id = seafile_api.get_file_id_by_path(repo_id, path)
|
||||||
path)
|
|
||||||
except SearpcError as e:
|
except SearpcError as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR,
|
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
'Internal error.')
|
'Internal error.')
|
||||||
if not obj_id:
|
if not file_id:
|
||||||
return api_error(status.HTTP_404_NOT_FOUND, 'File not found.')
|
return api_error(status.HTTP_404_NOT_FOUND, 'File not found.')
|
||||||
|
|
||||||
comment = request.data.get('comment', '')
|
# permission check
|
||||||
if not comment:
|
if check_folder_permission(request, repo_id, '/') is None:
|
||||||
return api_error(status.HTTP_400_BAD_REQUEST, 'Comment can not be empty.')
|
return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied.')
|
||||||
|
|
||||||
|
detail = request.data.get('detail', '')
|
||||||
username = request.user.username
|
username = request.user.username
|
||||||
o = FileComment.objects.add_by_file_path(
|
file_comment = FileComment.objects.add_by_file_path(
|
||||||
repo_id=repo_id, file_path=path, author=username, comment=comment)
|
repo_id=repo_id, file_path=path, author=username, comment=comment, detail=detail)
|
||||||
repo = seafile_api.get_repo(repo_id)
|
repo = seafile_api.get_repo(repo_id)
|
||||||
repo_owner = get_repo_owner(request, repo.id)
|
repo_owner = get_repo_owner(request, repo.id)
|
||||||
comment_file_successful.send(sender=None,
|
comment_file_successful.send(sender=None,
|
||||||
@@ -115,7 +126,6 @@ class FileCommentsView(APIView):
|
|||||||
comment=comment,
|
comment=comment,
|
||||||
author=username)
|
author=username)
|
||||||
|
|
||||||
comment = o.to_dict()
|
comment = file_comment.to_dict()
|
||||||
comment.update(user_to_dict(request.user.username, request=request,
|
comment.update(user_to_dict(username, request=request, avatar_size=avatar_size))
|
||||||
avatar_size=avatar_size))
|
|
||||||
return Response(comment, status=201)
|
return Response(comment, status=201)
|
||||||
|
@@ -55,21 +55,21 @@ class FileDiscuss(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
class FileCommentManager(models.Manager):
|
class FileCommentManager(models.Manager):
|
||||||
def add(self, repo_id, parent_path, item_name, author, comment):
|
def add(self, repo_id, parent_path, item_name, author, comment, detail):
|
||||||
fileuuidmap = FileUUIDMap.objects.get_or_create_fileuuidmap(repo_id,
|
fileuuidmap = FileUUIDMap.objects.get_or_create_fileuuidmap(repo_id,
|
||||||
parent_path,
|
parent_path,
|
||||||
item_name,
|
item_name,
|
||||||
False)
|
False)
|
||||||
c = self.model(uuid=fileuuidmap, author=author, comment=comment)
|
c = self.model(uuid=fileuuidmap, author=author, comment=comment, detail=detail)
|
||||||
c.save(using=self._db)
|
c.save(using=self._db)
|
||||||
return c
|
return c
|
||||||
|
|
||||||
def add_by_file_path(self, repo_id, file_path, author, comment):
|
def add_by_file_path(self, repo_id, file_path, author, comment, detail):
|
||||||
file_path = self.model.normalize_path(file_path)
|
file_path = self.model.normalize_path(file_path)
|
||||||
parent_path = os.path.dirname(file_path)
|
parent_path = os.path.dirname(file_path)
|
||||||
item_name = os.path.basename(file_path)
|
item_name = os.path.basename(file_path)
|
||||||
|
|
||||||
return self.add(repo_id, parent_path, item_name, author, comment)
|
return self.add(repo_id, parent_path, item_name, author, comment, detail)
|
||||||
|
|
||||||
def get_by_file_path(self, repo_id, file_path):
|
def get_by_file_path(self, repo_id, file_path):
|
||||||
parent_path = os.path.dirname(file_path)
|
parent_path = os.path.dirname(file_path)
|
||||||
@@ -100,6 +100,7 @@ class FileComment(models.Model):
|
|||||||
updated_at = models.DateTimeField(default=timezone.now)
|
updated_at = models.DateTimeField(default=timezone.now)
|
||||||
objects = FileCommentManager()
|
objects = FileCommentManager()
|
||||||
resolved = models.BooleanField(default=False)
|
resolved = models.BooleanField(default=False)
|
||||||
|
detail = models.TextField()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def normalize_path(self, path):
|
def normalize_path(self, path):
|
||||||
@@ -115,6 +116,7 @@ class FileComment(models.Model):
|
|||||||
'comment': o.comment,
|
'comment': o.comment,
|
||||||
'created_at': datetime_to_isoformat_timestr(o.created_at),
|
'created_at': datetime_to_isoformat_timestr(o.created_at),
|
||||||
'resolved': o.resolved,
|
'resolved': o.resolved,
|
||||||
|
'detail': o.detail,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user