You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by he...@apache.org on 2015/04/03 21:52:43 UTC

[1/4] allura git commit: [#7865] add docstrings and pass user param through

Repository: allura
Updated Branches:
  refs/heads/master d503b14a1 -> 99ed9568f


[#7865] add docstrings and pass user param through


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

Branch: refs/heads/master
Commit: 99ed9568fd8c94bddaba0c1e6b589fa9b503b7a8
Parents: 7ee7734
Author: Dave Brondsema <da...@brondsema.net>
Authored: Thu Apr 2 17:59:38 2015 -0400
Committer: Heith Seewald <hs...@slashdotmedia.com>
Committed: Fri Apr 3 15:43:49 2015 -0400

----------------------------------------------------------------------
 Allura/allura/model/repository.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/99ed9568/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 96c9358..8083e17 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -823,19 +823,25 @@ class MergeRequest(VersionedArtifact, ActivityObject):
         return result
 
     def merge_allowed(self, user):
+        """
+        Returns true if a merge is allowed by system and tool configuration.
+        """
         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'):
+        if not h.has_access(c.app, 'write', user):
             return False
         if self.app.config.options.get('merge_disabled'):
             return False
         return True
 
     def can_merge(self):
+        """
+        Returns true if you can merge cleanly (no conflicts)
+        """
         if not self.app.forkable:
             return False
         try:


[2/4] allura git commit: [#7865] add per-tool option to disable one-click merging

Posted by he...@apache.org.
[#7865] add per-tool option to disable one-click merging


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

Branch: refs/heads/master
Commit: 85043855baeb1cc23e462ed2678295526b173efa
Parents: 3a1c6cc
Author: Dave Brondsema <da...@brondsema.net>
Authored: Tue Mar 31 18:35:31 2015 -0400
Committer: Heith Seewald <hs...@slashdotmedia.com>
Committed: Fri Apr 3 15:43:49 2015 -0400

----------------------------------------------------------------------
 Allura/allura/lib/repository.py                | 23 +++++++++++++++++----
 Allura/allura/model/repository.py              |  2 ++
 Allura/allura/templates/repo/checkout_url.html | 12 +++++++++++
 3 files changed, 33 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/85043855/Allura/allura/lib/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/repository.py b/Allura/allura/lib/repository.py
index 8fd414f..31e1395 100644
--- a/Allura/allura/lib/repository.py
+++ b/Allura/allura/lib/repository.py
@@ -20,10 +20,11 @@ from urllib import quote
 
 from pylons import tmpl_context as c, app_globals as g
 from pylons import request
-from tg import expose, redirect, flash, validate
+from tg import expose, redirect, flash, validate, config
 from tg.decorators import with_trailing_slash, without_trailing_slash
 from webob import exc
 from bson import ObjectId
+from paste.deploy.converters import asbool
 
 from ming.utils import LazyProperty
 
@@ -262,20 +263,34 @@ class RepoAdminController(DefaultAdminController):
     @without_trailing_slash
     @expose('jinja:allura:templates/repo/checkout_url.html')
     def checkout_url(self):
-        return dict(app=self.app)
+        return dict(app=self.app,
+                    merge_allowed=not asbool(config.get('scm.merge.{}.disabled'.format(self.app.config.tool_name))),
+                    )
 
     @without_trailing_slash
     @expose()
     @require_post()
     @validate({'external_checkout_url': v.NonHttpUrl})
     def set_checkout_url(self, **post_data):
+        flash_msgs = []
         external_checkout_url = (post_data.get('external_checkout_url') or '').strip()
         if 'external_checkout_url' not in c.form_errors:
             if (self.app.config.options.get('external_checkout_url') or '') != external_checkout_url:
                 self.app.config.options.external_checkout_url = external_checkout_url
-                flash("External checkout URL successfully changed")
+                flash_msgs.append("External checkout URL successfully changed.")
         else:
-            flash("Invalid external checkout URL: %s" % c.form_errors['external_checkout_url'], "error")
+            flash_msgs.append("Invalid external checkout URL: %s." % c.form_errors['external_checkout_url'])
+
+        merge_disabled = bool(post_data.get('merge_disabled'))
+        if merge_disabled != self.app.config.options.get('merge_disabled', False):
+            self.app.config.options.merge_disabled = merge_disabled
+            flash_msgs.append('One-click merge {}.'.format('disabled' if merge_disabled else 'enabled'))
+
+        if flash_msgs:
+            message = ' '.join(flash_msgs)
+            flash(message,
+                  'error' if 'Invalid' in message else 'ok')
+
         redirect(c.project.url() + 'admin/tools')
 
 

http://git-wip-us.apache.org/repos/asf/allura/blob/85043855/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 7933a27..96c9358 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -831,6 +831,8 @@ class MergeRequest(VersionedArtifact, ActivityObject):
             return False
         if not h.has_access(c.app, 'write'):
             return False
+        if self.app.config.options.get('merge_disabled'):
+            return False
         return True
 
     def can_merge(self):

http://git-wip-us.apache.org/repos/asf/allura/blob/85043855/Allura/allura/templates/repo/checkout_url.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/repo/checkout_url.html b/Allura/allura/templates/repo/checkout_url.html
index 8eaafd9..450d912 100644
--- a/Allura/allura/templates/repo/checkout_url.html
+++ b/Allura/allura/templates/repo/checkout_url.html
@@ -26,6 +26,18 @@
         Override the checkout URL with an external one.  This is useful if this repository is a mirror
         of another, canonical repository.
     </div>
+    {% if merge_allowed %}
+        <div class="grid-13">&nbsp;</div>
+        <div class="grid-9">
+            <label>
+            <input type="checkbox" name="merge_disabled" {% if app.config.options.get('merge_disabled') %}checked="checked"{% endif %}/>
+            Disable one-click merge via web.
+            </label>
+        </div>
+        <div class="grid-13">
+            You may want to disable one-click merge, if this repository is a mirror and not the primary repository.
+        </div>
+    {% endif %}
     <div class="grid-13">&nbsp;</div>
     <hr>
     <div class="grid-13">&nbsp;</div>


[4/4] allura git commit: [#7865] factor out a merge_allowed method and check for sitewide config to disable it

Posted by he...@apache.org.
[#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 <da...@brondsema.net>
Authored: Tue Mar 31 17:12:46 2015 -0400
Committer: Heith Seewald <hs...@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)


[3/4] allura git commit: [#7865] add test

Posted by he...@apache.org.
[#7865] add test


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

Branch: refs/heads/master
Commit: 7ee773459f12a85f7d207c83a2a7825264dfc6fc
Parents: 8504385
Author: Dave Brondsema <da...@brondsema.net>
Authored: Wed Apr 1 10:46:50 2015 -0400
Committer: Heith Seewald <hs...@slashdotmedia.com>
Committed: Fri Apr 3 15:43:49 2015 -0400

----------------------------------------------------------------------
 ForgeGit/forgegit/tests/functional/test_controllers.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/7ee77345/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 6a81b87..dacec3e 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -415,6 +415,19 @@ class TestRootController(_TestCase):
         assert_not_in('<span>bad</span>', r)
         assert_in('<span>README</span>', r)
 
+    def test_set_checkout_url(self):
+        r = self.app.get('/p/test/admin/src-git/checkout_url')
+        r.form['external_checkout_url'].value = 'http://foo.bar/baz'
+        r.form['merge_disabled'].checked = True
+        r = r.form.submit()
+        assert_equal(json.loads(self.webflash(r))['message'],
+                     "External checkout URL successfully changed. One-click merge disabled.")
+        # for some reason c.app.config.options has old values still
+        app_config = M.AppConfig.query.get(_id=c.app.config._id)
+        assert_equal(app_config.options['external_checkout_url'], 'http://foo.bar/baz')
+        assert_equal(app_config.options['merge_disabled'], True)
+
+
 
 class TestRestController(_TestCase):