changeset 5285:fdf6df128d89

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.
author Mads Kiilerich <madski@unity3d.com>
date Thu, 23 Jul 2015 00:52:29 +0200
parents 5d161c096260
children bd2ca76af903
files kallithea/controllers/admin/repos.py kallithea/lib/helpers.py kallithea/model/forms.py kallithea/model/repo.py kallithea/model/validators.py kallithea/templates/admin/repos/repo_edit_settings.html
diffstat 6 files changed, 20 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- 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()
--- 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 *
--- 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)]
--- 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
--- 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:
--- 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 @@
                     <label for="clone_uri">${_('Remote repository')}:</label>
                 </div>
                 <div class="input">
-                  %if c.repo_info.clone_uri:
-                    <div id="clone_uri_hidden" style="font-size: 14px">
-                        <span id="clone_uri_hidden_value">${c.repo_info.clone_uri_hidden}</span>
-                        <span style="cursor: pointer; padding: 0px 0px 5px 0px" id="edit_clone_uri"><i class="icon-edit"></i>${_('Edit')}</span>
-                    </div>
-                    <div id="alter_clone_uri" style="display: none">
-                        ${h.text('clone_uri',class_="medium", placeholder=_('New URL'))}
-                    </div>
-                  %else:
-                    ## not set yet, display form to set it
-                    ${h.text('clone_uri',class_="medium")}
-                    ${h.hidden('clone_uri_change', 'NEW')}
-                  %endif
+                  <div id="alter_clone_uri">
+                        ${h.text('clone_uri',class_="medium", placeholder=_('Repository URL'))}
+                        ${h.hidden('clone_uri_hidden', c.repo_info.clone_uri_hidden)}
+                  </div>
                   <span id="alter_clone_uri_help_block" class="help-block">
                     ${_('Optional: URL of a remote repository. If set, the repository can be pulled from this URL.')}
                   </span>
@@ -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 = '<input id="clone_uri_change" name="clone_uri_change" type="hidden" value="${h.md5(c.repo_info.clone_uri or "").hexdigest()}" />';
-          $('#alter_clone_uri_help_block').html($('#alter_clone_uri_help_block').html()+" ("+$('#clone_uri_hidden_value').html()+")");
-        });
 
         $('#repo_landing_rev').select2({
             'dropdownAutoWidth': true