# HG changeset patch # User Marcin Kuzminski # Date 2018-02-12 13:14:33 # Node ID 25341b46bd7e2712d9b77e1784e8c5d04a9ff4ab # Parent d072c29acc868271a2ba04dada5b6a5b3df086a9 repositories: allow properly updating repository push url. diff --git a/rhodecode/api/views/repo_api.py b/rhodecode/api/views/repo_api.py --- a/rhodecode/api/views/repo_api.py +++ b/rhodecode/api/views/repo_api.py @@ -563,6 +563,7 @@ def create_repo( description=Optional(''), private=Optional(False), clone_uri=Optional(None), + push_uri=Optional(None), landing_rev=Optional('rev:tip'), enable_statistics=Optional(False), enable_locking=Optional(False), @@ -596,6 +597,8 @@ def create_repo( :type private: bool :param clone_uri: set clone_uri :type clone_uri: str + :param push_uri: set push_uri + :type push_uri: str :param landing_rev: : :type landing_rev: str :param enable_locking: @@ -639,6 +642,7 @@ def create_repo( description = Optional.extract(description) copy_permissions = Optional.extract(copy_permissions) clone_uri = Optional.extract(clone_uri) + push_uri = Optional.extract(push_uri) landing_commit_ref = Optional.extract(landing_rev) defs = SettingsModel().get_default_repo_settings(strip_prefix=True) @@ -666,6 +670,7 @@ def create_repo( repo_description=description, repo_landing_commit_ref=landing_commit_ref, repo_clone_uri=clone_uri, + repo_push_uri=push_uri, repo_private=private, repo_copy_permissions=copy_permissions, repo_enable_statistics=enable_statistics, @@ -684,6 +689,7 @@ def create_repo( 'repo_description': schema_data['repo_description'], 'repo_private': schema_data['repo_private'], 'clone_uri': schema_data['repo_clone_uri'], + 'push_uri': schema_data['repo_push_uri'], 'repo_landing_rev': schema_data['repo_landing_commit_ref'], 'enable_statistics': schema_data['repo_enable_statistics'], 'enable_locking': schema_data['repo_enable_locking'], @@ -907,6 +913,7 @@ def update_repo( repo_owner=updates['user'], repo_description=updates['repo_description'], repo_clone_uri=updates['clone_uri'], + repo_push_uri=updates['push_uri'], repo_fork_of=updates['fork_id'], repo_private=updates['repo_private'], repo_landing_commit_ref=updates['repo_landing_rev'], @@ -925,6 +932,7 @@ def update_repo( repo_description=schema_data['repo_description'], repo_private=schema_data['repo_private'], clone_uri=schema_data['repo_clone_uri'], + push_uri=schema_data['repo_push_uri'], repo_landing_rev=schema_data['repo_landing_commit_ref'], repo_enable_statistics=schema_data['repo_enable_statistics'], repo_enable_locking=schema_data['repo_enable_locking'], diff --git a/rhodecode/apps/repository/__init__.py b/rhodecode/apps/repository/__init__.py --- a/rhodecode/apps/repository/__init__.py +++ b/rhodecode/apps/repository/__init__.py @@ -373,6 +373,9 @@ def includeme(config): config.add_route( name='edit_repo_remote_pull', pattern='/{repo_name:.*?[^/]}/settings/remote/pull', repo_route=True) + config.add_route( + name='edit_repo_remote_push', + pattern='/{repo_name:.*?[^/]}/settings/remote/push', repo_route=True) # Statistics config.add_route( diff --git a/rhodecode/apps/repository/views/repo_settings.py b/rhodecode/apps/repository/views/repo_settings.py --- a/rhodecode/apps/repository/views/repo_settings.py +++ b/rhodecode/apps/repository/views/repo_settings.py @@ -138,15 +138,19 @@ class RepoSettingsView(RepoAppView): repo_description=schema_data['repo_description'], repo_private=schema_data['repo_private'], clone_uri=schema_data['repo_clone_uri'], + push_uri=schema_data['repo_push_uri'], repo_landing_rev=schema_data['repo_landing_commit_ref'], repo_enable_statistics=schema_data['repo_enable_statistics'], repo_enable_locking=schema_data['repo_enable_locking'], repo_enable_downloads=schema_data['repo_enable_downloads'], ) - # detect if CLONE URI changed, if we get OLD means we keep old values + # detect if SYNC URI changed, if we get OLD means we keep old values if schema_data['repo_clone_uri_change'] == 'OLD': validated_updates['clone_uri'] = self.db_repo.clone_uri + if schema_data['repo_push_uri_change'] == 'OLD': + validated_updates['push_uri'] = self.db_repo.push_uri + # use the new full name for redirect new_repo_name = schema_data['repo_group']['repo_name_with_group'] diff --git a/rhodecode/apps/repository/views/repo_settings_remote.py b/rhodecode/apps/repository/views/repo_settings_remote.py --- a/rhodecode/apps/repository/views/repo_settings_remote.py +++ b/rhodecode/apps/repository/views/repo_settings_remote.py @@ -35,8 +35,6 @@ log = logging.getLogger(__name__) class RepoSettingsRemoteView(RepoAppView): def load_default_context(self): c = self._get_local_tmpl_context() - - return c @LoginRequired() diff --git a/rhodecode/model/repo.py b/rhodecode/model/repo.py --- a/rhodecode/model/repo.py +++ b/rhodecode/model/repo.py @@ -304,6 +304,7 @@ class RepoModel(BaseModel): {'k': 'repo_enable_locking', 'strip': True}, {'k': 'repo_landing_rev', 'strip': True}, {'k': 'clone_uri', 'strip': False}, + {'k': 'push_uri', 'strip': False}, {'k': 'repo_private', 'strip': True}, {'k': 'repo_enable_statistics', 'strip': True} ) @@ -319,6 +320,8 @@ class RepoModel(BaseModel): defaults[item['k']] = val if item['k'] == 'clone_uri': defaults['clone_uri_hidden'] = repo_info.clone_uri_hidden + if item['k'] == 'push_uri': + defaults['push_uri_hidden'] = repo_info.push_uri_hidden # fill owner if repo_info.user: @@ -348,6 +351,7 @@ class RepoModel(BaseModel): (1, 'repo_enable_locking'), (1, 'repo_enable_statistics'), (0, 'clone_uri'), + (0, 'push_uri'), (0, 'fork_id') ] for strip, k in update_keys: diff --git a/rhodecode/model/validation_schema/schemas/repo_schema.py b/rhodecode/model/validation_schema/schemas/repo_schema.py --- a/rhodecode/model/validation_schema/schemas/repo_schema.py +++ b/rhodecode/model/validation_schema/schemas/repo_schema.py @@ -66,7 +66,7 @@ def deferred_landing_ref_validator(node, @colander.deferred -def deferred_clone_uri_validator(node, kw): +def deferred_sync_uri_validator(node, kw): repo_type = kw.get('repo_type') validator = validators.CloneUriValidator(repo_type) return validator @@ -323,6 +323,12 @@ class RepoSchema(colander.MappingSchema) preparers=[preparers.strip_preparer], missing='') + repo_push_uri = colander.SchemaNode( + colander.String(), + validator=colander.All(colander.Length(min=1)), + preparers=[preparers.strip_preparer], + missing='') + repo_fork_of = colander.SchemaNode( colander.String(), validator=deferred_fork_of_validator, @@ -381,7 +387,17 @@ class RepoSettingsSchema(RepoSchema): repo_clone_uri = colander.SchemaNode( colander.String(), preparers=[preparers.strip_preparer], - validator=deferred_clone_uri_validator, + validator=deferred_sync_uri_validator, + missing='') + + repo_push_uri_change = colander.SchemaNode( + colander.String(), + missing='NEW') + + repo_push_uri = colander.SchemaNode( + colander.String(), + preparers=[preparers.strip_preparer], + validator=deferred_sync_uri_validator, missing='') def deserialize(self, cstruct): diff --git a/rhodecode/public/js/rhodecode/routes.js b/rhodecode/public/js/rhodecode/routes.js --- a/rhodecode/public/js/rhodecode/routes.js +++ b/rhodecode/public/js/rhodecode/routes.js @@ -232,6 +232,7 @@ function registerRCRoutes() { pyroutes.register('repo_edit_toggle_locking', '/%(repo_name)s/settings/toggle_locking', ['repo_name']); pyroutes.register('edit_repo_remote', '/%(repo_name)s/settings/remote', ['repo_name']); pyroutes.register('edit_repo_remote_pull', '/%(repo_name)s/settings/remote/pull', ['repo_name']); + pyroutes.register('edit_repo_remote_push', '/%(repo_name)s/settings/remote/push', ['repo_name']); pyroutes.register('edit_repo_statistics', '/%(repo_name)s/settings/statistics', ['repo_name']); pyroutes.register('edit_repo_statistics_reset', '/%(repo_name)s/settings/statistics/update', ['repo_name']); pyroutes.register('edit_repo_issuetracker', '/%(repo_name)s/settings/issue_trackers', ['repo_name']); diff --git a/rhodecode/templates/admin/repos/repo_edit.mako b/rhodecode/templates/admin/repos/repo_edit.mako --- a/rhodecode/templates/admin/repos/repo_edit.mako +++ b/rhodecode/templates/admin/repos/repo_edit.mako @@ -65,7 +65,7 @@ %if c.rhodecode_db_repo.repo_type != 'svn':
  • - ${_('Remote')} + ${_('Remote sync')}
  • %endif
  • diff --git a/rhodecode/templates/admin/repos/repo_edit_remote.mako b/rhodecode/templates/admin/repos/repo_edit_remote.mako --- a/rhodecode/templates/admin/repos/repo_edit_remote.mako +++ b/rhodecode/templates/admin/repos/repo_edit_remote.mako @@ -1,31 +1,60 @@
    -

    ${_('Remote url')}

    +

    ${_('Remote Sync')}

    -

    ${_('Manually pull changes from external repository.')}

    +

    ${_('Manually pull/push changes from/to external URLs.')}

    - %if c.rhodecode_db_repo.clone_uri: - - ${_('Remote mirror url')}: - ${c.rhodecode_db_repo.clone_uri_hidden} + %if c.rhodecode_db_repo.clone_uri or c.rhodecode_db_repo.push_uri: -

    - ${_('Pull can be automated by such api call. Can be called periodically in crontab etc.')} -
    - - ${h.api_call_example(method='pull', args={"repoid": c.rhodecode_db_repo.repo_name})} - -

    + + % if c.rhodecode_db_repo.clone_uri: + + + + + + + + + + + + + % endif - ${h.secure_form(h.route_path('edit_repo_remote_pull', repo_name=c.repo_name), request=request)} -
    -
    - ${h.submit('remote_pull_%s' % c.rhodecode_db_repo.repo_name,_('Pull changes from remote location'),class_="btn btn-small",onclick="return confirm('"+_('Confirm to pull changes from remote side')+"');")} -
    -
    - ${h.end_form()} + % if c.rhodecode_db_repo.push_uri: + + + + + + + + + % endif + +
    ${_('Pull url')}
    ${c.rhodecode_db_repo.clone_uri_hidden}
    +

    + ${_('Pull can be automated by such api call. Can be called periodically in crontab etc.')} +
    + + ${h.api_call_example(method='pull', args={"repoid": c.rhodecode_db_repo.repo_name})} + +

    +
    + ${h.secure_form(h.route_path('edit_repo_remote_pull', repo_name=c.repo_name), request=request)} +
    +
    + ${h.submit('remote_pull_%s' % c.rhodecode_db_repo.repo_name,_('Pull changes from remote location'),class_="btn btn-small",onclick="return confirm('"+_('Confirm to pull changes from remote side')+"');")} +
    +
    + ${h.end_form()} +
    ${_('Push url')}
    ${c.rhodecode_db_repo.push_uri_hidden}
    + ${_('This feature is available in RhodeCode EE edition only. Contact {sales_email} to obtain a trial license.').format(sales_email='sales@rhodecode.com')|n} +
    + %else: ${_('This repository does not have any remote mirror url set.')} diff --git a/rhodecode/templates/admin/repos/repo_edit_settings.mako b/rhodecode/templates/admin/repos/repo_edit_settings.mako --- a/rhodecode/templates/admin/repos/repo_edit_settings.mako +++ b/rhodecode/templates/admin/repos/repo_edit_settings.mako @@ -46,9 +46,10 @@
    % if c.rhodecode_db_repo.repo_type != 'svn': + <% sync_link = h.literal(h.link_to('remote sync', h.route_path('edit_repo_remote', repo_name=c.repo_name))) %>
    - +
    %if c.rhodecode_db_repo.clone_uri: @@ -83,14 +84,56 @@ ${h.hidden('repo_clone_uri_change', 'NEW')} %endif

    - <% pull_link = h.literal(h.link_to('remote sync', h.route_path('edit_repo_remote', repo_name=c.repo_name))) %> - ${_('http[s] url where from repository was imported, this field can used for doing {pull_link}.').format(pull_link=pull_link)|n}
    + ${_('http[s] url where from repository was imported. This field can used for doing {sync_link}.').format(sync_link=sync_link)|n}
    + ${_('This field is stored encrypted inside Database, a format of http://user:password@server.com/repo_name can be used and will be hidden from display.')} +

    +
    +
    +
    +
    + +
    +
    + %if c.rhodecode_db_repo.push_uri: + ## display, if we don't have any errors + % if not c.form['repo_push_uri'].error: +
    + ${c.rhodecode_db_repo.push_uri_hidden} + ${_('edit')} +
    + % endif + + ## alter field +
    + ${c.form['repo_push_uri'].render(css_class='medium', oid='push_uri', placeholder=_('enter new value, or leave empty to remove'))|n} + ${c.form.render_error(request, c.form['repo_push_uri'])|n} + % if c.form['repo_push_uri'].error: + ## we got error from form subit, means we modify the url + ${h.hidden('repo_push_uri_change', 'MOD')} + % else: + ${h.hidden('repo_push_uri_change', 'OLD')} + % endif + + % if not c.form['repo_push_uri'].error: + ${_('cancel')} + % endif + +
    + %else: + ## not set yet, display form to set it + ${c.form['repo_push_uri'].render(css_class='medium', oid='push_uri')|n} + ${c.form.render_error(request, c.form['repo_push_uri'])|n} + ${h.hidden('repo_push_uri_change', 'NEW')} + %endif +

    + ${_('http[s] url to sync data back. This field can used for doing {sync_link}.').format(sync_link=sync_link)|n}
    ${_('This field is stored encrypted inside Database, a format of http://user:password@server.com/repo_name can be used and will be hidden from display.')}

    % else: ${h.hidden('repo_clone_uri', '')} + ${h.hidden('repo_push_uri', '')} % endif
    @@ -207,16 +250,11 @@