changeset 2746:49a4864b11c1 beta

Authors of pull-requests can now delete them
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 26 Aug 2012 01:04:43 +0200
parents fe47ff8ef3f7
children cdce3d7282b2
files rhodecode/config/routing.py rhodecode/controllers/pullrequests.py rhodecode/model/pull_request.py rhodecode/templates/admin/users/user_edit_my_account_pullrequests.html
diffstat 4 files changed, 31 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/config/routing.py	Sun Aug 26 00:26:59 2012 +0200
+++ b/rhodecode/config/routing.py	Sun Aug 26 01:04:43 2012 +0200
@@ -462,6 +462,11 @@
                  controller='pullrequests',
                  action='update', conditions=dict(function=check_repo,
                                                 method=["PUT"]))
+    rmap.connect('pullrequest_delete',
+                 '/{repo_name:.*?}/pull-request/{pull_request_id}',
+                 controller='pullrequests',
+                 action='delete', conditions=dict(function=check_repo,
+                                                method=["DELETE"]))
 
     rmap.connect('pullrequest_show_all',
                  '/{repo_name:.*?}/pull-request',
--- a/rhodecode/controllers/pullrequests.py	Sun Aug 26 00:26:59 2012 +0200
+++ b/rhodecode/controllers/pullrequests.py	Sun Aug 26 01:04:43 2012 +0200
@@ -203,6 +203,20 @@
         Session.commit()
         return True
 
+    @NotAnonymous()
+    @jsonify
+    def delete(self, repo_name, pull_request_id):
+        pull_request = PullRequest.get_or_404(pull_request_id)
+        #only owner can delete it !
+        if pull_request.author.user_id == c.rhodecode_user.user_id:
+            PullRequestModel().delete(pull_request)
+            Session().commit()
+            h.flash(_('Successfully deleted pull request'),
+                    category='success')
+            return redirect(url('admin_settings_my_account'))
+        else:
+            raise HTTPForbidden()
+
     def _load_compare_data(self, pull_request, enable_comments=True):
         """
         Load context data needed for generating compare diff
--- a/rhodecode/model/pull_request.py	Sun Aug 26 00:26:59 2012 +0200
+++ b/rhodecode/model/pull_request.py	Sun Aug 26 01:04:43 2012 +0200
@@ -125,6 +125,10 @@
             if reviewer:
                 self.sa.delete(reviewer)
 
+    def delete(self, pull_request):
+        pull_request = self.__get_pull_request(pull_request)
+        Session().delete(pull_request)
+
     def close_pull_request(self, pull_request):
         pull_request = self.__get_pull_request(pull_request)
         pull_request.status = PullRequest.STATUS_CLOSED
--- a/rhodecode/templates/admin/users/user_edit_my_account_pullrequests.html	Sun Aug 26 00:26:59 2012 +0200
+++ b/rhodecode/templates/admin/users/user_edit_my_account_pullrequests.html	Sun Aug 26 01:04:43 2012 +0200
@@ -4,9 +4,16 @@
     %if c.my_pull_requests:
       %for pull_request in c.my_pull_requests:
       <li>
+      <div style="float:left">
       <a href="${h.url('pullrequest_show',repo_name=pull_request.other_repo.repo_name,pull_request_id=pull_request.pull_request_id)}">
       ${_('Pull request #%s opened on %s') % (pull_request.pull_request_id, h.fmt_date(pull_request.created_on))}
       </a>
+      </div>
+      <div style="float:left;margin-top: -5px">
+        ${h.form(url('pullrequest_delete', repo_name=pull_request.other_repo.repo_name, pull_request_id=pull_request.pull_request_id),method='delete')}
+          ${h.submit('remove_%s' % pull_request.pull_request_id,'',class_="delete_icon action_button",onclick="return confirm('"+_('Confirm to delete this pull request')+"');")}
+        ${h.end_form()}
+     </div>      
       </li>
       %endfor
    %else:
@@ -14,7 +21,7 @@
    %endif
 </ul>
 
-<div class="pullrequests_section_head">${_('I participate in')}</div>
+<div class="pullrequests_section_head" style="clear:both">${_('I participate in')}</div>
 <ul>
     %if c.my_pull_requests:
       %for pull_request in c.participate_in_pull_requests: