You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2015/04/01 00:35:53 UTC
[1/2] allura git commit: [#7865] factor out a merge_allowed method
and check for sitewide config to disable it
Repository: allura
Updated Branches:
refs/heads/db/7865 [created] 7f451eeb8
[#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/8a8343c7
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/8a8343c7
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/8a8343c7
Branch: refs/heads/db/7865
Commit: 8a8343c7cca3dd1ebcb8a0ca1aec1e96a1bc3395
Parents: 758b51b
Author: Dave Brondsema <da...@brondsema.net>
Authored: Tue Mar 31 17:12:46 2015 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Tue Mar 31 17:12:46 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/8a8343c7/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/8a8343c7/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/8a8343c7/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/8a8343c7/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/8a8343c7/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)
[2/2] allura git commit: [#7865] add per-tool option to disable
one-click merging
Posted by br...@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/7f451eeb
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/7f451eeb
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/7f451eeb
Branch: refs/heads/db/7865
Commit: 7f451eeb81942db9296585b905696ce03cfdc522
Parents: 8a8343c
Author: Dave Brondsema <da...@brondsema.net>
Authored: Tue Mar 31 18:35:31 2015 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Tue Mar 31 18:35:31 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/7f451eeb/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/7f451eeb/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/7f451eeb/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"> </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"> </div>
<hr>
<div class="grid-13"> </div>