allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hei...@apache.org
Subject [4/4] allura git commit: [#7865] factor out a merge_allowed method and check for sitewide config to disable it
Date Fri, 03 Apr 2015 19:52:46 GMT
[#7865] factor out a merge_allowed method and check for sitewide config to disable it


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/3a1c6cc0
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/3a1c6cc0
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/3a1c6cc0

Branch: refs/heads/master
Commit: 3a1c6cc0b154bdecc8ccf04ddce365a6cfff91b3
Parents: d503b14
Author: Dave Brondsema <dave@brondsema.net>
Authored: Tue Mar 31 17:12:46 2015 -0400
Committer: Heith Seewald <hseewald@slashdotmedia.com>
Committed: Fri Apr 3 15:43:49 2015 -0400

----------------------------------------------------------------------
 Allura/allura/controllers/repository.py                |  3 +--
 Allura/allura/model/repository.py                      | 13 ++++++++++++-
 Allura/allura/templates/repo/merge_request.html        |  2 +-
 Allura/development.ini                                 |  4 ++++
 ForgeGit/forgegit/tests/functional/test_controllers.py |  4 ++++
 5 files changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/3a1c6cc0/Allura/allura/controllers/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index c08ec99..34210ce 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -445,8 +445,7 @@ class MergeRequestController(object):
     @expose()
     @require_post()
     def merge(self):
-        require_access(c.app, 'write')
-        if self.req.status != 'open' or not self.req.can_merge():
+        if not self.req.merge_allowed(c.user) or not self.req.can_merge():
             raise exc.HTTPNotFound
         self.req.merge()
         redirect(self.req.url())

http://git-wip-us.apache.org/repos/asf/allura/blob/3a1c6cc0/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 362f725..7933a27 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -33,7 +33,7 @@ from itertools import chain
 from difflib import SequenceMatcher, unified_diff
 
 import tg
-from paste.deploy.converters import asint
+from paste.deploy.converters import asint, asbool
 from pylons import tmpl_context as c
 from pylons import app_globals as g
 import pymongo
@@ -822,6 +822,17 @@ class MergeRequest(VersionedArtifact, ActivityObject):
                 self.request_number, self.project.name, self.app.repo.name))
         return result
 
+    def merge_allowed(self, user):
+        if not c.app.forkable:
+            return False
+        if self.status != 'open':
+            return False
+        if asbool(tg.config.get('scm.merge.{}.disabled'.format(self.app.config.tool_name))):
+            return False
+        if not h.has_access(c.app, 'write'):
+            return False
+        return True
+
     def can_merge(self):
         if not self.app.forkable:
             return False

http://git-wip-us.apache.org/repos/asf/allura/blob/3a1c6cc0/Allura/allura/templates/repo/merge_request.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/repo/merge_request.html b/Allura/allura/templates/repo/merge_request.html
index 1520270..928a0db 100644
--- a/Allura/allura/templates/repo/merge_request.html
+++ b/Allura/allura/templates/repo/merge_request.html
@@ -57,7 +57,7 @@ Merge Request #{{req.request_number}}: {{req.summary}} ({{req.status}})
 
     <div>{{g.markdown.convert(req.description)}}</div>
 
-    {% if req.status == 'open' and c.app.forkable and h.has_access(c.app, 'write')() %}
+    {% if req.merge_allowed(c.user) %}
       {% set can_merge = req.can_merge() %}
       <div class="grid-19">
         <form action="merge" method="POST">

http://git-wip-us.apache.org/repos/asf/allura/blob/3a1c6cc0/Allura/development.ini
----------------------------------------------------------------------
diff --git a/Allura/development.ini b/Allura/development.ini
index bda8d37..b6c3154 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -243,6 +243,10 @@ scm.repos.tarball.zip_binary = /usr/bin/zip
 ;scm.import.retry_count = 50
 ;scm.import.retry_sleep_secs = 5
 
+; One-click merge is enabled by default, but can be turned off on for each type of repo
+;scm.merge.git.disabled = true
+;scm.merge.hg.disabled = true
+
 bulk_export_path = /tmp/bulk_export/{nbhd}/{project}
 bulk_export_filename = {project}-backup-{date:%Y-%m-%d-%H%M%S}.zip
 bulk_export_download_instructions = Sample instructions for {project}

http://git-wip-us.apache.org/repos/asf/allura/blob/3a1c6cc0/ForgeGit/forgegit/tests/functional/test_controllers.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/functional/test_controllers.py b/ForgeGit/forgegit/tests/functional/test_controllers.py
index 772ac05..6a81b87 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -542,6 +542,10 @@ class TestFork(_TestCase):
         assert 'git merge {}'.format(c_id) in merge_instructions
         assert_in('less than 1 minute ago', r.html.findAll('p')[0].getText())
 
+        merge_form = r.html.find('form', action='merge')
+        assert merge_form
+        assert_in('Merge request has no conflicts. You can merge automatically.', merge_form.getText())
+
     def test_merge_request_detail_noslash(self):
         self._request_merge()
         r = self.app.get('/p/test/src-git/merge-requests/1', status=302)


Mime
View raw message