# HG changeset patch # User Mads Kiilerich # Date 1437605549 -7200 # Node ID fdf6df128d89e039279a43b94784179a30262501 # Parent 5d161c09626032ebe7e009b7450b761ed825b57c remote: simplify clone_uri UI The UI was a bit weird ... probably in an attempt of making it editable while hiding passwords. Instead, just show the URL with password hidden, and only save it back if it changed. The UI only contains the clone_uri with passwords hidden. It will thus only be saved when the form result is different from the value that was shown to the user. diff -r 5d161c096260 -r fdf6df128d89 kallithea/controllers/admin/repos.py --- a/kallithea/controllers/admin/repos.py Thu Jul 23 00:52:29 2015 +0200 +++ b/kallithea/controllers/admin/repos.py Thu Jul 23 00:52:29 2015 +0200 @@ -108,6 +108,7 @@ choices, c.landing_revs = ScmModel().get_repo_landing_revs(c.repo_info) c.landing_revs_choices = choices defaults = RepoModel()._get_defaults(repo_name) + defaults['clone_uri'] = c.repo_info.clone_uri_hidden # don't show password return defaults @@ -231,9 +232,8 @@ repo = Repository.get_by_repo_name(repo_name) if repo and repo.repo_state == Repository.STATE_CREATED: if repo.clone_uri: - clone_uri = repo.clone_uri_hidden h.flash(_('Created repository %s from %s') - % (repo.repo_name, clone_uri), category='success') + % (repo.repo_name, repo.clone_uri_hidden), category='success') else: repo_url = h.link_to(repo.repo_name, h.url('summary_home', @@ -365,9 +365,6 @@ """GET /repo_name/settings: Form to edit an existing item""" # url('edit_repo', repo_name=ID) defaults = self.__load_data(repo_name) - if 'clone_uri' in defaults: - del defaults['clone_uri'] - c.repo_fields = RepositoryField.query()\ .filter(RepositoryField.repository == c.repo_info).all() repo_model = RepoModel() diff -r 5d161c096260 -r fdf6df128d89 kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py Thu Jul 23 00:52:29 2015 +0200 +++ b/kallithea/lib/helpers.py Thu Jul 23 00:52:29 2015 +0200 @@ -29,7 +29,6 @@ from pygments import highlight as code_highlight from pylons import url from pylons.i18n.translation import _, ungettext -from hashlib import md5 # used as h.md5 from webhelpers.html import literal, HTML, escape from webhelpers.html.tools import * diff -r 5d161c096260 -r fdf6df128d89 kallithea/model/forms.py --- a/kallithea/model/forms.py Thu Jul 23 00:52:29 2015 +0200 +++ b/kallithea/model/forms.py Thu Jul 23 00:52:29 2015 +0200 @@ -232,7 +232,8 @@ if edit: #this is repo owner user = All(v.UnicodeString(not_empty=True), v.ValidRepoUser()) - clone_uri_change = v.UnicodeString(not_empty=False, if_missing=v.Missing) + # Not a real field - just for reference for validation: + # clone_uri_hidden = v.UnicodeString(if_missing='') chained_validators = [v.ValidCloneUri(), v.ValidRepoName(edit, old_data)] diff -r 5d161c096260 -r fdf6df128d89 kallithea/model/repo.py --- a/kallithea/model/repo.py Thu Jul 23 00:52:29 2015 +0200 +++ b/kallithea/model/repo.py Thu Jul 23 00:52:29 2015 +0200 @@ -325,25 +325,18 @@ if 'repo_group' in kwargs: cur_repo.group = RepoGroup.get(kwargs['repo_group']) log.debug('Updating repo %s with params:%s' % (cur_repo, kwargs)) - for strip, k in [(1, 'repo_enable_downloads'), - (1, 'repo_description'), - (1, 'repo_enable_locking'), - (1, 'repo_landing_rev'), - (1, 'repo_private'), - (1, 'repo_enable_statistics'), - (0, 'clone_uri'),]: + for k in ['repo_enable_downloads', + 'repo_description', + 'repo_enable_locking', + 'repo_landing_rev', + 'repo_private', + 'repo_enable_statistics', + ]: if k in kwargs: - val = kwargs[k] - if strip: - k = remove_prefix(k, 'repo_') - if k == 'clone_uri': - from kallithea.model.validators import Missing - _change = kwargs.get('clone_uri_change') - if _change == Missing: - # we don't change the value, so use original one - val = cur_repo.clone_uri - - setattr(cur_repo, k, val) + setattr(cur_repo, remove_prefix(k, 'repo_'), kwargs[k]) + clone_uri = kwargs.get('clone_uri') + if clone_uri is not None and clone_uri != cur_repo.clone_uri_hidden: + cur_repo.clone_uri = clone_uri new_name = cur_repo.get_new_name(kwargs['repo_name']) cur_repo.repo_name = new_name diff -r 5d161c096260 -r fdf6df128d89 kallithea/model/validators.py --- a/kallithea/model/validators.py Thu Jul 23 00:52:29 2015 +0200 +++ b/kallithea/model/validators.py Thu Jul 23 00:52:29 2015 +0200 @@ -44,11 +44,6 @@ log = logging.getLogger(__name__) -class _Missing(object): - pass - -Missing = _Missing() - class StateObj(object): """ @@ -480,9 +475,7 @@ repo_type = value.get('repo_type') url = value.get('clone_uri') - if not url: - pass - else: + if url and url != value.get('clone_uri_hidden'): try: url_handler(repo_type, url, make_ui('db', clear_session=False)) except Exception: diff -r 5d161c096260 -r fdf6df128d89 kallithea/templates/admin/repos/repo_edit_settings.html --- a/kallithea/templates/admin/repos/repo_edit_settings.html Thu Jul 23 00:52:29 2015 +0200 +++ b/kallithea/templates/admin/repos/repo_edit_settings.html Thu Jul 23 00:52:29 2015 +0200 @@ -21,19 +21,10 @@
- %if c.repo_info.clone_uri: -
- ${c.repo_info.clone_uri_hidden} - ${_('Edit')} -
- - %else: - ## not set yet, display form to set it - ${h.text('clone_uri',class_="medium")} - ${h.hidden('clone_uri_change', 'NEW')} - %endif +
+ ${h.text('clone_uri',class_="medium", placeholder=_('Repository URL'))} + ${h.hidden('clone_uri_hidden', c.repo_info.clone_uri_hidden)} +
${_('Optional: URL of a remote repository. If set, the repository can be pulled from this URL.')} @@ -146,14 +137,6 @@ $('#clone_id').show(); e.preventDefault(); }); - $('#edit_clone_uri').on('click', function(e){ - $('#alter_clone_uri').show(); - $('#edit_clone_uri').hide(); - $('#clone_uri_hidden').hide(); - ## store hash of old value for change detection - var uri_change = ''; - $('#alter_clone_uri_help_block').html($('#alter_clone_uri_help_block').html()+" ("+$('#clone_uri_hidden_value').html()+")"); - }); $('#repo_landing_rev').select2({ 'dropdownAutoWidth': true