changeset 5672:b4b57beb4928

comments: limit comment deletion to a 5 minutes grace period It is really a bad idea to delete a comment after the content and references to it has been sent in mails. Ultimately, comments should be editable and versioned - "delete" should then just hide the comment. Note: this is just done at the UI level - not verified on the server
author Mads Kiilerich <madski@unity3d.com>
date Wed, 20 Jan 2016 01:47:11 +0100
parents 779d43be59c6
children 7e160a65caa4
files kallithea/model/db.py kallithea/templates/changeset/changeset_file_comment.html
diffstat 2 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/model/db.py	Wed Jan 20 01:47:11 2016 +0100
+++ b/kallithea/model/db.py	Wed Jan 20 01:47:11 2016 +0100
@@ -2197,6 +2197,10 @@
         elif self.pull_request_id is not None:
             return self.pull_request.url(anchor=anchor)
 
+    def deletable(self):
+        return self.created_on > datetime.datetime.now() - datetime.timedelta(minutes=5)
+
+
 class ChangesetStatus(Base, BaseModel):
     __tablename__ = 'changeset_statuses'
     __table_args__ = (
--- a/kallithea/templates/changeset/changeset_file_comment.html	Wed Jan 20 01:47:11 2016 +0100
+++ b/kallithea/templates/changeset/changeset_file_comment.html	Wed Jan 20 01:47:11 2016 +0100
@@ -26,8 +26,10 @@
               <a class="permalink" href="${co.url()}">&para;</a>
           </span>
 
-          %if h.HasPermissionAny('hg.admin')() or h.HasRepoPermissionAny('repository.admin')(c.repo_name) or co.author.user_id == c.authuser.user_id:
-            <div onClick="confirm('${_("Delete comment?")}') && deleteComment(${co.comment_id})" class="buttons delete-comment btn btn-mini">${_('Delete')}</div>
+          %if co.author.user_id == c.authuser.user_id or h.HasRepoPermissionAny('repository.admin')(c.repo_name):
+            %if co.deletable():
+              <div onClick="confirm('${_("Delete comment?")}') && deleteComment(${co.comment_id})" class="buttons delete-comment btn btn-mini" style="margin:0 5px">${_('Delete')}</div>
+            %endif
           %endif
       </div>
       <div class="text">