[PATCH 4 of 7] changeset: draft comment on changesets
Jan Heylen
heyleke at gmail.com
Tue Apr 14 12:03:42 EDT 2015
# HG changeset patch
# User Jan Heylen <heyleke at gmail.com>
# Date 1427526729 -3600
# Sat Mar 28 08:12:09 2015 +0100
# Node ID f26b18234a7731a361f75e7a68ad143fc78218bf
# Parent f48bc03627761dd62f7e7094bb0d322834da336c
changeset: draft comment on changesets
diff -r f48bc0362776 -r f26b18234a77 kallithea/controllers/changeset.py
--- a/kallithea/controllers/changeset.py Mon Mar 30 19:13:08 2015 +0200
+++ b/kallithea/controllers/changeset.py Sat Mar 28 08:12:09 2015 +0100
@@ -222,11 +222,14 @@
comments = dict()
c.statuses = []
c.inline_comments = []
+ c.drafts = []
c.inline_cnt = 0
+ c.draft_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 +250,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] = []
@@ -291,6 +299,11 @@
for comments in lines.values():
c.inline_cnt += len(comments)
+ # count draft comments
+ for __, lines in c.drafts:
+ for drafts in lines.values():
+ c.draft_cnt += len(drafts)
+
if len(c.cs_ranges) == 1:
c.changeset = c.cs_ranges[0]
c.parent_tmpl = ''.join(['# Parent %s\n' % x.raw_id
@@ -347,6 +360,39 @@
@HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
'repository.admin')
@jsonify
+ def draft(self, repo_name, revision=None, pull_request_id=None):
+ text = request.POST.get('text', '').strip() or _('No comments.')
+ c.co = comm = ChangesetCommentsModel().create(
+ text=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 comm:
+ data.update(comm.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() or _('No comments.')
@@ -359,7 +405,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 !
@@ -367,7 +414,6 @@
# if latest status was from pull request and it's closed
# disallow changing status !
# dont_allow_on_closed_pull_request = True !
-
try:
ChangesetStatusModel().set_status(
c.db_repo.repo_id,
@@ -384,6 +430,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 +470,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