[PATCH 5 of 8 v2] changeset controller: draft comment on changesets, backend code

Jan Heylen heyleke at gmail.com
Sat May 16 08:02:30 EDT 2015


# HG changeset patch
# User Jan Heylen <heyleke at gmail.com>
# Date 1430766152 -7200
#      Mon May 04 21:02:32 2015 +0200
# Node ID 5e62c263fe2dbd6a46a6cd21e22b26bbf387e997
# Parent  fa1872a9f955ac81cdd7a3bc3516ad05f1263400
changeset controller: draft comment on changesets, backend code

diff -r fa1872a9f955 -r 5e62c263fe2d kallithea/controllers/changeset.py
--- a/kallithea/controllers/changeset.py	Thu May 07 17:25:27 2015 +0200
+++ b/kallithea/controllers/changeset.py	Mon May 04 21:02:32 2015 +0200
@@ -222,11 +222,13 @@
         comments = dict()
         c.statuses = []
         c.inline_comments = []
+        c.drafts = []
         c.inline_cnt = 0
 
         # Iterate over ranges (default changeset view is always one changeset)
         for changeset in c.cs_ranges:
             inlines = []
+            drafts = []
             if method == 'show':
                 c.statuses.extend([ChangesetStatusModel().get_status(
                             c.db_repo.repo_id, changeset.raw_id)])
@@ -247,6 +249,11 @@
                             .get_inline_comments(c.db_repo.repo_id,
                                                  revision=changeset.raw_id)
                 c.inline_comments.extend(inlines)
+                drafts = ChangesetCommentsModel()\
+                            .get_inline_drafts(c.db_repo.repo_id,
+                                                 revision=changeset.raw_id,
+                                                 user_id=c.authuser.user_id)
+                c.drafts.extend(drafts)
 
             c.changes[changeset.raw_id] = []
 
@@ -347,6 +354,39 @@
     @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
                                    'repository.admin')
     @jsonify
+    def draft(self, repo_name, revision=None, pull_request_id=None):
+        draft_text = request.POST.get('text', '').strip() or _('No comments.')
+        c.comment = comment = ChangesetCommentsModel().create(
+            text=draft_text,
+            repo=c.db_repo.repo_id,
+            user=c.authuser.user_id,
+            revision=revision,
+            pull_request=pull_request_id,
+            f_path=request.POST.get('f_path'),
+            line_no=request.POST.get('line'),
+            status_change=None,
+            draft=True
+        )
+
+        Session().commit()
+
+        #only ajax below
+        data = {
+           'target_id': h.safeid(h.safe_unicode(request.POST.get('f_path'))),
+        }
+        if comment:
+            data.update(comment.get_dict())
+            data.update({'rendered_text':
+                         render('changeset/changeset_comment_block.html')})
+
+        return data
+
+
+    @LoginRequired()
+    @NotAnonymous()
+    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
+                                   'repository.admin')
+    @jsonify
     def comment(self, repo_name, revision):
         status = request.POST.get('changeset_status')
         text = request.POST.get('text', '').strip()
@@ -359,7 +399,8 @@
             f_path=request.POST.get('f_path'),
             line_no=request.POST.get('line'),
             status_change=(ChangesetStatus.get_status_lbl(status)
-                           if status else None)
+                           if status else None),
+            draft=True
         )
 
         # get status if set !
@@ -384,6 +425,9 @@
                 h.flash(msg, category='warning')
                 return redirect(h.url('changeset_home', repo_name=repo_name,
                                       revision=revision))
+        self.commit_all_drafts(repo_name,revision,status_change=(ChangesetStatus.get_status_lbl(status)
+                       if status else None))
+
         action_logger(self.authuser,
                       'user_commented_revision:%s' % revision,
                       c.db_repo, self.ip_addr, self.sa)
@@ -421,6 +465,16 @@
     @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
                                    'repository.admin')
     @jsonify
+    def commit_all_drafts(self, repo_name, revision, status_change=None):
+        ChangesetCommentsModel().commit_drafts(c.db_repo.repo_id,c.authuser.user_id,revision=revision, status_change=status_change)
+        Session().commit()
+        return True
+
+    @LoginRequired()
+    @NotAnonymous()
+    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
+                                   'repository.admin')
+    @jsonify
     def delete_comment(self, repo_name, comment_id):
         co = ChangesetComment.get(comment_id)
         if not co:


More information about the kallithea-general mailing list