@@ -643,3 +643,40 @@ def _add_file_type_and_warns(node):
643643 return HttpResponse (json .dumps (allfiles ))
644644 else :
645645 return HttpResponse (st ('browsefiles.html' , ** locals ()))
646+
647+
648+ @csrf_exempt
649+ def codereview_delete (request , username , projectname , id ):
650+ from vilya .models .linecomment import PullLineComment
651+ comment = PullLineComment .get (id )
652+ if not comment :
653+ raise Http404 ("Unable to find comment %s" % id )
654+
655+ user = request .user
656+ if comment .author == user .name :
657+ ok = comment .delete ()
658+ if ok :
659+ return HttpResponse (json .dumps ({'r' : 1 })) # FIXME: 这里 r=1 表示成功,跟其他地方不统一
660+ return HttpResponse (json .dumps ({'r' : 0 }))
661+
662+
663+ @csrf_exempt
664+ def codereview_edit (request , username , projectname , id ):
665+ from vilya .models .linecomment import PullLineComment
666+ from vilya .models .project import CodeDoubanProject
667+ name = '/' .join ([username , projectname ])
668+ comment = PullLineComment .get (id )
669+ if not comment :
670+ raise Http404 ("Unable to find comment %s" % id )
671+
672+ user = request .user
673+ project = CodeDoubanProject .get_by_name (name )
674+ content = request .POST .get (
675+ 'pull_request_review_comment' , '' ).decode ('utf-8' )
676+ if comment .author == user .name :
677+ comment .update (content )
678+ linecomment = PullLineComment .get (comment .id )
679+ pullreq = True
680+ return HttpResponse (json .dumps (dict (
681+ r = 0 , html = st ('/pull/ticket_linecomment.html' , ** locals ()))))
682+ return HttpResponse (json .dumps (dict (r = 1 )))
0 commit comments